SQL to C: Day-Time Intervals
SQL_INTERVAL_DAY
| SQL_INTERVAL_DAY_TO_MINUTE
|
SQL_INTERVAL_HOUR
| SQL_INTERVAL_DAY_TO_SECOND
|
SQL_INTERVAL_MINUTE
| SQL_INTERVAL_HOUR_TO_MINUTE
|
SQL_INTERVAL_SECOND
| SQL_INTERVAL_HOUR_TO_SECOND
|
SQL_INTERVAL_DAY_TO_HOUR
| SQL_INTERVAL_MINUTE_TO_SECOND
|
C type identifier |
Test |
*TargetValuePtr | *StrLen_or
_IndPtr | SQL-
STATE |
SQL_C_INTERVAL_ DAY [a] SQL_C_INTERVAL_ HOUR [a] SQL_C_INTERVAL_ MINUTE [a] SQL_C_INTERVAL_ SECOND [a] SQL_C_INTERVAL_ DAY_TO_HOUR [a] SQL_C_INTERVAL_ DAY_TO_MINUTE [a] SQL_C_INTERVAL_ DAY_TO_SECOND [a] SQL_C_INTERVAL_ HOUR_TO_MINUTE [a] SQL_C_INTERVAL_ HOUR_TO_SECOND [a] SQL_C_INTERVAL_ MINUTE_TO_ SECOND [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
Length of data 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 fractional. Interval precision was a single field and truncated whole. Interval precision was not a single field. | Data
Truncated data Truncated data Undefined | Size of the C data type
Length of data Length of data Size of the C data type | n/a
01S07 22003 |
SQL_C_BINARY | Byte length of data <= BufferLength
Byte length of data > BufferLength | Data
Undefined | Length of data
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 |
[a] A day-time interval SQL type can be converted to any day-time interval C type. [b] If the interval precision is a single field (one of DAY, HOUR, MINUTE, or SECOND), then 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). |
|
|
|
The following example demonstrates how to transfer data from a column of type SQL_INTERVAL_DAY_TO_MINUTE into the SQL_INTERVAL_STRUCT structure such that it comes back as a DAY_TO_HOUR interval.
SQL_INTERVAL_STRUCT is;
SQLINTEGER cbValue;
SQLUINTEGER days, hours;
// Execute a select statement;
“interval_column” is a column// whose data type is SQL_INTERVAL_DAY_TO_MINUTE.
SQLExecDirect(hstmt,
“SELECT interval_column FROM table”, SQL_NTS);
// Bind
SQLBindCol(hstmt, 1, SQL_C_INTERVAL_DAY_TO_MINUTE, &is, sizeof(SQL_INTERVAL_STRUCT), &cbValue);
//Fetch
SQLFetch(hstmt);
// Process data
days = is.intval.day_second.day;
hours = is.intval.day_second.hour;