summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-01-03 23:04:52 +0200
committerunknown <monty@mysql.com>2005-01-03 23:04:52 +0200
commit73c9909750c7e471a08ce90ccc130d80394b049a (patch)
tree0f73878fcf058ff862f3f7eb305aafae2ad3465d /sql/sql_insert.cc
parent57deb768672132dc7ee461ca9a1e65435f36037a (diff)
parenta75e31b3610c2fb6a16f2bae469367e4be78d1cb (diff)
downloadmariadb-git-73c9909750c7e471a08ce90ccc130d80394b049a.tar.gz
Merge with 4.1 tree to get fix for INSERT IGNORE ... ON DUPLICATE KEY
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union Makefile.am: Auto merged client/mysqltest.c: Auto merged configure.in: Auto merged innobase/log/log0recv.c: Auto merged myisam/mi_check.c: Auto merged mysql-test/r/cast.result: Auto merged mysql-test/r/drop.result: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/ps_2myisam.result: Auto merged mysql-test/r/ps_3innodb.result: Auto merged mysql-test/r/ps_4heap.result: Auto merged mysql-test/r/ps_5merge.result: Auto merged mysql-test/r/ps_6bdb.result: Auto merged mysql-test/r/ps_7ndb.result: Auto merged mysql-test/r/type_datetime.result: Auto merged mysql-test/t/drop.test: Auto merged mysql-test/t/func_time.test: Auto merged ndb/include/ndb_global.h.in: Auto merged ndb/src/kernel/blocks/suma/Suma.cpp: Auto merged sql/ha_ndbcluster.h: Auto merged sql/item_timefunc.h: Auto merged sql/log_event.cc: Auto merged sql/log_event.h: Auto merged sql/set_var.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_repl.h: Auto merged sql/sql_select.cc: Auto merged sql-common/my_time.c: Auto merged sql/sql_union.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/time.cc: Auto merged innobase/row/row0upd.c: Trivial merge mysql-test/t/func_concat.test: Keep local code mysql-test/t/multi_update.test: auto merge sql/ha_ndbcluster.cc: manual merge sql/item_timefunc.cc: manual merge sql/mysql_priv.h: manual merge sql/sql_class.h: manual merge sql/sql_delete.cc: manual merge sql/sql_insert.cc: manual merge sql/sql_lex.cc: manual merge sql/sql_lex.h: manual merge sql/sql_load.cc: manual merge sql/sql_parse.cc: manual merge sql/sql_table.cc: manual merge sql/sql_update.cc: manual merge
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc40
1 files changed, 21 insertions, 19 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 701ffe60cb3..2a6e772db32 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -25,7 +25,7 @@
static int check_null_fields(THD *thd,TABLE *entry);
#ifndef EMBEDDED_LIBRARY
static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list);
-static int write_delayed(THD *thd,TABLE *table, enum_duplicates dup,
+static int write_delayed(THD *thd,TABLE *table, enum_duplicates dup, bool ignore,
char *query, uint query_length, bool log_on);
static void end_delayed_insert(THD *thd);
extern "C" pthread_handler_decl(handle_delayed_insert,arg);
@@ -158,7 +158,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
List<List_item> &values_list,
List<Item> &update_fields,
List<Item> &update_values,
- enum_duplicates duplic)
+ enum_duplicates duplic,
+ bool ignore)
{
int error, res;
/*
@@ -168,7 +169,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/
bool log_on= (thd->options & OPTION_BIN_LOG) || (!(thd->master_access & SUPER_ACL));
bool transactional_table, log_delayed;
- bool ignore_err= (thd->lex->duplicates == DUP_IGNORE);
uint value_count;
ulong counter = 1;
ulonglong id;
@@ -271,11 +271,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/
info.records= info.deleted= info.copied= info.updated= 0;
+ info.ignore= ignore;
info.handle_duplicates=duplic;
- info.update_fields=&update_fields;
- info.update_values=&update_values;
+ info.update_fields= &update_fields;
+ info.update_values= &update_values;
info.view= (table_list->view ? table_list : 0);
- info.ignore= ignore_err;
+
/*
Count warnings for all inserts.
For single line insert, generate an error if try to set a NOT NULL field
@@ -366,7 +367,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
if ((res= table_list->view_check_option(thd,
(values_list.elements == 1 ?
0 :
- ignore_err))) ==
+ ignore))) ==
VIEW_CHECK_SKIP)
continue;
else if (res == VIEW_CHECK_ERROR)
@@ -377,7 +378,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
#ifndef EMBEDDED_LIBRARY
if (lock_type == TL_WRITE_DELAYED)
{
- error=write_delayed(thd,table,duplic,query, thd->query_length, log_on);
+ error=write_delayed(thd, table, duplic, ignore, query, thd->query_length, log_on);
query=0;
}
else
@@ -490,7 +491,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
else
{
char buff[160];
- if (duplic == DUP_IGNORE)
+ if (ignore)
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
@@ -851,7 +852,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
}
else if ((error=table->file->write_row(table->record[0])))
{
- if (info->handle_duplicates != DUP_IGNORE ||
+ if (!info->ignore ||
(error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE))
goto err;
table->file->restore_auto_increment();
@@ -906,13 +907,13 @@ public:
char *record,*query;
enum_duplicates dup;
time_t start_time;
- bool query_start_used,last_insert_id_used,insert_id_used, log_query;
+ bool query_start_used,last_insert_id_used,insert_id_used, ignore, log_query;
ulonglong last_insert_id;
timestamp_auto_set_type timestamp_field_type;
uint query_length;
- delayed_row(enum_duplicates dup_arg, bool log_query_arg)
- :record(0),query(0),dup(dup_arg),log_query(log_query_arg) {}
+ delayed_row(enum_duplicates dup_arg, bool ignore_arg, bool log_query_arg)
+ :record(0), query(0), dup(dup_arg), ignore(ignore_arg), log_query(log_query_arg) {}
~delayed_row()
{
x_free(record);
@@ -1224,7 +1225,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
/* Put a question in queue */
-static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic,
+static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, bool ignore,
char *query, uint query_length, bool log_on)
{
delayed_row *row=0;
@@ -1237,7 +1238,7 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic,
pthread_cond_wait(&di->cond_client,&di->mutex);
thd->proc_info="storing row into queue";
- if (thd->killed || !(row= new delayed_row(duplic, log_on)))
+ if (thd->killed || !(row= new delayed_row(duplic, ignore, log_on)))
goto err;
if (!query)
@@ -1600,8 +1601,9 @@ bool delayed_insert::handle_inserts(void)
thd.insert_id_used=row->insert_id_used;
table->timestamp_field_type= row->timestamp_field_type;
+ info.ignore= row->ignore;
info.handle_duplicates= row->dup;
- if (info.handle_duplicates == DUP_IGNORE ||
+ if (info.ignore ||
info.handle_duplicates == DUP_REPLACE)
{
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
@@ -1803,7 +1805,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
restore_record(table,default_values); // Get empty record
table->next_number_field=table->found_next_number_field;
thd->cuted_fields=0;
- if (info.handle_duplicates == DUP_IGNORE ||
+ if (info.ignore ||
info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->start_bulk_insert((ha_rows) 0);
@@ -1965,7 +1967,7 @@ bool select_insert::send_eof()
DBUG_RETURN(1);
}
char buff[160];
- if (info.handle_duplicates == DUP_IGNORE)
+ if (info.ignore)
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
else
@@ -2008,7 +2010,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
restore_record(table,default_values); // Get empty record
thd->cuted_fields=0;
- if (info.handle_duplicates == DUP_IGNORE ||
+ if (info.ignore ||
info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
table->file->start_bulk_insert((ha_rows) 0);