Skip to content

Fix ALTER DATABASE without a database name - #693

Open
kamil-tekiela wants to merge 1 commit into
phpmyadmin:5.11.xfrom
kamil-tekiela:Fix-ALTER-DATABASE-without-name
Open

kamil-tekiela wants to merge 1 commit into
phpmyadmin:5.11.xfrom
kamil-tekiela:Fix-ALTER-DATABASE-without-name

Conversation

@kamil-tekiela

Copy link
Copy Markdown
Contributor

MySQL allows ALTER {DATABASE | SCHEMA} [db_name] alter_option .... Without a name, the statement changes the default database.

AlterStatement::parse() always skipped the token after the name. Without a name, it skipped the first token of the alter operation:

Query Before After
ALTER DATABASE CHARACTER SET utf8mb4 operation utf8mb4, error "Unrecognized alter operation." operation CHARACTER SET utf8mb4, no errors
ALTER DATABASE DEFAULT CHARACTER SET utf8mb4 operation utf8mb4, error operation DEFAULT CHARACTER SET utf8mb4, no errors

build() then passed null to Expression::build(). On 5.11.x this gives "Attempt to read property "expr" on null" warnings; on 6.0.x and master $this->table->build() throws an Error.

Changes

  • Skip the token only when a name was parsed.
  • Leave the name out of build() when there is none. This removes a PHPStan baseline entry.
  • The parseAlter2 fixture changes. Its name is the unquoted reserved word table, which is not parsed as a name, so its first token was skipped too. The operation now keeps its CONVERT option. The errors stay the same.

When merging up to 6.0.x, the build() line there is . ' ' . $this->table->build(). It needs the same null check.

ALTER SCHEMA is still not supported, because SCHEMA is missing from AlterStatement::$statementOptions. I left it out of this PR.

🤖 Generated with Claude Code

MySQL allows `ALTER DATABASE alter_option ...` without a name; it
changes the default database. AlterStatement::parse() always skipped
the token after the name, so without a name it skipped the first token
of the alter operation: `ALTER DATABASE CHARACTER SET utf8mb4` gave the
operation `utf8mb4` and the error "Unrecognized alter operation.".
AlterStatement::build() then called Expression::build() with null.

Skip the token only when a name was parsed, and leave the name out of
build() when there is none.

The parseAlter2 fixture changes because its name is the unquoted
reserved word `table`, which is not parsed as a name: the `CONVERT`
option of the operation is now kept.

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

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

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