summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r--sql/sql_update.cc127
1 files changed, 66 insertions, 61 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 9d382baf155..dfc46150847 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -73,7 +73,8 @@ static bool check_fields(THD *thd, List<Item> &items)
if (!(field= item->filed_for_view_update()))
{
/* item has name, because it comes from VIEW SELECT list */
- my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name);
+ my_printf_error(ER_NONUPDATEABLE_COLUMN, ER(ER_NONUPDATEABLE_COLUMN),
+ MYF(0), item->name);
return TRUE;
}
/*
@@ -86,21 +87,21 @@ static bool check_fields(THD *thd, List<Item> &items)
}
-int mysql_update(THD *thd,
- TABLE_LIST *table_list,
- List<Item> &fields,
- List<Item> &values,
- COND *conds,
- uint order_num, ORDER *order,
- ha_rows limit,
- enum enum_duplicates handle_duplicates)
+bool mysql_update(THD *thd,
+ TABLE_LIST *table_list,
+ List<Item> &fields,
+ List<Item> &values,
+ COND *conds,
+ uint order_num, ORDER *order,
+ ha_rows limit,
+ enum enum_duplicates handle_duplicates)
{
bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->options & OPTION_SAFE_UPDATES;
bool used_key_is_modified, transactional_table, log_delayed;
bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
+ bool res;
int error=0;
- int res;
uint used_index;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
uint want_privilege;
@@ -117,8 +118,8 @@ int mysql_update(THD *thd,
LINT_INIT(used_index);
LINT_INIT(timestamp_query_id);
- if ((error= open_and_lock_tables(thd, table_list)))
- DBUG_RETURN(error);
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
thd->proc_info="init";
table= table_list->table;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
@@ -156,16 +157,17 @@ int mysql_update(THD *thd,
res= setup_fields(thd, 0, table_list, fields, 1, 0, 0);
select_lex->no_wrap_view_item= 0;
if (res)
- DBUG_RETURN(-1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
if (table_list->view && check_fields(thd, fields))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (!table_list->updatable || check_key_in_view(thd, table_list))
{
- my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE");
- DBUG_RETURN(-1);
+ my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE),
+ MYF(0), table_list->alias, "UPDATE");
+ DBUG_RETURN(TRUE);
}
if (table->timestamp_field)
{
@@ -184,7 +186,7 @@ int mysql_update(THD *thd,
if (setup_fields(thd, 0, table_list, values, 0, 0, 0))
{
free_underlaid_joins(thd, select_lex);
- DBUG_RETURN(-1); /* purecov: inspected */
+ DBUG_RETURN(TRUE); /* purecov: inspected */
}
// Don't count on usage of 'only index' when calculating which key to use
@@ -197,10 +199,10 @@ int mysql_update(THD *thd,
free_underlaid_joins(thd, select_lex);
if (error)
{
- DBUG_RETURN(-1); // Error in where
+ DBUG_RETURN(TRUE); // Error in where
}
send_ok(thd); // No matching records
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
/* If running in safe sql mode, don't allow updates without keys */
if (table->quick_keys.is_clear_all())
@@ -362,8 +364,9 @@ int mysql_update(THD *thd,
if (!(select && select->skip_record()))
{
store_record(table,record[1]);
- if (fill_record(fields,values, 0) || thd->net.report_error)
+ if (fill_record(thd, fields, values, 0))
break; /* purecov: inspected */
+
found++;
if (table->triggers)
@@ -457,9 +460,7 @@ int mysql_update(THD *thd,
}
free_underlaid_joins(thd, select_lex);
- if (error >= 0)
- send_error(thd,thd->killed_errno()); /* purecov: inspected */
- else
+ if (error < 0)
{
char buff[80];
sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
@@ -473,7 +474,7 @@ int mysql_update(THD *thd,
thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */
thd->abort_on_warning= 0;
free_io_cache(table);
- DBUG_RETURN(0);
+ DBUG_RETURN(error >= 0 || thd->net.report_error);
err:
delete select;
@@ -484,7 +485,7 @@ err:
table->file->extra(HA_EXTRA_NO_KEYREAD);
}
thd->abort_on_warning= 0;
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
/*
@@ -499,11 +500,10 @@ err:
order - ORDER BY clause list
RETURN VALUE
- 0 - OK
- 1 - error (message is sent to user)
- -1 - error (message is not sent to user)
+ FALSE OK
+ TRUE error
*/
-int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
+bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
Item **conds, uint order_num, ORDER *order)
{
TABLE *table= table_list->table;
@@ -527,16 +527,17 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
setup_order(thd, select_lex->ref_pointer_array,
table_list, all_fields, all_fields, order) ||
setup_ftfuncs(select_lex))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
/* Check that we are not using table that we are updating in a sub select */
if (unique_table(table_list, table_list->next_global))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
- DBUG_RETURN(-1);
+ my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), MYF(0),
+ table_list->real_name);
+ DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, conds);
- DBUG_RETURN(0);
+ DBUG_RETURN(FALSE);
}
@@ -569,11 +570,11 @@ static table_map get_table_map(List<Item> *items)
thd thread handler
RETURN
- 0 OK
- -1 Error
+ FALSE OK
+ TRUE Error
*/
-int mysql_multi_update_prepare(THD *thd)
+bool mysql_multi_update_prepare(THD *thd)
{
LEX *lex= thd->lex;
ulong opened_tables;
@@ -619,7 +620,7 @@ int mysql_multi_update_prepare(THD *thd)
res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0),
lex->select_lex.no_wrap_view_item= 0,
res))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
for (tl= table_list; tl ; tl= tl->next_local)
{
@@ -632,7 +633,7 @@ int mysql_multi_update_prepare(THD *thd)
if (update_view && check_fields(thd, *fields))
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
tables_for_update= get_table_map(fields);
@@ -657,8 +658,10 @@ int mysql_multi_update_prepare(THD *thd)
{
if (!tl->updatable || check_key_in_view(thd, tl))
{
- my_error(ER_NON_UPDATABLE_TABLE, MYF(0), tl->alias, "UPDATE");
- DBUG_RETURN(-1);
+ my_printf_error(ER_NON_UPDATABLE_TABLE,
+ ER(ER_NON_UPDATABLE_TABLE), MYF(0),
+ tl->alias, "UPDATE");
+ DBUG_RETURN(TRUE);
}
/*
@@ -668,8 +671,9 @@ int mysql_multi_update_prepare(THD *thd)
if (lex->select_lex.check_updateable_in_subqueries(tl->db,
tl->real_name))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), tl->real_name);
- DBUG_RETURN(-1);
+ my_printf_error(ER_UPDATE_TABLE_USED,
+ ER(ER_UPDATE_TABLE_USED), MYF(0), tl->real_name);
+ DBUG_RETURN(TRUE);
}
DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
tl->lock_type= lex->multi_lock_option;
@@ -688,7 +692,7 @@ int mysql_multi_update_prepare(THD *thd)
opened_tables= thd->status_var.opened_tables;
/* now lock and fill tables */
if (lock_tables(thd, table_list, table_count))
- DBUG_RETURN(thd->net.report_error ? -1 : 1);
+ DBUG_RETURN(TRUE);
/*
we have to re-call fixfields for fixed items, because lock maybe
@@ -719,12 +723,12 @@ int mysql_multi_update_prepare(THD *thd)
res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0),
lex->select_lex.no_wrap_view_item= 0,
res))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
}
if (thd->fill_derived_tables() &&
mysql_handle_derived(lex, &mysql_derived_filling))
DBUG_RETURN(thd->net.report_error ? -1 : 1);
- DBUG_RETURN (0);
+ DBUG_RETURN (FALSE);
}
@@ -732,16 +736,16 @@ int mysql_multi_update_prepare(THD *thd)
Setup multi-update handling and call SELECT to do the join
*/
-int mysql_multi_update(THD *thd,
- TABLE_LIST *table_list,
- List<Item> *fields,
- List<Item> *values,
- COND *conds,
- ulong options,
- enum enum_duplicates handle_duplicates,
- SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
+bool mysql_multi_update(THD *thd,
+ TABLE_LIST *table_list,
+ List<Item> *fields,
+ List<Item> *values,
+ COND *conds,
+ ulong options,
+ enum enum_duplicates handle_duplicates,
+ SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
{
- int res;
+ bool res;
multi_update *result;
DBUG_ENTER("mysql_multi_update");
@@ -750,7 +754,7 @@ int mysql_multi_update(THD *thd,
if (!(result= new multi_update(thd, table_list, fields, values,
handle_duplicates)))
- DBUG_RETURN(-1);
+ DBUG_RETURN(TRUE);
thd->no_trans_update= 0;
thd->abort_on_warning= test(thd->variables.sql_mode &
@@ -767,7 +771,7 @@ int mysql_multi_update(THD *thd,
result, unit, select_lex);
delete result;
thd->abort_on_warning= 0;
- DBUG_RETURN(res);
+ DBUG_RETURN(TRUE);
}
@@ -805,7 +809,7 @@ int multi_update::prepare(List<Item> &not_used_values,
if (!tables_to_update)
{
- my_error(ER_NO_TABLES_USED, MYF(0));
+ my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0));
DBUG_RETURN(1);
}
@@ -1091,8 +1095,10 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
table->status|= STATUS_UPDATED;
store_record(table,record[1]);
- if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0))
+ if (fill_record(thd, *fields_for_table[offset],
+ *values_for_table[offset], 0))
DBUG_RETURN(1);
+
found++;
if (compare_record(table, thd->query_id))
{
@@ -1135,7 +1141,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
int error;
TABLE *tmp_table= tmp_tables[offset];
- fill_record(tmp_table->field+1, *values_for_table[offset], 1);
+ fill_record(thd, tmp_table->field+1, *values_for_table[offset], 1);
found++;
/* Store pointer to row */
memcpy((char*) tmp_table->field[0]->ptr,
@@ -1161,7 +1167,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
void multi_update::send_error(uint errcode,const char *err)
{
/* First send error what ever it is ... */
- ::send_error(thd,errcode,err);
+ my_error(errcode, MYF(0), err);
/* If nothing updated return */
if (!updated)
@@ -1354,7 +1360,6 @@ bool multi_update::send_eof()
/* Safety: If we haven't got an error before (should not happen) */
my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update",
MYF(0));
- ::send_error(thd);
return 1;
}