Skip to content

Store the database name in the database field for ALTER and DROP DATABASE - #692

Open
kamil-tekiela wants to merge 1 commit into
phpmyadmin:masterfrom
kamil-tekiela:Fix-database-name-in-alter-and-drop
Open

kamil-tekiela wants to merge 1 commit into
phpmyadmin:masterfrom
kamil-tekiela:Fix-database-name-in-alter-and-drop

Conversation

@kamil-tekiela

Copy link
Copy Markdown
Contributor

AlterStatement and DropStatement parse the name of a database as a table name:

Query Before After
ALTER DATABASE db ... $stmt->table->table = 'db' $stmt->table->database = 'db'
DROP DATABASE db / DROP SCHEMA db $stmt->fields[0]->table = 'db' $stmt->fields[0]->database = 'db'

CreateStatement already uses parseField => database for CREATE DATABASE/SCHEMA, so the three statements were inconsistent. Query::getTables() also returned the database of ALTER DATABASE db as a table; it now returns [].

Changes

  • AlterStatement::parse() parses the name into database when the DATABASE option is set.
  • Statement::parse() looked up the clause parser options before it parsed the statement options. It now gets them, after the statement options, from the new protected getKeywordParserOptions(). DropStatement overrides it for DATABASE/SCHEMA.
  • DROP DATABASE a.b now reports "Unexpected dot.", the same as CREATE DATABASE a.b.

Compatibility

Code that reads the database name from ->table of these statements must read ->database instead. phpMyAdmin does this in Tracker::parseQuery(), so I target master and not a patch branch.

🤖 Generated with Claude Code

…BASE

AlterStatement and DropStatement parsed the name of a database as a
table name, so `ALTER DATABASE db` and `DROP DATABASE db` had the name
in `$expr->table`. Query::getTables() also listed the database of
`ALTER DATABASE db` as a table.

Parse the name with `parseField => database` when the statement has the
DATABASE or SCHEMA option, as CreateStatement already does. For DROP,
the generic Statement::parse() looked up the clause parser options
before the statement options were known; Statement now gets them from
the new getKeywordParserOptions() method, which DropStatement overrides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.82%. Comparing base (bd435f5) to head (50ba60b).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #692      +/-   ##
============================================
+ Coverage     96.79%   96.82%   +0.02%     
- Complexity     2252     2258       +6     
============================================
  Files            90       91       +1     
  Lines          4966     4973       +7     
============================================
+ Hits           4807     4815       +8     
+ Misses          159      158       -1     
Flag Coverage Δ
unit-8.2-ubuntu-latest 96.82% <100.00%> (+0.02%) ⬆️
unit-8.3-ubuntu-latest 96.82% <100.00%> (+0.02%) ⬆️
unit-8.4-ubuntu-latest 96.82% <100.00%> (+0.02%) ⬆️
unit-8.5-ubuntu-latest 96.82% <100.00%> (+0.02%) ⬆️
unit-8.6-ubuntu-latest 96.82% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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.

1 participant