summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorhf@deer.mysql.r18.ru <>2003-01-15 13:15:35 +0400
committerhf@deer.mysql.r18.ru <>2003-01-15 13:15:35 +0400
commit96089e2b3a013c83e812672284bf10a34ba9d11c (patch)
tree937beb6f27e5e7958081a4a5ba13ceb2f5251396 /sql/sql_prepare.cc
parentc59bff7c96bf90c9c4dafdb80684fb438bb43734 (diff)
parent809af00b0672242cc1b0fee114a34f414ec9055a (diff)
downloadmariadb-git-96089e2b3a013c83e812672284bf10a34ba9d11c.tar.gz
resolving conflicts
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc59
1 files changed, 43 insertions, 16 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index fde81ad9044..3a5bf8ebaad 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -331,9 +331,12 @@ static bool setup_params_data(PREP_STMT *stmt)
if (!param->long_data_supplied)
{
if (IS_PARAM_NULL(pos,param_no))
- param->maybe_null=param->null_value=1;
+ param->maybe_null= param->null_value= 1;
else
+ {
+ param->maybe_null= param->null_value= 0;
param->setup_param_func(param,&read_pos);
+ }
}
param_no++;
}
@@ -450,10 +453,9 @@ static bool mysql_test_upd_fields(PREP_STMT *stmt, TABLE_LIST *table_list,
COND *conds)
{
THD *thd= stmt->thd;
- TABLE *table;
DBUG_ENTER("mysql_test_upd_fields");
- if (!(table = open_ltable(thd,table_list,table_list->lock_type)))
+ if (open_and_lock_tables(thd, table_list))
DBUG_RETURN(1);
if (setup_tables(table_list) || setup_fields(thd,table_list,fields,1,0,0) ||
@@ -487,13 +489,12 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
COND *conds, ORDER *order, ORDER *group,
Item *having)
{
- TABLE *table;
bool hidden_group_fields;
THD *thd= stmt->thd;
List<Item> all_fields(fields);
DBUG_ENTER("mysql_test_select_fields");
- if (!(table = open_ltable(thd,tables,TL_READ)))
+ if (open_and_lock_tables(thd, tables))
DBUG_RETURN(1);
thd->used_tables=0; // Updated by setup_fields
@@ -522,7 +523,7 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
sending any info on where clause.
*/
if (send_prep_stmt(stmt, fields.elements) ||
- thd->protocol_prep.send_fields(&fields,0) ||
+ thd->protocol_simple.send_fields(&fields,0) ||
send_item_params(stmt))
DBUG_RETURN(1);
DBUG_RETURN(0);
@@ -636,19 +637,40 @@ static bool parse_prepare_query(PREP_STMT *stmt,
/*
Initialize parameter items in statement
*/
-static bool init_param_items(THD *thd, PREP_STMT *stmt)
+
+static bool init_param_items(PREP_STMT *stmt)
{
+ List<Item> &params= stmt->thd->lex.param_list;
Item_param **to;
+
if (!(stmt->param= to= (Item_param **)
my_malloc(sizeof(Item_param *)*(stmt->param_count+1),
MYF(MY_WME))))
return 1;
- List_iterator<Item> param_iterator(thd->lex.param_list);
+ List_iterator<Item> param_iterator(params);
while ((*(to++) = (Item_param *)param_iterator++));
return 0;
}
/*
+ Initialize stmt execution
+*/
+
+static void init_stmt_execute(PREP_STMT *stmt)
+{
+ THD *thd= stmt->thd;
+ 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
+ to indicate the table is altered, and re-do the setup_*
+ and open the tables back.
+ */
+ if (tables)
+ tables->table=0; //safety - nasty init
+}
+
+/*
Parse the query and send the total number of parameters
and resultset metadata information back to client (if any),
without executing the query i.e. with out any log/disk
@@ -669,29 +691,32 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
DBUG_ENTER("mysql_stmt_prepare");
bzero((char*) &stmt, sizeof(stmt));
- stmt.thd= thd;
+
stmt.stmt_id= ++thd->current_stmt_id;
init_sql_alloc(&stmt.mem_root, 8192, 8192);
+
+ stmt.thd= thd;
+ stmt.thd->mem_root= stmt.mem_root;
- thd->mem_root= stmt.mem_root;
- if (alloc_query(thd, packet, packet_length))
+ if (alloc_query(stmt.thd, packet, packet_length))
goto err;
+
if (parse_prepare_query(&stmt, thd->query, thd->query_length))
goto err;
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR);
- if (init_param_items(thd, &stmt))
+ if (init_param_items(&stmt))
goto err;
- stmt.mem_root= thd->mem_root;
+ stmt.mem_root= stmt.thd->mem_root;
tree_insert(&thd->prepared_statements, (void *)&stmt, 0, (void *)0);
thd->mem_root= thd_root; // restore main mem_root
DBUG_RETURN(0);
err:
- stmt.mem_root= thd->mem_root;
+ stmt.mem_root= stmt.thd->mem_root;
free_prep_stmt(&stmt, free_free, (void*) 0);
thd->mem_root = thd_root; // restore main mem_root
DBUG_RETURN(1);
@@ -725,6 +750,8 @@ void mysql_stmt_execute(THD *thd, char *packet)
DBUG_VOID_RETURN;
}
+ init_stmt_execute(stmt);
+
if (stmt->param_count && setup_params_data(stmt))
DBUG_VOID_RETURN;
@@ -737,9 +764,9 @@ 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->protocol= &thd->protocol_prep; // Switch to binary protocol
+ stmt->thd->protocol= &thd->protocol_prep; // Switch to binary protocol
mysql_execute_command(stmt->thd);
- thd->protocol= &thd->protocol_simple; // Use normal protocol
+ stmt->thd->protocol= &thd->protocol_simple; // Use normal protocol
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);