C 数据类型C Data Types

ODBC C 数据类型表示用于在应用程序中存储数据的 C 缓冲区的数据类型。ODBC C data types indicate the data type of C buffers used to store data in the application.

所有驱动程序必须支持所有的 C 数据类型。All drivers must support all C data types. 这是必需的因为所有驱动程序必须支持到它们支持的 SQL 类型可以进行转换,所有 C 类型和所有驱动程序都支持至少一个字符 SQL 类型。This is required because all drivers must support all C types to which SQL types that they support can be converted, and all drivers support at least one character SQL type. 与所有 C 类型可以转换的字符 SQL 类型,因为所有驱动程序必须支持所有的 C 类型。Because the character SQL type can be converted to and from all C types, all drivers must support all C types.

中指定的 C 数据类型SQLBindColSQLGetData函数与TargetType自变量并在SQLBindParameter函数与ValueType参数。The C data type is specified in the SQLBindCol and SQLGetData functions with the TargetType argument and in the SQLBindParameter function with the ValueType argument. 它还可以指定通过调用SQLSetDescField若要设置 SQL_DESC_CONCISE_TYPE 字段 ARD 或 APD,或通过调用SQLSetDescRec类型自变量 (和子类型参数,如果需要) 和DescriptorHandle参数设置为 ARD 或 APD 的句柄。It can also be specified by calling SQLSetDescField to set the SQL_DESC_CONCISE_TYPE field of an ARD or APD, or by calling SQLSetDescRec with the Type argument (and the SubType argument if needed) and the DescriptorHandle argument set to the handle of an ARD or APD.

下表列出了有效的类型标识符的 C 数据类型。The following tables lists valid type identifiers for the C data types. 该表还列出对应于每个标识符和此数据类型的定义的 ODBC C 数据类型。The table also lists the ODBC C data type that corresponds to each identifier and the definition of this data type.

C 类型标识符C type identifier ODBC C typedefODBC C typedef C 类型C type
SQL_C_CHARSQL_C_CHAR SQLCHAR *SQLCHAR * unsigned char *unsigned char *
SQL_C_WCHARSQL_C_WCHAR SQLWCHAR *SQLWCHAR * wchar_t *wchar_t *
SQL_C_SSHORT[j]SQL_C_SSHORT[j] SQLSMALLINTSQLSMALLINT short intshort int
SQL_C_USHORT[j]SQL_C_USHORT[j] SQLUSMALLINTSQLUSMALLINT 无符号短整数unsigned short int
SQL_C_SLONG[j]SQL_C_SLONG[j] SQLINTEGERSQLINTEGER long intlong int
SQL_C_ULONG[j]SQL_C_ULONG[j] SQLUINTEGERSQLUINTEGER 无符号长整型unsigned long int
SQL_C_FLOATSQL_C_FLOAT SQLREALSQLREAL FLOATfloat
SQL_C_DOUBLESQL_C_DOUBLE SQLDOUBLE SQLFLOATSQLDOUBLE, SQLFLOAT doubledouble
SQL_C_BITSQL_C_BIT SQLCHARSQLCHAR 无符号的 charunsigned char
SQL_C_STINYINT[j]SQL_C_STINYINT[j] SQLSCHARSQLSCHAR 有符号的字符signed char
SQL_C_UTINYINT[j]SQL_C_UTINYINT[j] SQLCHARSQLCHAR 无符号的 charunsigned char
SQL_C_SBIGINTSQL_C_SBIGINT SQLBIGINTSQLBIGINT _int64 [h]_int64[h]
SQL_C_UBIGINTSQL_C_UBIGINT SQLUBIGINTSQLUBIGINT 无符号的 _int64 [h]unsigned _int64[h]
SQL_C_BINARYSQL_C_BINARY SQLCHAR *SQLCHAR * unsigned char *unsigned char *
SQL_C_BOOKMARK[i]SQL_C_BOOKMARK[i] 书签BOOKMARK 无符号 long int [d]unsigned long int[d]
SQL_C_VARBOOKMARKSQL_C_VARBOOKMARK SQLCHAR *SQLCHAR * unsigned char *unsigned char *
所有 C 间隔数据类型All C interval data types SQL_INTERVAL_STRUCTSQL_INTERVAL_STRUCT 请参阅C 间隔结构部分中的,稍后在本附录中。See the C Interval Structure section, later in this appendix.

