Fix HY093 in loadTableForeignKeys() when prepare emulation is off - #478
Open
KalimeroMK wants to merge 2 commits into
Open
Fix HY093 in loadTableForeignKeys() when prepare emulation is off#478KalimeroMK wants to merge 2 commits into
KalimeroMK wants to merge 2 commits into
Conversation
The foreign key query used :schemaName in both the CASE expression and the WHERE clause. With PDO::ATTR_EMULATE_PREPARES disabled the statement is prepared natively, where each marker needs its own bound value, and MySQL rejects it: SQLSTATE[HY093]: Invalid parameter number Emulated prepares hid the problem because PDO rewrites the placeholders client-side, which is why the default configuration was unaffected. Bind the same value under :schemaName1 and :schemaName2 instead. Closes yiisoft#458
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #478 +/- ##
=========================================
Coverage 99.10% 99.10%
Complexity 256 256
=========================================
Files 24 24
Lines 779 781 +2
=========================================
+ Hits 772 774 +2
Misses 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Tigrov
approved these changes
Aug 3, 2026
Tigrov
approved these changes
Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Schema::loadTableForeignKeys()used:schemaNametwice in one statement, once in theCASEexpression and once in theWHEREclause.@vjik asked on the issue whether PDO allows that. It depends on
PDO::ATTR_EMULATE_PREPARES, which is why the suite never caught it — with emulation on, PDO rewrites the placeholders client-side, but with it off the statement is prepared natively and each marker needs its own value:Binds the value as
:schemaName1and:schemaName2instead. AddedtestGetTableForeignKeysWithoutEmulatedPrepares(), which opens a connection withsetEmulatePrepare(false); it errors with the exception above without the fix.