[Commits] ab7b218c487: c
revision-id: ab7b218c487f9dcf63874759bb20818b017a4fde (mariadb-10.4.0-40-gab7b218c487) parent(s): af735cd52e54959dedc542acd23b89551cccf19b author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-12-13 10:08:24 +0100 message: c --- include/mysql.h | 3 ++- include/mysql.h.pp | 6 +++-- include/mysql_com.h | 3 ++- sql/sql_class.cc | 18 +++++++------- sql/sql_insert.cc | 2 ++ sql/sql_prepare.cc | 17 ++++++++++++-- tests/mysql_client_test.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-- 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index a42f90db1ae..8d38835e002 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -785,7 +785,8 @@ enum enum_stmt_attr_type Amount of rows to retrieve from server per one fetch if using cursors. Accepts unsigned long attribute in the range 1 - ulong_max */ - STMT_ATTR_PREFETCH_ROWS + STMT_ATTR_PREFETCH_ROWS, + STMT_ATTR_ALL_INSER_ID }; MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 4da8a5be491..c405642fa36 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -93,13 +93,14 @@ enum enum_cursor_type CURSOR_TYPE_READ_ONLY= 1, CURSOR_TYPE_FOR_UPDATE= 2, CURSOR_TYPE_SCROLLABLE= 4, + INSERT_ID_REQUEST= 128 }; enum stmt_flags_type { STMTFLG_CURSOR_TYPE_READ_ONLY= CURSOR_TYPE_READ_ONLY, STMTFLG_CURSOR_TYPE_FOR_UPDATE= CURSOR_TYPE_FOR_UPDATE, STMTFLG_CURSOR_TYPE_SCROLLABLE= CURSOR_TYPE_FOR_UPDATE, - STMTFLG_INSERT_ID_REQUEST= 128 + STMTFLG_INSERT_ID_REQUEST= INSERT_ID_REQUEST }; enum enum_mysql_set_option { @@ -688,7 +689,8 @@ enum enum_stmt_attr_type { STMT_ATTR_UPDATE_MAX_LENGTH, STMT_ATTR_CURSOR_TYPE, - STMT_ATTR_PREFETCH_ROWS + STMT_ATTR_PREFETCH_ROWS, + STMT_ATTR_ALL_INSER_ID }; MYSQL_STMT * mysql_stmt_init(MYSQL *mysql); int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, diff --git a/include/mysql_com.h b/include/mysql_com.h index 4217d6ca0e5..b5029307aa2 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -579,6 +579,7 @@ enum enum_cursor_type CURSOR_TYPE_READ_ONLY= 1, CURSOR_TYPE_FOR_UPDATE= 2, CURSOR_TYPE_SCROLLABLE= 4, + INSERT_ID_REQUEST= 128 }; /* first values should be the same as enum_cursor_type */ enum stmt_flags_type @@ -586,7 +587,7 @@ enum stmt_flags_type STMTFLG_CURSOR_TYPE_READ_ONLY= CURSOR_TYPE_READ_ONLY, STMTFLG_CURSOR_TYPE_FOR_UPDATE= CURSOR_TYPE_FOR_UPDATE, STMTFLG_CURSOR_TYPE_SCROLLABLE= CURSOR_TYPE_FOR_UPDATE, - STMTFLG_INSERT_ID_REQUEST= 128 + STMTFLG_INSERT_ID_REQUEST= INSERT_ID_REQUEST }; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1f8f011bfa6..947f6bfcdfb 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -7696,13 +7696,13 @@ bool Qualified_column_ident::append_to(THD *thd, String *str) const bool THD::init_collecting_insert_id() { List<Item> field_list; + bool res; // it should not be done on statement memory) - DBUG_ASSERT(stmt_arena->is_conventional() || - mem_root != stmt_arena->mem_root); + DBUG_ASSERT(mem_root == &main_mem_root); DBUG_ASSERT(insert_id_info == NULL); - if ((insert_id_info= (insert_id_desc*) calloc(sizeof(insert_id_desc)))) + if (!(insert_id_info= (insert_id_desc*) calloc(sizeof(insert_id_desc)))) return TRUE; field_list.push_back(new (mem_root) @@ -7715,13 +7715,12 @@ bool THD::init_collecting_insert_id() Item_return_int(this, "Inc", 0, MYSQL_TYPE_LONG), mem_root); - if (protocol_binary.send_result_set_metadata(&field_list, - Protocol::SEND_NUM_ROWS | - Protocol::SEND_EOF)) - return TRUE; - + res= protocol_binary.send_result_set_metadata(&field_list, + Protocol::SEND_NUM_ROWS | + Protocol::SEND_EOF); + free_items(); - return FALSE; + return res; } @@ -7789,6 +7788,7 @@ bool THD::report_collected_insert_id() send_collected_insert_id(); stop_collecting_insert_id(); + return TRUE; } return FALSE; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 349ac2646fe..9bfa5bd696c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1073,6 +1073,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, thd->collect_insert_id(table->file->insert_id_for_cur_row); } + table->auto_increment_field_not_null= FALSE; + } while (bulk_parameters_iterations(thd)); values_loop_end: diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 5346af194ef..8d92c15fce7 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -3134,6 +3134,7 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length) @return none: in case of success OK packet or a result set is sent to the client, otherwise an error message is set in THD. + */ void mysqld_stmt_bulk_execute(THD *thd, char *packet_arg, uint packet_length) @@ -3160,7 +3161,10 @@ void mysqld_stmt_bulk_execute(THD *thd, char *packet_arg, uint packet_length) /* stmt id and two bytes of flags */ packet+= 4 + 2; - mysql_stmt_execute_common(thd, stmt_id, packet, packet_end, 0, TRUE, + + // bulk execute support only STMTFLG_INSERT_ID_REQUEST flag + mysql_stmt_execute_common(thd, stmt_id, packet, packet_end, + (flags & STMTFLG_INSERT_ID_REQUEST), TRUE, (flags & STMT_BULK_FLAG_CLIENT_SEND_TYPES)); DBUG_VOID_RETURN; } @@ -4356,7 +4360,16 @@ Prepared_statement::execute_bulk_loop(String *expanded_query, thd->set_bulk_execution(0); return TRUE; } - if (lex->sql_command == SQLCOM_INSERT && insert_id_request && + + if (lex->sql_command != SQLCOM_INSERT && insert_id_request) + { + DBUG_PRINT("error", ("Request insert IDs on non-INSERT.")); + my_error(ER_UNSUPPORTED_PS, MYF(0)); + thd->set_bulk_execution(0); + return TRUE; + } + + if (insert_id_request && thd->init_collecting_insert_id()) { thd->set_bulk_execution(0); diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index cbf3dad0965..08f187ebf48 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -20305,6 +20305,59 @@ static void test_bulk_autoinc() myquery(rc); } +static void test_bulk_autoinc_all_id() +{ + int rc; + int all_ids= 1; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_ROW row; + char indicator[]= {STMT_INDICATOR_NONE, STMT_INDICATOR_NULL, STMT_INDICATOR_NONE}; + my_bool error[1]; + int id[]= {2, 3, 777}, count= sizeof(id)/sizeof(id[0]); + MYSQL_RES *result; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS ai_field_value"); + myquery(rc); + rc= mysql_query(mysql, "CREATE TABLE ai_field_value (id int not null primary key auto_increment)"); + myquery(rc); + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "INSERT INTO ai_field_value(id) values(?)", -1); + check_execute(stmt, rc); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type = MYSQL_TYPE_LONG; + bind[0].buffer = (void *)id; + bind[0].buffer_length = 0; + bind[0].is_null = NULL; + bind[0].length = NULL; + bind[0].error = error; + bind[0].u.indicator= indicator; + + + mysql_stmt_attr_set(stmt, STMT_ATTR_ALL_INSER_ID, (void*)&all_ids); + mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, (void*)&count); + rc= mysql_stmt_bind_param(stmt, bind); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + myquery(rc); + + rc= mysql_stmt_store_result(stmt); + mytest(rc); + + result= mysql_stmt_result_metadata(stmt); + mytest(result); + + + while ((row= mysql_fetch_row(result))) + { + mct_log("Ids: %d %d %d\n", + atoi(row[0]), atoi(row[1]), atoi(row[2])); + } + rc= mysql_query(mysql, "DROP TABLE ai_field_value"); + myquery(rc); +} #endif @@ -20833,6 +20886,7 @@ static struct my_tests_st my_tests[]= { { "test_bug14845", test_bug14845 }, { "test_opt_reconnect", test_opt_reconnect }, { "test_bug15510", test_bug15510}, +#if 0 #ifndef EMBEDDED_LIBRARY { "test_bug12744", test_bug12744 }, #endif @@ -20895,7 +20949,7 @@ static struct my_tests_st my_tests[]= { { "test_bug56976", test_bug56976 }, { "test_mdev3885", test_mdev3885 }, { "test_mdev4603", test_mdev4603 }, - { "test_bug11766854", test_bug11766854 }, + //{ "test_bug11766854", test_bug11766854 }, { "test_bug12337762", test_bug12337762 }, { "test_progress_reporting", test_progress_reporting }, { "test_bug11754979", test_bug11754979 }, @@ -20912,9 +20966,11 @@ static struct my_tests_st my_tests[]= { { "test_mdev14013", test_mdev14013 }, { "test_mdev14013_1", test_mdev14013_1 }, { "test_mdev14454", test_mdev14454 }, +#endif #ifndef EMBEDDED_LIBRARY - { "test_proxy_header", test_proxy_header}, + // { "test_proxy_header", test_proxy_header}, { "test_bulk_autoinc", test_bulk_autoinc}, + { "test_bulk_autoinc_all_id", test_bulk_autoinc_all_id }, #endif { "test_explain_meta", test_explain_meta }, { 0, 0 }
participants (1)
-
Oleksandr Byelkin