summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorunknown <lars/lthalmann@mysql.com/dl145h.mysql.com>2007-03-31 12:36:50 +0200
committerunknown <lars/lthalmann@mysql.com/dl145h.mysql.com>2007-03-31 12:36:50 +0200
commit0c6731fdfa2438d20a027099b1038d0bea12a010 (patch)
tree76754b54bbb7ab35d9cb84592a5ff63cb6e19a0a /sql/sql_base.cc
parentf47c23288a1cf6b5b43363542de72276eaf6a923 (diff)
parent2016b21ce1517e0c3969231bd50de5181355edcc (diff)
downloadmariadb-git-0c6731fdfa2438d20a027099b1038d0bea12a010.tar.gz
Merge mysql.com:/nfsdisk1/lars/bkroot/mysql-5.0-rpl
into mysql.com:/nfsdisk1/lars/MERGE/mysql-5.0-merge sql/sql_base.cc: Auto merged sql/sql_select.cc: Auto merged sql/table.h: Auto merged
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc69
1 files changed, 62 insertions, 7 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index b67fc73ba7b..1100a452b15 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1640,6 +1640,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->used_keys= table->s->keys_for_keyread;
table->fulltext_searched= 0;
table->file->ft_handler= 0;
+ /* Catch wrong handling of the auto_increment_field_not_null. */
+ DBUG_ASSERT(!table->auto_increment_field_not_null);
+ table->auto_increment_field_not_null= FALSE;
if (table->timestamp_field)
table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
table->pos_in_table_list= table_list;
@@ -4865,7 +4868,6 @@ bool setup_tables_and_check_access(THD *thd,
TABLE_LIST *leaves_tmp = NULL;
bool first_table= true;
- thd->leaf_count= 0;
if (setup_tables (thd, context, from_clause, tables, conds,
&leaves_tmp, select_insert))
return TRUE;
@@ -4883,7 +4885,6 @@ bool setup_tables_and_check_access(THD *thd,
return TRUE;
}
first_table= false;
- thd->leaf_count++;
}
return FALSE;
}
@@ -5274,6 +5275,11 @@ err_no_arena:
values values to fill with
ignore_errors TRUE if we should ignore errors
+ NOTE
+ fill_record() may set table->auto_increment_field_not_null and a
+ caller should make sure that it is reset after their last call to this
+ function.
+
RETURN
FALSE OK
TRUE error occured
@@ -5286,27 +5292,52 @@ fill_record(THD * thd, List<Item> &fields, List<Item> &values,
List_iterator_fast<Item> f(fields),v(values);
Item *value, *fld;
Item_field *field;
+ TABLE *table= 0;
DBUG_ENTER("fill_record");
+ /*
+ Reset the table->auto_increment_field_not_null as it is valid for
+ only one row.
+ */
+ if (fields.elements)
+ {
+ /*
+ On INSERT or UPDATE fields are checked to be from the same table,
+ thus we safely can take table from the first field.
+ */
+ fld= (Item_field*)f++;
+ if (!(field= fld->filed_for_view_update()))
+ {
+ my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name);
+ goto err;
+ }
+ table= field->field->table;
+ table->auto_increment_field_not_null= FALSE;
+ f.rewind();
+ }
while ((fld= f++))
{
if (!(field= fld->filed_for_view_update()))
{
my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name);
- DBUG_RETURN(TRUE);
+ goto err;
}
value=v++;
Field *rfield= field->field;
- TABLE *table= rfield->table;
+ table= rfield->table;
if (rfield == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
{
my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
- DBUG_RETURN(TRUE);
+ goto err;
}
}
DBUG_RETURN(thd->net.report_error);
+err:
+ if (table)
+ table->auto_increment_field_not_null= FALSE;
+ DBUG_RETURN(TRUE);
}
@@ -5355,6 +5386,11 @@ fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
values list of fields
ignore_errors TRUE if we should ignore errors
+ NOTE
+ fill_record() may set table->auto_increment_field_not_null and a
+ caller should make sure that it is reset after their last call to this
+ function.
+
RETURN
FALSE OK
TRUE error occured
@@ -5365,19 +5401,38 @@ fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors)
{
List_iterator_fast<Item> v(values);
Item *value;
+ TABLE *table= 0;
DBUG_ENTER("fill_record");
Field *field;
+ /*
+ Reset the table->auto_increment_field_not_null as it is valid for
+ only one row.
+ */
+ if (*ptr)
+ {
+ /*
+ On INSERT or UPDATE fields are checked to be from the same table,
+ thus we safely can take table from the first field.
+ */
+ table= (*ptr)->table;
+ table->auto_increment_field_not_null= FALSE;
+ }
while ((field = *ptr++))
{
value=v++;
- TABLE *table= field->table;
+ table= field->table;
if (field == table->next_number_field)
table->auto_increment_field_not_null= TRUE;
if (value->save_in_field(field, 0) == -1)
- DBUG_RETURN(TRUE);
+ goto err;
}
DBUG_RETURN(thd->net.report_error);
+
+err:
+ if (table)
+ table->auto_increment_field_not_null= FALSE;
+ DBUG_RETURN(TRUE);
}