Databases Reference
In-Depth Information
rc = SQLBindCol (...);
rc = SQLExtendedFetch (...);
// user must retrieve N rows from the server
// N = # result columns of UnknownTable
// result column information has now been obtained
Example B:
SQLDescribeCol
Function
A simple query that retrieves result set information is prepared, but the
query is not executed and result rows are not retrieved by the driver.
Only information about the result set is retrieved (the same information
retrieved by
SQLColumns
in Example A).
// prepare dummy query
rc = SQLPrepare (... "SELECT * FROM UnknownTable" +
"WHERE 1 = 0" ...);
// query is never executed on the server - only prepared
rc = SQLNumResultCols (...);
for (irow = 1; irow <= NumColumns; irow++) {
rc = SQLDescribeCol (...)
// + optional calls to SQLColAttributes
}
// result column information has now been obtained
// Note we also know the column ordering within the table!
// This information cannot be
// assumed from the SQLColumns example.
What if the database server, such as a Microsoft SQL Server server does
not support prepared statements by default? The performance of
Example A wouldn't change, but the performance of Example B would
decrease slightly because the dummy query is evaluated in addition to
being prepared. Because the
Where
clause of the query always evaluates
to
FALSE
, the query generates no result rows and executes the state-
ment without retrieving result rows. So, even with a slight decrease in
performance, Example B still outperforms Example A.