C 类型标识符SQL_C_TYPE_DATE [c]C type identifier SQL_C_TYPE_DATE[c]

ODBC C typedef SQL_DATE_STRUCTODBC C typedef SQL_DATE_STRUCT

C 类型C type

struct tagDATE_STRUCT {  
   SQLSMALLINT year;  
   SQLUSMALLINT month;  
   SQLUSMALLINT day;    
} DATE_STRUCT;[a]  

C 类型标识符SQL_C_TYPE_TIME [c]C type identifier SQL_C_TYPE_TIME[c]

ODBC C typedef SQL_TIME_STRUCTODBC C typedef SQL_TIME_STRUCT

C 类型C type

struct tagTIME_STRUCT {  
   SQLUSMALLINT hour;  
   SQLUSMALLINT minute;  
   SQLUSMALLINT second;  
} TIME_STRUCT;[a]  

C 类型标识符SQL_C_TYPE_TIMESTAMP [c]C type identifier SQL_C_TYPE_TIMESTAMP[c]

ODBC C typedef SQL_TIMESTAMP_STRUCTODBC C typedef SQL_TIMESTAMP_STRUCT

C 类型C type

struct tagTIMESTAMP_STRUCT {  
   SQLSMALLINT year;  
   SQLUSMALLINT month;  
   SQLUSMALLINT day;  
   SQLUSMALLINT hour;  
   SQLUSMALLINT minute;  
   SQLUSMALLINT second;  
   SQLUINTEGER fraction;[b]   
} TIMESTAMP_STRUCT;[a]  

C 类型标识符SQL_C_NUMERICC type identifier SQL_C_NUMERIC

ODBC C typedef SQL_NUMERIC_STRUCTODBC C typedef SQL_NUMERIC_STRUCT

C 类型C type

struct tagSQL_NUMERIC_STRUCT {  
   SQLCHAR precision;  
   SQLSCHAR scale;  
   SQLCHAR sign[g];  
   SQLCHAR val[SQL_MAX_NUMERIC_LEN];[e], [f]   
} SQL_NUMERIC_STRUCT;  

C 类型标识符SQL_C_GUIDC type identifier SQL_C_GUID

ODBC C typedef SQLGUIDODBC C typedef SQLGUID

C 类型C type

struct tagSQLGUID {  
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   BYTE Data4[8];  
} SQLGUID;[k]  

[a] 的年、 月、 日、 小时、 分钟、 和 datetime C 数据类型中的第二个字段的值必须符合公历的约束。[a] The values of the year, month, day, hour, minute, and second fields in the datetime C data types must conform to the constraints of the Gregorian calendar. (请参阅公历的约束本附录中更高版本。)(See Constraints of the Gregorian Calendar later in this appendix.)

[b] 部分字段的值是第二个和范围是从 0 到 999999999 (1 小于 10 亿) 的十亿分之一。[b] The value of the fraction field is the number of billionths of a second and ranges from 0 through 999,999,999 (1 less than 1 billion). 例如,半秒的部分字段的值是 500,000,000,秒的千分位的是 1000000,对于第二个万,(1 毫秒) (一微秒) 为 1000,对于第 10 亿用户的第二个 (一纳秒) 为 1。For example, the value of the fraction field for a half-second is 500,000,000, for a thousandth of a second (one millisecond) is 1,000,000, for a millionth of a second (one microsecond) is 1,000, and for a billionth of a second (one nanosecond) is 1.

[c] 在 ODBC 2。x,C 日期、 时间和时间戳数据类型为 SQL_C_DATE、 SQL_C_TIME 和 SQL_C_TIMESTAMP。[c] In ODBC 2.x, the C date, time, and timestamp data types are SQL_C_DATE, SQL_C_TIME, and SQL_C_TIMESTAMP.

[d] ODBC 3 .x应用程序应使用 SQL_C_VARBOOKMARK,不 SQL_C_BOOKMARK。[d] ODBC 3 .x applications should use SQL_C_VARBOOKMARK, not SQL_C_BOOKMARK. 当 ODBC 3 .x应用程序适用于 ODBC 2。x驱动程序,ODBC 3 .x驱动程序管理器将映射到 SQL_C_BOOKMARK SQL_C_VARBOOKMARK。When an ODBC 3 .x application works with an ODBC 2.x driver, the ODBC 3 .x Driver Manager will map SQL_C_VARBOOKMARK to SQL_C_BOOKMARK.

