使用ODBC访问数据库(二)

类别:编程语言 点击:0 评论:0 推荐:

使用C/C++语言开发,那么必定会在与ODBC语言间存在数据的转换的问题,因为ODBC所存在的一些数据类型在C语言中是不存在的。所以在ODBC的开发过程中不要使用int,float之类的C语言的实际类型来定义变量而应该使用ODBC定义的数据类型来定义变量,如SQLINTEGER,SQLFLOAT。在ODBC以宏定义的方式定义了C语言和ODBC中使用的数据类型:

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[h]

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.

本文地址:http://com.8s8s.com/it/it23788.htm