Skip to content

SQLRDD: LastRec() as the table's highest record number, "" for DBOI_CONDITION without FOR condition - #2115

Merged
RobertvanderHulst merged 2 commits into
X-Sharp:devfrom
ecosSystem:homebase/sqlrdd-lastrec-condition
Oct 24, 2026
Merged

RobertvanderHulst merged 2 commits into
X-Sharp:devfrom
ecosSystem:homebase/sqlrdd-lastrec-condition

Conversation

@ecosSystem

Copy link
Copy Markdown
Contributor

Two ADS/DBF compatibility fixes found with a generic table browser (bBrowser) on SQLRDD tables. Both are independent of each other; base is dev.

1. OrderInfo(DBOI_CONDITION) returned NIL for a tag without FOR condition

SqlDbOrder:Condition is only set by SetCondition() for a non-empty condition, so for an unconditional tag it stays null and DBOI_CONDITION returned NIL. DBF/ADS return "". Code that passes the result straight to a string function failed, e.g.

cCond := StrTran(oServer:OrderInfo(DBOI_CONDITION,,n), " .AND. .NOT. DELETED()", "")

raised an argument error (uTarget) for every table in a "choose order" dialog. DBOI_CONDITION and DBOI_EXPRESSION now return "" instead of null.

2. LastRec()/RecCount is the table's highest record number, as in DBF

RecCount returned the row count of the current order, including its FOR condition and scope. With a conditional order this is smaller than the highest record number. Two consequences:

  • RecNo at EOF (RecCount + 1) was the number of a real record.
  • Records with a number above RecCount looked like they were past the end of the table.

Example: ADRESSDB has 63 rows. Its order has the condition typ='L' and contains 60 of them. LastRec() was 60, the last two records of the order have the numbers 61 and 62, and the phantom record at EOF also had number 61. A browser on that order skipped record 61 and then showed only record 62.

RecCount now reports MAX(<recno column>) for the whole table (COUNT(*) when there is no recno column), independent of order, condition and scope. That is the same as LastRec() under DBF: no record number is ever above it, and RecNo at EOF is always LastRec() + 1. The value is:

  • queried on demand and cached,
  • raised by Append(),
  • requeried after an order change, Zap() or Pack() (_CloseCursor()).

Paging and EOF detection keep using the order's row count (_serverReccount, now read through _OrderRowCount() where RecCount was used internally).

Testing

  • Against SQL Server with the HomeBase database: walked the conditional order forward and backward, browser-like Skip(1)/Skip(-n) refills, OrderKeyNo/OrderKeyGoto, GoBottom, GoTo(0), GoTo(n) + Skip. LastRec() is now 63, RecNo at EOF 64.
  • Our existing regression harness (paging, seeks on concatenated keys, GoTo(0), order switches, decimal columns) gives identical results before and after the change.
  • Verified in the application: the "choose order" dialog works, and browsing the conditional order shows all 60 records.

🤖 Generated with Claude Code

ecosSystem and others added 2 commits October 23, 2026 10:28
… FOR condition

A tag without FOR condition kept Condition = null, so OrderInfo(DBOI_CONDITION)
returned NIL where DBF/ADS return "". Code that passes the result straight to
string functions failed, e.g. StrTran(OrderInfo(DBOI_CONDITION,,n), ...) raised
an argument error for every table in a generic "choose order" dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n DBF

RecCount returned the row count of the current order (FOR condition, scope).
With a conditional order this is smaller than the highest record number, so
RecNo at EOF (RecCount+1) was the number of a real record, and records with a
number above RecCount looked like they were past the end of the table: a
browser on an order with condition typ='L' (60 of 63 rows) skipped record 61
and then showed only record 62.

RecCount now reports MAX(recno column) for the whole table (COUNT(*) without a
recno column), independent of order, condition and scope. It is queried on
demand, cached, raised on Append() and requeried after an order change,
Zap() or Pack(). Paging and EOF detection keep using the order's row count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RobertvanderHulst
RobertvanderHulst merged commit 20007f7 into X-Sharp:dev Oct 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants