diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-07-31 12:55:21 +0530 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-09-15 08:55:34 +0200 |
commit | ea06c67a49cf6f4b8daa7287454faba6b7cae874 (patch) | |
tree | 5ca3baa1ed755803a16c43d36b10fe2896b22fbe /tests/mysql_client_test.c | |
parent | 50e08f3da00bbc800de7eec278ad98cf0acd0845 (diff) | |
download | mariadb-git-ea06c67a49cf6f4b8daa7287454faba6b7cae874.tar.gz |
MDEV-10075: Provide index of error causing error in array INSERT
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 'tests/mysql_client_test.c')
-rw-r--r-- | tests/mysql_client_test.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 8f4e2b2fdad..128215d01a7 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -21505,6 +21505,95 @@ static void test_cache_metadata() mysql_stmt_close(stmt); } +void test_mdev_10075() +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_RES *result; + MYSQL_BIND my_bind[1]; + MYSQL_BIND my_bind2[1]; + + struct st_data { + unsigned long id; + char id_ind; + }; + + struct st_data data[]= { + {0, STMT_INDICATOR_NONE}, + {1, STMT_INDICATOR_NONE}, + {2, STMT_INDICATOR_NONE} + }; + + struct st_data data2[]= { + {3, STMT_INDICATOR_NONE}, + {2, STMT_INDICATOR_NONE}, + {4, STMT_INDICATOR_NONE} + }; + + myheader("test_mdev_10075"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + myquery(rc); + + rc= mysql_query(mysql, "CREATE TABLE t1(id INT PRIMARY KEY)"); + myquery(rc); + + /* insert by prepare */ + stmt= mysql_simple_prepare(mysql, + "INSERT INTO t1 VALUES(?)"); + check_stmt(stmt); + verify_param_count(stmt, 1); + + /* bzero bind structure */ + bzero((char*) my_bind, sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&data[0].id; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_execute(stmt, rc); + + /* Set array size, row size and bind the parameter */ + mysql_stmt_bind_param(stmt, my_bind); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + mysql_stmt_close(stmt); + + stmt= mysql_simple_prepare(mysql, + "INSERT IGNORE INTO t1 VALUES(?)"); + check_stmt(stmt); + verify_param_count(stmt, 1); + + /* bzero bind structure */ + bzero((char*) my_bind2, sizeof(my_bind2)); + my_bind2[0].buffer_type= MYSQL_TYPE_LONG; + my_bind2[0].buffer= (void *)&data2[0].id; + + rc= mysql_stmt_bind_param(stmt, my_bind2); + check_execute(stmt, rc); + + mysql_stmt_bind_param(stmt, my_bind2); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "GET DIAGNOSTICS CONDITION 1 @var1 = ERROR_INDEX"); + myquery(rc); + + rc= mysql_query(mysql, "SELECT @var1"); + myquery(rc); + + result= mysql_store_result(mysql); + mytest(result); + + rc= my_process_result_set(result); + DIE_UNLESS(rc == 1); + + mysql_free_result(result); +} static struct my_tests_st my_tests[]= { { "test_mdev_26145", test_mdev_26145 }, @@ -21809,6 +21898,7 @@ static struct my_tests_st my_tests[]= { { "test_mdev20261", test_mdev20261 }, { "test_execute_direct", test_execute_direct }, { "test_cache_metadata", test_cache_metadata}, + { "test_mdev_10075", test_mdev_10075}, { 0, 0 } }; |