Commit a584117c authored by Monty's avatar Monty

Fixed max length calculation for embedded server

The old code did not take into account unsigned numbers when calculating
max_lengths of fields.
parent 03a10706
...@@ -3925,6 +3925,7 @@ static my_bool is_binary_compatible(enum enum_field_types type1, ...@@ -3925,6 +3925,7 @@ static my_bool is_binary_compatible(enum enum_field_types type1,
static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
{ {
my_bool field_is_unsigned;
DBUG_ENTER("setup_one_fetch_function"); DBUG_ENTER("setup_one_fetch_function");
/* Setup data copy functions for the different supported types */ /* Setup data copy functions for the different supported types */
...@@ -4001,6 +4002,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) ...@@ -4001,6 +4002,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
/* Setup skip_result functions (to calculate max_length) */ /* Setup skip_result functions (to calculate max_length) */
param->skip_result= skip_result_fixed; param->skip_result= skip_result_fixed;
field_is_unsigned= MY_TEST(field->flags & UNSIGNED_FLAG);
switch (field->type) { switch (field->type) {
case MYSQL_TYPE_NULL: /* for dummy binds */ case MYSQL_TYPE_NULL: /* for dummy binds */
param->pack_length= 0; param->pack_length= 0;
...@@ -4008,23 +4010,23 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field) ...@@ -4008,23 +4010,23 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *param, MYSQL_FIELD *field)
break; break;
case MYSQL_TYPE_TINY: case MYSQL_TYPE_TINY:
param->pack_length= 1; param->pack_length= 1;
field->max_length= 4; /* as in '-127' */ field->max_length= field_is_unsigned ? 3 : 4; /* '255' and '-127' */
break; break;
case MYSQL_TYPE_YEAR: case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_SHORT: case MYSQL_TYPE_SHORT:
param->pack_length= 2; param->pack_length= 2;
field->max_length= 6; /* as in '-32767' */ field->max_length= field_is_unsigned ? 5 : 6; /* 65536 and '-32767' */
break; break;
case MYSQL_TYPE_INT24: case MYSQL_TYPE_INT24:
field->max_length= 9; /* as in '16777216' or in '-8388607' */ field->max_length= 8; /* '16777216' or in '-8388607' */
param->pack_length= 4; param->pack_length= 4;
break; break;
case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONG:
field->max_length= 11; /* '-2147483647' */ field->max_length= field_is_unsigned ? 10 : 11; /* '4294967295' and '-2147483647' */
param->pack_length= 4; param->pack_length= 4;
break; break;
case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_LONGLONG:
field->max_length= 21; /* '18446744073709551616' */ field->max_length= 20; /* '18446744073709551616' or -9223372036854775808 */
param->pack_length= 8; param->pack_length= 8;
break; break;
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_FLOAT:
......
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