Skip to content

v1.1.0

Choose a tag to compare

@SoloPHP SoloPHP released this 28 Oct 10:40
· 4 commits to main since this release

Solo Repository 1.1 makes LIKE patterns escape the same way on every supported database and adds Like, which builds such patterns from plain text.

Fixes

  • LIKE and NOT LIKE escape with \ on SQLite, MySQL, MariaDB and PostgreSQL, so \%, \_ and \\ match %, _ and \ themselves. SQLite has no default escape character, and under NO_BACKSLASH_ESCAPES neither has MySQL, nor MariaDB for single-byte character sets; there 50\% matched 50\ followed by anything. A LIKE now ends in ESCAPE '\' on SQLite and ESCAPE X'5C' on MySQL and MariaDB. Both are literals, so patterns with a fixed prefix keep their index ranges. PostgreSQL, which always escapes with \, gets no clause, and LIKE on bytea fields keeps working.

Features

  • Like::escape(), contains(), startsWith() and endsWith() turn plain text, such as a search term, into a pattern that matches it literally:

    use Solo\Repository\Like;
    
    $products->read()->findBy(['name LIKE' => Like::contains($search)]);

Behavior changes

  • On SQLite, and on MySQL and MariaDB under NO_BACKSLASH_ESCAPES, a \ in a pattern escapes the character after it instead of matching a backslash: the pattern C:\dir matches C:dir. Patterns without \, PostgreSQL and MySQL/MariaDB in their default mode are unchanged.
  • A pattern that ends in an unpaired \ throws InvalidArgumentException before SQL instead of a result that differs by database.

Upgrade

composer update solophp/repository

See LIKE patterns, the changelog and the full diff since 1.0.0.