SqlDB.Table.Read traps in 2 situations

All except GUI problems

SqlDB.Table.Read traps in 2 situations

Postby manumart1 » Mon Jul 06, 2015 8:02 am

Sql developer manual:
SqlDB.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.

So instead of
Code: Select all
FOR r := 0 TO table.rows-1 DO
  table.Read(r, rec);
  ...
END

documentation recommends
Code: Select all
r := 0; table.Read(r, rec);
WHILE table.res # SqlDB.noData DO
  ...
  INC(r); table.Read(r, rec);
END

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
Code: Select all
IF table.rows > 0 THEN
  r := 0; table.Read(r, rec);
  WHILE table.res # SqlDB.noData DO ...
END

but it is somehow annoying. The specification of SqlDB.Table.Read says clearly that:
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.


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").
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
manumart1
 
Posts: 61
Joined: Tue Sep 17, 2013 6:25 am

Re: SqlDB.Table.Read traps in 2 situations

Postby manumart1 » Fri Jan 29, 2016 11:27 pm

Problem solved, see viewtopic.php?f=16&t=109
manumart1
 
Posts: 61
Joined: Tue Sep 17, 2013 6:25 am


Return to BlackBox Framework

Who is online

Users browsing this forum: No registered users and 1 guest

cron