diff options
author | unknown <kroki@mysql.com> | 2006-06-30 12:52:05 +0400 |
---|---|---|
committer | unknown <kroki@mysql.com> | 2006-06-30 12:52:05 +0400 |
commit | 86155590380cc7a69e330ccf8ba7790475875a1a (patch) | |
tree | b15d181ea088a873081fce94ac611bdbf7fb05fe /tests | |
parent | 79952ec0d044d0c561f777e02a56c6981949dfcc (diff) | |
download | mariadb-git-86155590380cc7a69e330ccf8ba7790475875a1a.tar.gz |
bug #20152: mysql_stmt_execute() overwrites parameter buffers
When using a parameter bind MYSQL_TYPE_DATE in a prepared statement,
the time part of the MYSQL_TIME buffer was written to zero in
mysql_stmt_execute(). The param_store_date() function in libmysql.c
worked directly on the provided buffer.
Changed to use a copy of the buffer.
libmysql/libmysql.c:
fix for bug #20152
tests/mysql_client_test.c:
added test for bug#20152
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mysql_client_test.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 3c54bf50c15..94034141d81 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11855,6 +11855,58 @@ static void test_bug15613() mysql_stmt_close(stmt); } + +/* + Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer + */ +static void test_bug20152() +{ + MYSQL_BIND bind[1]; + MYSQL_STMT *stmt; + MYSQL_TIME tm; + int rc; + const char *query= "INSERT INTO t1 (f1) VALUES (?)"; + + myheader("test_bug20152"); + + memset(bind, 0, sizeof(bind)); + bind[0].buffer_type= MYSQL_TYPE_DATE; + bind[0].buffer= (void*)&tm; + + tm.year = 2006; + tm.month = 6; + tm.day = 18; + tm.hour = 14; + tm.minute = 9; + tm.second = 42; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + myquery(rc); + rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)"); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, query, strlen(query)); + check_execute(stmt, rc); + rc= mysql_stmt_bind_param(stmt, bind); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + rc= mysql_stmt_close(stmt); + check_execute(stmt, rc); + rc= mysql_query(mysql, "DROP TABLE t1"); + myquery(rc); + + if (tm.hour == 14 && tm.minute == 9 && tm.second == 42) { + if (!opt_silent) + printf("OK!"); + } else { + printf("[14:09:42] != [%02d:%02d:%02d]\n", tm.hour, tm.minute, tm.second); + DIE_UNLESS(0==1); + } +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -12078,6 +12130,7 @@ static struct my_tests_st my_tests[]= { { "test_bug11718", test_bug11718 }, { "test_bug12925", test_bug12925 }, { "test_bug15613", test_bug15613 }, + { "test_bug20152", test_bug20152 }, { 0, 0 } }; |