Commit ebf5459
committed
Patch Turso translate_drop_table sqlite_sequence db mismatch
ROOT CAUSE for testCreateTemporaryTable + testTemporaryTableHasPriority:
In core/translate/schema.rs::translate_drop_table, the
"// if drops table, sequence table should reset." block looks up
`sqlite_sequence` via `resolver.schema()` — which always returns
MAIN's schema (Resolver::schema() at translate/emitter/mod.rs:228
just returns `self.schema`). It then opens the cursor with
`db: database_id` set to TEMP_DB_ID for temp tables, telling the
pager to read MAIN's sqlite_sequence root_page (e.g. page 25) from
the TEMP database where that page doesn't exist.
The result: "I/O error: short read on page 25: expected 4096 bytes,
got 0" when DROPping a TEMP AUTOINCREMENT table after the suite has
created any other AUTOINCREMENT tables in MAIN (which makes
MAIN's sqlite_sequence land on page 25). Reproduces in fresh PDO
when the test class's setUp() creates two AUTOINCREMENT tables
before the test method.
Fix: use `resolver.with_schema(database_id, |s| s.get_table(...))`
so the sqlite_sequence root_page comes from the same database the
cursor will open in. For TEMP tables, that yields temp's
sqlite_sequence (created lazily when the temp table itself is
created with AUTOINCREMENT).
Worth reporting upstream — the same bug would affect any
non-MAIN-DB DROP TABLE path with AUTOINCREMENT.1 parent 08a4715 commit ebf5459
1 file changed
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
598 | 641 | | |
599 | 642 | | |
600 | 643 | | |
| |||
0 commit comments