summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2021-07-31 12:55:21 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2021-09-09 14:39:03 +0530
commit9295921e8740335e12b2697ffa8e444cc942b0a2 (patch)
tree7a5642d5c8b4ae1d56c245355f6d868a04fc938b /sql/sql_insert.cc
parent76149650764ea9660ae05d4987ea6c91534851ab (diff)
downloadmariadb-git-bb-10.7-MDEV-10075.tar.gz
MDEV-10075: Provide index of error causing error in array INSERTbb-10.7-MDEV-10075
Extended the parser for GET DIAGNOSTICS to use ERROR_INDEX to get warning/error index. Error information is stored in Sql_condition. So it can be used to store the index of warning/error too. THD::current_insert_index keeps a track of count for each row that is processed or going to be inserted in the table (or first row in case of prepare phase). When an error occurs, first we need to fetch corrected error index (using correct_error_index()) for an error number. This is needed because in prepare phase, the error may not be because of rows/values. In such case, correct value of error_index should be 0. Once correct value if fetched, assign it to Sql_condition::error_index when the object is created during error/warning. This error_index variable is returned when ERROR_INDEX is used in GET DIAGNOSTICS.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index eaafb8d7742..7b2b820752c 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -711,6 +711,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
Name_resolution_context_state ctx_state;
SELECT_LEX *returning= thd->lex->has_returning() ? thd->lex->returning() : 0;
unsigned char *readbuff= NULL;
+ thd->current_insert_index= 0;
#ifndef EMBEDDED_LIBRARY
char *query= thd->query();
@@ -830,7 +831,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
while ((values= its++))
{
- counter++;
+ thd->current_insert_index= ++counter;
if (values->elements != value_count)
{
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
@@ -842,6 +843,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
switch_to_nullable_trigger_fields(*values, table);
}
its.rewind ();
+ thd->current_insert_index= 0;
/* Restore the current context. */
ctx_state.restore_state(context, table_list);
@@ -1008,6 +1010,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
while ((values= its++))
{
+ thd->current_insert_index++;
if (fields.elements || !value_count)
{
/*
@@ -1131,6 +1134,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
} while (bulk_parameters_iterations(thd));
values_loop_end:
+ thd->current_insert_index= 0;
free_underlaid_joins(thd, thd->lex->first_select_lex());
joins_freed= TRUE;
@@ -1606,6 +1610,8 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
bool res= 0;
table_map map= 0;
TABLE *table;
+ thd->current_insert_index= 1;
+
DBUG_ENTER("mysql_prepare_insert");
DBUG_PRINT("enter", ("table_list: %p view: %d",
table_list, (int) insert_into_view));
@@ -1659,6 +1665,7 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
if (!res)
res= setup_fields(thd, Ref_ptr_array(),
update_values, MARK_COLUMNS_READ, 0, NULL, 0);
+ thd->current_insert_index= 0;
if (!res && duplic == DUP_UPDATE)
{