Informix 4gl details
Posted in 1993
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
To all users/developers of Informix 4gl 2.10 or higher:
My company is still using Informix 1.10, and I am trying to determine if
the following limitation in our compiler is limited to 1.10:
DEFINE i INTEGER
DEFINE my_arr ARRAY[100] OF RECORD LIKE my_table
DECLARE my_cursor CURSOR FOR
SELECT * FROM my_tableLET i = 1
FOREACH my_cursor INTO my_arr[i].*
LET i = i + 1
END FOREACH
This block of code will produce a run-time error if the table contains
exactly 100 rows, because the Operating System attempts to calculate the
addresses of my_arr[101].* before the database engine can justify ending
the FOREACH loop with the non-existence of another row. Although this
problem is not difficult to work around, it is annoying for 3 reasons:
1) The code above is so human-readable that any other solution is
awfully cumbersome by comparison.
2) The reference manual is silent about the order of operations in
a FOREACH loop, whereas most reference manuals easily plumb this
level of detail to avoid off-by-one errors by their end-users.
3) The unnatural order of operations in the FOREACH loop is
reminiscent of programming languages that eschew short-circuit
evaluation of boolean conditions in favor of evaluating both
sides of an AND or an OR essentially in parallel, thus leading
to convoluted coding.
Now for the questions: does any version of Informix 4gl later than 1.10
perform the FOREACH end-of-loop check by querying the database before
calculating the destination memory addresses?
-Richard H.