re: Informix 4gl details
Posted in 1993
richard,
a slight modification to your code (still human readable) gets around this
'problem'. what if my_table has more than 100 rows?
DEFINE i INTEGER
DEFINE my_arr ARRAY[100] OF RECORD LIKE my_table
DECLARE my_cursor CURSOR FOR
SELECT * FROM my_table
DEFINE MAX_RECS INTEGER
LET MAX_RECS = 100
LET i = 1
FOREACH my_cursor INTO my_arr[i].*
LET i = i + 1
IF (i = MAX_RECS)
THEN
display some error message
EXIT FOREACH
END IF
END FOREACH
> 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_table> LET 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.
--
regards,
+----------------------------------------------------------------------------+
| . . | |
| ... ... | Bob Baskett |
| ..... ..... | Software Engineer, DBA |
| .. ... .. | Business Systems Integration Group |
| . . . | Semiconductor Products Sector |
| | Mesa, AZ |
| Motorola, Inc. | |
|----------------------------------------------------------------------------|
| 'connectionLESS IS MORE' -- Data Broker |
|----------------------------------------------------------------------------|
| Duct tape is like the force. It has a light side, and a dark side, and |
| it holds the universe together ... |
| -- Carl Zwanzig |
+----------------------------------------------------------------------------+