HDBC-odbc: Retrieve broken data from MySQL
HDBC-odbc: Retrieve broken data from MySQL

Hi John,

I'm using HDBC-odbc to connect to my MySQL server and found some problems
when I dealt with large data. When I fetch data from a text column it
sometimes returns a string which contains NUL characters.

I digged into the source code and found that the return value of
sqlGetData was not handled correctly. What I saw in "ffetchrow" function
was:

1. sqlDescribeCol returns a column size which is less than actual data.
Maybe this is because the column's charset is utf-8.
2. sqlGetData returns SQL_SUCCESS_WITH_INFO but the caller ignores
it. In this case plen contains the actual length which is greater than
the buffer size.
3. peekCStringLen peeks data after the end of the buffer.

I attached a patch to fix this.

First, it uses peekCString instead of peekCStringLen because the buffer
must be terminated by NUL. Second, it calls sqlGetData twice when plen is
greater than the buffer size. As a result, it eliminates the call of
sqlDescribeCol because sqlGetData returns a needed buffer size.

Best Regards,

--
Satoshi Nakamura <snakamura@infoteria.co.jp>
Infoteria Corporation

hdbc/hdbc-odbc