diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index 2da04651..3dde3c40 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -1240,11 +1240,11 @@ void mysql_init_ps_subsystem(void) mysql_ps_fetch_functions[MYSQL_TYPE_TINY].func = ps_fetch_int8; mysql_ps_fetch_functions[MYSQL_TYPE_TINY].pack_len = 1; - mysql_ps_fetch_functions[MYSQL_TYPE_TINY].max_len = 3; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY].max_len = 4; mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].func = ps_fetch_int16; mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].pack_len = 2; - mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].max_len = 5; + mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].max_len = 6; mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].func = ps_fetch_int16; mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].pack_len = 2; @@ -1256,7 +1256,7 @@ void mysql_init_ps_subsystem(void) mysql_ps_fetch_functions[MYSQL_TYPE_LONG].func = ps_fetch_int32; mysql_ps_fetch_functions[MYSQL_TYPE_LONG].pack_len = 4; - mysql_ps_fetch_functions[MYSQL_TYPE_LONG].max_len = 10; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG].max_len = 11; mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].func = ps_fetch_int64; mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].pack_len= 8; diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index ee117d31..96d87c67 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -252,13 +252,24 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) { if (stmt->fields[i].flags & ZEROFILL_FLAG) { - size_t len= MAX(stmt->fields[i].length, mysql_ps_fetch_functions[stmt->fields[i].type].max_len); + /* The -1 is because a ZEROFILL:ed field is always unsigned */ + size_t len= MAX(stmt->fields[i].length, mysql_ps_fetch_functions[stmt->fields[i].type].max_len-1); if (len > stmt->fields[i].max_length) stmt->fields[i].max_length= (unsigned long)len; } else if (!stmt->fields[i].max_length) { stmt->fields[i].max_length= mysql_ps_fetch_functions[stmt->fields[i].type].max_len; + if (stmt->fields[i].flags & UNSIGNED_FLAG && + stmt->fields[i].type != MYSQL_TYPE_INT24 && + stmt->fields[i].type != MYSQL_TYPE_LONGLONG) + { + /* + Unsigned integers has one character less than signed integers + as '-' is counted as part of max_length + */ + stmt->fields[i].max_length--; + } } cp+= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; }