fix(database-pgsql): JSON-encode array bindings before passing to PDO#72
Conversation
PDO silently casts PHP arrays to the string "Array" when bound as query parameters. For json/jsonb columns this causes an "invalid input syntax for type json" error at the database level. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bare json_encode() silently returns false on encoding failures (NAN, INF, recursive references, malformed UTF-8) and emits a PHP warning, which violates Marko's loud-errors principle. Match the established EntityHydrator::encodeJson() pattern: pass JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE, catch JsonException, and convert to a ConnectionException with a clear message identifying the offending parameter. Co-Authored-By: Michał Biarda <1135380+michalbiarda@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ee6c7da to
67123e4
Compare
|
Thanks @michalbiarda — good catch on this one. The PDO Maintainer changesTightened the encoder to match the loud-errors pattern already in use elsewhere in the framework:
Rebased onto current Heads-up: same bug exists for MySQLWhile in here I noticed |
Fixes #71
Summary
PgSqlConnection::bindValues()and calljson_encode()before binding, sojson/jsonbcolumns receive a valid JSON string instead of the literal"Array"Test plan
./vendor/bin/pest packages/database-pgsql/tests/Connection/PgSqlConnectionTest.php— all 29 tests pass including the new one🤖 Generated with Claude Code