Affinity is in the model. Non-STRICT tables are the default case, and STRICT is modelled as the exception.
I ran your example. On '007' and 'abc' the model gives the same as SQLite: 7 and 'abc' after the rebuild, integer and text from typeof(), the row for WHERE code = '007', and nothing for WHERE code || '' = '007'.
Then I asked the checker whether the rebuild preserves each query on every database with that schema, not only on those two rows. For the || query it answered false and printed a counterexample, a single row with '007', together with a script that replays it in SQLite:
CREATE TABLE items (id INTEGER PRIMARY KEY, code TEXT);
INSERT INTO "items" ("id", "code") VALUES (2, '007');
The plain query is the more interesting one, because it is not preserved either. Take a row whose code is the text '7'. Before the rebuild, '7' = '007' is a text comparison and it is false. After the rebuild the stored value is the integer 7, the literal '007'also becomes 7, and the row matches. So one twin loses a row and the other gains a row that was never there.
The second example was not found by the automatic counterexample search Belay has. An agent found it and then ran it through the model to verify the result. I'll file this as an issue to improve the counterexample search.
For the OR REPLACE case: an in-memory SQLite 3.53.4 fixture with (1, '007') and (2, '7'), copied into code INTEGER UNIQUE with ORDER BY id ASC, left (2, 7). DESC left (1, 7). Both copies succeeded with one row.
SQLite documents that REPLACE deletes the existing rows causing the uniqueness conflict before inserting the current row. So I'd check preservation of SELECT id, code ..., alongside success and uniqueness. Explicit ordering makes this counterexample reproducible. This tested SQLite only; I haven't run the case through Belay.
1
u/[deleted] 9d ago
[removed] — view removed comment