Subject | Using Wide-Functions on unixODBC fails |
---|---|
Author | Daniel Vogelbacher |
Post date | 2013-04-10T19:41:35Z |
Hi,
when using the Firebird ODBC driver with unixODBC, the Wide-Functions
like SQLExecDirectW fails.
UnixODBC defines SQLWCHAR as a 2-Byte value. I've transformed my
wchar_t* strings to UCS2 and call SQLExecDirectW() with them.
Here is the trace (debug version):
----
SQLExecDirectW
Preparing statement:
INSERT INTO FOO VALUES(NU
Preparing statement:
INSERT INTO FOO VALUES(NU
HY000:1:-104:[ODBC Firebird Driver][Firebird]Dynamic SQL Error
SQL error code = -104
Unexpected end of command - line 1, column 24
----
It seems that something in the ODBC driver truncates the
statement to the half. A short look into the code shows this function
inside the ConvertingString template (MainUnicode.cpp):
SQLCHAR * convUnicodeToString( SQLWCHAR *wcString, int length )
{
size_t bytesNeeded;
wchar_t *ptEndWC = NULL;
wchar_t saveWC;
if ( length == SQL_NTS )
length = (int)wcslen( (const wchar_t*)wcString );
...
I think the problem is that wcslen() expects a whar_t (4 bytes) sequence,
while SQLWCHAR is 2 bytes long.
Because I'm unsure if my code is correct, I've tested the same with
python3 and pyodbc (which uses the wide-functions, too).
This results in the same issue, so using the firebird odbc driver
with pyodbc/python3 is impossible for the moment.
Could anyone confirm this issue?
--
Daniel Vogelbacher
www.chaospixel.com
cytrinox@freenode/ircnet/quakenet
[Non-text portions of this message have been removed]
when using the Firebird ODBC driver with unixODBC, the Wide-Functions
like SQLExecDirectW fails.
UnixODBC defines SQLWCHAR as a 2-Byte value. I've transformed my
wchar_t* strings to UCS2 and call SQLExecDirectW() with them.
Here is the trace (debug version):
----
SQLExecDirectW
Preparing statement:
INSERT INTO FOO VALUES(NU
Preparing statement:
INSERT INTO FOO VALUES(NU
HY000:1:-104:[ODBC Firebird Driver][Firebird]Dynamic SQL Error
SQL error code = -104
Unexpected end of command - line 1, column 24
----
It seems that something in the ODBC driver truncates the
statement to the half. A short look into the code shows this function
inside the ConvertingString template (MainUnicode.cpp):
SQLCHAR * convUnicodeToString( SQLWCHAR *wcString, int length )
{
size_t bytesNeeded;
wchar_t *ptEndWC = NULL;
wchar_t saveWC;
if ( length == SQL_NTS )
length = (int)wcslen( (const wchar_t*)wcString );
...
I think the problem is that wcslen() expects a whar_t (4 bytes) sequence,
while SQLWCHAR is 2 bytes long.
Because I'm unsure if my code is correct, I've tested the same with
python3 and pyodbc (which uses the wide-functions, too).
This results in the same issue, so using the firebird odbc driver
with pyodbc/python3 is impossible for the moment.
Could anyone confirm this issue?
--
Daniel Vogelbacher
www.chaospixel.com
cytrinox@freenode/ircnet/quakenet
[Non-text portions of this message have been removed]