diff options
author | bell@sanja.is.com.ua <> | 2004-09-29 17:10:17 +0300 |
---|---|---|
committer | bell@sanja.is.com.ua <> | 2004-09-29 17:10:17 +0300 |
commit | 013512abab682e5346a08ee5bb487e6efa1b54b7 (patch) | |
tree | aeac5ada3224a0f38d6477026dfc659193a88437 /sql/sql_insert.cc | |
parent | 3bddaaf80f7e521f07a17b77d87397165d8b3f5d (diff) | |
parent | 392292a46b99b6403436a30578f40c4dd515f03d (diff) | |
download | mariadb-git-013512abab682e5346a08ee5bb487e6efa1b54b7.tar.gz |
merge
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index d7f254502c0..3b4d903c90d 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -130,6 +130,7 @@ int 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; @@ -243,6 +244,8 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, info.handle_duplicates=duplic; 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 @@ -304,6 +307,14 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, break; } } + if ((res= table_list->view_check_option(thd, ignore_err)) == + VIEW_CHECK_SKIP) + continue; + else if (res == VIEW_CHECK_ERROR) + { + error= 1; + break; + } // FIXME: Actually we should do this before check_null_fields. // Or even go into write_record ? @@ -699,6 +710,7 @@ int write_record(TABLE *table,COPY_INFO *info) } if (info->handle_duplicates == DUP_UPDATE) { + int res= 0; /* we don't check for other UNIQUE keys - the first row that matches, is updated. If update causes a conflict again, an error is returned @@ -707,6 +719,15 @@ int write_record(TABLE *table,COPY_INFO *info) restore_record(table,record[1]); if (fill_record(*info->update_fields, *info->update_values, 0)) goto err; + + /* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */ + if (info->view && + (res= info->view->view_check_option(current_thd, info->ignore)) == + VIEW_CHECK_SKIP) + break; + else if (res == VIEW_CHECK_ERROR) + goto err; + if ((error=table->file->update_row(table->record[1],table->record[0]))) goto err; info->updated++; @@ -1614,6 +1635,11 @@ int mysql_insert_select_prepare(THD *thd) { LEX *lex= thd->lex; DBUG_ENTER("mysql_insert_select_prepare"); + /* + SELECT_LEX do not belong to INSERT statement, so we can't add WHERE + clasue if table is VIEW + */ + lex->query_tables->no_where_clause= 1; if (mysql_prepare_insert_check_table(thd, lex->query_tables, lex->field_list, &lex->select_lex.where)) @@ -1622,6 +1648,21 @@ int mysql_insert_select_prepare(THD *thd) } +select_insert::select_insert(TABLE_LIST *table_list_par, TABLE *table_par, + List<Item> *fields_par, enum_duplicates duplic, + bool ignore_check_option_errors) + :table_list(table_list_par), table(table_par), fields(fields_par), + last_insert_id(0), + insert_into_view(table_list_par && table_list_par->view != 0) +{ + bzero((char*) &info,sizeof(info)); + info.handle_duplicates=duplic; + if (table_list_par) + info.view= (table_list_par->view ? table_list_par : 0); + info.ignore= ignore_check_option_errors; +} + + int select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) { @@ -1675,6 +1716,14 @@ bool select_insert::send_data(List<Item> &values) fill_record(*fields, values, 1); else fill_record(table->field, values, 1); + switch (table_list->view_check_option(thd, + thd->lex->duplicates == DUP_IGNORE)) + { + case VIEW_CHECK_SKIP: + DBUG_RETURN(0); + case VIEW_CHECK_ERROR: + DBUG_RETURN(1); + } if (thd->net.report_error || write_record(table,&info)) DBUG_RETURN(1); if (table->next_number_field) // Clear for next record |