Commit 7d0d2d4f authored by unknown's avatar unknown

Fix 'n' concurrent prepared executions


sql/sql_prepare.cc:
  Fix 'n' concurrent executions
libmysql/errmsg.c:
  Fix the missing semicolon for errors
libmysql/libmysql.c:
  Fix the result meta info for non-SELECT statements
parent a8abb047
...@@ -59,7 +59,7 @@ const char *client_errors[]= ...@@ -59,7 +59,7 @@ const char *client_errors[]=
"No parameters exists in the statement", "No parameters exists in the statement",
"Invalid parameter number", "Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)", "Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)" "Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)", "Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)", "Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)", "Can't open shared memory. Answer event don't create (%lu)",
...@@ -114,7 +114,7 @@ const char *client_errors[]= ...@@ -114,7 +114,7 @@ const char *client_errors[]=
"No parameters exists in the statement", "No parameters exists in the statement",
"Invalid parameter number", "Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)", "Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)" "Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)", "Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)", "Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)", "Can't open shared memory. Answer event don't create (%lu)",
...@@ -167,7 +167,7 @@ const char *client_errors[]= ...@@ -167,7 +167,7 @@ const char *client_errors[]=
"No parameters exists in the statement", "No parameters exists in the statement",
"Invalid parameter number", "Invalid parameter number",
"Can't send long data for non string or binary data types (parameter: %d)", "Can't send long data for non string or binary data types (parameter: %d)",
"Using un supported parameter type: %d (parameter: %d)" "Using un supported buffer type: %d (parameter: %d)",
"Shared memory (%lu)", "Shared memory (%lu)",
"Can't open shared memory. Request event don't create (%lu)", "Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)", "Can't open shared memory. Answer event don't create (%lu)",
......
...@@ -3925,6 +3925,28 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) ...@@ -3925,6 +3925,28 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
DBUG_RETURN(stmt); DBUG_RETURN(stmt);
} }
/*
Get the execute query meta information for non-select
statements (on demand).
*/
unsigned int alloc_stmt_fields(MYSQL_STMT *stmt)
{
MYSQL_FIELD *fields;
if (!stmt->mysql->field_count)
return 0;
stmt->field_count= stmt->mysql->field_count;
fields= stmt->mysql->fields;
if (!(stmt->fields= (MYSQL_FIELD *) alloc_root(&stmt->mem_root,
sizeof(fields))) ||
!(stmt->bind= (MYSQL_BIND *) alloc_root(&stmt->mem_root,
sizeof(MYSQL_BIND ) * stmt->field_count)))
return 0;
memcpy((char *)stmt->fields, (char *)fields, sizeof(fields));
return stmt->field_count;
}
/* /*
Returns prepared meta information in the form of resultset Returns prepared meta information in the form of resultset
...@@ -3938,8 +3960,10 @@ mysql_prepare_result(MYSQL_STMT *stmt) ...@@ -3938,8 +3960,10 @@ mysql_prepare_result(MYSQL_STMT *stmt)
DBUG_ENTER("mysql_prepare_result"); DBUG_ENTER("mysql_prepare_result");
if (!stmt->field_count || !stmt->fields) if (!stmt->field_count || !stmt->fields)
{
if (!alloc_stmt_fields(stmt))
DBUG_RETURN(0); DBUG_RETURN(0);
}
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+ if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
sizeof(ulong)*stmt->field_count, sizeof(ulong)*stmt->field_count,
MYF(MY_WME | MY_ZEROFILL)))) MYF(MY_WME | MY_ZEROFILL))))
...@@ -4436,7 +4460,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4436,7 +4460,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
default: default:
sprintf(stmt->last_error, sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
param->buffer_type, param->param_number); param->buffer_type, count);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
...@@ -4984,6 +5008,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4984,6 +5008,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
{ {
MYSQL_BIND *param, *end; MYSQL_BIND *param, *end;
ulong bind_count; ulong bind_count;
uint param_count= 0;
DBUG_ENTER("mysql_bind_result"); DBUG_ENTER("mysql_bind_result");
DBUG_ASSERT(stmt != 0); DBUG_ASSERT(stmt != 0);
...@@ -4999,7 +5024,10 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4999,7 +5024,10 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
#endif #endif
bind_count= stmt->field_count; if (!(bind_count= stmt->field_count) &&
!(bind_count= alloc_stmt_fields(stmt)))
DBUG_RETURN(0);
memcpy((char*) stmt->bind, (char*) bind, memcpy((char*) stmt->bind, (char*) bind,
sizeof(MYSQL_BIND)*bind_count); sizeof(MYSQL_BIND)*bind_count);
...@@ -5015,6 +5043,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -5015,6 +5043,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
if (!param->length) if (!param->length)
param->length= &param->buffer_length; param->length= &param->buffer_length;
param->param_number= param_count++;
/* Setup data copy functions for the different supported types */ /* Setup data copy functions for the different supported types */
switch (param->buffer_type) { switch (param->buffer_type) {
case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY:
...@@ -5066,7 +5095,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -5066,7 +5095,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
default: default:
sprintf(stmt->last_error, sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE), ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
param->buffer_type, param->param_number); param->buffer_type, param_count);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
...@@ -5303,6 +5332,7 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list) ...@@ -5303,6 +5332,7 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list)
free_root(&stmt->mem_root, MYF(0)); free_root(&stmt->mem_root, MYF(0));
if (!skip_list) if (!skip_list)
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list); stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
stmt->mysql->status= MYSQL_STATUS_READY;
my_free((gptr) stmt, MYF(MY_WME)); my_free((gptr) stmt, MYF(MY_WME));
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
...@@ -327,6 +327,7 @@ public: ...@@ -327,6 +327,7 @@ public:
typedef struct st_prep_stmt typedef struct st_prep_stmt
{ {
THD *thd; THD *thd;
LEX lex;
Item_param **param; Item_param **param;
Item *free_list; Item *free_list;
MEM_ROOT mem_root; MEM_ROOT mem_root;
......
...@@ -684,6 +684,7 @@ static bool init_param_items(PREP_STMT *stmt) ...@@ -684,6 +684,7 @@ static bool init_param_items(PREP_STMT *stmt)
List<Item> &params= stmt->thd->lex.param_list; List<Item> &params= stmt->thd->lex.param_list;
Item_param **to; Item_param **to;
stmt->lex= stmt->thd->lex;
if (!stmt->param_count) if (!stmt->param_count)
stmt->param= (Item_param **)0; stmt->param= (Item_param **)0;
else else
...@@ -705,7 +706,7 @@ static bool init_param_items(PREP_STMT *stmt) ...@@ -705,7 +706,7 @@ static bool init_param_items(PREP_STMT *stmt)
static void init_stmt_execute(PREP_STMT *stmt) static void init_stmt_execute(PREP_STMT *stmt)
{ {
THD *thd= stmt->thd; THD *thd= stmt->thd;
TABLE_LIST *tables=(TABLE_LIST*) thd->lex.select_lex.table_list.first; TABLE_LIST *tables= (TABLE_LIST*) thd->lex.select_lex.table_list.first;
/* /*
TODO: When the new table structure is ready, then have a status bit TODO: When the new table structure is ready, then have a status bit
...@@ -713,7 +714,7 @@ static void init_stmt_execute(PREP_STMT *stmt) ...@@ -713,7 +714,7 @@ static void init_stmt_execute(PREP_STMT *stmt)
and open the tables back. and open the tables back.
*/ */
if (tables) if (tables)
tables->table=0; //safety - nasty init tables->table= 0; //safety - nasty init
} }
/* /*
...@@ -796,10 +797,8 @@ void mysql_stmt_execute(THD *thd, char *packet) ...@@ -796,10 +797,8 @@ void mysql_stmt_execute(THD *thd, char *packet)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
if (my_pthread_setspecific_ptr(THR_THD, stmt->thd) || LEX thd_lex= thd->lex;
my_pthread_setspecific_ptr(THR_MALLOC, &stmt->thd->mem_root)) thd->lex= stmt->lex;
DBUG_VOID_RETURN;
init_stmt_execute(stmt); init_stmt_execute(stmt);
if (stmt->param_count && setup_params_data(stmt)) if (stmt->param_count && setup_params_data(stmt))
...@@ -814,17 +813,14 @@ void mysql_stmt_execute(THD *thd, char *packet) ...@@ -814,17 +813,14 @@ void mysql_stmt_execute(THD *thd, char *packet)
mysql_delete(), mysql_update() and mysql_select() to not to mysql_delete(), mysql_update() and mysql_select() to not to
have re-check on setup_* and other things .. have re-check on setup_* and other things ..
*/ */
THD *cur_thd= stmt->thd; thd->protocol= &thd->protocol_prep; // Switch to binary protocol
cur_thd->protocol= &cur_thd->protocol_prep; // Switch to binary protocol mysql_execute_command(thd);
mysql_execute_command(cur_thd); thd->protocol= &thd->protocol_simple; // Use normal protocol
cur_thd->protocol= &cur_thd->protocol_simple; // Use normal protocol
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR); my_pthread_setprio(pthread_self(), WAIT_PRIOR);
my_pthread_setspecific_ptr(THR_THD, thd); thd->lex= thd_lex;
my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment