Fix Appending ORDER BY Clauses#125
Conversation
Greptile SummaryThis PR fixes a long-standing bug where clicking a table column header to sort would append a second
Confidence Score: 5/5Safe to merge; the tokeniser correctly handles all SQL noise tokens and the two call-site replacements are straightforward. The core tokenising logic is well-constructed: quoted strings, both comment styles, and nested parentheses are all skipped before keywords are inspected. The only notable edge case — empty No files require special attention.
|
| Filename | Overview |
|---|---|
| centrallix-os/sys/js/htdrv_osrc.js | Adds osrc_replace_orderby, which correctly tokenises SQL (handling single-quoted strings, -- and /* */ comments, and nested parens) to splice a new ORDER BY in place of any existing one; replaces the two old naïve-append blocks with single calls to this helper. Minor edge case: empty orderby_items silently strips an existing ORDER BY. |
| centrallix-os/sys/js/htdrv_table.js | Refactors header-click sort logic: extracts sort_key/sort_asc/sort_desc constants, switches to strict equality (===), and adds verbatim pass-through for colon-prefixed column names (e.g. :t:a_field). No logic regressions observed. |
Reviews (2): Last reviewed commit: "Update table ORDER BY generation to supp..." | Re-trigger Greptile
|
This PR is ready for human review. |
|
I'd like to zig here instead of zagging. Having the JS code splice code into an existing ORDER BY clause seems prone to issues. Instead, I'd like to update the SQL parser to allow multiple ORDER BY clauses in the same way that it allows multiple WHERE and HAVING clauses for the exact same reason. This should be doable by replacing some IF blocks with WHILE blocks where ORDER BY items are collected in a few places and by updating We will need a small SQL syntax change, adding a DEFAULT keyword to optionally follow ORDER BY, thus indicating that the ORDER BY clause can be overridden by another ORDER BY instead of just added to. That clarifies the SQL author's intent with the ORDER BY to be preset functionally vs providing a useful default ordering. |
gbeeley
left a comment
There was a problem hiding this comment.
See note in conversation. I think there is a much better way to solve this problem.
|
I suppose I should have realized that this would turn into a rearchitecting problem instead of a patch-it-until-it-works problem and reached out to you sooner. I'll see if I can figure out how to implement that. |
Question 1Let me clarify. In the following SQL example: SELECT *
FROM /path/to/object
ORDER BY
:prop1,
:prop2
ORDER BY DEFAULT
:prop3
ORDER BY
:prop4
ORDER BY DEFAULT
:prop5The final ordering would be by |
Question 2Are you sure I'll call it |
|
I think the principles here should be:
So, the question above would end up being the same as The ordering in your edited version would be I'm open to alternate terminology on this vs |
|
I just created #127 to implement this new feature, with tests and docs. That PR is ready for human review, closing this now-obsolete implementation. |
This PR will fix osrc widgets appending
ORDER BYclauses to queries that already have anORDER BYclause.This is most commonly seen a table uses an osrc with a query that contains an
ORDER BYclause. When the user clicks a column in the table header row to sort by that column, the user's new order is appended to the query and subsequently ignored by the parser, which only parses the first clause.