Skip to content

Sort Execute SQL results by header click and show small BLOBs as hex - #4241

Open
deepsidhu1313 wants to merge 2 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/exec-sql-ux
Open

deepsidhu1313 wants to merge 2 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/exec-sql-ux

Conversation

@deepsidhu1313

Copy link
Copy Markdown
Contributor

Two commits, both behind settings that are off by default.

  1. Sort Execute SQL results by clicking a column header (editor/sort_results, Preferences > SQL). Clicking cycles ascending, descending, original order by wrapping the query as SELECT * FROM () ORDER BY . Only read-only SELECT/WITH statements are wrapped (prefix check plus sqlite3_stmt_readonly); PRAGMA, EXPLAIN and DML with RETURNING are left alone. Known limitation: the Plot dock is not refreshed after a sort. test-result-sort, 19 cases (10 failed before).
  2. Option to show small BLOBs as hex (databrowser/blob_hex_limit in bytes, 0 = off). Only the display role changes. test-blob-display, 10 cases (5 failed before).

Closes #1177, closes #1201

Clicking the header of a result column in the Execute SQL tab only selected the
column. Add an option to sort the results by it instead: the first click sorts
ascending, the second descending and the third goes back to the original order.
The option is off by default and can be changed in the SQL tab of the
preferences (editor/sort_results), so nothing changes for anyone who doesn't
turn it on.

The results of a custom query can't be sorted by changing its ORDER BY clause,
so the query is wrapped instead: SELECT * FROM (<query>) ORDER BY <column
number>. Using the column number makes this work for columns which have the
same name or no usable name. This is only done for SELECT and WITH statements
which don't modify data. PRAGMA and EXPLAIN statements and statements which
return the rows they changed using RETURNING keep their behaviour, they cannot
be used as a subquery. Exporting the results and saving them as a view use
what is shown, like they do for the table browser.

The sort indicator in the header of custom query results is based on the
column number, too. Before, columns with the same name all got the indicator.

The sorting is part of SqliteTableModel and covered by the new test-result-sort.
BLOBs are shown as the BLOB text (BLOB, unless changed in the preferences) in
the cells of the data browser and the Execute SQL results. Add the option to
show BLOBs up to a given size as hexadecimal string instead, like the one the
hex() function returns, so values like hashes or UUIDs can be read at a glance.
The size is set in the Data Browser tab of the preferences (databrowser/
blob_hex_limit) in bytes. It is 0 by default, which turns the option off and
keeps showing the BLOB text. BLOBs which are larger than the limit still show
the BLOB text, and long hex strings are cut off at the symbol limit like text.

Only the text shown in the cell changes. The data used for editing, exporting
and copying as SQL is the same as before.

Covered by the new test-blob-display.

This branch has not been deployed

No deployments
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.

Add option to show (small) BLOBs as hex strings Sorting query results by click on result column title

2 participants