mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
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.
This commit is contained in:
committed by
Sergei Golubchik
parent
50e08f3da0
commit
ea06c67a49
@@ -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 }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user