=== modified file 'driver/execute.c' --- driver/execute.c 2012-04-27 22:08:34 +0000 +++ driver/execute.c 2012-07-12 12:55:09 +0000 @@ -562,7 +562,13 @@ length= 19; - if (time->fraction) + /* + allow fractional parts only for MySQL Server 5.6 or + if the query is SELECT + */ + if (time->fraction && + (is_minimum_version(dbc->mysql.server_version, "5.6.", 4) || + is_select_statement(stmt->query))) { sprintf(buff + length, ".%09d", time->fraction); length+= 10; === modified file 'test/my_datetime.c' --- test/my_datetime.c 2012-04-27 10:32:05 +0000 +++ test/my_datetime.c 2012-07-12 13:06:27 +0000 @@ -48,6 +48,10 @@ ok_stmt(hstmt, SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN, 0)); + + /* We want to know if fractional part was truncated */ + ok_sql(hstmt, "set sql_mode='STRICT_ALL_TABLES'"); + /* insert using SQL_C_TIMESTAMP to SQL_TIMESTAMP */ ts.year= 2002; ts.month= 1; @@ -125,6 +129,11 @@ is_num(8, ts.month); is_num(25, ts.day); + ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_UNBIND)); + ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE)); + /* Set SQL_MODE back to the default value */ + ok_sql(hstmt, "set sql_mode=''"); + return OK; } @@ -1150,52 +1159,99 @@ DECLARE_TEST(t_b13975271) { - if (!mysql_min_version(hdbc, "5.6.", 4)) - { - skip("Necessary feature added in MySQL 5.6.*"); - } - else - { - SQLCHAR ts[27]; - SQLLEN len; - - ok_sql(hstmt, "DROP TABLE IF EXISTS t_b13975271"); + SQLCHAR ts[27]; + SQLLEN len; + BOOL is_server_5_6 = mysql_min_version(hdbc, "5.6.", 4); + TIMESTAMP_STRUCT tss; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_b13975271"); + + if(is_server_5_6) + { ok_sql(hstmt, "CREATE TABLE t_b13975271 (ts TIMESTAMP(6), dt DATETIME(6),\ t TIME(6))"); - - strcpy((char *)ts, "2012-04-25 10:20:49.0194"); - - ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, - SQL_TIMESTAMP,0, 0, ts, sizeof(ts), NULL)); - ok_stmt(hstmt, SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, - SQL_CHAR,0, 0, ts, sizeof(ts), NULL)); - ok_stmt(hstmt, SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, - SQL_CHAR,0, 0, ts, sizeof(ts), NULL)); - ok_stmt(hstmt, SQLPrepare(hstmt, "INSERT INTO t_b13975271(ts,dt,t) \ - VALUES (?,?,?)", - SQL_NTS)); - ok_stmt(hstmt, SQLExecute(hstmt)); - - ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE)); - - /* now fetch and verify the results .. */ - ok_sql(hstmt, "SELECT * FROM t_b13975271"); - - ok_stmt(hstmt, SQLFetch(hstmt)); - ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, ts, sizeof(ts), &len)); - is_str(ts, "2012-04-25 10:20:49.019400", 26); - - /*To make sure that for next test we compare not the data from prev call */ - ts[0]='\0'; - ok_stmt(hstmt, SQLGetData(hstmt, 2, SQL_C_CHAR, ts, sizeof(ts), &len)); - is_str(ts, "2012-04-25 10:20:49.0194", 24); - ok_stmt(hstmt, SQLGetData(hstmt, 3, SQL_C_CHAR, ts, sizeof(ts), &len)); - is_str(ts, "10:20:49.0194", 13); - - ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE)); - - ok_sql(hstmt, "DROP TABLE IF EXISTS t_b13975271"); - } + } + else + { + ok_sql(hstmt, "CREATE TABLE t_b13975271 (ts TIMESTAMP, dt DATETIME,\ + t TIME)"); + } + + /* We want to know if fractional part was truncated */ + ok_sql(hstmt, "set sql_mode='STRICT_ALL_TABLES'"); + + strcpy((char *)ts, "2012-04-25 10:20:49.0000194"); + tss.year= 2012; + tss.month= 4; + tss.day= 25; + tss.hour= 10; + tss.minute= 20; + tss.second= 49; + tss.fraction= 19400; + + ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_TIMESTAMP, + SQL_TIMESTAMP,0, 0, &tss, sizeof(tss), NULL)); + /* take out the fractional part because of SQL_CHAR target type */ + ok_stmt(hstmt, SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, + SQL_CHAR,0, 0, ts, + sizeof(ts) - (is_server_5_6 ? 0 : 1), + NULL)); + /* take out the fractional part because of SQL_CHAR target type */ + ok_stmt(hstmt, SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, + SQL_CHAR,0, 0, ts, + sizeof(ts) - (is_server_5_6 ? 0 : 1), + NULL)); + ok_stmt(hstmt, SQLPrepare(hstmt, "INSERT INTO t_b13975271(ts,dt,t) \ + VALUES (?,?,?)", + SQL_NTS)); + ok_stmt(hstmt, SQLExecute(hstmt)); + + ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE)); + + /* now fetch and verify the results .. */ + ok_sql(hstmt, "SELECT * FROM t_b13975271"); + + ok_stmt(hstmt, SQLFetch(hstmt)); + ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, ts, sizeof(ts), &len)); + + if(is_server_5_6) + { + is_str(ts, "2012-04-25 10:20:49.000019", 26); + } + else + { + is_str(ts, "2012-04-25 10:20:49", 19); + } + + /*To make sure that for next test we compare not the data from prev call */ + ts[0]='\0'; + ok_stmt(hstmt, SQLGetData(hstmt, 2, SQL_C_CHAR, ts, sizeof(ts), &len)); + + if(is_server_5_6) + { + is_str(ts, "2012-04-25 10:20:49.000019", 26); + } + else + { + is_str(ts, "2012-04-25 10:20:49", 19); + } + + ok_stmt(hstmt, SQLGetData(hstmt, 3, SQL_C_CHAR, ts, sizeof(ts), &len)); + if(is_server_5_6) + { + is_str(ts, "10:20:49.000019", 15); + } + else + { + is_str(ts, "10:20:49", 8); + } + + ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_b13975271"); + + /* Set SQL_MODE back to the default value */ + ok_sql(hstmt, "set sql_mode=''"); return OK; }