Skip to content

fix: return false from fetchField on empty result - #727

Merged
n0nag0n merged 3 commits into
masterfrom
fix-726-fetchfield-null
Sep 4, 2026
Merged

fix: return false from fetchField on empty result#727
n0nag0n merged 3 commits into
masterfrom
fix-726-fetchfield-null

Conversation

@ambrose5773

@ambrose5773 ambrose5773 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • SimplePdo::fetchRow() returns null when there are no rows; PdoWrapper::fetchField() called getData() without a null check and fatals.
  • Guard empty results (null or empty Collection) and return false. Matching rows still use getData() + reset().
  • Closes Database SimplePdo #726.

Empty result vs SQL NULL

  • No matching rows → false (SimplePdo: fetchRow is null; PdoWrapper: empty Collection, count === 0).
  • Matching row with a SQL NULL column → PHP null (reset(['col' => null]) is null; not treated as empty).
  • Matching row with 0 or '' stays 0 / '' (assertSame).
  • PDO FETCH_ASSOC maps SQL NULL → PHP null the same on mysql / pgsql / sqlite. Tests use sqlite::memory: as the stand-in; no new live MySQL/Postgres CI in this PR.

Test plan

  • Both wrappers: empty → false
  • Both wrappers: SQL NULL column → null
  • Both wrappers: 0 and '' with assertSame
  • Happy-path string/int still green
  • Local: SimplePdoTest 49 OK, PdoWrapperTest 19 OK

SimplePdo::fetchRow() returns null when there are no rows. Guard
PdoWrapper::fetchField() so empty queries return false instead of
calling getData() on null. Closes #726.
Distinguish empty result sets (false) from SQL NULL columns (null),
and keep 0 / '' as assertSame on both PdoWrapper and SimplePdo.
assertEquals for integer-ish fetchField values; keep assertSame for
false / empty string and assertNull for SQL NULL.
@n0nag0n
n0nag0n merged commit 24640dc into master Sep 4, 2026
21 checks passed
@n0nag0n
n0nag0n deleted the fix-726-fetchfield-null branch September 4, 2026 03:50
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.

Database SimplePdo

2 participants