From 9dde418895f2d236234b975c4ada88ad624e8ba4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 Jun 2004 19:08:36 +0400 Subject: Fix for Bug#4030 "Client side conversion string -> date type doesn't work (prepared statements)" and after-review fixes: - str_to_TIME renamed to str_to_datetime to pair with str_to_time - functions str_to_time and str_to_TIME moved to sql-common - send_data_str now supports MYSQL_TYPE_TIME, MYSQL_TIME_DATE, MYSQL_TIME_DATETIME types of user input buffers. - few more comments in the client library - a test case added. VC++Files/libmysql/libmysql.dsp: new file: my_time.c VC++Files/libmysqld/libmysqld.dsp: new file: my_time.c VC++Files/sql/mysqld.dsp: new file: my_time.c include/Makefile.am: - mysql_time.h added to the list of installed client library headers include/mysql.h: - declarations for MYSQL_TIME and enum_mysql_timestamp_type moved to mysql_time.h, which is in shared use of client library and mysys. libmysql/Makefile.shared: - my_time.lo added to the list of libmysql objects libmysql/libmysql.c: Fix for bug#4030 "Client side conversion string -> date type doesn't work (prepared statements)" and cleanup. - added case labels for TIME/DATE/DATETIME types to send_data_str - comments for read_binary_{date,time,datetime}, fetch_result_*, fetch_results. libmysqld/Makefile.am: - my_time.c added sql-common/Makefile.am: - my_time.c added to the list of files included into source distribution. sql/Makefile.am: my_time.c added to the list of mysqld sources. sql/field.cc: - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...} sql/item.cc: - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...} sql/item_timefunc.cc: - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...} sql/mysql_priv.h: - added typedefs for TIME and timestamp_type - removed declarations for str_to_time and str_to_TIME (now this functions reside in mysys) sql/mysqld.cc: - log_10_int moved to mysys (it's used by str_to_TIME and str_to_time) - enum values TIMESTAMP_{TIME,DATE,DATETIME} were renamed to MYSQL_TIMESTAMP_{TIME,DATE,DATETIME} sql/set_var.cc: - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...} sql/set_var.h: - fixed timestamp_type usage to be compatible with typedef. sql/sql_prepare.cc: - TIMESTAMP_{TIME,DATE,DATETIME} were renamed to MYSQL_TIMESTAMP_{TIME,DATE,DATETIME} - embedded library implementation of set_param_{time,date,datetime} is much simplier now, as MYSQL_TIME is the same as TIME. sql/sql_yacc.yy: - s/\ date type doesn't work (prepared statements)" --- tests/client_test.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'tests') diff --git a/tests/client_test.c b/tests/client_test.c index c035691fe47..de9f9cfd577 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -9964,6 +9964,80 @@ static void test_bug4236() } +static void test_bug4030() +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + MYSQL_TIME time_canonical, time_out; + MYSQL_TIME date_canonical, date_out; + MYSQL_TIME datetime_canonical, datetime_out; + const char *stmt_text; + int rc; + + myheader("test_bug4030"); + + /* Check that microseconds are inserted and selected successfully */ + + /* Execute a query with time values in prepared mode */ + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT '23:59:59.123456', '2003-12-31', " + "'2003-12-31 23:59:59.123456'"; + rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); + check_execute(stmt, rc); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + /* Bind output buffers */ + bzero(bind, sizeof(bind)); + bzero(&time_canonical, sizeof(time_canonical)); + bzero(&time_out, sizeof(time_out)); + bzero(&date_canonical, sizeof(date_canonical)); + bzero(&date_out, sizeof(date_out)); + bzero(&datetime_canonical, sizeof(datetime_canonical)); + bzero(&datetime_out, sizeof(datetime_out)); + + bind[0].buffer_type= MYSQL_TYPE_TIME; + bind[0].buffer= (char*) &time_out; + bind[1].buffer_type= MYSQL_TYPE_DATE; + bind[1].buffer= (char*) &date_out; + bind[2].buffer_type= MYSQL_TYPE_DATETIME; + bind[2].buffer= (char*) &datetime_out; + + time_canonical.hour= 23; + time_canonical.minute= 59; + time_canonical.second= 59; + time_canonical.second_part= 123456; + time_canonical.time_type= MYSQL_TIMESTAMP_TIME; + + date_canonical.year= 2003; + date_canonical.month= 12; + date_canonical.day= 31; + date_canonical.time_type= MYSQL_TIMESTAMP_DATE; + + datetime_canonical= time_canonical; + datetime_canonical.year= 2003; + datetime_canonical.month= 12; + datetime_canonical.day= 31; + datetime_canonical.time_type= MYSQL_TIMESTAMP_DATETIME; + + mysql_stmt_bind_result(stmt, bind); + + rc= mysql_stmt_fetch(stmt); + assert(rc == 0); + printf("%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second, + time_out.second_part); + printf("%d-%d-%d\n", date_out.year, date_out.month, date_out.day); + printf("%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month, + datetime_out.day, datetime_out.hour, + datetime_out.minute, datetime_out.second, + datetime_out.second_part); + assert(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0); + assert(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0); + assert(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0); + mysql_stmt_close(stmt); +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -10259,6 +10333,8 @@ int main(int argc, char **argv) test_bug4026(); /* test microseconds precision of time types */ test_bug4079(); /* erroneous subquery in prepared statement */ test_bug4236(); /* init -> execute */ + test_bug4030(); /* test conversion string -> time types in + libmysql */ /* XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH. -- cgit v1.2.1