Working with Conversions

From InterBase
Jump to: navigation, search

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 C date structure.
  • isc_encode_sql_date() converts the C date structure to the internal InterBase date format.
  • isc_decode_sql_time() converts the InterBase internal time format to the C time structure.
  • isc_encode_sql_time() converts the C time structure to the internal InterBase time format.
  • isc_decode_timestamp() converts the InterBase internal timestamp format to the C timestamp structure; this call was formerly isc_decode_date().
  • isc_encode_timestamp() converts the C timestamp structure to the internal InterBase timestamp format; this call was formerly isc_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.

Note: 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

Advance To: