Commit a9aebd43 authored by venu@myvenu.com's avatar venu@myvenu.com

protocol merge

parents 1c8e36d5 b74c43f4
...@@ -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 not supported parameter type: %d (parameter: %d)" "Using un supported parameter 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)",
...@@ -113,7 +113,7 @@ const char *client_errors[]= ...@@ -113,7 +113,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 not supported parameter type: %d (parameter: %d)" "Using un supported parameter 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)",
...@@ -165,7 +165,7 @@ const char *client_errors[]= ...@@ -165,7 +165,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 not supported parameter type: %d (parameter: %d)" "Using un supported parameter 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)",
......
...@@ -242,7 +242,7 @@ my_bool my_connect(my_socket s, const struct sockaddr *name, ...@@ -242,7 +242,7 @@ my_bool my_connect(my_socket s, const struct sockaddr *name,
{ {
tv.tv_sec = (long) timeout; tv.tv_sec = (long) timeout;
tv.tv_usec = 0; tv.tv_usec = 0;
#if defined(HPUX10) && defined(THREAD) #if defined(HPUX) && defined(THREAD)
if ((res = select(s+1, NULL, (int*) &sfds, NULL, &tv)) >= 0) if ((res = select(s+1, NULL, (int*) &sfds, NULL, &tv)) >= 0)
break; break;
#else #else
...@@ -927,7 +927,8 @@ static const char *default_options[]= ...@@ -927,7 +927,8 @@ static const char *default_options[]=
"character-sets-dir", "default-character-set", "interactive-timeout", "character-sets-dir", "default-character-set", "interactive-timeout",
"connect-timeout", "local-infile", "disable-local-infile", "connect-timeout", "local-infile", "disable-local-infile",
"replication-probe", "enable-reads-from-master", "repl-parse-query", "replication-probe", "enable-reads-from-master", "repl-parse-query",
"ssl-cipher","protocol", "shared_memory_base_name", "ssl-cipher","protocol",
"shared_memory_base_name",
NullS NullS
}; };
...@@ -1736,11 +1737,10 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , ...@@ -1736,11 +1737,10 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
Free strings in the SSL structure and clear 'use_ssl' flag. Free strings in the SSL structure and clear 'use_ssl' flag.
NB! Errors are not reported until you do mysql_real_connect. NB! Errors are not reported until you do mysql_real_connect.
**************************************************************************/ **************************************************************************/
static void static void
mysql_ssl_free(MYSQL *mysql __attribute__((unused))) mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
{ {
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSLL
my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR));
my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR));
...@@ -1754,7 +1754,7 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused))) ...@@ -1754,7 +1754,7 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
mysql->options.ssl_cipher= 0; mysql->options.ssl_cipher= 0;
mysql->options.use_ssl = FALSE; mysql->options.use_ssl = FALSE;
mysql->connector_fd = 0; mysql->connector_fd = 0;
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSLL */
} }
/************************************************************************** /**************************************************************************
...@@ -1807,7 +1807,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1807,7 +1807,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
#endif #endif
init_sigpipe_variables init_sigpipe_variables
DBUG_ENTER("mysql_real_connect"); DBUG_ENTER("mysql_real_connect");
LINT_INIT(host_info);
DBUG_PRINT("enter",("host: %s db: %s user: %s", DBUG_PRINT("enter",("host: %s db: %s user: %s",
host ? host : "(Null)", host ? host : "(Null)",
...@@ -2189,18 +2188,15 @@ Try also with PIPE or TCP/IP ...@@ -2189,18 +2188,15 @@ Try also with PIPE or TCP/IP
options->ssl_capath, options->ssl_capath,
options->ssl_cipher))) options->ssl_cipher)))
{ {
net->last_errno= CR_SSL_CONNECTION_ERROR; /* TODO: Change to SSL error */
net->last_errno= CR_SERVER_LOST;
strmov(net->last_error,ER(net->last_errno)); strmov(net->last_error,ER(net->last_errno));
goto error; goto error;
} }
DBUG_PRINT("info", ("IO layer change in progress...")); DBUG_PRINT("info", ("IO layer change in progress..."));
if(sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd), /* TODO: Add proper error checking here, with return error message */
mysql->net.vio, (long) (mysql->options.connect_timeout))) sslconnect((struct st_VioSSLConnectorFd*)(mysql->connector_fd),
{ mysql->net.vio, (long) (mysql->options.connect_timeout));
net->last_errno= CR_SSL_CONNECTION_ERROR;
strmov(net->last_error,ER(net->last_errno));
goto error;
}
DBUG_PRINT("info", ("IO layer change done!")); DBUG_PRINT("info", ("IO layer change done!"));
} }
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
...@@ -2571,7 +2567,7 @@ my_bool STDCALL mysql_read_query_result(MYSQL *mysql) ...@@ -2571,7 +2567,7 @@ my_bool STDCALL mysql_read_query_result(MYSQL *mysql)
{ {
mysql->affected_rows= net_field_length_ll(&pos); mysql->affected_rows= net_field_length_ll(&pos);
mysql->insert_id= net_field_length_ll(&pos); mysql->insert_id= net_field_length_ll(&pos);
if (mysql->server_capabilities & CLIENT_PROTOCOL_41) if (protocol_41(mysql))
{ {
mysql->server_status=uint2korr(pos); pos+=2; mysql->server_status=uint2korr(pos); pos+=2;
mysql->warning_count=uint2korr(pos); pos+=2; mysql->warning_count=uint2korr(pos); pos+=2;
...@@ -3654,10 +3650,10 @@ MYSQL_STMT *STDCALL ...@@ -3654,10 +3650,10 @@ MYSQL_STMT *STDCALL
mysql_prepare(MYSQL *mysql, const char *query, ulong length) mysql_prepare(MYSQL *mysql, const char *query, ulong length)
{ {
MYSQL_STMT *stmt; MYSQL_STMT *stmt;
DBUG_ENTER("mysql_real_prepare"); DBUG_ENTER("mysql_prepare");
DBUG_ASSERT(mysql != 0); DBUG_ASSERT(mysql != 0);
#ifdef EXTRA_CHECK_ARGUMENTS #ifdef CHECK_EXTRA_ARGUMENTS
if (!query) if (!query)
{ {
set_mysql_error(mysql, CR_NULL_POINTER); set_mysql_error(mysql, CR_NULL_POINTER);
...@@ -3678,7 +3674,6 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) ...@@ -3678,7 +3674,6 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
stmt->state= MY_ST_PREPARE;
init_alloc_root(&stmt->mem_root,8192,0); init_alloc_root(&stmt->mem_root,8192,0);
if (read_prepare_result(mysql, stmt)) if (read_prepare_result(mysql, stmt))
...@@ -3686,8 +3681,8 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length) ...@@ -3686,8 +3681,8 @@ mysql_prepare(MYSQL *mysql, const char *query, ulong length)
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
stmt->state= MY_ST_PREPARE;
stmt->mysql= mysql; stmt->mysql= mysql;
DBUG_PRINT("info", ("Parameter count: %ld", stmt->param_count)); DBUG_PRINT("info", ("Parameter count: %ld", stmt->param_count));
DBUG_RETURN(stmt); DBUG_RETURN(stmt);
} }
...@@ -3823,7 +3818,7 @@ static void store_param_str(NET *net, MYSQL_BIND *param) ...@@ -3823,7 +3818,7 @@ static void store_param_str(NET *net, MYSQL_BIND *param)
ulong length= *param->length; ulong length= *param->length;
char *to= (char *) net_store_length((char *) net->write_pos, length); char *to= (char *) net_store_length((char *) net->write_pos, length);
memcpy(to, param->buffer, length); memcpy(to, param->buffer, length);
net->write_pos+= length; net->write_pos= to+length;
} }
...@@ -3857,17 +3852,19 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param) ...@@ -3857,17 +3852,19 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
MYSQL *mysql= stmt->mysql; MYSQL *mysql= stmt->mysql;
NET *net = &mysql->net; NET *net = &mysql->net;
DBUG_ENTER("store_param"); DBUG_ENTER("store_param");
DBUG_PRINT("enter",("type : %d, buffer :%lx", param->buffer_type, DBUG_PRINT("enter",("type: %d, buffer:%lx, length: %d", param->buffer_type,
param->buffer)); param->buffer ? param->buffer : "0", *param->length));
/* Allocate for worst case (long string) */ if (param->is_null || param->buffer_type == MYSQL_TYPE_NULL)
if ((my_realloc_str(net, 9 + *param->length)))
return 1;
if (!param->buffer)
store_param_null(net, param); store_param_null(net, param);
else else
{
/* Allocate for worst case (long string) */
if ((my_realloc_str(net, 9 + *param->length)))
DBUG_RETURN(1);
(*param->store_param_func)(net, param); (*param->store_param_func)(net, param);
DBUG_RETURN(1); }
DBUG_RETURN(0);
} }
...@@ -3879,13 +3876,13 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length) ...@@ -3879,13 +3876,13 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
{ {
MYSQL *mysql= stmt->mysql; MYSQL *mysql= stmt->mysql;
NET *net= &mysql->net; NET *net= &mysql->net;
char buff[4]; char buff[MYSQL_STMT_HEADER];
DBUG_ENTER("execute"); DBUG_ENTER("execute");
DBUG_PRINT("enter",("packet: %s, length :%d",packet ? packet :" ", length)); DBUG_PRINT("enter",("packet: %s, length :%d",packet ? packet :" ", length));
mysql->last_used_con= mysql; mysql->last_used_con= mysql;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */ int4store(buff, stmt->stmt_id); /* Send stmt id to server */
if (advanced_command(mysql, COM_EXECUTE, buff, sizeof(buff), packet, if (advanced_command(mysql, COM_EXECUTE, buff, MYSQL_STMT_HEADER, packet,
length, 1) || length, 1) ||
mysql_read_query_result(mysql)) mysql_read_query_result(mysql))
{ {
...@@ -3893,12 +3890,14 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length) ...@@ -3893,12 +3890,14 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
stmt->state= MY_ST_EXECUTE; stmt->state= MY_ST_EXECUTE;
mysql_free_result(stmt->result);
if (stmt->bind) #if USED_IN_FETCH
if (stmt->res_buffers) /* Result buffers exists, cache results */
{ {
mysql_free_result(stmt->result); mysql_free_result(stmt->result);
stmt->result= mysql_store_result(mysql); stmt->result= mysql_store_result(mysql);
} }
#endif
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -3909,8 +3908,6 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length) ...@@ -3909,8 +3908,6 @@ static my_bool execute(MYSQL_STMT * stmt, char *packet, ulong length)
int STDCALL mysql_execute(MYSQL_STMT *stmt) int STDCALL mysql_execute(MYSQL_STMT *stmt)
{ {
ulong length;
uint null_count;
DBUG_ENTER("mysql_execute"); DBUG_ENTER("mysql_execute");
if (stmt->state == MY_ST_UNKNOWN) if (stmt->state == MY_ST_UNKNOWN)
...@@ -3924,14 +3921,18 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) ...@@ -3924,14 +3921,18 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
NET *net= &stmt->mysql->net; NET *net= &stmt->mysql->net;
MYSQL_BIND *param, *param_end; MYSQL_BIND *param, *param_end;
char *param_data; char *param_data;
my_bool result; ulong length;
uint null_count;
my_bool result;
if (!stmt->params) #ifdef CHECK_EXTRA_ARGUMENTS
if (!stmt->param_buffers)
{ {
/* Parameters exists, but no bound buffers */ /* Parameters exists, but no bound buffers */
set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND); set_stmt_error(stmt, CR_NOT_ALL_PARAMS_BOUND);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
#endif
net_clear(net); /* Sets net->write_pos */ net_clear(net); /* Sets net->write_pos */
/* Reserve place for null-marker bytes */ /* Reserve place for null-marker bytes */
null_count= (stmt->param_count+7) /8; null_count= (stmt->param_count+7) /8;
...@@ -3940,10 +3941,9 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) ...@@ -3940,10 +3941,9 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
param_end= stmt->params + stmt->param_count; param_end= stmt->params + stmt->param_count;
/* In case if buffers (type) altered, indicate to server */ /* In case if buffers (type) altered, indicate to server */
*(net->write_pos)++= (uchar) stmt->types_supplied; *(net->write_pos)++= (uchar) stmt->send_types_to_server;
if (!stmt->types_supplied) if (stmt->send_types_to_server)
{ {
stmt->types_supplied=1;
/* /*
Store types of parameters in first in first package Store types of parameters in first in first package
that is sent to the server. that is sent to the server.
...@@ -3957,21 +3957,22 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt) ...@@ -3957,21 +3957,22 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
/* Check for long data which has not been propery given/terminated */ /* Check for long data which has not been propery given/terminated */
if (param->is_long_data) if (param->is_long_data)
{ {
if (!param->long_ended) if (!param->long_ended)
DBUG_RETURN(MYSQL_NEED_DATA); DBUG_RETURN(MYSQL_NEED_DATA);
} }
else if (store_param(stmt, param)) else if (store_param(stmt, param))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
length= (ulong) (net->write_pos - net->buff); length= (ulong) (net->write_pos - net->buff);
/* TODO: Look into avoding the following memdup */ /* TODO: Look into avoding the following memdup */
if (!(param_data= my_memdup((byte *) net->buff, length, MYF(0)))) if (!(param_data= my_memdup( net->buff, length, MYF(0))))
{ {
set_stmt_error(stmt, CR_OUT_OF_MEMORY); set_stmt_error(stmt, CR_OUT_OF_MEMORY);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
net->write_pos= net->buff; /* Reset for net_write() */ net->write_pos= net->buff; /* Reset for net_write() */
result= execute(stmt, param_data, length); result= execute(stmt, param_data, length);
stmt->send_types_to_server=0;
my_free(param_data, MYF(MY_WME)); my_free(param_data, MYF(MY_WME));
DBUG_RETURN(result); DBUG_RETURN(result);
} }
...@@ -4034,15 +4035,19 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4034,15 +4035,19 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
param->param_number); param->param_number);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
/* /*
If param->length is not given, change it to point to bind_length. If param->length is not given, change it to point to bind_length.
This way we can always use *param->length to get the length of data This way we can always use *param->length to get the length of data
*/ */
if (!param->length) if (!param->length)
param->length= &param->bind_length; param->length= &param->bind_length;
/* 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_NULL:
param->is_null=1;
break;
case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY:
param->bind_length= 1; param->bind_length= 1;
param->store_param_func= store_param_tinyint; param->store_param_func= store_param_tinyint;
...@@ -4064,12 +4069,13 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4064,12 +4069,13 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
param->store_param_func= store_param_float; param->store_param_func= store_param_float;
break; break;
case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_DOUBLE:
param->bind_length= 4; param->bind_length= 8;
param->store_param_func= store_param_double; param->store_param_func= store_param_double;
break; break;
case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING: case MYSQL_TYPE_STRING:
param->bind_length= param->buffer_length; param->bind_length= param->buffer_length;
...@@ -4082,7 +4088,8 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4082,7 +4088,8 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
} }
} }
/* We have to send/resendtype information to MySQL */ /* We have to send/resendtype information to MySQL */
stmt->types_supplied= 0; stmt->send_types_to_server= 1;
stmt->param_buffers= 1;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -4156,6 +4163,73 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number, ...@@ -4156,6 +4163,73 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
Fetch-bind related implementations Fetch-bind related implementations
*********************************************************************/ *********************************************************************/
/****************************************************************************
Functions to fetch data to application buffers
All functions has the following characteristics:
SYNOPSIS
fetch_result_xxx()
param MySQL bind param
row Row value
RETURN VALUES
0 ok
1 Error (Can't alloc net->buffer)
****************************************************************************/
static void fetch_result_tinyint(MYSQL_BIND *param, uchar **row)
{
*param->buffer= (uchar) **row;
*row++;
}
static void fetch_result_short(MYSQL_BIND *param, uchar **row)
{
short value= *(short *)row;
int2store(param->buffer, value);
*row+=2;
}
static void fetch_result_int32(MYSQL_BIND *param, uchar **row)
{
int32 value= *(int32 *)row;
int4store(param->buffer, value);
*row+=4;
}
static void fetch_result_int64(MYSQL_BIND *param, uchar **row)
{
longlong value= *(longlong *)row;
int8store(param->buffer, value);
*row+=8;
}
static void fetch_result_float(MYSQL_BIND *param, uchar **row)
{
float value;
float4get(value,*row);
float4store(param->buffer, *row);
*row+=4;
}
static void fetch_result_double(MYSQL_BIND *param, uchar **row)
{
double value;
float8get(value,*row);
float8store(param->buffer, value);
*row+=8;
}
static void fetch_result_str(MYSQL_BIND *param, uchar **row)
{
ulong length= net_field_length(row);
memcpy(param->buffer, (char *)*row, length);
*param->length= length;
*row+=length;
}
/* /*
Setup the bind buffers for resultset processing Setup the bind buffers for resultset processing
*/ */
...@@ -4167,21 +4241,62 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4167,21 +4241,62 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_ENTER("mysql_bind_result"); DBUG_ENTER("mysql_bind_result");
DBUG_ASSERT(stmt != 0); DBUG_ASSERT(stmt != 0);
#ifdef EXTRA_CHECK_ARGUMENTS #ifdef CHECK_EXTRA_ARGUMENTS
if (!bind) if (!bind)
{ {
set_stmt_error(stmt, CR_NULL_POINTER); set_stmt_error(stmt, CR_NULL_POINTER);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
#endif #endif
bind_count= stmt->result->field_count; bind_count= stmt->field_count;
memcpy((char*) stmt->bind, (char*) bind, memcpy((char*) stmt->bind, (char*) bind,
sizeof(MYSQL_BIND)*bind_count); sizeof(MYSQL_BIND)*bind_count);
for (param= stmt->bind, end= param+bind_count; param < end ; param++) for (param= stmt->bind, end= param+bind_count; param < end ; param++)
{ {
/* TODO: Set up convert functions like in mysql_bind_param */ /* Setup data copy functions for the different supported types */
switch (param->buffer_type) {
case MYSQL_TYPE_TINY:
param->bind_length= 1;
param->fetch_result= fetch_result_tinyint;
break;
case MYSQL_TYPE_SHORT:
param->bind_length= 2;
param->fetch_result= fetch_result_short;
break;
case MYSQL_TYPE_LONG:
param->bind_length= 4;
param->fetch_result= fetch_result_int32;
break;
case MYSQL_TYPE_LONGLONG:
param->bind_length= 8;
param->fetch_result= fetch_result_int64;
break;
case MYSQL_TYPE_FLOAT:
param->bind_length= 4;
param->fetch_result= fetch_result_float;
break;
case MYSQL_TYPE_DOUBLE:
param->bind_length= 8;
param->fetch_result= fetch_result_double;
break;
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
param->length= &param->buffer_length;
param->fetch_result= fetch_result_str;
break;
default:
sprintf(stmt->last_error, ER(stmt->last_errno= CR_UNSUPPORTED_PARAM_TYPE),
param->buffer_type, param->param_number);
DBUG_RETURN(1);
}
if (!param->length)
param->length= &param->bind_length;
} }
stmt->res_buffers= 1;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -4191,16 +4306,16 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4191,16 +4306,16 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
*/ */
static my_bool static my_bool
my_fetch_row(MYSQL_STMT *stmt, MYSQL_RES *result, const byte *row) stmt_fetch_row(MYSQL_STMT *stmt, uchar **row)
{ {
MYSQL_BIND *bind, *end; MYSQL_BIND *bind, *end;
uchar *null_ptr= (uchar*) row, bit; uchar *null_ptr= (uchar*) *row, bit;
result->row_count++; *row+= (stmt->field_count+7)/8;
row+= (result->field_count+7)/8;
/* Copy complete row to application buffers */
bit=1; bit=1;
for (bind= stmt->bind, end= (MYSQL_BIND *) bind + result->field_count;
/* Copy complete row to application buffers */
for (bind= stmt->bind, end= (MYSQL_BIND *) bind + stmt->field_count;
bind < end; bind < end;
bind++) bind++)
{ {
...@@ -4209,7 +4324,7 @@ my_fetch_row(MYSQL_STMT *stmt, MYSQL_RES *result, const byte *row) ...@@ -4209,7 +4324,7 @@ my_fetch_row(MYSQL_STMT *stmt, MYSQL_RES *result, const byte *row)
else else
{ {
bind->is_null= 0; bind->is_null= 0;
row= (byte*) (*bind->fetch_result)(bind, (char*) row); (*bind->fetch_result)(bind, row);
} }
if (! (bit<<=1) & 255) if (! (bit<<=1) & 255)
{ {
...@@ -4220,12 +4335,9 @@ my_fetch_row(MYSQL_STMT *stmt, MYSQL_RES *result, const byte *row) ...@@ -4220,12 +4335,9 @@ my_fetch_row(MYSQL_STMT *stmt, MYSQL_RES *result, const byte *row)
return 0; return 0;
} }
static int read_binary_data(MYSQL *mysql)
static int {
read_binary_data(MYSQL *mysql) if (packet_error == net_safe_read(mysql))
{
ulong pkt_len;
if ((pkt_len= net_safe_read(mysql)) == packet_error)
return -1; return -1;
if (mysql->net.read_pos[0]) if (mysql->net.read_pos[0])
return 1; /* End of data */ return 1; /* End of data */
...@@ -4239,57 +4351,30 @@ read_binary_data(MYSQL *mysql) ...@@ -4239,57 +4351,30 @@ read_binary_data(MYSQL *mysql)
int STDCALL mysql_fetch(MYSQL_STMT *stmt) int STDCALL mysql_fetch(MYSQL_STMT *stmt)
{ {
MYSQL_RES *result; MYSQL *mysql= stmt->mysql;
DBUG_ENTER("mysql_fetch"); DBUG_ENTER("mysql_fetch");
result= stmt->result; if (stmt->res_buffers)
if (!result)
DBUG_RETURN(MYSQL_NO_DATA);
if (!result->data)
{ {
MYSQL *mysql= stmt->mysql; int res;
if (!result->eof) if (!(res= read_binary_data(mysql)))
{ {
int res; if (stmt->res_buffers)
if (!(res= read_binary_data(result->handle))) DBUG_RETURN((int) stmt_fetch_row(stmt,(uchar **) &mysql->net.read_pos+1));
DBUG_RETURN((int) my_fetch_row(stmt, result, DBUG_RETURN(0);
(byte*) mysql->net.read_pos+1));
DBUG_PRINT("info", ("end of data"));
result->eof= 1;
result->handle->status= MYSQL_STATUS_READY;
/* Don't clear handle in mysql_free_results */
result->handle= 0;
if (res < 0) /* Network error */
{
set_stmt_errmsg(stmt,(char *)mysql->net.last_error,
mysql->net.last_errno);
DBUG_RETURN(MYSQL_STATUS_ERROR);
}
} }
DBUG_RETURN(MYSQL_NO_DATA); /* no more data */ DBUG_PRINT("info", ("end of data"));
} mysql->status= MYSQL_STATUS_READY;
{
/* if (res < 0) /* Network error */
For prepared statements, the row data is a string of binary bytes,
not a set of string pointers as for normal statements
It's however convenient to use the data pointer also for prepared
statements.
*/
MYSQL_ROW values;
if (!result->data_cursor)
{ {
DBUG_PRINT("info", ("end of data")); set_stmt_errmsg(stmt,(char *)mysql->net.last_error,
result->current_row= (MYSQL_ROW) NULL; mysql->net.last_errno);
DBUG_RETURN(MYSQL_NO_DATA); DBUG_RETURN(MYSQL_STATUS_ERROR);
} }
values= result->data_cursor->data; DBUG_RETURN(MYSQL_NO_DATA); /* no more data */
result->data_cursor= result->data_cursor->next;
DBUG_RETURN((int) my_fetch_row(stmt,result, (byte*) values));
} }
DBUG_RETURN(0); DBUG_RETURN(0); //?? do we need to set MYSQL_STATUS_READY ?
} }
...@@ -4306,17 +4391,15 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) ...@@ -4306,17 +4391,15 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
my_bool error=0; my_bool error=0;
DBUG_ENTER("mysql_stmt_close"); DBUG_ENTER("mysql_stmt_close");
if (stmt->state) if (stmt->state != MY_ST_UNKNOWN)
{ {
char buff[4]; char buff[4];
int4store(buff, stmt->stmt_id); int4store(buff, stmt->stmt_id);
error= simple_command(stmt->mysql, COM_CLOSE_STMT, buff, 4, 0); error= simple_command(stmt->mysql, COM_CLOSE_STMT, buff, 4, 0);
} }
mysql_free_result(stmt->result);
free_root(&stmt->mem_root, MYF(0)); free_root(&stmt->mem_root, MYF(0));
my_free((gptr) stmt->query, MYF(MY_WME | MY_ALLOW_ZERO_PTR)); my_free((gptr) stmt->query, MYF(MY_WME | MY_ALLOW_ZERO_PTR));
my_free((gptr) stmt->bind, MY_ALLOW_ZERO_PTR);
my_free((gptr) stmt->params, MY_ALLOW_ZERO_PTR);
my_free((gptr) stmt, MYF(MY_WME)); my_free((gptr) stmt, MYF(MY_WME));
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
...@@ -102,8 +102,24 @@ EXPORTS ...@@ -102,8 +102,24 @@ EXPORTS
mysql_add_slave mysql_add_slave
mysql_warning_count mysql_warning_count
mysql_warnings mysql_warnings
mysql_prepare
mysql_execute
mysql_param_count
mysql_bind_param
mysql_bind_result
mysql_prepare_result
mysql_stmt_close
mysql_stmt_error
mysql_stmt_errno
mysql_fetch
mysql_send_long_data
mysql_multi_query
mysql_next_result
mysql_commit
mysql_rollback
mysql_autocommit
......
...@@ -315,32 +315,27 @@ void Item_param::set_null() ...@@ -315,32 +315,27 @@ void Item_param::set_null()
void Item_param::set_int(longlong i) void Item_param::set_int(longlong i)
{ {
int_value=(longlong)i; int_value=(longlong)i;
item_result_type = INT_RESULT;
item_type = INT_ITEM; item_type = INT_ITEM;
} }
void Item_param::set_double(double value) void Item_param::set_double(double value)
{ {
real_value=value; real_value=value;
item_result_type = REAL_RESULT;
item_type = REAL_ITEM; item_type = REAL_ITEM;
} }
void Item_param::set_value(const char *str, uint length, CHARSET_INFO *cs) void Item_param::set_value(const char *str, uint length)
{ {
str_value.set(str,length,cs); str_value.set(str,length,thd_charset());
item_result_type = STRING_RESULT;
item_type = STRING_ITEM; item_type = STRING_ITEM;
} }
void Item_param::set_longdata(const char *str, ulong length, CHARSET_INFO *cs) void Item_param::set_longdata(const char *str, ulong length)
{ {
/* TODO: Fix this for binary handling by making use of str_value.append(str,length);
buffer_type.. long_data_supplied= 1;
*/
str_value.append(str,length);
} }
......
...@@ -186,8 +186,8 @@ class Item_param :public Item ...@@ -186,8 +186,8 @@ class Item_param :public Item
Item_param(char *name_par=0) Item_param(char *name_par=0)
{ {
name= name_par ? name_par : (char*) "?"; name= name_par ? name_par : (char*) "?";
long_data_supplied = false; long_data_supplied= false;
item_type = STRING_ITEM; item_type= STRING_ITEM;
item_result_type = STRING_RESULT; item_result_type = STRING_RESULT;
} }
enum Type type() const { return item_type; } enum Type type() const { return item_type; }
...@@ -199,12 +199,13 @@ class Item_param :public Item ...@@ -199,12 +199,13 @@ class Item_param :public Item
void set_null(); void set_null();
void set_int(longlong i); void set_int(longlong i);
void set_double(double i); void set_double(double i);
void set_value(const char *str, uint length, CHARSET_INFO *cs); void set_value(const char *str, uint length);
void set_long_str(const char *str, ulong length, CHARSET_INFO *cs); void set_long_str(const char *str, ulong length);
void set_long_binary(const char *str, ulong length, CHARSET_INFO *cs); void set_long_binary(const char *str, ulong length);
void set_longdata(const char *str, ulong length, CHARSET_INFO *cs); void set_longdata(const char *str, ulong length);
void set_long_end(); void set_long_end();
void reset() {} void reset() {}
void (*setup_param_func)(Item_param *param, uchar **pos);
enum Item_result result_type () const enum Item_result result_type () const
{ return item_result_type; } { return item_result_type; }
Item *new_item() { return new Item_param(name); } Item *new_item() { return new Item_param(name); }
......
...@@ -512,7 +512,7 @@ int mysqld_show_column_types(THD *thd); ...@@ -512,7 +512,7 @@ int mysqld_show_column_types(THD *thd);
int mysqld_help (THD *thd, const char *text); int mysqld_help (THD *thd, const char *text);
/* sql_prepare.cc */ /* sql_prepare.cc */
int compare_prep_stmt(PREP_STMT *a, PREP_STMT *b, void *not_used); int compare_prep_stmt(void *not_used, PREP_STMT *stmt, ulong *key);
void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used); void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used);
bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length); bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length);
void mysql_stmt_execute(THD *thd, char *packet); void mysql_stmt_execute(THD *thd, char *packet);
......
...@@ -325,7 +325,7 @@ typedef struct st_prep_stmt ...@@ -325,7 +325,7 @@ typedef struct st_prep_stmt
uint param_count; uint param_count;
uint last_errno; uint last_errno;
char last_error[MYSQL_ERRMSG_SIZE]; char last_error[MYSQL_ERRMSG_SIZE];
bool error_in_prepare, long_data_used; bool error_in_prepare, long_data_used, param_inited;
} PREP_STMT; } PREP_STMT;
...@@ -510,7 +510,6 @@ class THD :public ilink { ...@@ -510,7 +510,6 @@ class THD :public ilink {
bool safe_to_cache_query; bool safe_to_cache_query;
bool volatile killed; bool volatile killed;
bool prepare_command; bool prepare_command;
Item_param *params; // Pointer to array of params
/* /*
If we do a purge of binary logs, log index info of the threads If we do a purge of binary logs, log index info of the threads
......
...@@ -127,7 +127,7 @@ static const char *warning_level_names[]= {"Note", "Warning", "Error", "?"}; ...@@ -127,7 +127,7 @@ static const char *warning_level_names[]= {"Note", "Warning", "Error", "?"};
my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
{ {
List<Item> field_list; List<Item> field_list;
DBUG_ENTER("mysqld_show_errors"); DBUG_ENTER("mysqld_show_warnings");
field_list.push_back(new Item_empty_string("Level", 7)); field_list.push_back(new Item_empty_string("Level", 7));
field_list.push_back(new Item_int("Code",0,4)); field_list.push_back(new Item_int("Code",0,4));
......
...@@ -30,10 +30,11 @@ This file contains the implementation of prepare and executes. ...@@ -30,10 +30,11 @@ This file contains the implementation of prepare and executes.
Prepare-execute: Prepare-execute:
- Server gets the command 'COM_EXECUTE' to execute the - Server gets the command 'COM_EXECUTE' to execute the
previously prepared query. previously prepared query. If there is any param markers; then client
- If there is are any parameters, then replace the markers with the will send the data in the following format:
data supplied by client with the following format: [null_bits][types_specified(0/1)][[length][data]][[length][data] .. [length][data].
[types_specified(0/1)][type][length][data] .. [type][length].. - Replace the param items with this new data. If it is a first execute
or types altered by client; then setup the conversion routines.
- Execute the query without re-parsing and send back the results - Execute the query without re-parsing and send back the results
to client to client
...@@ -53,33 +54,9 @@ Long data handling: ...@@ -53,33 +54,9 @@ Long data handling:
#include <assert.h> // for DEBUG_ASSERT() #include <assert.h> // for DEBUG_ASSERT()
#include <m_ctype.h> // for isspace() #include <m_ctype.h> // for isspace()
extern int yyparse(void); #define IS_PARAM_NULL(pos, param_no) pos[param_no/8] & (1 << param_no & 7)
static ulong get_param_length(uchar **packet);
static uint get_buffer_type(uchar **packet);
static bool param_is_null(uchar **packet);
static bool setup_param_fields(THD *thd,List<Item> &params);
static uchar* setup_param_field(Item_param *item_param, uchar *pos,
uint buffer_type);
static void setup_longdata_field(Item_param *item_param, uchar *pos);
static bool setup_longdata(THD *thd,List<Item> &params);
static bool send_prepare_results(PREP_STMT *stmt);
static bool parse_prepare_query(PREP_STMT *stmt, char *packet, uint length);
static bool mysql_send_insert_fields(PREP_STMT *stmt, TABLE_LIST *table_list,
List<Item> &fields,
List<List_item> &values_list,
thr_lock_type lock_type);
static bool mysql_test_insert_fields(PREP_STMT *stmt, TABLE_LIST *table_list,
List<Item> &fields,
List<List_item> &values_list,
thr_lock_type lock_type);
static bool mysql_test_upd_fields(PREP_STMT *stmt, TABLE_LIST *table_list,
List<Item> &fields, List<Item> &values,
COND *conds,thr_lock_type lock_type);
static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
List<Item> &fields, List<Item> &values,
COND *conds, ORDER *order, ORDER *group,
Item *having,thr_lock_type lock_type);
extern int yyparse(void);
/* /*
Find prepared statement in thd Find prepared statement in thd
...@@ -114,9 +91,9 @@ static PREP_STMT *find_prepared_statement(THD *thd, ulong stmt_id, ...@@ -114,9 +91,9 @@ static PREP_STMT *find_prepared_statement(THD *thd, ulong stmt_id,
Compare two prepared statements; Used to find a prepared statement Compare two prepared statements; Used to find a prepared statement
*/ */
int compare_prep_stmt(PREP_STMT *a, PREP_STMT *b, void *not_used) int compare_prep_stmt(void *not_used, PREP_STMT *stmt, ulong *key)
{ {
return (a->stmt_id < b->stmt_id) ? -1 : (a->stmt_id == b->stmt_id) ? 0 : 1; return (stmt->stmt_id == *key) ? 0 : (stmt->stmt_id < *key) ? -1 : 1;
} }
...@@ -132,22 +109,23 @@ int compare_prep_stmt(PREP_STMT *a, PREP_STMT *b, void *not_used) ...@@ -132,22 +109,23 @@ int compare_prep_stmt(PREP_STMT *a, PREP_STMT *b, void *not_used)
*/ */
void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used) void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
{ {
free_root(&stmt->mem_root, MYF(0));
free_items(stmt->free_list); free_items(stmt->free_list);
free_root(&stmt->mem_root, MYF(0));
} }
/* /*
Send prepared stmt info to client after prepare Send prepared stmt info to client after prepare
*/ */
bool send_prep_stmt(PREP_STMT *stmt, uint columns) static bool send_prep_stmt(PREP_STMT *stmt, uint columns)
{ {
NET *net=&stmt->thd->net;
char buff[8]; char buff[8];
int4store(buff, stmt->stmt_id); int4store(buff, stmt->stmt_id);
int2store(buff+4, columns); int2store(buff+4, columns);
int2store(buff+6, stmt->param_count); int2store(buff+6, stmt->param_count);
return my_net_write(&stmt->thd->net, buff, sizeof(buff)); return (my_net_write(net, buff, sizeof(buff)) || net_flush(net));
} }
/* /*
...@@ -156,43 +134,15 @@ bool send_prep_stmt(PREP_STMT *stmt, uint columns) ...@@ -156,43 +134,15 @@ bool send_prep_stmt(PREP_STMT *stmt, uint columns)
TODO: Not yet ready TODO: Not yet ready
*/ */
bool send_item_params(PREP_STMT *stmt) static bool send_item_params(PREP_STMT *stmt)
{ {
#if 0
char buff[1]; char buff[1];
buff[0]=0; buff[0]=0;
return my_net_write(&stmt->thd->net, buff, sizeof(buff)); if (my_net_write(&stmt->thd->net, buff, sizeof(buff)))
}
/*
Read the buffer type, this happens only first time
*/
static uint get_buffer_type(uchar **packet)
{
reg1 uchar *pos= *packet;
(*packet)+= 2;
return (uint) uint2korr(pos);
}
/*
Check for NULL param data
RETURN VALUES
0 Value was not NULL
1 Value was NULL
*/
static bool param_is_null(uchar **packet)
{
reg1 uchar *pos= *packet;
if (*pos == 251)
{
(*packet)++;
return 1; return 1;
} send_eof(stmt->thd);
#endif
return 0; return 0;
} }
...@@ -222,60 +172,103 @@ static ulong get_param_length(uchar **packet) ...@@ -222,60 +172,103 @@ static ulong get_param_length(uchar **packet)
(*packet)+=9; // Must be 254 when here (*packet)+=9; // Must be 254 when here
return (ulong) uint4korr(pos+1); return (ulong) uint4korr(pos+1);
} }
/*
Setup param conversion routines
/* setup_param_xx()
Read and return the data for parameters supplied by client param Parameter Item
pos Input data buffer
All these functions reads the data from pos and sets up that data
through 'param' and advances the buffer position to predifined
length position.
Make a note that the NULL handling is examined at first execution
(i.e. when input types altered) and for all subsequent executions
we don't read any values for this.
RETURN VALUES
*/ */
static uchar* setup_param_field(Item_param *item_param, static void setup_param_tiny(Item_param *param, uchar **pos)
uchar *pos, uint buffer_type)
{ {
if (param_is_null(&pos)) param->set_int((longlong)(**pos));
{ *pos+= 1;
item_param->set_null(); }
return(pos);
} static void setup_param_short(Item_param *param, uchar **pos)
switch (buffer_type) { {
param->set_int((longlong)sint2korr(*pos));
*pos+= 2;
}
static void setup_param_int32(Item_param *param, uchar **pos)
{
param->set_int((longlong)sint4korr(*pos));
*pos+= 4;
}
static void setup_param_int64(Item_param *param, uchar **pos)
{
param->set_int((longlong)sint8korr(*pos));
*pos+= 8;
}
static void setup_param_float(Item_param *param, uchar **pos)
{
float data;
float4get(data,*pos);
param->set_double((double) data);
*pos+= 4;
}
static void setup_param_double(Item_param *param, uchar **pos)
{
double data;
float8get(data,*pos);
param->set_double((double) data);
*pos+= 8;
}
static void setup_param_str(Item_param *param, uchar **pos)
{
ulong len=get_param_length(pos);
param->set_value((const char *)*pos, len);
*pos+=len;
}
static void setup_param_functions(Item_param *param, uchar read_pos)
{
switch (read_pos) {
case FIELD_TYPE_TINY: case FIELD_TYPE_TINY:
item_param->set_int((longlong)(*pos)); param->setup_param_func= setup_param_tiny;
pos += 1; param->item_result_type = INT_RESULT;
break; break;
case FIELD_TYPE_SHORT: case FIELD_TYPE_SHORT:
item_param->set_int((longlong)sint2korr(pos)); param->setup_param_func= setup_param_short;
pos += 2; param->item_result_type = INT_RESULT;
break;
case FIELD_TYPE_INT24:
item_param->set_int((longlong)sint4korr(pos));
pos += 3;
break; break;
case FIELD_TYPE_LONG: case FIELD_TYPE_LONG:
item_param->set_int((longlong)sint4korr(pos)); param->setup_param_func= setup_param_int32;
pos += 4; param->item_result_type = INT_RESULT;
break; break;
case FIELD_TYPE_LONGLONG: case FIELD_TYPE_LONGLONG:
item_param->set_int((longlong)sint8korr(pos)); param->setup_param_func= setup_param_int64;
pos += 8; param->item_result_type = INT_RESULT;
break; break;
case FIELD_TYPE_FLOAT: case FIELD_TYPE_FLOAT:
float data; param->setup_param_func= setup_param_float;
float4get(data,pos); param->item_result_type = REAL_RESULT;
item_param->set_double((double) data);
pos += 4;
break; break;
case FIELD_TYPE_DOUBLE: case FIELD_TYPE_DOUBLE:
double j; param->setup_param_func= setup_param_double;
float8get(j,pos) param->item_result_type = REAL_RESULT;
item_param->set_double(j);
pos += 8;
break; break;
default: default:
{ param->setup_param_func= setup_param_str;
ulong len=get_param_length(&pos); param->item_result_type = STRING_RESULT;
item_param->set_value((const char*)pos,len,current_thd->thd_charset);
pos+=len;
}
} }
return(pos);
} }
/* /*
...@@ -283,42 +276,45 @@ static uchar* setup_param_field(Item_param *item_param, ...@@ -283,42 +276,45 @@ static uchar* setup_param_field(Item_param *item_param,
from client .. from client ..
*/ */
static bool setup_param_fields(THD *thd, PREP_STMT *stmt) static bool setup_params_data(THD *thd, PREP_STMT *stmt)
{ {
DBUG_ENTER("setup_param_fields"); List<Item> &params= thd->lex.param_list;
#ifdef READY_TO_BE_USED List_iterator<Item> param_iterator(params);
Item_param *item_param; Item_param *param;
ulong param_count=0; DBUG_ENTER("setup_params_data");
uchar *pos=(uchar*) thd->net.read_pos+1;// skip command type
uchar *pos=(uchar*) thd->net.read_pos+1+MYSQL_STMT_HEADER; //skip header
if (*pos++) // No types supplied, read only param data uchar *read_pos= pos+(stmt->param_count+7) / 8; //skip null bits
{ ulong param_no;
while ((item_param=(Item_param *)it++) &&
(param_count++ < stmt->param_count))
{
if (item_param->long_data_supplied)
continue;
if (!(pos=setup_param_field(item_param,pos,item_param->buffer_type))) if (*read_pos++) //types supplied / first execute
DBUG_RETURN(1); {
/*
First execute or types altered by the client, setup the
conversion routines for all parameters (one time)
*/
while ((param= (Item_param *)param_iterator++))
{
if (!param->long_data_supplied)
{
setup_param_functions(param,*read_pos);
read_pos+= 2;
}
} }
} param_iterator.rewind();
else // Types supplied, read and store it along with param data }
param_no= 0;
while ((param= (Item_param *)param_iterator++))
{ {
while ((item_param=(Item_param *)it++) && if (!param->long_data_supplied)
(param_count++ < thd->param_count))
{ {
if (item_param->long_data_supplied) if (IS_PARAM_NULL(pos,param_no))
continue; param->maybe_null=param->null_value=1;
else
if (!(pos=setup_param_field(item_param,pos, param->setup_param_func(param,&read_pos);
item_param->buffer_type=
(enum_field_types) get_buffer_type(&pos))))
DBUG_RETURN(1);
} }
param_no++;
} }
#endif
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -583,6 +579,8 @@ static bool send_prepare_results(PREP_STMT *stmt) ...@@ -583,6 +579,8 @@ static bool send_prepare_results(PREP_STMT *stmt)
Rest fall through to default category, no parsing Rest fall through to default category, no parsing
for non-DML statements for non-DML statements
*/ */
if (send_prep_stmt(stmt, 0))
goto abort;
} }
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -597,7 +595,7 @@ static bool send_prepare_results(PREP_STMT *stmt) ...@@ -597,7 +595,7 @@ static bool send_prepare_results(PREP_STMT *stmt)
*/ */
static bool parse_prepare_query(PREP_STMT *stmt, static bool parse_prepare_query(PREP_STMT *stmt,
char *packet, uint length) char *packet, uint length)
{ {
bool error= 1; bool error= 1;
THD *thd= stmt->thd; THD *thd= stmt->thd;
...@@ -607,6 +605,7 @@ static bool parse_prepare_query(PREP_STMT *stmt, ...@@ -607,6 +605,7 @@ static bool parse_prepare_query(PREP_STMT *stmt,
mysql_init_query(thd); mysql_init_query(thd);
thd->prepare_command=true; thd->prepare_command=true;
thd->safe_to_cache_query= 0; thd->safe_to_cache_query= 0;
thd->lex.param_count=0;
LEX *lex=lex_start(thd, (uchar*) packet, length); LEX *lex=lex_start(thd, (uchar*) packet, length);
if (!yyparse() && !thd->fatal_error) if (!yyparse() && !thd->fatal_error)
...@@ -615,6 +614,25 @@ static bool parse_prepare_query(PREP_STMT *stmt, ...@@ -615,6 +614,25 @@ static bool parse_prepare_query(PREP_STMT *stmt,
DBUG_RETURN(error); DBUG_RETURN(error);
} }
/*
Initialize parameter items in statement
*/
static bool init_param_items(THD *thd, PREP_STMT *stmt)
{
#if TO_BE_TESTED
Item_param **to;
if (!(to= (Item_param *)
my_malloc(sizeof(Item_param*) * stmt->param_count, MYF(MY_WME))))
return 1;
List<Item> &params= thd->lex.param_list;
List_iterator<Item> param_iterator(params);
while ((to++ = (Item_param *)param_iterator++))
{
DBUG_PRINT("info",("param: %lx", to));
}
return 0;
#endif
}
/* /*
Parse the query and send the total number of parameters Parse the query and send the total number of parameters
...@@ -648,10 +666,15 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) ...@@ -648,10 +666,15 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
goto err; goto err;
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR); my_pthread_setprio(pthread_self(),WAIT_PRIOR);
#if 0
stmt.mem_root= thd->mem_root; if (init_param_items(thd, &stmt))
goto err;
#endif
stmt.mem_root= thd->mem_root;
tree_insert(&thd->prepared_statements, (void *)&stmt, 0, (void *)0);
thd->mem_root= thd_root; // restore main mem_root thd->mem_root= thd_root; // restore main mem_root
thd->last_prepared_stmt= &stmt;
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
...@@ -685,11 +708,11 @@ void mysql_stmt_execute(THD *thd, char *packet) ...@@ -685,11 +708,11 @@ void mysql_stmt_execute(THD *thd, char *packet)
/* Check if we got an error when sending long data */ /* Check if we got an error when sending long data */
if (stmt->error_in_prepare) if (stmt->error_in_prepare)
{ {
send_error(thd); send_error(thd, stmt->last_errno, stmt->last_error);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
if (stmt->param_count && setup_param_fields(thd, stmt)) if (stmt->param_count && setup_params_data(thd, stmt))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
MEM_ROOT thd_root= thd->mem_root; MEM_ROOT thd_root= thd->mem_root;
...@@ -705,6 +728,8 @@ void mysql_stmt_execute(THD *thd, char *packet) ...@@ -705,6 +728,8 @@ void mysql_stmt_execute(THD *thd, char *packet)
*/ */
mysql_execute_command(thd); mysql_execute_command(thd);
thd->last_prepared_stmt= stmt;
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR); my_pthread_setprio(pthread_self(), WAIT_PRIOR);
...@@ -768,8 +793,10 @@ void mysql_stmt_close(THD *thd, char *packet) ...@@ -768,8 +793,10 @@ void mysql_stmt_close(THD *thd, char *packet)
send_error(thd); send_error(thd);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
stmt->param= 0;
my_free((char *)stmt->param, MYF(MY_ALLOW_ZERO_PTR));
/* Will call free_prep_stmt() */ /* Will call free_prep_stmt() */
tree_delete(&thd->prepared_statements, (void*) stmt, NULL); tree_delete(&thd->prepared_statements, (void*) &stmt, (void *)0);
thd->last_prepared_stmt=0; thd->last_prepared_stmt=0;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -800,17 +827,16 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length) ...@@ -800,17 +827,16 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length)
DBUG_ENTER("mysql_stmt_get_longdata"); DBUG_ENTER("mysql_stmt_get_longdata");
/* The following should never happen */ /* The following should never happen */
if (packet_length < 9) if (packet_length < MYSQL_LONG_DATA_HEADER+1)
{ {
my_error(ER_WRONG_ARGUMENTS, MYF(0), "get_longdata"); my_error(ER_WRONG_ARGUMENTS, MYF(0), "get_longdata");
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
pos++; // skip command type at first position
ulong stmt_id= uint4korr(pos); ulong stmt_id= uint4korr(pos);
uint param_number= uint2korr(pos+4); uint param_number= uint2korr(pos+4);
uint param_type= uint2korr(pos+6); uint param_type= uint2korr(pos+6);
pos+=8; // Point to data pos+=MYSQL_LONG_DATA_HEADER; // Point to data
if (!(stmt=find_prepared_statement(thd, stmt_id, "get_longdata"))) if (!(stmt=find_prepared_statement(thd, stmt_id, "get_longdata")))
{ {
...@@ -829,7 +855,8 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length) ...@@ -829,7 +855,8 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length)
sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), "get_longdata"); sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), "get_longdata");
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
stmt->param[param_number].set_longdata(pos, packet_length-9, current_thd->thd_charset); stmt->param[param_number].set_longdata(pos, packet_length-9);
stmt->long_data_used= 1; stmt->long_data_used= 1;
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