SQLDescribeParam

ODBC and SQL Server

ODBC and SQL Server

SQLDescribeParam

To describe the parameters of any SQL statement, the Microsoft® SQL Server™ ODBC driver builds and executes a Transact-SQL SELECT statement when SQLDescribeParam is called on a prepared ODBC statement handle. The driver uses the SET FMTONLY statement when executing the query. The meta data of the result set determines the characteristics of the parameters in the prepared statement.

Consider this ODBC SQL statement:

INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES (?, ?, ?)

On a call to SQLDescribeParam, this ODBC SQL statement causes the driver to execute the following Transact-SQL statement:

SET FMTONLY ON SELECT ShipperID, CompanyName, Phone FROM Shippers SET FMTONLY OFF

SQLDescribeParam can, therefore, return any error code that SQLExecute or SQLExecDirect might return.

Further, the driver does not support calling SQLDescribeParam after SQLExecDirect for any Transact-SQL UPDATE or DELETE statements containing the FROM clause; for any ODBC or Transact-SQL statement depending on a subquery containing parameters; for ODBC SQL statements containing parameter markers in both expressions of a comparison, like, or quantified predicate; or queries where one of the parameters is a parameter to a function.

When processing a batch of Transact-SQL statements, the driver also does not support calling SQLDescribeParam for parameter markers in statements after the first statement in the batch.

When describing the parameters of prepared stored procedures, SQLDescribeParam uses the system stored procedure sp_sproc_columns to retrieve parameter characteristics. sp_sproc_columns can report data for stored procedures within the current user database. Preparing a fully qualified stored procedure name allows SQLDescribeParam to execute across databases. For example, the system stored procedure sp_who can be prepared and executed in any database as:

SQLPrepare(hstmt, "{call sp_who(?)}", SQL_NTS);

Executing SQLDescribeParam after successful preparation returns an empty row set when connected to any database but master. The same call, prepared as follows, causes SQLDescribeParam to succeed regardless of the current user database:

SQLPrepare(hstmt, "{call master..sp_who(?)}", SQL_NTS);