SQL programming / SQL portability |
Good practices for date and time handling in SQL.
SELECT COUNT(*) FROM table WHERE date_col = '24/12/2005'
Other database servers do support date/time literals as quoted character strings, but the date/time format specification is quite different. The parameter to specify the date/time format can be a database parameter, an environment variable, or a session option.
DEFINE cnt INTEGER DEFINE adate DATE LET adate = MDY(12,24,2005) SELECT COUNT(*) INTO cnt FROM table WHERE date_col = adate
DEFINE cnt INTEGER DEFINE adate DATE LET adate = MDY(12,24,2005) PREPARE s1 FROM "SELECT COUNT(*) FROM table WHERE date_col = ?" EXECUTE s1 USING adate INTO cnt
SELECT COUNT(*) FROM order WHERE ord_when > DATETIME (1999-10-12) YEAR TO DAY
Check your code, to detect where you are using such expressions in the SQL statements, and use an SQL parameter instead.
SQL Statements using expressions such as TODAY, CURRENT and EXTEND must be reviewed and adapted to the native syntax of the target database engine.
Check your code, to detect where you are using such expressions in the SQL statements.
Date-time arithmetic expressions using SQL parameters (USING variables) are not portable.
PREPARE s1 FROM "SELECT ... WHERE datecol < ? + 1"
Might generate an error with non-Informix databases.
IBM Informix can automatically convert integers to a DATE values, as a number of days since 12/31/1899 ( 1 = 01/01/1900 ). This is however not supported by other database engines.
Check your code, to detect where you are using integers with DATE columns.