Repository navigation
Fix temporary table lookup without stringified fetches and with a different case - #522
Conversation
…ferent case The temporary table lookup compared the fetched value to the string "1". PDO SQLite returns native types unless fetches are stringified, so on PHP 8.1 and newer, the lookup never found a temporary table for callers that don't set PDO::ATTR_STRINGIFY_FETCHES. Statements like ALTER TABLE, SHOW COLUMNS, or DESCRIBE then failed or used a standard table of the same name instead. The lookup also matched the table name case-sensitively, unlike the information schema tables, so a temporary table was not found when the statement used a differently cased name. Match the name case-insensitively and check the fetched value for presence rather than comparing it to a string. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
When translating a reference to an information schema table, the driver checked whether a temporary table with the same name existed, such as "columns". If it did, the query read the temporary table metadata instead of the standard one, so all standard tables disappeared from the result. With the case-insensitive temporary table lookup, any differently cased name triggers this too, e.g., a temporary table named "Columns". Temporary tables are not listed in the information schema, so always read the standard table metadata.
Test the differently cased name with a standard table of the same name, including DROP TABLE. Before the lookup fix, DROP TABLE removed the temporary table, but deleted the metadata of the standard table. Run the temporary table priority test with stringified fetches both enabled and disabled instead of keeping a partial copy of it.
|
Thanks for the contribution, @Nandan108! The fix looks good. I pushed two small improvements:
|
Summary
The internal check for whether a table is temporary (
temporary_table_exists()) has two defects. It is used byALTER TABLE,DROP TABLE,SHOW COLUMNS,SHOW CREATE TABLE,DESCRIBE,UPDATE, and others to decide whether to use the temporary or the standard information schema.It compares the fetched value to the string
'1'. PDO SQLite returns native types unlessPDO::ATTR_STRINGIFY_FETCHESis set, so on PHP 8.1 and newer, the check never finds a temporary table for callers that don't set that attribute. The WordPress plugin and the MySQL proxy set it, so they are unaffected, but the PDO-compatible API is:When a standard table of the same name exists, the statement silently applies to that table instead.
It matches the table name case-sensitively, unlike the information schema tables (
COLLATE NOCASE), so a temporary table is not found by a differently cased name:Fix
The lookup matches the name with
COLLATE NOCASEand checks the fetched value for presence (false !== fetchColumn()) rather than comparing it to a string. The translation tests filter this query out of the recorded SQLite statements by its text, so the filter is updated to match.Queries to the information schema no longer use this lookup with the name of the information schema table, such as
columns. Temporary tables are not listed in the information schema, but with a case-insensitive lookup, a temporary table namedColumnswould hide all standard tables frominformation_schema.columns.Tests
testTemporaryTableHasPriorityOverStandardTableruns with stringified fetches enabled and disabled.testTemporaryTableIsFoundByDifferentlyCasedNameuses a differently cased name inALTER TABLE,SHOW COLUMNS, andDROP TABLEwhile a standard table with the same name exists.testTemporaryTableNamedLikeInformationSchemaTablechecks that temporary tables named like information schema tables don't change the information schema results.All three fail on
trunk.Found while preparing a fix for
CREATE TEMPORARY TABLE IF NOT EXISTS, which will reuse this lookup.Part of #451.
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
Summary by CodeRabbit
ALTER TABLEandDROP TABLEcorrectly target temporary tables when names differ only by capitalization or overlap with a regular table.