Contents|Index|Previous|Next

SQL to C: Character

The identifiers for the character ODBC SQL data types are:

SQL_CHAR
SQL_VARCHAR
SQL_LONGVARCHAR

The following table shows the ODBC C data types to which character SQL data may be converted. For an explanation of the columns and terms in the table, see Converting Data from SQL to C Data Types earlier in this appendix.


C Type Identifier

Test

*TargetValuePtr
*StrLen_or
_IndPtr
SQL-
STATE



SQL_C_CHAR
Byte length of data < BufferLength.
Byte length of data >= BufferLength.
Data

Truncated data
Length of data in bytes
Length of data in bytes
n/a

01004



SQL_C_STINYINT
SQL_C_UTINYINT
SQL_C_TINYINT
SQL_C_SBIGINT
SQL_C_UBIGINT
SQL_C_SSHORT
SQL_C_USHORT
SQL_C_SHORT
SQL_C_SLONG
SQL_C_ULONG
SQL_C_LONG
SQL_C_NUMERIC
Data converted without truncation. [b]

Data converted with truncation of fractional digits. [a]
Conversion of data would result in loss of whole (as opposed to fractional) digits. [a]
Data is not a numeric-literal. [b]
Data


Truncated data


Undefined



Undefined
Number of bytes of the C data type
Number of bytes of the C data type
Undefined



Undefined
n/a


01S07


22003



22018



SQL_C_FLOAT
SQL_C_DOUBLE
Data is within the range of the data type to which the number is being converted. [a]
Data is outside the range of the data type to which the number is being converted. [a]
Data is not a numeric-litera.l [b]
Data



Undefined



Undefined
Size of the C data type


Undefined



Undefined
n/a



22003



22018



SQL_C_BIT
Data is 0 or 1.
Data is greater than 0, less than 2, and not equal to 1.
Data is less than 0 or greater than or equal to 2.
Data is not a numeric-literal.
Data
Truncated data


Undefined


Undefined
1 [b]
1 [b]


Undefined


Undefined
n/a
01S07


22003


22018



SQL_C_BINARY
Byte length of data <= BufferLength.
Byte length of data > BufferLength.
Data

Truncated data
Length of data in bytes
Length of data
n/a

01004



SQL_C_TYPE_DATE
Data value is a valid date-value. [a]
Data value is a valid timestamp-value; time portion is zero. [a]
Data value is a valid timestamp-value; time portion is non-zero. [a], [c]
Data value is not a valid date-value or timestamp-value. [a]
Data

Data


Truncated data



Undefined
6 [b]

6 [b]


6 [b]



Undefined

n/a

n/a


01S07



22018




SQL_C_TYPE_TIME
Data value is a valid time-value and the fractional seconds value is 0. [a]
Data value is a valid timestamp-value or a valid time-value; fractional seconds portion is zero. [a], [d]
Data value is a valid timestamp-value; fractional seconds portion is non-zero. [a], [d], [e]
Data value is not a valid time-value or timestamp-value. [a]
Data



Data




Truncated data




Undefined

6 [b]



6 [b]




6 [b]




Undefined

n/a



n/a




01S07




22018




SQL_C_TYPE_
TIMESTAMP
Data value is a valid timestamp-value or a valid time-value; fractional seconds portion not truncated. [a]
Data value is a valid timestamp-value or a valid time-value; fractional seconds portion truncated. [a]
Data value is a valid date-value. [a]
Data value is not a valid date-value, time-value, or timestamp-value. [a]
Data




Truncated data




Data [f]

Undefined

16 [b]




16 [b]




16 [b]

Undefined

n/a




01S07




n/a

22018




All interval types
Data value is a valid interval value; no truncation.
Data value is a valid interval value; truncation of one or more trailing fields.
Data is valid interval; leading field significant precision is lost.
The data value is not a valid interval value.
Data


Truncated data



Undefined


Undefined
Length of data in bytes

Length of data in bytes


Undefined


Undefined
n/a


01S07



22015


22018



[a] The value of BufferLength is ignored for this conversion. The driver assumes that the size of
*TargetValuePtr is the size of the C data type.
[b] This is the size of the corresponding C data type.
[c] The time portion of the timestamp-value is truncated.
[d] The date portion of the timestamp-value is ignored.
[e] The fractional seconds portion of the timestamp is truncated.
[f] The time fields of the timestamp structure are set to zero.
[g] The date fields of the timestamp structure are set to the current date.





When character SQL data is converted to numeric, date, time, timestamp, or interval C data, leading and trailing spaces are ignored.