ref(pdo): fix boundary/coercion bugs and polish wrapper DX#34
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
connect/preparepassed a Phel options map straight to PDO.phel->phpcannot convert integer map keys (and PDOATTR_*keys are integers), so any options map threwTypeError/getName() on int. New privateoptions->phpbuilds the PHP array key-safely. Regression test added.bind-value/bind-paramdid(str column), turning positional index1into"1"— PDO then errors on?placeholders. Now an integer column is kept as a 1-based index (param-keyhelper). Test added.inserton empty map: producedINSERT INTO t () VALUES ()(SQL syntax error). Now throwsInvalidArgumentExceptionat the Phel boundary. Test added.set-fetch-modesilent no-op:casehad no default, so >2 extra args returnedniland never calledsetFetchMode. Now throwsInvalidArgumentException. Test added.Breaking changes (documented in CHANGELOG)
error-code→ SQLSTATE string (anderror-info's first element):intvalcorrupted non-numeric states (HY000→0,42S02→42). SQLSTATE is a 5-char code.driver-codestays int.last-insert-id/insert→ string id: PDO reports it as a string; coercing to int loses big integers and PostgreSQL named sequences. Coerce withphp/intvalat the call site when needed.get-available-drivers→ no connection arg:PDO::getAvailableDriversis static; requiring a connection was a DX wart and blocked the pre-connection use case.DX / docs / tests
from-connectionrejects a non-\PDOwith a clear error.fetch-allguards against afalsereturn under silent error mode.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).insert-namenow uses a prepared statement instead of string interpolation.docs/recipes.md+docs/troubleshooting.mdupdated for all signature/return changes.composer testgreen (66 assertions, up from 60).Aligns the library for a clean release.