Skip to content

Fix exact number filters, multi-cell BLOB paste and export write errors - #4245

Open
deepsidhu1313 wants to merge 3 commits into
sqlitebrowser:masterfrom
deepsidhu1313:fix/browse-bugs
Open

deepsidhu1313 wants to merge 3 commits into
sqlitebrowser:masterfrom
deepsidhu1313:fix/browse-bugs

Conversation

@deepsidhu1313

Copy link
Copy Markdown
Contributor

Three independent commits.

  1. Don't quote numbers in exact-match filters. = filters quoted every value, so a computed column such as COUNT(*) never matched. A value stays unquoted only if it round-trips as an integer or a 15-digit double (so 007, 1.50, 1e5 and 0x10 stay quoted). In a column without type affinity that holds the text '5', =5 now matches only the number 5, like <>5 and >=5 already did.
  2. Keep binary data as BLOB when pasting several cells (the loop used setData(), which stores text). New test-paste.
  3. Detect incomplete writes when exporting to CSV and JSON. JSON ignored the result of write(), CSV missed errors in its last buffered chunk, and an existing file was replaced by the truncated one. New writeAll()/flushStream() helpers; commit() is skipped on error.

Fixes #3608, #3243; related to #3307

An exact filter such as =2 always put the value in quotes. SQLite never
considers a number equal to a quoted string when the column has no type
affinity, e.g. the result of COUNT(*) in a view, so such a filter never
matched anything.

Leave numbers unquoted, but only those which are the same number when
read as text or as a number. Values like 007, 1.50 or 12345678901234567890123
are kept as text, otherwise they would stop matching the text stored in a
text column.

Fixes sqlitebrowser#3608
Pasting a single cell already stores binary data as a BLOB, but pasting
several cells went through setData(), which always stores the value as
text. Binary data copied from a BLOB cell ended up as corrupt TEXT in the
destination cells, which other applications can not read back.

Use setTypedData() for each cell, like the single cell cases do, and
keep the editability check that setData() did.

Add test-paste, which copies and pastes cells through the key shortcuts
of the table view.

Fixes the multi-cell case of sqlitebrowser#3307
When the disk is full, write() first writes as much as still fits and
returns the smaller number. The JSON export ignored this, so it reported
success and left a truncated file. The CSV export did not notice a
failure to write the last chunk of data either, because a QTextStream
only writes it when it is flushed, which happened after the last check.

Check the result of writing the JSON document and flush the CSV stream
before checking it. Don't commit the QSaveFile when something went
wrong, because that replaced an existing file with the incomplete one.

Add writeAll() and flushStream() for this and test them with a device
that behaves like a full disk.

Fixes sqlitebrowser#3243

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.

[Bug]: Exact filter on COUNT() column doesn't work

2 participants