If you use C/C ++ for development, there will be a data conversion problem between ODBC and ODBC, because some ODBC data types do not exist in C. Therefore, do not use int, float or other types of C language to define variables during ODBC development. Instead, use the data types defined by ODBC to define variables, such as sqlinteger and sqlfloat. ODBC defines the data types used in the C language and ODBC in macro-defined mode:
C type identifier |
Odbc c typedef |
C type |
SQL _c_char |
Sqlchar * |
Unsigned char * |
SQL _c_sshort |
Sqlsmallint |
Short int |
SQL _c_ushort |
Sqlusmallint |
Unsigned short int |
SQL _c_slong |
Sqlinteger |
Long int |
SQL _c_ulong |
Sqluinteger |
Unsigned long int |
SQL _c_float |
Sqlreal |
Float |
SQL _c_double |
Sqldouble, sqlfloat |
Double |
SQL _c_bit |
Sqlchar |
Unsigned char |
SQL _c_stinyint |
Sqlschar |
Signed Char |
SQL _c_utinyint |
Sqlchar |
Unsigned char |
SQL _c_sbigint |
Sqlbigint |
_ Int64 |
SQL _c_ubigint |
Sqlubigint |
Unsigned _ int64 |
SQL _c_binary |
Sqlchar * |
Unsigned char * |
SQL _c_xml |
Sqlchar * |
Unsigned char * |
SQL _c_bookmark |
Bookmark |
Unsigned long int |
SQL _c_varbookmark |
Sqlchar * |
Unsigned char * |
SQL _c_type_date |
SQL _date_struct |
Struct tagdate_struct { Sqlsmallint year; Sqlusmallint month; Sqlusmallint Day; } Date_struct; |
SQL _c_type_time |
SQL _time_struct |
Struct tagtime_struct { Sqlusmallint hour; Sqlusmallint minute; Sqlusmallint second; } Time_struct; |
SQL _c_type_timestamp |
SQL _timestamp_struct |
Struct tagtimestamp_struct { Sqlsmallint year; Sqlusmallint month; Sqlusmallint Day; Sqlusmallint hour; Sqlusmallint minute; Sqlusmallint second; Sqluinteger fraction; } Timestamp_struct |
SQL _c_numeric |
SQL _numeric_struct |
Struct tagsql_numeric_struct { Sqlchar precision; Sqlschar scale; Sqlchar sign; Sqlchar Val [SQL _max_numeric_len]; } SQL _numeric_struct; |
SQL _c_guid |
Sqlguid |
Struct tagsqlguid { DWORD data1; Word data2; Word data3; Byte data4 [8]; } Sqlguid; |
All C interval Data Types |
SQL _interval_struct |
See the "C interval structure" section, later in this appendix. |