Issue Details (XML | Word | Printable)

Key: ODBC-192
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Alexander Potapchenko
Reporter: Enno Kehrer
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
ODBC Driver

Incorrect conversion of time values when retrieved as string

Created: 21/Aug/15 03:26 PM   Updated: 06/Mar/16 05:35 PM
Component/s: None
Affects Version/s: 2.0.3
Fix Version/s: 2.0.4

File Attachments: 1. File FirebirdODBC_time.cpp (6 kB)

Environment: Windows 8.1 (64 bit), Firebird 2.5


 Description  « Hide
My test table looks like this:

CREATE TABLE test_time (id int, val time);
INSERT INTO test_time VALUES (0, NULL);
INSERT INTO test_time VALUES (1, '00:00:00');
INSERT INTO test_time VALUES (2, '00:00:00.1');
INSERT INTO test_time VALUES (3, '00:00:00.01');
INSERT INTO test_time VALUES (4, '00:00:00.001');
INSERT INTO test_time VALUES (5, '00:00:00.0001');

I connect to Firebird using ODBC and run the query:
SELECT id, val FROM test_time ORDER BY id;

Reading the time value using the TIME_STRUCT I get no fractional seconds,
therefore I tried reading it as strings using the following code:

std::string readString(HSTMT hstmt, SQLUSMALLINT col) {
SQLLEN ind;
std::string val(1024, 0);
RETCODE rc = SQLGetData(hstmt, col, SQL_C_CHAR, (SQLPOINTER)(val.data()), val.size(), &ind);
if (!SQL_SUCCEEDED(rc)) { reportErrors(SQL_HANDLE_STMT, hstmt); }
return (ind != SQL_NULL_DATA) ? std::string(val.c_str()) : nullValue;
}

the result looks like this:
'0','NULL'
'1','00:00:00'
'2','00:00:00.1000'
'3','00:00:00.100'
'4','00:00:00.10'
'5','00:00:00.1'

=> notice that the fracional seconds are wrong.

I looked in conversion code an found in
OdbcConvert::convTimeToString and
OdbcConvert::convTimeToStringW
that the format string
"%02d:%02d:%02d.%lu"
is wrong and should look like
"%02d:%02d:%02d.%04lu"
and the nnano value must be divided by 10000 to get 4 digits precision.


=> workaround: retrieve the time value as timestamp (SQL_C_TIMESTAMP using the TIMESTAMP_STRUCT) and extract the time part.



 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alexander Potapchenko added a comment - 29/Dec/15 02:35 PM
Fixed in CVS