diff options
author | unknown <konstantin@mysql.com> | 2004-10-27 23:46:22 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-10-27 23:46:22 +0400 |
commit | 447fef48fdb3bb96ad51394d24708a68f56cda9f (patch) | |
tree | fcb5060d1e0aaee633ead3e6796369ac3fef7e0d /tests | |
parent | 8ace53109ecc69efc166816b01470ed7333bd862 (diff) | |
download | mariadb-git-447fef48fdb3bb96ad51394d24708a68f56cda9f.tar.gz |
A fix and test case for Bug#6096 "field.max_length is always zero for
numeric columns (stmt_resultset_metadata)"
libmysql/libmysql.c:
A fix for Bug#6096 "field.max_length is always zero for numeric columns
(stmt_resultset_metadata)": set field->max_lenght for numeric
columns when we set up skip_result functions. A minor drawback for this
approach is that field->max_length can be not zero even if
STMT_ATTR_UPDATE_MAX_LENGTH is not set.
sql-common/my_time.c:
Fix valgrind warning.
tests/client_test.c:
A test case for Bug#6096 "field.max_length is always zero for numeric
columns (stmt_resultset_metadata)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/client_test.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/client_test.c b/tests/client_test.c index 562f6e307d3..48676ae7e12 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -10713,6 +10713,106 @@ static void test_bug6081() rc= simple_command(mysql, COM_CREATE_DB, current_db, (ulong)strlen(current_db), 0); myquery_r(rc); + rc= mysql_select_db(mysql, current_db); + myquery(rc); +} + + +static void test_bug6096() +{ + MYSQL_STMT *stmt; + MYSQL_RES *query_result, *stmt_metadata; + const char *stmt_text; + MYSQL_BIND bind[12]; + MYSQL_FIELD *query_field_list, *stmt_field_list; + ulong query_field_count, stmt_field_count; + int rc; + uint i; + + myheader("test_bug6096"); + + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + + stmt_text= "create table t1 (c_tinyint tinyint, c_smallint smallint, " + " c_mediumint mediumint, c_int int, " + " c_bigint bigint, c_float float, " + " c_double double, c_varchar varchar(20), " + " c_char char(20), c_time time, c_date date, " + " c_datetime datetime)"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + stmt_text= "insert into t1 values (-100, -20000, 30000000, 4, 8, 1.0, " + "2.0, 'abc', 'def', now(), now(), now())"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + + stmt_text= "select * from t1"; + + /* Run select in prepared and non-prepared mode and compare metadata */ + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + query_result= mysql_store_result(mysql); + query_field_list= mysql_fetch_fields(query_result); + query_field_count= mysql_num_fields(query_result); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + rc= 1; + mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc); + mysql_stmt_store_result(stmt); + stmt_metadata= mysql_stmt_result_metadata(stmt); + stmt_field_list= mysql_fetch_fields(stmt_metadata); + stmt_field_count= mysql_num_fields(stmt_metadata); + DIE_UNLESS(stmt_field_count == query_field_count); + + /* Print out and check the metadata */ + + printf(" ---------------------------------------------------------------\n"); + printf(" | Metadata \n"); + printf(" ---------------------------------------------------------------\n"); + printf(" | Query | Prepared statement \n"); + printf(" ---------------------------------------------------------------\n"); + printf(" field name | length | max_length | length | max_length \n"); + printf(" ---------------------------------------------------------------\n"); + + for (i= 0; i < query_field_count; ++i) + { + MYSQL_FIELD *f1= &query_field_list[i], *f2= &stmt_field_list[i]; + printf(" %-11s | %9lu | %10lu | %9lu | %10lu \n", + f1->name, f1->length, f1->max_length, f2->length, f2->max_length); + DIE_UNLESS(f1->length == f2->length); + } + printf(" ---------------------------------------------------------------\n"); + + /* Bind and fetch the data */ + + bzero(bind, sizeof(bind)); + for (i= 0; i < stmt_field_count; ++i) + { + bind[i].buffer_type= MYSQL_TYPE_STRING; + bind[i].buffer_length= stmt_field_list[i].max_length + 1; + bind[i].buffer= malloc(bind[i].buffer_length); + } + mysql_stmt_bind_result(stmt, bind); + rc= mysql_stmt_fetch(stmt); + check_execute(stmt, rc); + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == MYSQL_NO_DATA); + + /* Clean up */ + + for (i= 0; i < stmt_field_count; ++i) + free(bind[i].buffer); + mysql_stmt_close(stmt); + mysql_free_result(query_result); + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); } @@ -11031,6 +11131,7 @@ int main(int argc, char **argv) test_bug6059(); /* correct metadata for SELECT ... INTO OUTFILE */ test_bug6046(); /* NATURAL JOIN transformation works in PS */ test_bug6081(); /* test of mysql_create_db()/mysql_rm_db() */ + test_bug6096(); /* max_length for numeric columns */ /* XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH. |