2015년 3월 26일 목요일

C vs ODBC 테이터 타입 관계

C Type identifier
ODBC C Typedef
C Type
SQL_C_CHAR
SQLCHAR
unsigned char
SQL_C_STINYINT
SCHAR
char
SQL_C_UTINYINT [i]
UCHAR
unsigned char
SQL_C_SSHORT [h]
SQLSMALLINT
short int
SQL_C_USHORT [h] [i]
SQLUSMALLINT
unsigned short int
SQL_C_SLONG [h]
SQLINTEGER
int
SQL_C_ULONG [h] [i]
SQLUINTEGER
unsigned int
SQL_C_SBIGINT
SQLBIGINT
_int64 [g]
SQL_C_UBIGINT [i]
SQLUBIGINT
unsigned _int64 [g]
solidDB does not support unsigned data types such as this.
SQL_C_FLOAT
SQLREAL
float
SQL_C_DOUBLE
SQLDOUBLE
SQLFLOAT
double
SQL_C_NUMERIC
SQLNUMERIC
unsigned char [f]
SQL_C_DECIMAL
SQLDECIMAL
unsigned char [f]
SQL_C_BINARY
SQLCHAR *
unsigned char *
SQL_C_TYPE_DATE [c]
SQL_DATE_STRUCT
struct tagDATE_STRUCT{
    SQLSMALLINT year;
    SQLUSMALLINT month;
    SQLUSMALLINT day;
} DATE_STRUCT; [a]          
SQL_C_TYPE_TIME [c]
SQL_TIME_STRUCT
struct tagTIME_STRUCT {
    SQLUSMALLINT hour;
    SQLUSMALLINT minute;[d]
    SQLUSMALLINT second;[e]
}          
SQL_C_TYPE_TIMESTAMP [c]
SQL_TIMESTAMP_STRUCT
struct tagTIMESTAMP_STRUCT {
    SQLSMALLINT year; [a]
    SQLUSMALLINT month; [b]
    SQLUSMALLINT day; [c]
    SQLUSMALLINT hour;
    SQLUSMALLINT minute; [d]
    SQLUSMALLINT second;[e]
    SQLUINTEGER fraction; 
}          

Note:
[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.)
[b] The value of the fraction field is the number of nanoseconds (billionths of a second) and ranges from 0 through 999,999,999 (1 less than 1 billion). 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] In ODBC 2.x, the C date, time, and timestamp data types are SQL_C_DATE, SQL_C_TIME, and SQL_C_TIMESTAMP.
[d] 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). For example, the number 10.001 base 10, with a scale of 4, is scaled to an integer of 100010. Because 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.
[e] The precision and scale fields of the SQL_C_NUMERIC data type are never used for input from an application, only for output from the driver to the application. 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. 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.
[f] The DECIMAL and NUMERIC data types take up more than one byte/character. The data types will actually be declared as arrays based on the precision required for the column. For example, a column of type SQL DECIMAL(10,4) might be declared as SQL_DECIMAL[13] to take into account the 10 digits, the sign character, the decimal point character, and the string terminator.
[g] _int64 might not be supplied by some compilers.
[h] _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. 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.
[i] solidDB does not support unsigned SQL data types. You may bind an unsigned C data type to a signed SQL column, but you should not do this unless the values stored in the SQL column and the C variable are within the valid range for both data types. For example, since signed TINYINT columns hold values from -128 to +127, while unsigned SQL_C_UTINYINT variables hold values from 0 to 255, you may only store values between 0 and +127 in the column and bound variable if you want the values to be interpreted properly.

>>>> 출처 : http://www-01.ibm.com/support/knowledgecenter/SSPK3V_7.0.0/com.ibm.swg.im.soliddb.programmer.doc/doc/s0005314.c.data.types.html