Skip to content

Fix HY093 in loadTableForeignKeys() when prepare emulation is off - #478

Open
KalimeroMK wants to merge 2 commits into
yiisoft:masterfrom
KalimeroMK:fix-458-duplicate-schema-name-param
Open

Fix HY093 in loadTableForeignKeys() when prepare emulation is off#478
KalimeroMK wants to merge 2 commits into
yiisoft:masterfrom
KalimeroMK:fix-458-duplicate-schema-name-param

Conversation

@KalimeroMK

@KalimeroMK KalimeroMK commented Aug 2, 2026

Copy link
Copy Markdown

Schema::loadTableForeignKeys() used :schemaName twice in one statement, once in the CASE expression and once in the WHERE clause.

@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:

ATTR_EMULATE_PREPARES = true   ->  OK
ATTR_EMULATE_PREPARES = false  ->  SQLSTATE[HY093]: Invalid parameter number

Binds the value as :schemaName1 and :schemaName2 instead. Added testGetTableForeignKeysWithoutEmulatedPrepares(), which opens a connection with setEmulatePrepare(false); it errors with the exception above without the fix.

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Fixed issues #458

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

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.10%. Comparing base (a65712f) to head (8b29ce3).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/Schema.php Outdated
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.

3 participants