SqlDB.Table.Read traps in 2 situations
Posted: Mon Jul 06, 2015 8:02 am
Sql developer manual:
documentation recommends
But the WHILE loop causes trap in 2 situations:
1. The result set is empty, i.e. table.rows = 0
This trap can be avoided by
but it is somehow annoying. The specification of SqlDB.Table.Read says clearly that:
The last call to table.Read(r, rec) is made with r >= table.rows, and would return SqlDB.noData, but before, the record rec must be cleared. The problem here is that Dialog.Currency has a field of type LONGINT that is not expected in procedure ClearItem.
I use the FOR loop instead of the WHILE.
These 2 problems could be recorded in documentation of Sql developer manual as "Known bugs".
Regards,
Manuel
So instead ofSqlDB.Table
...
Note that the field table.rows cannot be computed by all database drivers, some may return MAX(INTEGER) instead. To loop over all rows of a result table, it is therefore better to avoid using table.rows in the loop termination condition. Instead, looping can be done while table.res # SqlDB.noData holds.
Code: Select all
FOR r := 0 TO table.rows-1 DO
table.Read(r, rec);
...
END
Code: Select all
r := 0; table.Read(r, rec);
WHILE table.res # SqlDB.noData DO
...
INC(r); table.Read(r, rec);
END
1. The result set is empty, i.e. table.rows = 0
This trap can be avoided by
Code: Select all
IF table.rows > 0 THEN
r := 0; table.Read(r, rec);
WHILE table.res # SqlDB.noData DO ...
END
2. The destination record rec has a field of type Dialog.Currency (intended to receive the value of a decimal fixed point number stored in database as e.g. "1234.56").It is permissible to read past the end of the table (row >= t.rows). The whole interactor is cleared in this case and t.res is set to noData.
The last call to table.Read(r, rec) is made with r >= table.rows, and would return SqlDB.noData, but before, the record rec must be cleared. The problem here is that Dialog.Currency has a field of type LONGINT that is not expected in procedure ClearItem.
I use the FOR loop instead of the WHILE.
These 2 problems could be recorded in documentation of Sql developer manual as "Known bugs".
Regards,
Manuel