Repository navigation
Commit 7a01ec4
Fix '0' column default preservation during non-strict INSERT (#569)
Fixes #552.
### Description
In MySQL non-strict mode, omitted columns during `INSERT` are filtered
out from the synthetic wrapper subquery if they have a default value
defined, allowing SQLite to populate their schema default.
Previously, `translate_insert_or_replace_body()` evaluated
`$column['COLUMN_DEFAULT']` with a loose truthiness check (`$has_default
= $column['COLUMN_DEFAULT']`). In PHP, string `'0'` evaluates to
`false`, treating the column as having no default value and incorrectly
populating it with an implicit default empty string (`''`).
This PR:
- Updates the check to `null !== $column['COLUMN_DEFAULT']`, consistent
with other default checks in the driver.
- Adds regression test assertions in
`testNonStrictSqlModeNotNullWithDefault` covering `DEFAULT '0'` and
`DEFAULT 0`.
### Testing instructions
Run unit tests in `packages/mysql-on-sqlite`:
```bash
cd packages/mysql-on-sqlite
composer run test -- --filter testNonStrictSqlModeNotNullWithDefault
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Corrected handling of columns with a default value of `0` when
inserting rows without explicitly providing those columns. Omitted
values now receive their configured defaults rather than being treated
as though no default were set.
* **Tests**
* Added coverage confirming that omitted values in columns with text or
numeric zero defaults are populated as expected.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Jan Jakeš <jan@jakes.pro>1 parent a5314e3 commit 7a01ec4
2 files changed
Lines changed: 9 additions & 1 deletion
File tree
- packages/mysql-on-sqlite
- src/sqlite
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6077 | 6077 | | |
6078 | 6078 | | |
6079 | 6079 | | |
6080 | | - | |
| 6080 | + | |
6081 | 6081 | | |
6082 | 6082 | | |
6083 | 6083 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8626 | 8626 | | |
8627 | 8627 | | |
8628 | 8628 | | |
| 8629 | + | |
| 8630 | + | |
| 8631 | + | |
| 8632 | + | |
| 8633 | + | |
| 8634 | + | |
| 8635 | + | |
| 8636 | + | |
8629 | 8637 | | |
8630 | 8638 | | |
8631 | 8639 | | |
| |||
0 commit comments