summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmysql/errmsg.c6
-rw-r--r--libmysql/libmysql.c40
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_prepare.cc22
4 files changed, 48 insertions, 21 deletions
diff --git a/libmysql/errmsg.c b/libmysql/errmsg.c
index 2eecb5c2afd..ea11a7b6120 100644
--- a/libmysql/errmsg.c
+++ b/libmysql/errmsg.c
@@ -59,7 +59,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"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)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
@@ -114,7 +114,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"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)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
@@ -167,7 +167,7 @@ const char *client_errors[]=
"No parameters exists in the statement",
"Invalid parameter number",
"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)",
"Can't open shared memory. Request event don't create (%lu)",
"Can't open shared memory. Answer event don't create (%lu)",
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 5825c055305..08011c376fb 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -3925,6 +3925,28 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
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
@@ -3938,8 +3960,10 @@ mysql_prepare_result(MYSQL_STMT *stmt)
DBUG_ENTER("mysql_prepare_result");
if (!stmt->field_count || !stmt->fields)
- DBUG_RETURN(0);
-
+ {
+ if (!alloc_stmt_fields(stmt))
+ DBUG_RETURN(0);
+ }
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
sizeof(ulong)*stmt->field_count,
MYF(MY_WME | MY_ZEROFILL))))
@@ -4436,7 +4460,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
default:
sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
- param->buffer_type, param->param_number);
+ param->buffer_type, count);
DBUG_RETURN(1);
}
}
@@ -4984,6 +5008,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
{
MYSQL_BIND *param, *end;
ulong bind_count;
+ uint param_count= 0;
DBUG_ENTER("mysql_bind_result");
DBUG_ASSERT(stmt != 0);
@@ -4999,7 +5024,10 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1);
}
#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,
sizeof(MYSQL_BIND)*bind_count);
@@ -5015,6 +5043,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
if (!param->length)
param->length= &param->buffer_length;
+ param->param_number= param_count++;
/* Setup data copy functions for the different supported types */
switch (param->buffer_type) {
case MYSQL_TYPE_TINY:
@@ -5066,7 +5095,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
default:
sprintf(stmt->last_error,
ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
- param->buffer_type, param->param_number);
+ param->buffer_type, param_count);
DBUG_RETURN(1);
}
}
@@ -5303,6 +5332,7 @@ static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list)
free_root(&stmt->mem_root, MYF(0));
if (!skip_list)
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
+ stmt->mysql->status= MYSQL_STATUS_READY;
my_free((gptr) stmt, MYF(MY_WME));
DBUG_RETURN(error);
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 216720da801..73264ae14da 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -327,6 +327,7 @@ public:
typedef struct st_prep_stmt
{
THD *thd;
+ LEX lex;
Item_param **param;
Item *free_list;
MEM_ROOT mem_root;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 820a153f855..775ecf17fb2 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -684,6 +684,7 @@ static bool init_param_items(PREP_STMT *stmt)
List<Item> &params= stmt->thd->lex.param_list;
Item_param **to;
+ stmt->lex= stmt->thd->lex;
if (!stmt->param_count)
stmt->param= (Item_param **)0;
else
@@ -705,7 +706,7 @@ static bool init_param_items(PREP_STMT *stmt)
static void init_stmt_execute(PREP_STMT *stmt)
{
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
@@ -713,7 +714,7 @@ static void init_stmt_execute(PREP_STMT *stmt)
and open the tables back.
*/
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)
DBUG_VOID_RETURN;
}
- if (my_pthread_setspecific_ptr(THR_THD, stmt->thd) ||
- my_pthread_setspecific_ptr(THR_MALLOC, &stmt->thd->mem_root))
- DBUG_VOID_RETURN;
-
+ LEX thd_lex= thd->lex;
+ thd->lex= stmt->lex;
init_stmt_execute(stmt);
if (stmt->param_count && setup_params_data(stmt))
@@ -814,17 +813,14 @@ void mysql_stmt_execute(THD *thd, char *packet)
mysql_delete(), mysql_update() and mysql_select() to not to
have re-check on setup_* and other things ..
*/
- THD *cur_thd= stmt->thd;
- cur_thd->protocol= &cur_thd->protocol_prep; // Switch to binary protocol
- mysql_execute_command(cur_thd);
- cur_thd->protocol= &cur_thd->protocol_simple; // Use normal protocol
+ thd->protocol= &thd->protocol_prep; // Switch to binary protocol
+ mysql_execute_command(thd);
+ thd->protocol= &thd->protocol_simple; // Use normal protocol
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);
- my_pthread_setspecific_ptr(THR_THD, thd);
- my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root);
-
+ thd->lex= thd_lex;
DBUG_VOID_RETURN;
}