Commit 5fa224b6 authored by unknown's avatar unknown

Remove bind_length + Fix the client-test


tests/client_test.c:
  Fix the tests
include/mysql.h:
  Remove bind_length
libmysql/libmysql.c:
  Remove bind_length
parent 8823fa22
...@@ -481,7 +481,6 @@ typedef struct st_mysql_bind ...@@ -481,7 +481,6 @@ typedef struct st_mysql_bind
unsigned long buffer_length; /* buffer length */ unsigned long buffer_length; /* buffer length */
/* The following are for internal use. Set by mysql_bind_param */ /* The following are for internal use. Set by mysql_bind_param */
unsigned long bind_length; /* Default length of data */
unsigned int param_number; /* For null count and error messages */ unsigned int param_number; /* For null count and error messages */
my_bool long_data_used; /* If used with mysql_send_long_data */ my_bool long_data_used; /* If used with mysql_send_long_data */
void (*store_param_func)(NET *net, struct st_mysql_bind *param); void (*store_param_func)(NET *net, struct st_mysql_bind *param);
......
...@@ -4058,7 +4058,7 @@ static void store_param_double(NET *net, MYSQL_BIND *param) ...@@ -4058,7 +4058,7 @@ static void store_param_double(NET *net, MYSQL_BIND *param)
static void store_param_str(NET *net, MYSQL_BIND *param) static void store_param_str(NET *net, MYSQL_BIND *param)
{ {
ulong length= *param->length; ulong length= min(*param->length, param->buffer_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= (uchar*) to+length; net->write_pos= (uchar*) to+length;
...@@ -4107,7 +4107,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param) ...@@ -4107,7 +4107,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
{ {
/* /*
Param->length should ALWAYS point to the correct length for the type Param->length should ALWAYS point to the correct length for the type
Either to the length pointer given by the user or param->bind_length Either to the length pointer given by the user or param->buffer_length
*/ */
if ((my_realloc_str(net, 9 + *param->length))) if ((my_realloc_str(net, 9 + *param->length)))
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -4277,12 +4277,14 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4277,12 +4277,14 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
param++) param++)
{ {
param->param_number= count++; param->param_number= count++;
param->long_data_used= 0;
/* /*
If param->length is not given, change it to point to bind_length. If param->length is not given, change it to point to buffer_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->buffer_length;
/* If param->is_null is not set, then the value can never be NULL */ /* If param->is_null is not set, then the value can never be NULL */
if (!param->is_null) if (!param->is_null)
...@@ -4295,33 +4297,33 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4295,33 +4297,33 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
break; break;
case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY:
/* Force param->length as this is fixed for this type */ /* Force param->length as this is fixed for this type */
param->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 1; param->buffer_length= 1;
param->store_param_func= store_param_tinyint; param->store_param_func= store_param_tinyint;
break; break;
case MYSQL_TYPE_SHORT: case MYSQL_TYPE_SHORT:
param->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 2; param->buffer_length= 2;
param->store_param_func= store_param_short; param->store_param_func= store_param_short;
break; break;
case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONG:
param->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 4; param->buffer_length= 4;
param->store_param_func= store_param_int32; param->store_param_func= store_param_int32;
break; break;
case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_LONGLONG:
param->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 8; param->buffer_length= 8;
param->store_param_func= store_param_int64; param->store_param_func= store_param_int64;
break; break;
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_FLOAT:
param->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 4; param->buffer_length= 4;
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->length= &param->bind_length; param->length= &param->buffer_length;
param->bind_length= param->buffer_length= 8; param->buffer_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:
...@@ -4330,7 +4332,6 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind) ...@@ -4330,7 +4332,6 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
case MYSQL_TYPE_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->store_param_func= store_param_str; param->store_param_func= store_param_str;
break; break;
default: default:
...@@ -4586,6 +4587,7 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length) ...@@ -4586,6 +4587,7 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length)
} }
default: default:
*param->length= length; *param->length= length;
length= min(length, param->buffer_length);
memcpy(buffer, value, length); memcpy(buffer, value, length);
buffer[length]='\0'; buffer[length]='\0';
} }
...@@ -4804,9 +4806,10 @@ static void fetch_result_double(MYSQL_BIND *param, uchar **row) ...@@ -4804,9 +4806,10 @@ static void fetch_result_double(MYSQL_BIND *param, uchar **row)
static void fetch_result_str(MYSQL_BIND *param, uchar **row) static void fetch_result_str(MYSQL_BIND *param, uchar **row)
{ {
ulong length= net_field_length(row); ulong length= net_field_length(row);
memcpy(param->buffer, (char *)*row, length); ulong copy_length= min(length, param->buffer_length);
*(param->buffer+length)= '\0'; memcpy(param->buffer, (char *)*row, copy_length);
*param->length= length; *(param->buffer+copy_length)= '\0';
*param->length= length; // return total length
*row+= length; *row+= length;
} }
...@@ -4882,7 +4885,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) ...@@ -4882,7 +4885,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if (!param->length) if (!param->length)
param->length= &param->bind_length; param->length= &param->buffer_length;
*param->length= (long)get_binary_length(param->buffer_type); *param->length= (long)get_binary_length(param->buffer_type);
} }
stmt->res_buffers= 1; stmt->res_buffers= 1;
......
This diff is collapsed.
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