diff options
author | unknown <konstantin@mysql.com> | 2004-10-20 16:43:36 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-10-20 16:43:36 +0400 |
commit | 8fe8912f4c1d01b9bb8c5c1aefe4ac6405a87976 (patch) | |
tree | ad37dd4f3cad10ec79a8a0cbaaab7173c8f8e6d4 /tests | |
parent | 9aefc403f9f707edf0f84ce401d32929067aea30 (diff) | |
download | mariadb-git-8fe8912f4c1d01b9bb8c5c1aefe4ac6405a87976.tar.gz |
A fix and test case for bug#6058 "Prepared statements return '0000-00-00'
(date) as empty string": preserve time type (date, time, or datetime) for
zero dates, times, and datetimes.
libmysql/libmysql.c:
A fix for bug#6058 "Prepared statements return '0000-00-00' (date) as empty
string": preserve time type (date, time, or datetime) for zero
dates, times, and datetimes.
tests/client_test.c:
A test case for Bug#6058, the existing tests required some adjustments too.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/client_test.c | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/tests/client_test.c b/tests/client_test.c index 5cafd2e033e..587515d0ba8 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -3439,7 +3439,7 @@ static void test_fetch_date() MYSQL_STMT *stmt; uint i; int rc, year; - char date[25], time[25], ts[25], ts_4[15], ts_6[20], dt[20]; + char date[25], time[25], ts[25], ts_4[25], ts_6[20], dt[20]; ulong d_length, t_length, ts_length, ts4_length, ts6_length, dt_length, y_length; MYSQL_BIND bind[8]; @@ -3549,8 +3549,8 @@ static void test_fetch_date() DIE_UNLESS(strcmp(dt, "2010-07-10 00:00:00") == 0); DIE_UNLESS(dt_length == 19); - DIE_UNLESS(ts_4[0] == '\0'); - DIE_UNLESS(ts4_length == 0); + DIE_UNLESS(strcmp(ts_4, "0000-00-00 00:00:00") == 0); + DIE_UNLESS(ts4_length == strlen("0000-00-00 00:00:00")); DIE_UNLESS(strcmp(ts_6, "1999-12-29 00:00:00") == 0); DIE_UNLESS(ts6_length == 19); @@ -10548,7 +10548,7 @@ static void test_bug6049() MYSQL_RES *res; MYSQL_ROW row; const char *stmt_text; - char *buffer[30]; + char buffer[30]; ulong length; int rc; @@ -10578,6 +10578,52 @@ static void test_bug6049() DIE_UNLESS(rc == 0); printf("Result from query: %s\n", row[0]); + printf("Result from prepared statement: %s\n", (char*) buffer); + + DIE_UNLESS(strcmp(row[0], (char*) buffer) == 0); + + mysql_free_result(res); + mysql_stmt_close(stmt); +} + + +static void test_bug6058() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + const char *stmt_text; + char buffer[30]; + ulong length; + int rc; + + myheader("test_bug6058"); + + stmt_text= "SELECT CAST('0000-00-00' AS DATE)"; + + rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text)); + myquery(rc); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + + 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); + + bzero(bind, sizeof(bind)); + bind[0].buffer_type = MYSQL_TYPE_STRING; + bind[0].buffer = &buffer; + bind[0].buffer_length = sizeof(buffer); + bind[0].length = &length; + + mysql_stmt_bind_result(stmt, bind); + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == 0); + + printf("Result from query: %s\n", row[0]); printf("Result from prepared statement: %s\n", buffer); DIE_UNLESS(strcmp(row[0], buffer) == 0); @@ -10587,6 +10633,7 @@ static void test_bug6049() } + /* Read and parse arguments and MySQL options from my.cnf */ @@ -10898,6 +10945,7 @@ int main(int argc, char **argv) test_bug5315(); /* check that mysql_change_user closes all prepared statements */ test_bug6049(); /* check support for negative TIME values */ + test_bug6058(); /* check support for 0000-00-00 dates */ /* XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH. |