skip to main content
Developing ODBC Applications : ODBC API Functions : Binding SQL Statements
 

Binding SQL Statements

An ODBC application can prepare a query that contains dynamic parameters. Each parameter in a SQL statement must be associated, or bound, to a variable in the application before the statement is executed. When the application binds a variable to a parameter, it describes that variable and that parameter to the driver. Therefore, the application must supply the following information:
The data type of the variable that the application wishes to map to the dynamic parameter.
The SQL data type of the dynamic parameter (the data type that the database system assigned to the parameter marker).
The two data types are identified separately using the SQLBindParameter API.
The ODBC Client relies on the binding of parameters to know how to send information to the database system in its native format. If an application furnishes incorrect parameter binding information to the ODBC driver, the results will be unpredictable. For example, the statement might not be executed correctly.
To ensure interoperability, the ODBC Client uses only the parameter binding information provided by the application.
NOTES:
The OpenAccess SDK SQL engine determines the SQL data type at prepare time, fixing it for the life of the statement. The SQL data type is not dependent on the data being used by the application. For example, it is not valid to bind the SQL type to SQL_NUMERIC with a precision of 15 and a scale of 5, and then bind it on a later execution to a SQL type of SQL_NUMERIC with a precision of 13 and a scale of 3.
A third-party SQL engine may not be able to determine parameter types at prepare time.
You can implement SQLDescribeParam only when a database system publishes parameter information after prepare time. The ODBC driver returns this information when the application requests it, but depending on the database, performance penalties can be incurred. You can tune this feature through the OpenAccess data source service attribute DataSourceDescribeParam. Refer to the OpenAccess SDK Administrator’s Guide for information about service attributes.