Skip to content

[4.x] Leave out empty strings for decimal and temporal columns in MySQL insertObject() - #416

Open
Hackwar wants to merge 3 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-mysql-insertobject-empty-values
Open

Hackwar wants to merge 3 commits into
joomla-framework:4.x-devfrom
Hackwar:4.x-mysql-insertobject-empty-values

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

MysqlDriver::insertObject() and MysqliDriver::insertObject() leave out a column whose value cannot be stored in strict mode: '' for integer columns and empty values for datetime columns. Decimal, float, double, date, time, timestamp and year columns were not covered, so inserting an object with an empty decimal field failed with "Incorrect decimal value" (#347). An empty string for these types is now left out as well, so the column default applies, as it already did for integers. Inserts that used to work are unaffected; only inserts that used to fail change.

The other half of #255 is not part of this PR: updateObject() sends '' where insertObject() skips the column, so one object can insert fine and then fail to update. The review suggests a shared helper for both methods and all drivers, which maps '' to NULL for nullable columns and skips it otherwise. That changes what updateObject() writes, so it needs a decision; see the PR comments / report.

Testing Instructions

New testInsertObjectWithEmptyDecimalAndDate in MysqliDriverTest and MysqlDriverTest creates a table with decimal(10,2) NOT NULL DEFAULT 0 and date NULL columns and inserts '' into both. Before the change it fails in strict mode; after it the defaults are stored. It needs MySQL/MariaDB, so it runs in CI only (no server locally).

Documentation Changes Required

None on 4.x-dev. #373's docs/overview.md → "Writing" does not describe the empty-value rules.

Refs #255, fixes #347

🤖 Generated with Claude Code

Hackwar and others added 2 commits November 13, 2026 09:08
…ertObject()

The MySQL drivers' insertObject() already skipped '' for integer columns and
empty values for datetime columns, but not for decimal, float, double, date,
time, timestamp or year columns, so inserting an object with an empty
decimal field failed in strict mode. Those types are now skipped as well,
so the column default applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

First CI run failed because the new test was inserted between #[DataProvider('dataGetTableColumns')] and testGetTableColumns(), so it took over the data provider. Fixed in a follow-up commit (please squash on merge).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Empty decimal field is not treated in database driver

1 participant