In Chapter 2, "Understanding MFC's ODBC Database Classes," you learned about the MFC data access objects. These C++ classes were built on the data access functions that are part of the SQL library that interfaces with ODBC. These functions offer a powerful interface to ODBC.
The first part of this chapter is a reference to the SQL...() functions that make up the ODBC SDK 2.x interface. Those functions that were present in the ODBC SDK 1.0 version (such as SQLSetParam()) and that have been deleted in more recent versions of ODBC aren't covered in this chapter. The second part of this chapter presents a set of functions that you can use to access datasets. It generally is more difficult to use the SQL...() functions than to use the MFC database classes described in Chapter 2. However, these functions do offer more flexibility to the programmer who is writing an application that must access many different types of datasources, with differing tables and schema (layout and definitions).
Not withstanding the existing functionality found in the MFC ODBC classes, there is no reason why you can't use both the MFC classes and the SQL...() functions in the same code. The MFC ODBC classes have all the necessary handles to allow usage of the SQL...() functions; in fact, the MFC ODBC classes use the SQL...() functions to perform most of their database manipulation tasks.
This reference to the SQL...() functions will show virtually everything you need to know in order to use most of these functions. However, some functions are complex and return a substantial amount of information. If you need more information, you can refer to the various help files available (including the MSDN CD set, the ODBC SDK, and Visual C++'s help facility).
NOTE
The SQL...() functions haven't changed substantially since their introduction. Minor changes to accommodate 32-bit programming (the original SQL...() functions were 16-bit) account for virtually all the changes found.
When you use the SQL...() functions, remember that there is a fixed order of usage. The sample code in the second part of this chapter provides more information about how to use the functions.
Each function is presented with a prototype, function arguments (if any), an explanation of the return value (if any), a description of what the function should do, and an explanation of possible failures that might occur when you use the function. Some functions will fail for a number of reasons. When you encounter a failure, use SQLError() to determine the cause of the failure.
NOTE
Using the SQL logging facility is often very useful in determining why an SQL function failed during development. Of course, you shouldn't expect your application's users to have SQL logging turned on.
Don't forget that SQL logging will significantly affect ODBC performance because detailed information is written to the logging file for each and every SQL operation. Don't turn on SQL logging indiscriminately; use it when you need it and then turn it off.
In all cases where the return value is shown as type RETCODE, you should create a variable defined as this type to hold the return code. You can then use either an if() or a switch() statement to check the return code for errors.
NOTE
There are two versions of the ODBC SDK 2.1: 2.10a and 2.10b. You should use 2.10b, which was released in August of 1995, if you're using Visual C++ 2.x. The version of ODBC that is included with Visual C++ 4.0 is 2.5. Version 2.5 is intended for use on both Windows 95 and on Windows NT versions 3.5 and 3.51.
NOTE
The current version of the ODBC SDK is 2.5, which is included with both Visual C++ 4 and Visual C++ 1.5x. Microsoft hasn't announced whether (or when) further updates to the ODBC SDK will occur. It can be assumed that new versions of Visual C++ may well include new versions of ODBC.
Prototype:
RETCODE SQLAllocConnect(HENV henv, HDBC FAR * phdbc)
Parameters:
| HENV henv | The environment handle from the call to SQLAllocEnv(). |
| HDBC FAR * phdbc | A pointer to the storage for the connection handle. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
The SQLAllocConnect() function is used to allocate the connection between the application and the datasource. It's called after a call to SQLAllocEnv(), and SQLAllocStmt() is called after a call to SQLAllocEnv().
You must call the SQLAllocConnect() function after getting an HENV handle from SQLAllocEnv(). Without a valid HENV handle, this function won't succeed. Always check the return code from this function for errors.
Notes:
The function's results are placed in the handle pointed to by the phdbc parameter. If the SQLAllocConnect() function fails, the phdbc handle will be set to SQL_NULL_HDBC.
Prototype:
RETCODE SQLAllocEnv(HENV FAR * phenv)
Parameter:
| HENV FAR * phenv | A pointer to an environment handle. |
\Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed. Often, this function is the first SQL...() function that is called. If it fails, there may be no recovery.
Usage:
Call the SQLAllocEnv() function to initialize the SQL environment. You should make a matching SQLFreeEnv() call when your calling function has finished accessing the datasource. Always check the return code from these functions for errors.
Notes:
This function places the HENV in the supplied handle. If SQLAllocEnv() fails, the resultant phenv parameter is set to SQL_NULL_HENV.
Prototype:
RETCODE SQLAllocStmt(HDBC hdbc, HSTMT FAR * hstmt)
Parameters:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
| HSTMT FAR * hstmt | A pointer to a statement handle that will be filled in by this function. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
The SQLAllocStmt() function is used to allocate a statement handle. This statement handle is associated with the datasource to which the HDBC handle was connected.
Notes:
If this function fails, the returned HSTMT handle will be set to SQL_NULL_HSTMT.
Prototype:
RETCODE SQLBindCol(HSTMT hstmt, UWORD icol, SWORD fCType, PTR rbgValue, SDWORD cbValueMax, SDWORD FAR * pcbValue)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD icol | The index to the column in the table to which the variable is being bound. |
| SWORD fCType | The data type of the data variable that is being bound to column icol. |
| PTR rgbValue | A pointer to the location in the application where the column's data is to be stored. The data type of rgbValue should be defined by fCType. |
| SDWORD cbValueMax | The number of bytes in the storage location pointed to by rgbValue. Usually, the C sizeof() operator can be used for this parameter. |
| SDWORD FAR * pcbValue | A pointer to an SDWORD variable that will receive the count of how many bytes in rgbValue were used. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLBindCol() function only for the columns in a table that you need. You don't have to bind to every column in a table. Columns that don't have a variable bound to them will be discarded without error.
You make a callusually in a loopto SQLFetch() or SQLExtendedFetch() to actually get the data from a record.
Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why. When a column hasn't been bound and later must be accessed, use SQLGetData().
Prototype:
RETCODE SQLBindParameter(HSTMT hstmt, UWORD ipar, SWORD fParamType, SWORD fCType, SWORD fSqlType, UDWORD cbColDef, SWORD ibScale, PTR rgbValue, SDWORD cbValueMax, SDWORD pcbValue)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD ipar | The parameter number, which is one-based (not zero-based) from left to right. |
| SWORD fParamType | Parameter ipar's type. |
| SWORD fCType | The C data type of the parameter. |
| SWORD fSqlType | The SQL data type of the parameter. |
| UDWORD cbColDef | The column's precision. |
| SWORD ibScale | The column's scale. |
| PTR rgbValue | A pointer to the location in the application where the column's data is to be stored. The data type of rgbValue should be defined by fCType. |
| SDWORD cbValueMax | The number of bytes in the storage location pointed to by rgbValue. Usually the C sizeof() operator can be used for this parameter. |
| SDWORD FAR * pcbValue | A pointer to an SDWORD variable that will receive the count of how many bytes in rgbValue were used. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLBindParameter() function to bind a buffer to a parameter marker in an SQL statement. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why. This function replaces the SQLSetParam() function found in ODBC version 1.x.
Prototype:
RETCODE SQLBrowseConnect(HDBC hdbc, UCHAR FAR * szConnStrIn, SWORD cbConnStrIn, UCHAR FAR * szConnStrOut, SWORD cbConnStrOutMax, SWORD FAR * pcbConnStrOut)
Parameters:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
| UCHAR FAR * szConnStrIn | The input connection string. |
| SWORD cbConnStrIn | The number of bytes in szConnStrIn. |
| UCHAR FAR * szConnStrOut | The output connection string. |
| SWORD cbConnStrOutMax | The number of bytes available in szConnStrOut. |
| SWORD FAR * pcbConnStrOut | The count of the number of bytes actually used in szConnStrOut. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NEED_DATA | The function failed. More information in the input connect string was required than was supplied. Call SQLError() to get more information about the specific failure. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLBrowseConnect() function to enumerate the attributes of a specific datasource. Always check the return code from this function for errors, making additional calls as necessary to gather the desired information to establish the connection.
Notes:
When a return code of either SQL_SUCCESS or SQL_SUCCESS_WITH_INFO is returned, your application will know that the enumeration process has completed and the application is connected to the datasource.
Prototype:
RETCODE SQLCancel (HSTMT hstmt)
Parameter:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLCancel() function to cancel an asynchronous operation pending on the parameter statement indicated by hstmt. Always check the return code from this function for errors.
Notes:
You can cancel functions running on hstmt that are running on other threads. You also can cancel functions on hstmt that require more data.
Prototype:
RETCODE SQLColAttributes (HSTMT hstmt, UWORD icol, UWORD fDescType, PTR rgbDesc, SWORD cbDescMax, SWORD FAR * pcbDesc, SWORD FAR * pfDesc)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD icol | The index to the column in the table that the variable is being bound to. |
| UWORD fDescType | A valid descriptor. |
| PTR rgbDesc | A pointer to the location in the application where the column's data is to be stored. The data type of rgbValue should be defined by fCDescType. |
| SWORD cbDescMax | The number of bytes in the storage location pointed to by rgbDesc. Usually, the C sizeof() operator can be passed for this parameter. |
| SWORD FAR * pcbDesc | A pointer to an SDWORD variable that will receive the count of how many bytes in rgbDesc were used. |
| SWORD FAR * pfDesc | A pointer to an integer variable that will receive the results of a query which returns a numeric result. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLColAttributes() function to gather information about a column in a table. Always check the return code from this function for errors.
Notes:
Table 3.1 shows the information that will be returned for columns.
| Identifier | Minimum ODBC Version | Where Returned | Description |
| SQL_COLUMN_AUTO_INCREMENT | 1.0 | pfDesc | Returns TRUE if the column is an auto-increment column and FALSE if it isn't. Only numeric columns can be auto increment. Values may be inserted into an auto-increment column, but the auto-increment column can't be updated. |
| SQL_COLUMN_CASE_SENSITIVE | 1.0 | pfDesc | Returns TRUE if the column will be considered case-sensitive for sorts and comparisons. Columns that aren't character-based will return FALSE. |
| SQL_COLUMN_COUNT | 1.0 | pfDesc | Number of columns that are in the result set. The icol argument will be ignored. |
| SQL_COLUMN_DISPLAY_SIZE | 1.0 | pfDesc | Returns the maximum number of characters positions that will be necessary to display data from the column. |
| SQL_COLUMN_LABEL | 2.0 | rgbDesc | The column's label or title. As an example, an Access database may have a column called ZipCodes that could be labeled (or titled) "5-Digit Zip Code." The column name is returned for columns that don't have specified labels or titles. For unnamed columns (such as those found in a text file datasource), an empty string is returned. |
| SQL_COLUMN_LENGTH | 1.0 | pfDesc | The number of bytes of data that will be transferred on an SQLGetData() or SQLFetch() operation when the SQL_C_DEFAULT parameter is specified. |
| SQL_COLUMN_MONEY | 1.0 | pfDesc | Returns TRUE if the column is a money data type. |
| SQL_COLUMN_NAME | 1.0 | rgbDesc | Returns the column name. If the column is unnamed, an empty string is returned. See SQL_COLUMN_LABEL earlier in this table. |
| SQL_COLUMN_NULLABLE | 1.0 | pfDesc | Returns SQL_NO_NULLS if the column doesn't accept null values, or returns SQL_NULLABLE if the column accepts null values. Will return SQL_NULLABLE_UNKNOWN if it can't be determined whether the column accepts null values. |
| SQL_COLUMN_OWNER_NAME | 2.0 | rgbDesc | Returns the name of the owner of the table that contains the specified column. When the datasource doesn't support owners (such as for xBase files) or the owner name can't be determined, an empty string will be returned. |
| SQL_COLUMN_PRECISION | 1.0 | pfDesc | Returns the precision of the column on the datasource. |
| SQL_COLUMN_QUALIFIER_NAME | 2.0 | rgbDesc | Returns the table qualifier for the column. For datasources that don't support qualifiers or where the qualifier name can't be determined, an empty string will be returned. |
| SQL_COLUMN_SCALE | 1.0 | pfDesc | Returns the scale of the column on the datasource. |
| SQL_COLUMN_SEARCHABLE | 1.0 | pfDesc | Returns SQL_UNSEARCHABLE when the column can't be used in a WHERE clause. |
| Returns SQL_LIKE_ONLY if the column can be used in a WHERE clause only with the LIKE predicate. When the column is a type SQL_LONGVARCHAR or SQL_LONGVARBINARY this is the usual return. | |||
| Returns SQL_ALL_EXCEPT_LIKE if the column can be used in a WHERE clause with all comparison operators except LIKE. | |||
| Returns SQL_SEARCHABLE if the column can be used in a WHERE clause with any comparison operator. | |||
| SQL_COLUMN_TABLE_NAME | 2.0 | rgbDesc | Returns the table name for the table that contains the column. When the table name can't be determined, an empty string is returned. |
| SQL_COLUMN_TYPE | 1.0 | pfDesc | Returns the SQL data type for the column. |
| SQL_COLUMN_TYPE_NAME | 1.0 | rgbDesc | A character string indicating the data type of the column: CHAR, VARCHAR, MONEY, LONG VARBINARY, or CHAR ( ) FOR BIT DATA. When the data type is unknown, an empty string is returned. |
| SQL_COLUMN_UNSIGNED | 1.0 | pfDesc | Returns TRUE if the column is either nonnumeric or is an unsigned numeric value. |
|
SQL_COLUMN_UPDATABLE
|
1.0
|
pfDesc
| The column will be described with one of the following constants: SQL_ATTR_READONLY, SQL_ATTR_WRITE, SQL_ATTR_READWRITE_UNKNOWN, SQL_COLUMN_UPDATABLE, which describe how the column may be updated. When it can't be determined whether the column may be updatable, SQL_ATTR_READWRITE_UNKNOWN is typically returned. |
Prototype:
RETCODE SQLColumnPrivileges(HSTMT hstmt, UCHAR FAR * szTableQualifier, SWORD cbTableQualifier, UCHAR FAR * szTableOwner, SWORD cbTableOwner, UCHAR FAR * szTableName, SWORD cbTableName, UCHAR FAR * szColumnName, SWORD cbColumnName)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UCHAR FAR * szTableQualifier | The table qualifier. Use an empty string for tables that don't support table qualifiers. |
| SWORD cbTableQualifier | The length of szTableQualifier. |
| UCHAR FAR * szTableOwner | The table owner name. Use an empty string for tables that don't support table owners. |
| SWORD cbTableOwner | The length of szTableOwner. |
| UCHAR FAR * szTableName | The table name. |
| SWORD cbTableName | The length of szTableName. |
| UCHAR FAR * szColumnName | The search pattern string (used for column names). |
| SWORD cbColumnName | The length of szColumnName. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_STILL_EXECUTING | An asynchronous event is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLColumnPrivileges() function to obtain a list of columns and privileges for the specified table. Always check the return code from this function for errors.
Notes:
The information is returned as a result set.
Prototype:
RETCODE SQLColumns(HSTMT hstmt, UCHAR FAR * szTableQualifier, SWORD cbTableQualifier, UCHAR FAR * szTableOwner, SWORD cbTableOwner, UCHAR FAR * szTableName, SWORD cbTableName, UCHAR FAR * szColumnName, SWORD cbColumnName)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UCHAR FAR * szTableQualifier | The table qualifier. Use an empty string for tables that don't support table qualifiers. |
| SWORD cbTableQualifier | The length of szTableQualifier. |
| UCHAR FAR * szTableOwner | The table owner name. Use an empty string for tables that don't support table owners. |
| SWORD cbTableOwner | The length of szTableOwner. |
| UCHAR FAR * szTableName | The table name. |
| SWORD cbTableName | The length of szTableName. |
| UCHAR FAR * szColumnName | The search pattern string (used for column names). |
| SWORD cbColumnName | The length of szColumnName. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLColumns() function obtain a list of the columns in a specified table. Always check the return code from this function for errors.
Notes:
The results are returned as a result set. The columns returned in the result set are shown in Table 3.2.
| Column Number | Data Type | Description |
| 1 | SQL_C_CHAR | Qualifier |
| 2 | SQL_C_CHAR | Owner |
| 3 | SQL_C_CHAR | Table Name |
| 4 | SQL_C_CHAR | Column Name |
| 5 | SQL_C_SSHORT | Data Type |
| 6 | SQL_C_CHAR | Type Name |
| 7 | SQL_C_SLONG | Precision |
| 8 | SQL_C_SLONG | Length |
| 9 | SQL_C_SSHORT | Scale |
| 10 | SQL_C_SSHORT | Radix |
| 11 | SQL_C_SSHORT | Nullable |
| 12 | SQL_C_CHAR | Remarks |
Prototype:
RETCODE SQLConnect(HDBC hdbc, UCHAR FAR * szDSN, SWORD cbDSN, UCHAR FAR * szUID, SWORD cbUID, UCHAR FAR * szAuthStr, SWORD cbAuthStr)
Parameters:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
| UCHAR FAR * szDSN | A pointer to a string containing the datasource name. |
| SWORD cbDSN | The length of szDSN. |
| UCHAR FAR * szUID | A pointer to the string that contains the user's identifier. |
| SWORD cbUID | The length of szUID. |
| UCHAR FAR * szAuthStr | The password or authentication string. |
| SWORD cbAuthStr | The length of szAuthStr. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLConnect() function to establish a connection between the application and a specific datasource. Always check the return code from this function for errors.
Notes:
The SQLConnect() function tells ODBC to load the driver in preparation for using the datasource.
Prototype:
RETCODE SQL (HENV henv, UWORD fDirection, UCHAR FAR * szDSN, SWORD cbDSNMax, SWORD FAR * pcbDSN, UCHAR FAR * szDescription, SWORD cbDescriptionMax, SWORD FAR * pcbDescription)
Parameters:
| HENV henv | Environment handle. |
| UWORD fDirection | This parameter is used to determine whether the driver manager will fetch the next datasource name in the list (use the SQL_FETCH_NEXT identifier) or whether the search starts from the beginning of the list (use the SQL_FETCH_FIRST identifier). |
| UCHAR FAR * szDSN | A pointer to a storage buffer for the datasource name. |
| SWORD cbDSNMax | Maximum length of the szDSN buffer. The maximum length supported by ODBC is SQL_MAX_DSN_LENGTH + 1. |
| SWORD FAR * pcbDSN | The total number of bytes returned in szDSN. If the returned string won't fit in szDSN, the datasource name is truncated to cbDSNMax 1 bytes. |
| UCHAR FAR * szDescription | A pointer to storage buffer for the description string of the driver associated with the datasource. The szDescription buffer should be at least 255 bytes long. Driver descriptions might be dBASE or SQL Server. |
| SWORD cbDescriptionMax | Maximum length of szDescription. |
| SWORD FAR * pcbDescription | The total number of bytes returned in szDSN. If the returned string won't fit in szDescription, the description is truncated to cbDescriptionMax 1 bytes. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | There were no datasources remaining. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDataSources() function to enumerate a list of the currently installed datasources. Always check the return code from this function for errors.
Notes:
You should call the SQLDataSources() function in a loop while the application checks the return code. When the return code is SQL_NO_DATA_FOUND, then all the datasources have been enumerated.
Prototype:
RETCODE SQL (HSTMT hstmt, UWORD icol, UCHAR FAR * szColName, SWORD cbColNameMax, SWORD FAR * pcbColName, SWORD FAR * pfSqlType, UDWORD FAR * pcbColDef, SWORD FAR * pibScale, SWORD FAR * pfNullable)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD icol | The index to the column in the table to which the variable is being bound. |
| UCHAR FAR * szColName | A pointer to a string that will contain the column name. For columns that have no name, or when the name can't be determined, an empty string will be returned. |
| SWORD cbColNameMax | The size of the szColName. |
| SWORD FAR * pcbColName | The number of bytes returned in szColName. If the column name won't fit in szColName, the column name is truncated to cbColNameMax 1 bytes. |
| SWORD FAR * pfSqlType | The column's SQL data type. Use one of the constants shown in Table 3.3 for this parameter. |
| UDWORD FAR * pcbColDef | The column's precision, or zero if the precision can't be determined. |
| SWORD FAR * pibScale | The column's scale, or zero if the scale can't be determined. |
| SWORD FAR * pfNullable | A constant that indicates whether this column supports null data values. Will be either SQL_NO_NULLS, SQL_NULLABLE, or SQL_NULLABLE_UNKNOWN. |
| Identifier | Description |
| SQL_BIGINT | Integer data |
| SQL_BINARY | Binary data |
| SQL_BIT | Bit-field data |
| SQL_CHAR | Character data |
| SQL_DATE | Data field |
| SQL_DECIMAL | Decimal data |
| SQL_DOUBLE | Double data |
| SQL_FLOAT | Floating-point data |
| SQL_INTEGER | Integer data |
| SQL_LONGVARBINARY | Binary data |
| SQL_LONGVARCHAR | Variable-length character data |
| SQL_NUMERIC | Numeric data |
| SQL_REAL | Floating-point data |
| SQL_SMALLINT | Integer data |
| SQL_TIME | Time data |
| SQL_TIMESTAMP | Timestamp data |
| SQL_TINYINT | Integer data |
| SQL_VARBINARY | Variable-length binary data |
| SQL_VARCHAR | Variable-length character data |
| Other | Driver-specific data |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDescribeCol() function to get information about a specific column in a datasource. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLDescribeParam(HSTMT hstmt, UWORD ipar, SWORD FAR * pfSqlType, UWORD FAR * pcbColDef, SWORD FAR * pibScale, SWORD FAR * pfNullable)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD ipar | The parameter marker index, ordered sequentially left to right. This index is one-based, not zero-based. |
| SWORD FAR * pfSqlType | A pointer to a variable that will be used to return the SQL type of the parameter. Valid SQL types are listed in Table 3.4. |
| UDWORD FAR * pcbColDef | The column's precision. |
| SWORD FAR * pibScale | The column's scale. |
| SWORD FAR * pfNullable | A constant that indicates whether this column supports null data values. Will be either SQL_NO_NULLS, SQL_NULLABLE, or SQL_NULLABLE_UNKNOWN. |
| Identifier | Description |
| SQL_BIGINT | Integer data |
| SQL_BINARY | Binary data |
| SQL_BIT | Bit-field data |
| SQL_CHAR | Character data |
| SQL_DATE | Data field |
| SQL_DECIMAL | Decimal data |
| SQL_DOUBLE | Double data |
| SQL_FLOAT | Floating-point data |
| SQL_INTEGER | Integer data |
| SQL_LONGVARBINARY | Binary data |
| SQL_LONGVARCHAR | Variable-length character data |
| SQL_NUMERIC | Numeric data |
| SQL_REAL | Floating-point data |
| SQL_SMALLINT | Integer data |
| SQL_TIME | Time data |
| SQL_TIMESTAMP | Timestamp data |
| SQL_TINYINT | Integer data |
| SQL_VARBINARY | Variable-length binary data |
| SQL_VARCHAR | Variable-length character data |
| Other | Driver-specific data |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDescribeParam() function to obtain a description of the parameter marker in an SQL statement. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLDisconnect(HDBC hdbc)
Parameter:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDisconnect() function to disconnect from the currently connected datasource. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLDriverConnect(HDBC hdbc, HWND hwnd, UCHAR FAR * szConnStrIn, SWORD cbConnStrIn, UCHAR FAR * szConnStrOut, SWORD cbConnStrOutMax, SWORD FAR * pcbConnStrOut, UWORD fDriverCompletion)
Parameters:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
| HWND hwnd | The window handle of the parent window. This is used if the SQLDriverConnect() function must display any dialog boxes to prompt the user for information (such as user ID or passwords). If a NULL pointer is specified, SQLDriverConnect() won't present any dialog boxes. |
| UCHAR FAR * szConnStrIn | A pointer to a full connection string, a partial connection string, or an empty string. Don't pass a NULL pointer. |
| SWORD cbConnStrIn | The length of szConnStrIn. |
| UCHAR FAR * szConnStrOut | A pointer to a buffer that will receive the resulting string that is used to connect to the datasource. This buffer should be at least 255 bytes or longer. |
| SWORD cbConnStrOutMax | The size of the szConnStrOut buffer. |
| SWORD FAR * pcbConnStrOut | A pointer to the variable that will receive the number of bytes that have been stored in szConnStrOut. If the buffer was too small to contain the connect string, the connect string in szConnStrOut is truncated to cbConnStrOutMax 1 bytes. |
| UWORD fDriverCompletion | Contains a flag that tells whether the driver manager or driver must prompt for more connection information. See Table 3.5 for valid values for this string. |
| Value | Description |
| SQL_DRIVER_PROMPT | The driver manager will display the datasources dialog box for the user to select the datasource. |
| SQL_DRIVER_COMPLETE | The driver will use the connection string specified by the application if the connection string contains the DSN keyword; otherwise, the same action as SQL_DRIVER_PROMPT is taken. |
| SQL_DRIVER_COMPLETE_REQUIRED | The driver will use the connection string specified by the application if the connection string contains the DSN keyword; otherwise, the same action as SQL_DRIVER_PROMPT is taken. |
| SQL_DRIVER_NOPROMPT | The driver manager uses the connection string specified by the application. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | The command didn't find the driver to connect to. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDriverConnect() function to connect to a specific driver. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLDrivers(HENV henv, UWORD fDirection, UCHAR FAR * szDriverDesc, SWORD cbDriverDescMax, SWORD FAR * pcbDriverDesc, UCHAR fAR * szDriverAttributes, SWORD cbDrvrAttrMax, SWORD FAR * pcbDrvrAttr)
Parameters:
| HENV henv | An environment handle, as returned by a call to SQLAllocEnv(). |
| UWORD fDirection | This parameter is used to determine whether the driver manager fetches the next, or first, driver description in the list. Use SQL_FETCH_NEXT or SQL_FETCH_FIRST. |
| UCHAR FAR * szDriverDesc | A pointer to a buffer for the driver description. |
| SWORD cbDriverDescMax | The size of the szDriverDesc buffer. |
| SWORD FAR * pcbDriverDesc | A pointer to a variable that will hold the number of bytes returned in szDriverDesc. If the size of the string returned is too large for szDriverDesc, the driver description in szDriverDesc will be truncated to cbDriverDescMax 1 bytes. |
| UCHAR FAR * szDriverAttributes | A pointer to a buffer that will hold the list of driver attribute value pairs. |
| SWORD cbDrvrAttrMax | The size of the szDriverAttributes buffer. |
| SWORD FAR * pcbDrvrAttr | A pointer to a variable that will hold the number of bytes placed in szDriverAttributes. If the size of the string returned is too large for szDriverAttributes, the list of attribute value pairs in szDriverAttributes will be truncated to cbDrvrAttrMax 1 bytes. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLDrivers() function to list the drivers and driver attributes. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLError(HENV henv, HDBC hdbc, HSTMT hstmt, UCHAR FAR * szSqlState, SDWORD FAR * pfNativeError, UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax, SWORD FAR * pcbErrorMsg)
Parameters:
| HENV henv | A handle to an HENV as returned by the call to the SQLAllocEnv() function, or SQL_NULL_HENV to query all open environments. |
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function, or SQL_NULL_HDBC to query all open database connections. |
| HSTMT hstmt | A handle to a HSTMT as returned by the call to the SQLAllocStmt() function, or SQL_NULL_HSTMT to query all open statements. |
| UCHAR FAR * szSqlState | A buffer containing the SQLSTATE, formatted as a null-terminated string, will be returned. |
| SDWORD FAR * pfNativeError | The returned native error code. |
| UCHAR FAR * szErrorMsg | A buffer that will point to the error message text. |
| SWORD cbErrorMsgMax | A variable that specifies the maximum length of the szErrorMsg buffer. This buffer's size must be less than or equal to SQL_MAX_MESSAGE_LENGTH 1. |
| SWORD FAR * pcbErrorMsg | A pointer to a variable that will contain the number of bytes in szErrorMsg. If the string is too large for szErrorMsg, the text in szErrorMsg will be truncated to cbErrorMsgMax 1 bytes. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | The command didn't find any error conditions on which to report. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should try to recoverdisplaying or saving whatever diagnostic information is appropriateor the error should be corrected and the function should be re-executed.
Usage:
Call the SQLError() function to obtain more information about the error condition. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLExecDirect(HSTMT hstmt, UCHAR FAR * szSqlStr, SDWORD cbSqlStr)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UCHAR FAR * szSqlStr | A pointer to an SQL statement to be executed. |
| SDWORD cbSqlStr | The length of the string in szSqlStr. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NEED_DATA | The function needs more information to process the request. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLExecDirect() function to execute (usually once) a preparable SQL statement. Always check the return code from this function for errors.
Notes:
This function is probably the fastest way to execute SQL statements when the statement needs to be executed only one time. If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLExecute(HSTMT hstmt)
Parameter:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NEED_DATA | The function needs more information to process the request. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLExecute() function to execute a prepared statement using the parameter values contained in marker variables, if there are any. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLExtenedeFetch(HSTMT hstmt, UWORD fFetchType, SDWORD irow, UDWORD FAR * pcrow, UWORD FAR * rgfRowStatus)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD fFetchType | Specifies the type of fetch desired. Table 3.6 describes valid values for this parameter. |
| SDWORD irow | Specifies the number of the row to be fetched. |
| UDWORD FAR * pcrow | Returns the count of the number of rows that were actually fetched. |
| UWORD FAR * rgfRowStatus | A pointer to an array of status values. |
| Identifier | Description |
| SQL_FETCH_NEXT | Fetch the next row. |
| SQL_FETCH_FIRST | Fetch the first row. |
| SQL_FETCH_LAST | Fetch the last row. |
| SQL_FETCH_PRIOR | Fetch the previous row. |
| SQL_FETCH_ABSOLUTE | Fetch the row specified absolutely. |
| SQL_FETCH_RELATIVE | Fetch the row specified relative to the current row. |
| SQL_FETCH_BOOKMARK | Fetch the marked row. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | The command didn't find the driver to connect to. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLExtendedFetch() function to fetch one or more rows from a result set. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLFetch(HSTMT hstmt)
Parameter:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | The command didn't find the driver to connect to. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLFetch() function to fetch a single row of data from the result set. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLForeignKeys(HSTMT hstmt, UCHAR FAR * szPkTableQualifier, SWORD cbPkTableQualifier, UCHAR FAR * szPkTableOwner, SWORD cbPkTableOwner, UCHAR FAR * szPkTableName, SWORD cbPkTableName, UCHAR FAR * szFkTableQualifier, SWORD cbFkTableQualifier, UCHAR FAR * szFkTableOwner, SWORD cbFkTableOwner, UCHAR FAR * szFkTableName, SWORD cbFkTableName)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UCHAR FAR * szPkTableQualifier | A pointer to the primary key table qualifier. |
| SWORD cbPkTableQualifier | The length of szPkTableQualifier. |
| UCHAR FAR * szPkTableOwner | A pointer to the primary key owner name. |
| SWORD cbPkTableOwner | The length of szPkTableOwner. |
| UCHAR FAR * szPkTableName | A pointer to the primary key table name. |
| SWORD cbPkTableName | The length of szPkTableName. |
| UCHAR FAR * szFkTableQualifier | A pointer to the foreign key table qualifier. |
| SWORD cbFkTableQualifier | The length of szFkTableQualifier. |
| UCHAR FAR * szFkTableOwner | A pointer to the foreign key owner name. |
| SWORD cbFkTableOwner | The length of szFkTableOwner. |
| UCHAR FAR * szFkTableName | A pointer to the foreign key table name. |
| SWORD cbFkTableName | The length of szFkTableName. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_STILL_EXECUTING | An asynchronous operation is still pending. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLForeignKeys() function to return either a list of foreign keys in the specified table or a list of foreign keys in other tables that refer to the primary key in the specified table. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLFreeConnect(HDBC hdbc)
Parameter:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
Return Value:
This function will return one of the following values:
SQL_SUCCESS The function was successful.
SQL_SUCCESS_WITH_INFO The function was successful, and more information is available.
SQL_ERROR The function failed. Call SQLError() to get more information about the specific failure.
SLQ_INVALID_HANDLE The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle.
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLFreeConnect() function to release the connection established with the SQLAllocConnect() function. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQL (HENV henv)
Parameter:
| HENV henv | A handle to an HENV as returned by the call to the SQLAllocEnv() function. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLFreeEnv() function to free the environment established by the SQLAllocEnv() function. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLFreeStmt(HSTMT hstmt, UWORD fOption)
Parameters:
| HSTMT hstmt | A statement handle returned by the call to SQLAllocStmt(). |
| UWORD fOption | An option from the list shown in Table 3.7. |
| Identifier | Description |
| SQL_ CLOSE | Used to close the cursor associated with hstmt (if one was defined) and discard any pending results. Later, the application will be able to reopen the cursor by executing a SELECT statement again with the same or different parameter values. |
| SQL_DROP | Used to release the hstmt, free all resources associated with it, close the cursor, and discard any rows that are pending. This option terminates all access to the hstmt. The hstmt may not be reused. |
| SQL_UNBIND | Used to release any column buffers bound by SQLBindCol() for the given hstmt. |
| SQL_RESET_PARAMS | Used to release all parameter buffers set by SQLBindParameter() for the given hstmt. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLFreeStmt() function to free the statement handle allocated by the SQLAllocStmt() function. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQL (HDBC hdbc, UWORD fOption, PTR pvParam)
Parameters:
| HDBC hdbc | A handle to an HDBC as returned by the call to the SQLAllocConnect() function. |
| UWORD fOption | Specifies the option to retrieve. |
| PTR pvParam | The buffer where the value associated with fOption will be placed. This variable will be either a 32-bit integer value or a pointer to a null-terminated character string. |
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_NO_DATA_FOUND | The command didn't find the driver to connect to. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLGetConnectOption() function to get the settings for the current connection. Always check the return code from this function for errors.
Notes:
If this function fails, use the SQLError() function to find out why.
Prototype:
RETCODE SQLCursorName(HSTMT hstmt, UCHAR FAR * szCursor, SWORD cbCursorMax, SWORD FAR * pcbCursor)
Parameters:
Return Value:
This function will return one of the following values:
| SQL_SUCCESS | The function was successful. |
| SQL_SUCCESS_WITH_INFO | The function was successful, and more information is available. |
| SQL_ERROR | The function failed. Call SQLError() to get more information about the specific failure. |
| SLQ_INVALID_HANDLE | The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle. |
If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
Usage:
Call the SQLGetCursorName