1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +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:
Georg Richter
2018-05-28 15:51:58 +02:00
parent a12a0b8362
commit 407ca36f24
2 changed files with 130 additions and 54 deletions

View File

@@ -4654,39 +4654,68 @@ static int test_compress(MYSQL *mysql)
static int test_codbc138(MYSQL *mysql)
{
int rc;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
MYSQL_TIME tm;
int i= 0;
rc= mysql_stmt_prepare(stmt, SL("SELECT DATE_ADD('2018-02-01', INTERVAL -188 DAY)"));
check_stmt_rc(rc, stmt);
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}}
};
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, 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);
if (tm.year != 2017 && tm.day != 28 && tm.month != 7)
while (time_test[i].statement)
{
diag("Error: Expected 2017-07-02");
return FAIL;
}
if (tm.minute | tm.second || tm.second_part)
{
diag("Error: minute, second or second_part is not zero");
return FAIL;
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++;
}
mysql_stmt_close(stmt);
return OK;
}
@@ -4776,4 +4805,3 @@ int main(int argc, char **argv)
return(exit_status());
}