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

[11.x] Fix unescaped table names issue of DatabaseTruncation trait by introducing Connection::withoutTablePrefix() method #53842

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

hafezdivandari
Copy link
Contributor

Fixes #53838

On PR #53787, we had to pass the table names as Expression to the queries on DatabaseTruncation trait because table names are already prefixed and passing them as string (instead of Expression) causes query grammar to prefix the table names twice!

But when passing as Expression, the table names are not escaped which causes issue when tables have reserved names as reported on #53838.

This PR adds withoutTablePrefix() method to the Connection class. This method temporary disables the connection's table prefix when executing its given callback. This new method is then used on the DatabaseTruncation trait.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@hafezdivandari hafezdivandari changed the title [11.x] Add connection DB::withoutTablePrefix [11.x] Fix unescaped table names issue of DatabaseTruncation trait by introducing Connection::withoutTablePrefix() method Dec 11, 2024
@hafezdivandari hafezdivandari marked this pull request as ready for review December 11, 2024 12:55
@taylorotwell taylorotwell merged commit 0dabf8e into laravel:11.x Dec 11, 2024
38 checks passed
@hafezdivandari hafezdivandari deleted the 11.x-without-table-prefix branch December 11, 2024 16:19
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.

Use of raw DB Expression breaks truncation of reserved word table names
2 participants