当应用程序调用SQLFetch或SQLFetchScrollSQLGetData驱动程序从数据源中检索数据时。 If necessary, it converts the data from the data type in which the driver retrieved it to the data type specified by the TargetType argument in SQLBindCol or SQLGetData. Finally, it stores the data in the location pointed to by the TargetValuePtr argument in SQLBindCol or SQLGetData (and the SQL_DESC_DATA_PTR field of the ARD).
下表显示了从 ODBC SQL 数据类型到 ODBC C 数据类型支持的转换。 A filled circle indicates the default conversion for a SQL data type (the C data type to which the data will be converted when the value of TargetType is SQL_C_DEFAULT). 空心圆表示支持的转换。
For an ODBC 3.x application working with an ODBC 2.x driver, conversion from driver-specific data types might not be supported.
转换后的数据的格式不受 Windows 国家/地区设置的影响。
以下部分中的表介绍了驱动程序或数据源如何转换从数据源检索到的数据;驱动程序需要支持从它们支持的 ODBC SQL 数据类型转换为所有 ODBC C 数据类型。 For a given ODBC SQL data type, the first column of the table lists the legal input values of the TargetType argument in SQLBindCol and SQLGetData. The second column lists the outcomes of a test, often using the BufferLength argument specified in SQLBindCol or SQLGetData, which the driver performs to determine whether it can convert the data. For each outcome, the third and fourth columns list the values placed in the buffers specified by the TargetValuePtr and StrLen_or_IndPtr arguments specified in SQLBindCol or SQLGetData after the driver has attempted to convert the data. (The StrLen_or_IndPtr argument corresponds to the SQL_DESC_OCTET_LENGTH_PTR field of the ARD.) The last column lists the SQLSTATE returned for each outcome by SQLFetch, SQLFetchScroll, or SQLGetData.
If the TargetType argument in SQLBindCol or SQLGetData contains an identifier for an ODBC C data type not shown in the table for a given ODBC SQL data type, SQLFetch, SQLFetchScroll, or SQLGetData returns SQLSTATE 07006 (Restricted data type attribute violation). If the TargetType argument contains an identifier that specifies a conversion from a driver-specific SQL data type to an ODBC C data type and this conversion isn't supported by the driver, SQLFetch, SQLFetchScroll, or SQLGetData returns SQLSTATE HYC00 (Optional feature not implemented).
Although it's not shown in the tables, the driver returns SQL_NULL_DATA in the buffer specified by the StrLen_or_IndPtr argument when the SQL data value is NULL. For an explanation of the use of StrLen_or_IndPtr when multiple calls are made to retrieve data, see the SQLGetData Function function description. When SQL data is converted to character C data, the character count returned in StrLen_or_IndPtr doesn't include the null-termination byte. If TargetValuePtr is a null pointer, SQLGetData returns SQLSTATE HY009 (Invalid use of null pointer); in SQLBindCol, this unbinds the column.
表中使用以下术语和约定:
数据字节长度 是 可在 TargetValuePtr 中返回的 C 数据的字节数,无论数据在返回到应用程序之前是否被截断。 对于字符串数据,这不包括 null 终止字符的空间。
字符字节长度 是以字符格式显示数据所需的字节总数。 This is as defined for each C data type in the section Display Size, except that character byte length is in bytes while the display size is in characters.
Words in italics represent function arguments or elements of the SQL grammar. 有关语法元素的语法,请参阅 附录 C:SQL 语法。
本节包含以下文章。