Working with Conversions
Go Up to API Guide
InterBase uses a proprietary format for internal storage of TIMESTAMP
, TIME
, and DATE
data, but provides the following API calls for translating to and from this format:
isc_decode_sql_date()
converts the InterBase internal date format to the Cdate
structure.isc_encode_sql_date()
converts the Cdate
structure to the internal InterBase date format.isc_decode_sql_time()
converts the InterBase internal time format to the Ctime
structure.isc_encode_sql_time()
converts the Ctime
structure to the internal InterBase time format.isc_decode_timestamp()
converts the InterBase internal timestamp format to the Ctimestamp
structure; this call was formerlyisc_decode_date()
.isc_encode_timestamp()
converts the Ctimestamp
structure to the internal InterBase timestamp format; this call was formerlyisc_encode_date()
.
These calls merely translate date-time (DATE
, TIME
, and TIMESTAMP
) data between formats; they do not read or write date-time data directly. Date-time data is read from and written to the database using standard DSQL syntax processed with the isc_dsql
family of API calls.
The
DATE
data type holds only date information in dialect 3 and is not permitted in dialect 1 to avoid ambiguity. Beginning with InterBase 6, when an older database is migrated to dialect 1, all columns that previously had a DATE
data type are automatically converted to TIMESTAMP
. To store migrated data in a DATE
column in dialect 3, you must create a new column in dialect 3 that has the DATE
data type, and then move the data into it. InterBase does not allow you to use ALTER COLUMN
to change a TIMESTAMP
data type to a DATE
data type because of potential data loss.InterBase also requires that numbers entered in database and transaction parameter buffers be in a generic format, with the least significant byte last. Signed numbers require the sign to be in the last byte. Systems that represent numbers with the most significant byte last must use the isc_portable_integer()
API function to reverse the byte order of numbers entered in database parameter buffers (DPBs) and transaction parameter buffers (TPBs). When numeric information is returned by information calls on these systems, isc_portable_integer()
must be used once again to reverse the byte ordering.
For more information about using DSQL to read and write data, see Working with Dynamic SQL.
Topics
- Converting Date and Times from InterBase to C Format
- Converting Dates from C to InterBase Format
- Reversing the Byte Order of Numbers