Repository navigation
Commit 8dc5c27
Fix CREATE TEMPORARY TABLE IF NOT EXISTS and DROP TEMPORARY TABLE as the first temporary table (#524)
## Summary
When the first temporary table statement of a session is `CREATE
TEMPORARY TABLE IF NOT EXISTS` or `DROP TEMPORARY TABLE`, the statement
fails:
```sql
CREATE TEMPORARY TABLE IF NOT EXISTS t (a INT);
-- or
DROP TEMPORARY TABLE IF EXISTS t;
-- SQLSTATE[42S02]: Base table or view not found: 1146
-- Table '_wp_sqlite_mysql_information_schema_tmp_tables' doesn't exist
```
Both statements use the temporary information schema tables, but those
are only created together with the first temporary table of a session. A
plain `CREATE TEMPORARY TABLE` works, and once one has run, both
statements work too, which is why the existing tests pass.
This also breaks the common pattern of `DROP TEMPORARY TABLE IF EXISTS
x` followed by `CREATE TEMPORARY TABLE x`.
## Fix
Both statements now check for the temporary table with
`temporary_table_exists()`, which looks in `sqlite_temp_master`. It
already exists for exactly this reason ("it may not exist yet"):
- **`CREATE TEMPORARY TABLE IF NOT EXISTS`** uses it for the existence
check. Non-temporary tables are unchanged.
- **`DROP TEMPORARY TABLE`** skips the information schema update when no
such temporary table exists. SQLite then does nothing with `IF EXISTS`,
and reports the missing table without it, as it already did once a
temporary table had been created.
## Tests
The new tests run the statements before any temporary table exists. All
of them fail on `trunk` with the error above:
- **`testCreateTemporaryTableIfNotExistsAsFirstTemporaryTable`** creates
the table, inserts a row, and repeats the statement with the same and a
differently cased name, to check it is a no-op that keeps the data.
- **`testCreateTemporaryTableIfNotExistsWithStandardTableOfSameName`**
checks that a standard table with the same name doesn't make the
statement a no-op, and stays unchanged.
- **`testDropTemporaryTableIfExistsAsFirstTemporaryTable`** checks that
the statement succeeds, and that it doesn't drop a standard table with
the same name.
- **`testDropTemporaryTableAsFirstTemporaryTable`** checks that the
statement reports the missing table.
Found while running WooCommerce on WordPress Playground.
## Use of AI
This change was prepared with Claude Code (Claude Fable 5.1). I reviewed
the code, the tests, and this description, and I take responsibility for
the change.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Temporary-table creation now correctly handles existing tables,
including case-insensitive names and tables that share a name with a
standard table.
* Dropping a temporary table no longer affects a same-named standard
table. Attempts to drop a missing temporary table now follow the
expected behavior with or without `IF EXISTS`.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Jan Jakeš <jan@jakes.pro>1 parent 5deb4d6 commit 8dc5c27
3 files changed
Lines changed: 88 additions & 9 deletions
File tree
- packages/mysql-on-sqlite
- src/sqlite
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2925 | 2925 | | |
2926 | 2926 | | |
2927 | 2927 | | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
2932 | | - | |
2933 | | - | |
2934 | | - | |
2935 | | - | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
2936 | 2944 | | |
2937 | 2945 | | |
2938 | 2946 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
784 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
785 | 794 | | |
786 | 795 | | |
787 | 796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4433 | 4433 | | |
4434 | 4434 | | |
4435 | 4435 | | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + | |
| 4472 | + | |
| 4473 | + | |
| 4474 | + | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
| 4478 | + | |
| 4479 | + | |
| 4480 | + | |
| 4481 | + | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + | |
| 4490 | + | |
| 4491 | + | |
| 4492 | + | |
| 4493 | + | |
| 4494 | + | |
| 4495 | + | |
| 4496 | + | |
| 4497 | + | |
4436 | 4498 | | |
4437 | 4499 | | |
4438 | 4500 | | |
| |||
0 commit comments