Index: ChangeLog =================================================================== --- ChangeLog (revision 604) +++ ChangeLog (working copy) @@ -5,6 +5,9 @@ ODBC logging should be used. Bugs fixed: + * SQLSpecialColumns() returned all TIMESTAMP fields when queried for + SQL_ROWVER, not just an auto-updating TIMESTAMP field. (Bug #9927, still + limited by Bug #30081 in the server.) * SQLConnect() and SQLDriverConnect() were rewritten to eliminate duplicate code and ensure all options were supported using both connection methods. SQLDriverConnect() now only requires the setup library to be present when Index: driver/catalog.c =================================================================== --- driver/catalog.c (revision 605) +++ driver/catalog.c (working copy) @@ -1545,8 +1545,15 @@ (field = mysql_fetch_field(result)); ) { int type; - if ( (field->type != MYSQL_TYPE_TIMESTAMP) ) - continue; + if ((field->type != MYSQL_TYPE_TIMESTAMP)) + continue; + /* + TIMESTAMP_FLAG is only set on fields that are auto-set or + auto-updated. We really only want auto-updated, but we can't + tell the difference because of Bug #30081. + */ + if (!(field->flags & TIMESTAMP_FLAG)) + continue; field_count++; sprintf(buff,"%d",SQL_SCOPE_SESSION); row[0]= strdup_root(alloc,buff); Index: test/my_datetime.c =================================================================== --- test/my_datetime.c (revision 603) +++ test/my_datetime.c (working copy) @@ -686,6 +686,61 @@ } +/** + Bug #9927: Updating datetime columns +*/ +DECLARE_TEST(t_bug9927) +{ + SQLCHAR col[10]; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug9927"); + ok_sql(hstmt, + "CREATE TABLE t_bug9927 (a TIMESTAMP DEFAULT 0," + "b TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)"); + + ok_stmt(hstmt, SQLSpecialColumns(hstmt,SQL_ROWVER, NULL, 0, + NULL, 0, (SQLCHAR *)"t_bug9927", SQL_NTS, + 0, SQL_NO_NULLS)); + + ok_stmt(hstmt, SQLFetch(hstmt)); + + is_str(my_fetch_str(hstmt, col, 2), "b", 1); + + expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug9927"); + + return OK; +} + + +/** + Bug #30081: Can't distinguish between auto-set TIMESTAMP and auto-updated + TIMESTAMP +*/ +DECLARE_TEST(t_bug30081) +{ + SQLCHAR col[10]; + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug30081"); + ok_sql(hstmt, + "CREATE TABLE t_bug30081 (a TIMESTAMP DEFAULT 0," + "b TIMESTAMP DEFAULT CURRENT_TIMESTAMP)"); + + ok_stmt(hstmt, SQLSpecialColumns(hstmt,SQL_ROWVER, NULL, 0, + NULL, 0, (SQLCHAR *)"t_bug30081", SQL_NTS, + 0, SQL_NO_NULLS)); + + expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND); + + ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE)); + + ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug30081"); + + return OK; +} BEGIN_TESTS ADD_TEST(my_ts) ADD_TEST(t_tstotime) @@ -695,6 +750,8 @@ ADD_TEST(t_time1) ADD_TEST(t_bug12520) ADD_TEST(t_bug15773) + ADD_TEST(t_bug9927) + ADD_TODO(t_bug30081) END_TESTS