Skip to Content.
Sympa Menu

freetds - [freetds] SQLGetData returns SQL_ERROR by mistake

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: TDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] SQLGetData returns SQL_ERROR by mistake
  • Date: Mon, 28 Jan 2008 21:40:00 -0500

http://msdn2.microsoft.com/en-us/library/ms715441(VS.85).aspx

Sometimes SQLGetData returns an error on column 1 when there's no real
error. ISTM it's a bug. I am using CVS HEAD without a DM.

SQLGetData fetches the data even though it returns SQL_ERROR. If there is
an error, SQLGetDiagRec doesn't know about it.

Documentation:

"When SQLGetData returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an
associated SQLSTATE value can be obtained by calling SQLGetDiagRec with a
HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle."

I call:
SQLPrepare, SQL_SUCCESS
SQLExecute, SQL_SUCCESS
SQLNumResultCols, SQL_SUCCESS -> 3 columns
SQLDescribeCol, SQL_SUCCESS, 3 times
SQLFetch, SQL_SUCCESS

Then I call:

erc = SQLGetData( hstm, 1, native_type(col),
col.bound.buffer,
col.bound.size, &indicator );

It returns SQL_ERROR; I'm not sure why. I call:

SQLGetDiagField SQL_DIAG_NUMBER, SQL_SUCCESS -> 0 diagnositics
SQLGetDiagRec returns SQL_ERROR for field 1, too.

I then continue with columns 2 & 3. I print the data: the data are good.
The pattern continues:

SQLFetch, SQL_SUCCESS
SQLGetData 1, SQL_ERROR, no diagnostics
SQLGetData 2, SQL_SUCCESS
SQLGetData 3, SQL_SUCCESS

and get good data for all three columns, for all 8 rows in the table.

A log snippet follows. It doesn't show much, unfortunately.
src/odbc/unittests/getdata.c doesn't test these exact conditions, but I
couldn't see a quick way to modify it. So I'm just filing a bug report
instead. ;-)

--jkl

token.c:223:Eating CONTROL token
token.c:510:processing result tokens. marker is d1(ROW)
token.c:621:tds_process_tokens::SET_RETURN stopping on current token
util.c:162:Changed query state from READING to PENDING
odbc.c:3253:odbc_process_tokens: tds_process_tokens returned 1
odbc.c:3254: result_type=4040, TDS_DONE_COUNT=0, TDS_DONE_ERROR=0
odbc.c:3323:odbc_process_tokens: returning result_type 4040
odbc.c:3100:_SQLExecute: odbc_process_tokens returned result_type 4040
odbc.c:4060:SQLNumResultCols(0x806e100, 0xbfbff3c2)
odbc.c:1692:SQLDescribeCol(0x806e100, 1, 0xbfbff180, 512, 0xbfbff17e,
0xbfbff178
odbc.c:1692:SQLDescribeCol(0x806e100, 2, 0xbfbff180, 512, 0xbfbff17e,
0xbfbff178
odbc.c:1692:SQLDescribeCol(0x806e100, 3, 0xbfbff180, 512, 0xbfbff17e,
0xbfbff178
odbc.c:3613:SQLFetch(0x806e100)
odbc.c:3357:_SQLFetch(0x806e100, 1, 0)
token.c:495:tds_process_tokens(0x806e200, 0xbfbff2e0, 0xbfbff2e4, 0x6508)
util.c:162:Changed query state from PENDING to READING
token.c:510:processing result tokens. marker is d1(ROW)
token.c:2166:tds_process_row(): reading column 0
token.c:1915:tds_get_data: type 38, varint size 1
token.c:1975:tds_get_data(): wire column size is 4
token.c:2166:tds_process_row(): reading column 1
token.c:1915:tds_get_data: type 109, varint size 1
token.c:1975:tds_get_data(): wire column size is 4
token.c:2166:tds_process_row(): reading column 2
token.c:1915:tds_get_data: type 39, varint size 1
token.c:1975:tds_get_data(): wire column size is 3
util.c:162:Changed query state from READING to PENDING
odbc.c:3253:odbc_process_tokens: tds_process_tokens returned 1
odbc.c:3254: result_type=4040, TDS_DONE_COUNT=0, TDS_DONE_ERROR=0
odbc.c:3323:odbc_process_tokens: returning result_type 4040
odbc.c:4521:SQLGetData(0x806e100, 3, 12, 0x806b2e0, 0, 0xbfbff2a8)
convert_tds2sql.c:62:convert_tds2sql: src is 39 dest = 12
error.c:630:SQLGetDiagField(3, 0x806e100, 0, 2, 0xbfbff268, 4, 0xbfbfee3e)
odbc.c:4521:SQLGetData(0x806e100, 2, 7, 0x806b300, 0, 0xbfbff288)
convert_tds2sql.c:62:convert_tds2sql: src is 59 dest = 7
odbc.c:4521:SQLGetData(0x806e100, 1, 4, 0x806b310, 0, 0xbfbff268)
convert_tds2sql.c:62:convert_tds2sql: src is 56 dest = 4
odbc.c:3613:SQLFetch(0x806e100)






Archive powered by MHonArc 2.6.24.

Top of Page