summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc42
1 files changed, 31 insertions, 11 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 4abbbcaff1f..0ea3132eabc 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -77,7 +77,7 @@ Long data handling:
#define STMT_QUERY_LOG_LENGTH 8192
extern int yyparse(void *thd);
-static String null_string("NULL", 4, default_charset_info);
+String null_string("NULL", 4, default_charset_info);
/*
Find prepared statement in thd
@@ -142,6 +142,7 @@ void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
Send prepared stmt info to client after prepare
*/
+#ifndef EMBEDDED_LIBRARY
static bool send_prep_stmt(PREP_STMT *stmt, uint columns)
{
NET *net=&stmt->thd->net;
@@ -150,14 +151,21 @@ static bool send_prep_stmt(PREP_STMT *stmt, uint columns)
int4store(buff+1, stmt->stmt_id);
int2store(buff+5, columns);
int2store(buff+7, stmt->param_count);
-#ifndef EMBEDDED_LIBRARY
/* This should be fixed to work with prepared statements
*/
return (my_net_write(net, buff, sizeof(buff)) || net_flush(net));
+}
#else
- return true;
-#endif
+static bool send_prep_stmt(PREP_STMT *stmt, uint columns __attribute__((unused)))
+{
+ THD *thd= stmt->thd;
+
+ thd->client_stmt_id= stmt->stmt_id;
+ thd->client_param_count= stmt->param_count;
+
+ return 0;
}
+#endif /*!EMBEDDED_LIBRAYR*/
/*
Send information about all item parameters
@@ -345,7 +353,7 @@ static void setup_param_str(Item_param *param, uchar **pos)
*pos+= len;
}
-static void setup_param_functions(Item_param *param, uchar param_type)
+void setup_param_functions(Item_param *param, uchar param_type)
{
switch (param_type) {
case FIELD_TYPE_TINY:
@@ -391,6 +399,7 @@ static void setup_param_functions(Item_param *param, uchar param_type)
}
}
+#ifndef EMBEDDED_LIBRARY
/*
Update the parameter markers by reading data from client packet
and if binary/update log is set, generate the valid query.
@@ -476,11 +485,7 @@ static bool setup_params_data(PREP_STMT *stmt)
Item_param *param;
DBUG_ENTER("setup_params_data");
-#ifndef EMBEDDED_LIBRARY
uchar *pos=(uchar*) thd->net.read_pos+1+MYSQL_STMT_HEADER; //skip header
-#else
- uchar *pos= 0; //just to compile TODO code for embedded case
-#endif
uchar *read_pos= pos+(stmt->param_count+7) / 8; //skip null bits
if (*read_pos++) //types supplied / first execute
@@ -500,6 +505,8 @@ static bool setup_params_data(PREP_STMT *stmt)
DBUG_RETURN(0);
}
+#endif /*!EMBEDDED_LIBRARY*/
+
/*
Validate the following information for INSERT statement:
- field existance
@@ -659,13 +666,13 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
wild_num, conds, og_num, order, group, having, proc,
select_lex, unit, 0))
DBUG_RETURN(1);
-#ifndef EMBEDDED_LIBRARY
if (send_prep_stmt(stmt, fields.elements) ||
thd->protocol_simple.send_fields(&fields, 0) ||
+#ifndef EMBEDDED_LIBRARY
net_flush(&thd->net) ||
+#endif
send_item_params(stmt))
DBUG_RETURN(1);
-#endif
join->cleanup();
}
DBUG_RETURN(0);
@@ -784,10 +791,18 @@ static bool init_param_items(PREP_STMT *stmt)
if (mysql_bin_log.is_open() || mysql_update_log.is_open())
{
stmt->log_full_query= 1;
+#ifndef EMBEDDED_LIBRARY
stmt->setup_params= insert_params_withlog;
+#else
+ stmt->setup_params_data= setup_params_data_withlog;
+#endif
}
else
+#ifndef EMBEDDED_LIBRARY
stmt->setup_params= insert_params; // not fully qualified query
+#else
+ stmt->setup_params_data= setup_params_data;
+#endif
if (!stmt->param_count)
stmt->param= (Item_param **)0;
@@ -941,8 +956,13 @@ void mysql_stmt_execute(THD *thd, char *packet)
}
init_stmt_execute(stmt);
+#ifndef EMBEDDED_LIBRARY
if (stmt->param_count && setup_params_data(stmt))
DBUG_VOID_RETURN;
+#else
+ if (stmt->param_count && (*stmt->setup_params_data)(stmt))
+ DBUG_VOID_RETURN;
+#endif
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);