Skip to content

v3.1.0

Latest

Choose a tag to compare

@tommyknocker tommyknocker released this 05 Nov 16:20

PDOdb 3.1.0

3.1 fixes results that were wrong in 3.0.0 and earlier, so some code that depended on the old results changes. It needs the same PHP as 3.0 (8.4 or newer). Nothing is required of a custom dialect: every new dialect interface is optional.

Read Upgrading from 3.0 to 3.1 before updating.

Check these first: results can change without an error

  • insert() and replace() return the key of the row the statement wrote, or null when there is none to report (a skipped INSERT IGNORE, a composite key, a table without a key). 2.10 to 3.0.0 returned 1 there, which looked like a real id and let code attach child rows to the wrong parent. The type is int|string|null. insertFrom() and replaceMulti() return the number of affected rows.
  • JSON-path comparison with a number or a boolean (whereJsonPath(), Db::jsonPath()) is typed on all six databases. Before, the value was compared as text: age > 27 selected the row with 5, ok = true matched the number 1 and ok = false matched nothing.
  • Query parameters are bound with their own type instead of all as text. where('active', false) failed on PostgreSQL and MariaDB, and false was stored as NULL on Oracle.
  • limit() and offset() throw InvalidArgumentException for a negative number.
  • SQLite REGEXP, regexp_replace() and regexp_extract() throw a QueryException for an invalid pattern. They used to warn and act as "no match", so NOT REGEXP selected every row and an UPDATE with regexp_replace() wrote an empty string. A / in a pattern is a literal now.

Fixed

  • jsonSet() and jsonReplace() wrote every value as a JSON string on MariaDB, SQL Server and Oracle (999 as "999", true as "true", null as "null"; SQL Server also added quotes to text, and Oracle's jsonReplace() added a key named like the path instead of replacing the value). The JSON type of the value is written now.
  • SQL Server created DECIMAL(10) for decimal(10, 2), so every value was rounded to a whole number.
  • Insert keys stay correct after MySQL/MariaDB table changes and TEMP shadowing, without extra queries per insert.
  • Oracle returns an id beyond PHP_INT_MAX exactly; shard routing is exact for such keys.
  • The compiled-query cache ignored limit() and offset(), so a second query that differed only in them returned the rows of the first.
  • Cursor pagination and batch() / each() with a key qualified by a table alias; paginate(), getValue(), getColumn() and index() after asObject(); a write that joins another table now drops the cached reads of the joined tables.
  • On PHP 8.4 a SQLite connection the library creates is a Pdo\Sqlite object, as on 8.5.

Every change is in the CHANGELOG.

Added

  • A step-by-step guide to reliable events between services (outbox, worker, inbox), an end-to-end example that runs on every database, and a signed webhook publisher with a matching receiver.
  • Optional dialect interfaces: DialectInsertReturningInterface, DialectParameterTypesInterface, DialectMetadataMemoInterface, DialectJsonTypedComparisonInterface.

Data written by older versions

Nothing is rewritten for you. Documents written by jsonSet() on MariaDB, SQL Server and Oracle before the upgrade keep their JSON strings, and SQL Server decimal(p, s) columns created earlier keep scale 0. UPGRADE.md has a query to find each of them.

Known limits

They come from the databases, except the PostgreSQL one (details):

  • jsonSet() on a path whose parent object is missing writes nothing on SQL Server and Oracle (the other databases create it).
  • jsonReplace() on a missing key creates it on SQL Server.
  • A string that is JSON text (true, null, {...}) is written as that JSON, not as a string, on PostgreSQL.
  • A JSON string that holds a number ("30") or a boolean ("true") matches a numeric or boolean condition on SQL Server and Oracle.
  • A number beyond 1e35 or closer to zero than 1e-30 (SQL Server: beyond 1e20) matches no numeric JSON condition instead of being rounded.