Upravit

Sdílet prostřednictvím


SQL to C: Year-Month Intervals

The identifiers for the year-month interval ODBC SQL data types are the following:

  • SQL_INTERVAL_MONTH
  • SQL_INTERVAL_YEAR
  • SQL_INTERVAL_YEAR_TO_MONTH

The following table shows the ODBC C data types to which year-month interval 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.

C type identifier Test TargetValuePtr StrLen_or_IndPtr SQLSTATE
SQL_C_INTERVAL_MONTH[a]

SQL_C_INTERVAL_YEAR[a]

SQL_C_INTERVAL_YEAR_TO_MONTH[a]
Trailing fields portion not truncated

Trailing fields portion truncated

Leading precision of target is not big enough to hold data from source
Data

Truncated data

Undefined
Length of data in bytes

Length of data in bytes

Undefined
n/a

01S07

22015
SQL_C_STINYINT[b]

SQL_C_UTINYINT[b]

SQL_C_USHORT[b]

SQL_C_SHORT[b]

SQL_C_SLONG[b]

SQL_C_ULONG[b]

SQL_C_NUMERIC[b]

SQL_C_BIGINT[b]
Interval precision was a single field and the data was converted without truncation

Interval precision was a single field and truncated whole

Interval precision was not a single field
Data

Truncated data

Undefined
Size of the C data type

Length of data in bytes

Size of the C data type
n/a

22003

22015
SQL_C_BINARY Byte length of data <= BufferLength

Byte length of data > BufferLength
Data

Undefined
Length of data in bytes

Undefined
n/a

22003
SQL_C_CHAR Character byte length < BufferLength

Number of whole (as opposed to fractional) digits < BufferLength

Number of whole (as opposed to fractional) digits >= BufferLength
Data

Truncated data

Undefined
Size of the C data type

Size of the C data type

Undefined
n/a

01004

22003
SQL_C_WCHAR Character length < BufferLength

Number of whole (as opposed to fractional) digits < BufferLength

Number of whole (as opposed to fractional) digits >= BufferLength
Data

Truncated data

Undefined
Size of the C data type

Size of the C data type

Undefined
n/a

01004

22003

[a] A year-month interval SQL type can be converted to any year-month interval C type.

[b] If the interval precision is a single field (one of YEAR or MONTH), the interval SQL type can be converted to any exact numeric (SQL_C_STINYINT, SQL_C_UTINYINT, SQL_C_USHORT, SQL_C_SHORT, SQL_C_SLONG, SQL_C_ULONG, or SQL_C_NUMERIC).

Default conversions

The default conversion of an interval SQL type is to the corresponding C interval data type. The application then binds the column or parameter (or sets the SQL_DESC_DATA_PTR field in the appropriate record of the ARD) to point to the initialized SQL_INTERVAL_STRUCT structure (or passes a pointer to the SQL_ INTERVAL_STRUCT structure as the TargetValuePtr argument in a call to SQLGetData).