You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fixed string conversion to MYSQL_TIME_TYPE:
- added support for negative time values - invalid strings (and/or conversion) and invalid values will result in MYSQL_TIMESTAMP_ERROR time type - added support for 2digit year representation: values < 69 will be converted to 20YY values >= 69 will be converted to 19YY
This commit is contained in:
committed by
Sergei Golubchik
parent
e5a7852f42
commit
7d28557c8d
@@ -4685,9 +4685,78 @@ static int test_conc334(MYSQL *mysql)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_codbc138(MYSQL *mysql)
|
||||
{
|
||||
int rc;
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND bind[1];
|
||||
MYSQL_TIME tm;
|
||||
int i= 0;
|
||||
|
||||
struct st_time_test {
|
||||
char *statement;
|
||||
MYSQL_TIME tm;
|
||||
} time_test[]= {
|
||||
{"SELECT DATE_ADD('2018-02-01', INTERVAL -188 DAY)",
|
||||
{2017,7,28,0,0,0,0L,0, MYSQL_TIMESTAMP_DATE}
|
||||
},
|
||||
{"SELECT '2001-02-03 11:12:13.123456'",
|
||||
{2001,2,3,11,12,13,123456L,0, MYSQL_TIMESTAMP_DATETIME}
|
||||
},
|
||||
{"SELECT '-11:12:13'",
|
||||
{0,0,0,11,12,13,0,1, MYSQL_TIMESTAMP_TIME}
|
||||
},
|
||||
{"SELECT ' '",
|
||||
{0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
|
||||
},
|
||||
{"SELECT '1--'",
|
||||
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
|
||||
},
|
||||
{"SELECT '-2001-01-01'",
|
||||
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
|
||||
},
|
||||
{"SELECT '-11:00'",
|
||||
{1,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR}
|
||||
},
|
||||
{NULL, {0}}
|
||||
};
|
||||
|
||||
while (time_test[i].statement)
|
||||
{
|
||||
stmt= mysql_stmt_init(mysql);
|
||||
rc= mysql_stmt_prepare(stmt, SL(time_test[i].statement));
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_execute(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_store_result(stmt);
|
||||
|
||||
memset(bind, 0, sizeof(MYSQL_BIND));
|
||||
bind[0].buffer_type= MYSQL_TYPE_DATETIME;
|
||||
bind[0].buffer= &tm;
|
||||
bind[0].buffer_length= sizeof(MYSQL_TIME);
|
||||
|
||||
rc= mysql_stmt_bind_result(stmt, bind);
|
||||
check_stmt_rc(rc, stmt);
|
||||
rc= mysql_stmt_fetch(stmt);
|
||||
check_stmt_rc(rc, stmt);
|
||||
diag("test: %s %d %d", time_test[i].statement, tm.time_type, time_test[i].tm.time_type);
|
||||
if (time_test[i].tm.time_type == MYSQL_TIMESTAMP_ERROR)
|
||||
{
|
||||
FAIL_UNLESS(tm.time_type == MYSQL_TIMESTAMP_ERROR, "MYSQL_TIMESTAMP_ERROR expected");
|
||||
}
|
||||
else
|
||||
FAIL_UNLESS(memcmp(&tm, &time_test[i].tm, sizeof(MYSQL_TIME)) == 0, "time_in != time_out");
|
||||
mysql_stmt_close(stmt);
|
||||
i++;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL},
|
||||
{"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_mdev14165", test_mdev14165, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
@@ -4771,4 +4840,3 @@ int main(int argc, char **argv)
|
||||
|
||||
return(exit_status());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user