Skip to content

ref(pdo): fix boundary/coercion bugs and polish wrapper DX#34

Merged
Chemaclass merged 1 commit into
mainfrom
ref/wrapper-quality-polish
Jun 3, 2026
Merged

ref(pdo): fix boundary/coercion bugs and polish wrapper DX#34
Chemaclass merged 1 commit into
mainfrom
ref/wrapper-quality-polish

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

Whole-library bug hunt + quality pass over the new wrappers, driven by two independent reviews. Optimises for long-term DX; the breaking changes are intentional and documented.

Bugs fixed

  • Options map → TypeError: connect / prepare passed a Phel options map straight to PDO. phel->php cannot convert integer map keys (and PDO ATTR_* keys are integers), so any options map threw TypeError / getName() on int. New private options->php builds the PHP array key-safely. Regression test added.
  • Positional binding broken: bind-value / bind-param did (str column), turning positional index 1 into "1" — PDO then errors on ? placeholders. Now an integer column is kept as a 1-based index (param-key helper). Test added.
  • insert on empty map: produced INSERT INTO t () VALUES () (SQL syntax error). Now throws InvalidArgumentException at the Phel boundary. Test added.
  • set-fetch-mode silent no-op: case had no default, so >2 extra args returned nil and never called setFetchMode. Now throws InvalidArgumentException. Test added.

Breaking changes (documented in CHANGELOG)

  • error-code → SQLSTATE string (and error-info's first element): intval corrupted non-numeric states (HY0000, 42S0242). SQLSTATE is a 5-char code. driver-code stays int.
  • last-insert-id / insert → string id: PDO reports it as a string; coercing to int loses big integers and PostgreSQL named sequences. Coerce with php/intval at the call site when needed.
  • get-available-drivers → no connection arg: PDO::getAvailableDrivers is static; requiring a connection was a DX wart and blocked the pre-connection use case.

DX / docs / tests

  • from-connection rejects a non-\PDO with a clear error.
  • fetch-all guards against a false return under silent error mode.
  • Docstrings clarified: bind-param (value captured at call time, not by-ref), statement-seq (cursor stays open until consumed), next-rowset (throws on unsupported drivers), fetch-column (false-vs-nil), set-fetch-mode (fetch/fetch-all force FETCH_ASSOC).
  • Test fixture insert-name now uses a prepared statement instead of string interpolation.
  • README + docs/recipes.md + docs/troubleshooting.md updated for all signature/return changes.

composer test green (66 assertions, up from 60).

Aligns the library for a clean release.

- connect/prepare convert integer-keyed options maps to PHP arrays (was TypeError)
- bind-value/bind-param keep integer columns as positional indexes
- last-insert-id/insert return string ids (lossless); error-code returns SQLSTATE string
- get-available-drivers drops the unused connection arg (static method)
- insert rejects empty rows; set-fetch-mode rejects bad arity
- doc + test hardening across the new wrappers

BREAKING: last-insert-id/insert -> string, error-code/error-info[0] -> string,
get-available-drivers takes no args. See CHANGELOG.
@Chemaclass Chemaclass self-assigned this Jun 3, 2026
@Chemaclass Chemaclass added the bug Something isn't working label Jun 3, 2026
@Chemaclass Chemaclass merged commit da070ea into main Jun 3, 2026
1 check passed
@Chemaclass Chemaclass deleted the ref/wrapper-quality-polish branch June 3, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant