Skip to content

Fix createObjectContainer() uncaught PDOException on MySQL 8+#275

Open
opengeek wants to merge 1 commit intomodxcms:3.xfrom
opengeek:fix/207-mysql8-container
Open

Fix createObjectContainer() uncaught PDOException on MySQL 8+#275
opengeek wants to merge 1 commit intomodxcms:3.xfrom
opengeek:fix/207-mysql8-container

Conversation

@opengeek
Copy link
Copy Markdown
Member

What changed and why

The createObjectContainer() method in all four driver managers probes for table existence with a bare SELECT COUNT(*) FROM {table}. On MySQL 8+ (and any driver configured with PDO::ERRMODE_EXCEPTION), this query throws a PDOException when the table does not yet exist. The exception was not caught, causing the method to abort instead of proceeding to CREATE TABLE. Closes #207.

Files and methods changed

  • src/xPDO/Om/mysql/xPDOManager.phpcreateObjectContainer(): wrap existence probe in try/catch
  • src/xPDO/Om/pgsql/xPDOManager.phpcreateObjectContainer(): same
  • src/xPDO/Om/sqlite/xPDOManager.phpcreateObjectContainer(): same
  • src/xPDO/Om/sqlsrv/xPDOManager.phpcreateObjectContainer(): same

Cross-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.php with two test methods:

  • testCreateObjectContainerOnNonExistentTableReturnsTrue — primary regression test; forces ERRMODE_EXCEPTION and verifies no PDOException propagates when table is absent
  • testCreateObjectContainerOnExistingTableReturnsTrue — idempotency test; verifies the existing-table early-return path still works

Tests 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 returns true on success. Safe for patch-level consumers.

Contributors

Reported by the issue author. Community comment by @wshawn provided additional context.

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.
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.

[bug] don't work xPDOManager->createObjectContainer() in MySQL > 8

2 participants