[e] 的数字将存储在val SQL_NUMERIC_STRUCT 结构作为扩展的整数,小 endian 模式 (按最低有效字节的最左侧字节) 中的字段。[e] A number is stored in the val field of the SQL_NUMERIC_STRUCT structure as a scaled integer, in little endian mode (the leftmost byte being the least-significant byte). 例如,数字 10.001 基数为 10,小数位数为 4,缩放为 100010 的整数。For example, the number 10.001 base 10, with a scale of 4, is scaled to an integer of 100010. 由于这是以十六进制格式的 186AA,SQL_NUMERIC_STRUCT 中的值将为"AA 86 01 00 00...00",由 SQL_MAX_NUMERIC_LEN 定义的字节数 #defineBecause this is 186AA in hexadecimal format, the value in SQL_NUMERIC_STRUCT would be "AA 86 01 00 00 ... 00", with the number of bytes defined by the SQL_MAX_NUMERIC_LEN #define.

有关详细信息SQL_NUMERIC_STRUCT,请参阅操作方法:检索数值数据使用 SQL_NUMERIC_STRUCTFor more information about SQL_NUMERIC_STRUCT, see HOWTO: Retrieving Numeric Data with SQL_NUMERIC_STRUCT.

[SQL_C_NUMERIC 数据 f] 的精度和小数位数字段键入 areused 从应用程序的输入和输出从驱动程序到应用程序。[f] The precision and scale fields of the SQL_C_NUMERIC data type areused for input from an application and for output from the driver to the application. 在驱动程序将数字的值写入到 SQL_NUMERIC_STRUCT,它将使用其自己特定于驱动程序的默认为值精度字段中,并且它将在应用程序描述符 (SQL_DESC_SCALE 字段中使用值其默认值为 0) 的规模字段。When the driver writes a numeric value into the SQL_NUMERIC_STRUCT, it will use its own driver-specific default as the value for the precision field, and it will use the value in the SQL_DESC_SCALE field of the application descriptor (which defaults to 0) for the scale field. 应用程序可以通过设置应用程序描述符的 SQL_DESC_PRECISION 和 SQL_DESC_SCALE 字段的精度和小数位数提供其自己的值。An application can provide its own values for precision and scale by setting the SQL_DESC_PRECISION and SQL_DESC_SCALE fields of the application descriptor.

[g] 的登录字段为 1,如果为正数,0,如果为负数。[g] The sign field is 1 if positive, 0 if negative.

[小时] _int64 可能未提供的某些编译器中。[h] _int64 might not be supplied by some compilers.

[ODBC 3 中已弃用 i] _SQL_C_BOOKMARK .x[i] _SQL_C_BOOKMARK has been deprecated in ODBC 3 .x.

[j] _SQL_C_SHORT、 SQL_C_LONG 和 SQL_C_TINYINT 已替换为在 ODBC 中有符号和无符号类型:SQL_C_SSHORT 和 SQL_C_USHORT、 SQL_C_SLONG 和 SQL_C_ULONG,和 SQL_C_STINYINT 和 SQL_C_UTINYINT。[j] _SQL_C_SHORT, SQL_C_LONG, and SQL_C_TINYINT have been replaced in ODBC by signed and unsigned types: SQL_C_SSHORT and SQL_C_USHORT, SQL_C_SLONG and SQL_C_ULONG, and SQL_C_STINYINT and SQL_C_UTINYINT. ODBC 3 .x驱动程序,它应适用于 ODBC 2。x应用程序应支持 SQL_C_SHORT、 SQL_C_LONG 和 SQL_C_TINYINT,因为它们调用时,驱动程序管理器将其传递通过给驱动程序。An ODBC 3 .x driver that should work with ODBC 2.x applications should support SQL_C_SHORT, SQL_C_LONG, and SQL_C_TINYINT, because when they are called, the Driver Manager passes them through to the driver.

[可以仅向 SQL_CHAR 或 SQL_WCHAR 转换 k] SQL_C_GUID。[k] SQL_C_GUID can be converted only to SQL_CHAR or SQL_WCHAR.

本部分包含以下主题。This section contains the following topic.

请参阅See Also

ODBC 中的 C 数据类型C Data Types in ODBC