Fix createObjectContainer() uncaught PDOException on MySQL 8+#275
Open
opengeek wants to merge 1 commit intomodxcms:3.xfrom
Open
Fix createObjectContainer() uncaught PDOException on MySQL 8+#275opengeek wants to merge 1 commit intomodxcms:3.xfrom
opengeek wants to merge 1 commit intomodxcms:3.xfrom
Conversation
The SELECT COUNT(*) table-existence probe in all four driver managers threw an uncaught PDOException when the table did not exist and PDO was in ERRMODE_EXCEPTION mode. Wrapping the probe in try/catch allows the method to proceed to CREATE TABLE as intended. Closes modxcms#207.
JoshuaLuckers
approved these changes
Mar 28, 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.
What changed and why
The
createObjectContainer()method in all four driver managers probes for table existence with a bareSELECT COUNT(*) FROM {table}. On MySQL 8+ (and any driver configured withPDO::ERRMODE_EXCEPTION), this query throws aPDOExceptionwhen the table does not yet exist. The exception was not caught, causing the method to abort instead of proceeding toCREATE TABLE. Closes #207.Files and methods changed
src/xPDO/Om/mysql/xPDOManager.php—createObjectContainer(): wrap existence probe in try/catchsrc/xPDO/Om/pgsql/xPDOManager.php—createObjectContainer(): samesrc/xPDO/Om/sqlite/xPDOManager.php—createObjectContainer(): samesrc/xPDO/Om/sqlsrv/xPDOManager.php—createObjectContainer(): sameCross-driver impact
All four drivers (MySQL, PostgreSQL, SQLite, SQL Server) contained the identical bug. All four are fixed identically.
Test coverage
Added
test/xPDO/Test/Om/xPDOManagerCreateObjectContainerTest.phpwith two test methods:testCreateObjectContainerOnNonExistentTableReturnsTrue— primary regression test; forces ERRMODE_EXCEPTION and verifies no PDOException propagates when table is absenttestCreateObjectContainerOnExistingTableReturnsTrue— idempotency test; verifies the existing-table early-return path still worksTests run against all CI drivers (SQLite, MySQL, PostgreSQL).
Breaking change assessment
No public API signature or return type changed. The method already returned
bool. When a table is absent the method previously threw; now it correctly proceeds to CREATE TABLE and returnstrueon success. Safe for patch-level consumers.Contributors
Reported by the issue author. Community comment by @wshawn provided additional context.