Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of raw DB Expression breaks truncation of reserved word table names #53838

Closed
MizouziE opened this issue Dec 11, 2024 · 2 comments · Fixed by #53842
Closed

Use of raw DB Expression breaks truncation of reserved word table names #53838

MizouziE opened this issue Dec 11, 2024 · 2 comments · Fixed by #53842

Comments

@MizouziE
Copy link

Laravel Version

11.35.0

PHP Version

8.3.6

Database Driver & Version

8.0.40-0ubuntu0.22.04.1 (GitHub Actions)

Description

We use a reserved word (range) for a table name and in previous versions of Laravel this was never an issue when using /Illuminate/Foundation/Testing/DatabaseTruncation::truncateTablesForConnection() as the table names were escaped before their existence check and truncation.

Since #53787 was merged and

new Expression($table['schema'] ? $table['schema'].'.'.$table['name'] : $table['name'])
implements a new Expression containing the unescaped database and table names any tests that refresh our range table now blow up with:

  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'range) as `exists`' at line 1 (Connection: mysql-elevated, SQL: select exists(select * from range) as `exists`)

Steps To Reproduce

Have a database table with a reserved word for a name and the same thing will happen.

MizouziE added a commit to MizouziE/framework that referenced this issue Dec 11, 2024
This closes laravel#53838 by eliminating the passing of un-escaped schema and table names to the `exists()` and `truncate()` methods
@hafezdivandari
Copy link
Contributor

I've sent PR #53842 to address this. Sorry for the inconvenience.

@MizouziE
Copy link
Author

Thanks @hafezdivandari ! Glad I wasn't too far off the mark with a fix. I'm sure it didn't inconvenience many people as we're a bit of an edge case with singular named tables, but it was interesting to read up about reserved words etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants