Skip to content

Keep constraints when editing tables that use ON CONFLICT on CHECK or NULL - #4242

Open
deepsidhu1313 wants to merge 4 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/on-conflict
Open

deepsidhu1313 wants to merge 4 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/on-conflict

Conversation

@deepsidhu1313

Copy link
Copy Markdown
Contributor

SQLite accepts CHECK(expr) ON CONFLICT x at table level and NULL ON CONFLICT x on a column. Our grammar rejected both, so such a table counted as not fully parsed and any edit in the Edit Table dialog rebuilt it from the pragma name and type only, silently dropping every constraint (PRIMARY KEY, NOT NULL, UNIQUE, CHECK). The grammar now accepts both (CheckConstraint gets a conflict action). The dialog also keeps the conflict action when an index constraint is switched between Unique and Primary Key.

New tests in test-sqlobjects (7 failed before; 285 pass now). The first commit (Qt6 compile fix for test-sqlobjects) can be dropped if Qt6 work lands separately.

Refs #1264

QCOMPARE() cannot deduce the type of a bare braced-init-list in Qt6,
so spell out sqlb::StringVector for the rowidColumns() comparisons.
Check that the conflict action of column and table PRIMARY KEY, NOT NULL
and UNIQUE constraints survives parsing a CREATE TABLE statement and
writing it out again, for every conflict action, and that it also
survives the kind of edits the Edit Table dialog applies to a copy of
the table before DBBrowserDB::alterTable() recreates it from the
generated SQL (renaming the table or columns, changing or dropping
columns, extending the key).

Related: sqlitebrowser#1264
SQLite accepts a conflict clause after a table CHECK constraint and
after the NULL column constraint, but our grammar rejected both. A table
using either was then not fully parsed, so the Edit Table dialog could
only offer the columns reported by the pragma and recreating the table
from that dropped all of its constraints.

Accept the clause in both places. For CHECK it is kept and written out
again, so the definition isn't changed; for NULL, which isn't stored in
the model at all, it is ignored just like the constraint itself.

Related: sqlitebrowser#1264
Switching a constraint between Unique and Primary Key in the Edit Table
dialog replaces it by a new constraint, which only copied the name. The
ON CONFLICT clause of the old constraint was silently dropped. Carry it
over and update the primary key's "On Conflict" combo box accordingly.

Related: sqlitebrowser#1264

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.

2 participants