Conformance
Version Introduced:ODBC 2.0
Standards Compliance:ODBC
Summary
SQLDrivers lists driver descriptions and driver attribute keywords. This function is implemented solely by the Driver Manager.
Syntax
SQLRETURN SQLDrivers(
SQLHENVEnvironmentHandle,
SQLUSMALLINTDirection,
SQLCHAR *DriverDescription,
SQLSMALLINTBufferLength1,
SQLSMALLINT *DescriptionLengthPtr,
SQLCHAR *DriverAttributes,
SQLSMALLINTBufferLength2,
SQLSMALLINT *AttributesLengthPtr);
Arguments
EnvironmentHandle
[Input]
Environment handle.
Direction
[Input]
Determines whether the Driver Manager fetches the next driver description in the list (SQL_FETCH_NEXT) or whether the search starts from the beginning of the list (SQL_FETCH_FIRST).
DriverDescription
[Output]
Pointer to a buffer in which to return the driver description.
BufferLength1
[Input]
Length of the *DriverDescription buffer, in bytes.
DescriptionLengthPtr
[Output]
Pointer to a buffer in which to return the total number of bytes (excluding the null-termination byte) available to return in *DriverDescription. If the number of bytes available to return is greater than or equal to BufferLength1, the driver description in *DriverDescription is truncated to BufferLength1 minus the length of a null-termination character.
DriverAttributes
[Output]
Pointer to a buffer in which to return the list of driver attribute value pairs (see “Comments”).
BufferLength2
[Input]
Length of the *DriverAttributes buffer, in bytes. If the *DriverDescription value is a Unicode string (when calling SQLDriversW), the BufferLength argument must be an even number.
AttributesLengthPtr
[Output]
Pointer to a buffer in which to return the total number of bytes (excluding the null-termination byte) available to return in *DriverAttributes. If the number of bytes available to return is greater than or equal to BufferLength2, the list of attribute value pairs in *DriverAttributes is truncated to BufferLength2 minus the length of the null-termination character.
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLDrivers returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_ENV and a Handle of EnvironmentHandle. The following table lists the SQLSTATE values commonly returned by SQLDrivers and explains each one in the context of this function; the notation “(DM)” precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
SQLSTATE | Error | Description |
01000 | General warning | (DM) Driver Manager – specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
01004 | String data, right truncated | (DM) The buffer *DriverDescription was not large enough to return the entire driver description, so the description was truncated. The length of the entire driver description is returned in *DescriptionLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.) |
(DM) The buffer *DriverAttributes was not large enough to return the entire list of attribute value pairs, so the list was truncated. The length of the untruncated list of attribute value pairs is returned in *AttributesLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.) | ||
HY000 | General error | An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLGetDiagRec in the *MessageText buffer describes the error and its cause. |
HY001 | Memory allocation error |
(DM) The Driver Manager was unable to allocate memory required to support execution or completion of the function. |
HY013 | Memory management error | The function call could not be processed because the underlying memory objects could not be accessed, possibly because of low memory conditions. |
HY090 | Invalid string or buffer length | (DM) The value specified for argument BufferLength1 was less than 0. (DM) The value specified for argument BufferLength2 was less than 0 or equal to 1. |
HY103 | Invalid retrieval code | (DM) The value specified for the argument Direction was not equal to SQL_FETCH_FIRST or SQL_FETCH_NEXT. |
Comments
SQLDrivers returns the driver description in the *DriverDescription buffer. It returns additional information about the driver in the *DriverAttributes buffer as a list of keyword-value pairs. All keywords listed in the system information for drivers will be returned for all drivers, except for CreateDSN, which is used to prompt creation of data sources, and therefore is optional. Each pair is terminated with a null byte, and the entire list is terminated with a null byte (that is, two null bytes mark the end of the list). For example, a file-based driver using C syntax might return the following list of attributes (“\0” represents a null character):
FileUsage=1\0FileExtns=*.dbf\0\0
If *DriverAttributes is not large enough to hold the entire list, the list is truncated, SQLDrivers returns SQLSTATE 01004 (Data truncated), and the length of the list (excluding the final null-termination byte) is returned in *AttributesLengthPtr.
Driver attribute keywords are added from the system information when the driver is installed. For more information, see Chapter 18, “Installing ODBC Components.”
An application can call SQLDrivers multiple times to retrieve all driver descriptions. The Driver Manager retrieves this information from the system information. When there are no more driver descriptions, SQLDrivers returns SQL_NO_DATA. If SQLDrivers is called with SQL_FETCH_NEXT immediately after it returns SQL_NO_DATA, it returns the first driver description. For information about how an application uses the information returned by SQLDrivers, see “Choosing a Data Source or Driver” in Chapter 6, “Connecting to a Data Source or Driver.”
If SQL_FETCH_NEXT is passed to SQLDrivers the very first time it is called, SQLDrivers returns the first data source name.
Because SQLDrivers is implemented in the Driver Manager, it is supported for all drivers regardless of a particular driver’s standards compliance.
Related Functions
For information about | See |
Discovering and listing values required to connect to a data source | SQLBrowseConnect |
Connecting to a data source | SQLConnect |
Returning data source names | SQLDataSources |
Connecting to a data source using a connection string or dialog box | SQLDriverConnect |