Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vaintroub committed May 30, 2016
2 parents b825154 + b90b178 commit 7080d96
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libmariadb/ma_stmt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ my_bool mysql_ps_subsystem_initialized= 0;
((((val) > (max_range)) || ((val) < (min_range)) ? 1 : 0))


void ma_bmove_upp(register char *dst, register const char *src, register size_t len)
{
while (len-- != 0) *--dst = *--src;
}

/* {{{ ps_fetch_from_1_to_8_bytes */
void ps_fetch_from_1_to_8_bytes(MYSQL_BIND *r_param, const MYSQL_FIELD * const field,
unsigned char **row, unsigned int byte_count)
Expand Down Expand Up @@ -373,6 +378,13 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon
len= (uint)(endptr - buffer);

/* check if field flag is zerofill */
if (field->flags & ZEROFILL_FLAG &&
len < field->length && len < r_param->buffer_length)
{
ma_bmove_upp(buffer + field->length, buffer + len, len);
memset((char*) buffer, '0', field->length - len);
len= field->length;
}

convert_froma_string(r_param, buffer, len);
}
Expand Down Expand Up @@ -499,11 +511,6 @@ void ps_fetch_int64(MYSQL_BIND *r_param, const MYSQL_FIELD * const field,
}
/* }}} */

void ma_bmove_upp(register char *dst, register const char *src, register size_t len)
{
while (len-- != 0) *--dst = *--src;
}

static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, float val, int size)
{
double check_trunc_val= (val > 0) ? floor(val) : -floor(-val);
Expand Down
32 changes: 32 additions & 0 deletions unittest/libmariadb/ps_bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,38 @@ static int test_conc177(MYSQL *mysql)
FAIL_IF(strcmp(buf1, "00000000000000000008.8"), "Expected 00000000000000000008.8");
FAIL_IF(strcmp(buf2, "0000000008.8"), "Expected 0000000008.8");

rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql);

rc= mysql_query(mysql, "CREATE TABLE t1 (a int(8) zerofill default 1, b int(4) zerofill default 1)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (DEFAULT, DEFAULT)");
check_mysql_rc(rc, mysql);

stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, stmt_str, strlen(stmt_str));
check_stmt_rc(rc, stmt);
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);

memset(bind, 0, 2 * sizeof(MYSQL_BIND));
bind[0].buffer= &buf1;
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer_length= 128;
bind[1].buffer= &buf2;
bind[1].buffer_type= MYSQL_TYPE_STRING;
bind[1].buffer_length= 128;

rc= mysql_stmt_bind_result(stmt, bind);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_fetch(stmt);
mysql_stmt_close(stmt);

diag("buf1 %s\nbuf2 %s", buf1, buf2);

FAIL_IF(strcmp(buf1, "00000001"), "Expected 00000001");
FAIL_IF(strcmp(buf2, "0001"), "Expected 0001");
return OK;
}

Expand Down

0 comments on commit 7080d96

Please sign in to comment.