summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc38
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