There is a problem in libmysqld/libmysql.c in the function fetch_long_with_conversion(), in this fragment:
Note, for MYSQL_TYPE_TIME it should call number_to_time() instead of number_to_datetime().
Note, on the contrary, fetch_string_with_conversion() is OK: it correctly calls str_to_time() for MYSQL_TYPE_TIME, while str_to_datetime() for DATE, TIMESTAMP and DATETIME
The attached program demonstrates the problem: it binds expressions of various data types to MYSQL_TYPE_TIME, and it returns the following results:
One would expect that data type conversion will happen in the same way with what happens on the server side with CAST(AS TIME).
However this is not the case.
- Conversion from 1010 to TIME returns DATETIME '2000-10-10 00:00:00.000000', which looks wrong. The expected result is TIME'00:10:10', i.e what CAST(1010 AS TIME) does.
- Conversion from 8003344 returns an error. The expected result is TIME'800:33:44'.
- Conversion from 8001112 returns an error. The expected result is TIME'800:11:12'.
- Conversion from 20101010 returns a DATE. The expected result is zero time. No conversion from DATE to TIME happened.
- Conversion from 20101010223344 returns a full datetime. The expected result is TIME'22:33:44'. No conversion from DATETIME to TIME happened.
- Conversion from 10001112 returns a DATE. The expected result is zero time. No conversion from DATE to TIME happened.