Microsoft KB Archive/113469

BUG: SQLNumResultCols Returns 0 if Query Begins w/ Parenthesis

PSS ID Number: Q113469 Article last modified on 11-16-1995

1.01.2807

WINDOWS

BUG# ODBCSDK2: 2404 (1.01.2807)

= SYMPTOMS =

When a SQL statement that starts with a parenthesis is prepared through SQLPrepare, and SQLNumResultCols is called immediately after the SQLPrepare, the number of columns returned by SQLNumResultCols is always 0.

SQLNumResultCols returns 0 after a successful SQLPrepare.

= CAUSE =

This problem occurs only if the statement begins with a parenthesis. When SQLNumResultCols is called after a SQLPrepare, the SQL Server driver normally determines the number of columns by sending a SQL select statement of the application after adding the following where condition: “where 1=2”.

Since this is always going to be false, the server will only return meta- data and not the tabular data. Thus, the driver provides an efficient implementation for the SQLNumResultCols call.

However, in the above case, when a parenthesis is the first token in the SQL string, the driver mistakenly thinks that the SQL statement is not a SELECT statement. Hence, it returns 0 as the number of columns for SQLNumResultCols.

= WORKAROUND =

Call SQLNumResultCols after SQLExecute, or use SQLExecDirect instead. This will return the correct number of columns.

= STATUS =

Microsoft has confirmed this to be a problem in the SQL Server driver version 1.01.2807. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

KBCategory: kbusage KBSubcategory:

= Additional reference words: 1.01.2807 ODBC =

Copyright Microsoft Corporation 1995.