diff options
author | unknown <dlenev@jabberwock.localdomain> | 2004-04-02 10:12:53 +0400 |
---|---|---|
committer | unknown <dlenev@jabberwock.localdomain> | 2004-04-02 10:12:53 +0400 |
commit | 4ada2ea9c1b6628e49869454b1a2a48f6eb68861 (patch) | |
tree | 9a60588328f7225c26e34d7cf0ce3ae4875c3523 /sql/sql_insert.cc | |
parent | 4b5451f699a5d06c6b71e10b0ef3d2eb4d648fa9 (diff) | |
download | mariadb-git-4ada2ea9c1b6628e49869454b1a2a48f6eb68861.tar.gz |
WL#1266 "Separate auto-set logic from TIMESTAMP type."
Final version of patch.
Adds support for specifying of DEFAULT NOW() and/or ON UPDATE NOW()
clauses for TIMESTAMP field definition.
Current implementation allows only one such field per table and
uses several unireg types for storing info about this properties of
field. It should be replaced with better implementation when new
.frm format is introduced.
include/mysqld_error.h:
Added error codes for case when we have more than one column with NOW()
in DEFAULT or ON UPDATE clauses and for case when we are using ON UPDATE
clause with wrong type.
mysql-test/r/create.result:
Added tests for using of DEFAULT NOW() and ON UPDATE NOW() with
non-TIMESTAMP fields.
mysql-test/r/show_check.result:
Updated test results to reflect new default look of TIMESTAMP fields
in SHOW CREATE TABLE.
mysql-test/r/system_mysql_db.result:
Updated test results to reflect new default look of TIMESTAMP fields
in SHOW CREATE TABLE.
mysql-test/r/type_ranges.result:
Updated test results to reflect new default look of TIMESTAMP fields
in SHOW COLUMNS.
mysql-test/r/type_timestamp.result:
Added tests for various DEFAULT and ON UPDATE clauses for TIMESTAMP
fields definitions.
mysql-test/t/create.test:
Added tests for using of DEFAULT NOW() and ON UPDATE NOW() with
non-TIMESTAMP fields.
mysql-test/t/type_timestamp.test:
Added tests for various DEFAULT and ON UPDATE clauses for TIMESTAMP
fields definitions.
sql/field.cc:
Added support for various combinations of DEFAULT and ON UPDATE clauses
for TIMESTAMP field.
Setting TABLE::timestamp* members for TIMESTAMP fields with auto-set
option taking into account their unireg type (which corresponds to
various DEFAULT/ON UPDATE values combinations). Replaced
TABLE::time_stamp with TABLE::timestamp_default_now/on_update_now
couple moved their setup to separate method set_timestamp_offsets(),
which now is called from open_table instead of Field_timestamp cons.
sql/field.h:
Added more unireg types for handling of DEFAULT NOW() and ON UPDATE
NOW() for TIMESTAMP fields.
Fixed value corresponding to DEFAULT item for TIMESTAMP field.
sql/ha_berkeley.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_heap.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_innodb.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_isam.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_isammrg.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_myisam.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/ha_myisammrg.cc:
Now TIMESTAMP column with auto-set property could be updated during
INSERT or/and UPDATE independently.
sql/item_func.h:
We need to distinguish NOW() from other function for using in
DEFAULT and in ON UPDATE clauses.
sql/item_timefunc.h:
We need to distinguish NOW() from other function for using in
DEFAULT and in ON UPDATE clauses.
sql/mysql_priv.h:
Added parameter for ON UPDATE value to add_field_to_list() function.
sql/share/czech/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/danish/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/dutch/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/english/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/estonian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/french/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/german/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/greek/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/hungarian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/italian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/japanese/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/korean/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/norwegian-ny/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/norwegian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/polish/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/portuguese/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/romanian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/russian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/serbian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/slovak/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/spanish/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/swedish/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/share/ukrainian/errmsg.txt:
Added error messages for case when we have more than one column with
NOW() (CURRENT_TIMESTAMP is just more standard alias) in DEFAULT or
ON UPDATE clauses and for case when we are using ON UPDATE clause with
wrong type.
sql/sql_base.cc:
Added setup of TABLE::timestamp_default_now/on_update_now pair
for each statement to open_table().
sql/sql_insert.cc:
Using TABLE::timestamp_default_now/on_update_now pair instead of
old TABLE::time_stamp. Added check for case then REPLACE could not
be converted to UPDATE because of different DEFAULT/ON UPDATE values
for TIMESTAMP field.
sql/sql_lex.h:
Added member for value used in ON UPDATE clause to st_lex.
sql/sql_load.cc:
Using TABLE::timestamp_default_now/on_update_now pair instead of
old TABLE::time_stamp. We don't need to restore these members
since they are set up for each statement in open_table().
sql/sql_parse.cc:
Added handling of DEFAULT NOW() and ON UPDATE NOW() clauses for
TIMESTAMP fields to add_field_to_list() function.
sql/sql_show.cc:
Added support for DEFAULT CURRENT_TIMESTAMP (aka NOW() ) and
ON UPDATE CURRENT_TIMESTAMP to SHOW CREATE TABLE and SHOW COLUMNS.
sql/sql_table.cc:
mysql_create_table() function - added check for number of TIMESTAMP
fields with auto-set values and replacing of old style TIMESTAMPs
with their newer analogs.
mysql_alter_table(): Using TABLE::timestamp_default_now/on_update_now
pair instead of old TABLE::time_stamp. We don't need to restore these
members since they are set up for each statement in open_table().
sql/sql_update.cc:
Left only setting of TABLE::timestamp_default_now/on_update_now
to 0 since they should be already set up in open_table().
sql/sql_yacc.yy:
Added support for DEFAULT NOW() and ON UPDATE NOW() in field
definitions.
sql/table.h:
Replaced TABLE::time_stamp withTABLE::timestamp_default_now/timestamp_on_update_now
pair which allows to distinguish TIMESTAMP's with various DEFAULT/ON UPDATE
clauses and optimize checks if TIMESTAMP field should be set to NOW()
in handlers.
sql/unireg.cc:
Now we are marking only TIMESTAMP fields with NOW() as default or
as on update value as special field for unireg.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 9f30617e62f..f2764a6f1c0 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -42,9 +42,9 @@ static void unlink_blobs(register TABLE *table); #define DELAYED_LOG_BIN 2 /* - Check if insert fields are correct - Updates table->time_stamp to point to timestamp field or 0, depending on - if timestamp should be updated or not. + Check if insert fields are correct. + Sets table->timestamp_default_now/on_update_now to 0 o leaves it to point + to timestamp field, depending on if timestamp should be updated or not. */ int @@ -65,7 +65,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, check_grant_all_columns(thd,INSERT_ACL,table)) return -1; #endif - table->time_stamp=0; // This is saved by caller + table->timestamp_default_now= table->timestamp_on_update_now= 0; } else { // Part field list @@ -97,10 +97,9 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, my_error(ER_FIELD_SPECIFIED_TWICE,MYF(0), thd->dupp_field->field_name); return -1; } - table->time_stamp=0; if (table->timestamp_field && // Don't set timestamp if used - table->timestamp_field->query_id != thd->query_id) - table->time_stamp= table->timestamp_field->offset()+1; + table->timestamp_field->query_id == thd->query_id) + table->timestamp_default_now= table->timestamp_on_update_now= 0; } // For the values we need select_priv #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -551,9 +550,12 @@ int write_record(TABLE *table,COPY_INFO *info) an INSERT or DELETE(s) + INSERT; FOREIGN KEY checks in InnoDB do not function in the defined way if we allow MySQL to convert the latter operation internally to an UPDATE. + We also should not perform this conversion if we have + timestamp field with ON UPDATE which is different from DEFAULT. */ if (last_uniq_key(table,key_nr) && - !table->file->referenced_by_foreign_key()) + !table->file->referenced_by_foreign_key() && + table->timestamp_default_now == table->timestamp_on_update_now) { if ((error=table->file->update_row(table->record[1], table->record[0]))) @@ -629,7 +631,8 @@ public: bool query_start_used,last_insert_id_used,insert_id_used; int log_query; ulonglong last_insert_id; - ulong time_stamp; + ulong timestamp_default_now; + ulong timestamp_on_update_now; uint query_length; delayed_row(enum_duplicates dup_arg, int log_query_arg) @@ -920,9 +923,10 @@ TABLE *delayed_insert::get_local_table(THD* client_thd) if (table->timestamp_field) { /* Restore offset as this may have been reset in handle_inserts */ - copy->time_stamp=table->timestamp_field->offset()+1; copy->timestamp_field= (Field_timestamp*) copy->field[table->timestamp_field_offset]; + copy->timestamp_field->unireg_check= table->timestamp_field->unireg_check; + copy->timestamp_field->set_timestamp_offsets(); } /* _rowid is not used with delayed insert */ @@ -973,7 +977,8 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, row->last_insert_id_used= thd->last_insert_id_used; row->insert_id_used= thd->insert_id_used; row->last_insert_id= thd->last_insert_id; - row->time_stamp= table->time_stamp; + row->timestamp_default_now= table->timestamp_default_now; + row->timestamp_on_update_now= table->timestamp_on_update_now; di->rows.push_back(row); di->stacked_inserts++; @@ -1307,7 +1312,8 @@ bool delayed_insert::handle_inserts(void) thd.last_insert_id=row->last_insert_id; thd.last_insert_id_used=row->last_insert_id_used; thd.insert_id_used=row->insert_id_used; - table->time_stamp=row->time_stamp; + table->timestamp_default_now= row->timestamp_default_now; + table->timestamp_on_update_now= row->timestamp_on_update_now; info.handle_duplicates= row->dup; if (info.handle_duplicates == DUP_IGNORE || @@ -1597,11 +1603,9 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u) /* First field to copy */ field=table->field+table->fields - values.elements; - if (table->timestamp_field) // Don't set timestamp if used - { - table->timestamp_field->set_time(); - table->time_stamp=0; // This should be saved - } + /* Don't set timestamp if used */ + table->timestamp_default_now= table->timestamp_on_update_now= 0; + table->next_number_field=table->found_next_number_field; restore_record(table,default_values); // Get empty record |