1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Another fix for CONC-177: ps-protocol with integer values and zerofill

weren't correctly converted to strings
This commit is contained in:
Georg Richter
2016-05-30 20:46:29 +02:00
parent ec383d59fa
commit b90b17804d
3 changed files with 45 additions and 6 deletions

View File

@@ -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)
@@ -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);
}
@@ -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);

View File

@@ -1846,7 +1846,7 @@ mysql_close(MYSQL *mysql)
{
if (mysql) /* Some simple safety */
{
if ((mysql->extension && mysql->extension->conn_hdlr)
if (mysql->extension && mysql->extension->conn_hdlr)
{
MA_CONNECTION_HANDLER *p= mysql->extension->conn_hdlr;
p->plugin->close(mysql);

View File

@@ -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;
}