Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.3', '8.4', '8.5']
php: ['8.4', '8.5']
services:
mysql:
image: mysql:8.4
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Unreleased
* Requires PHP 8.4 or newer (was 8.3). PHP 8.4's PDO understands PostgreSQL dollar-quoted strings, so a "?" or ":name" inside one no longer fails. CI tests PHP 8.4-8.5.
* Added SQLite 3 support: Dialect::SQLite and SQLiteBindingFactory. With it, Statement::sql() reads '...' strings without backslash escapes, "...", `...` and [...] identifiers, "--" comments without a following space and non-nesting block comments, and "#" isn't a comment.
* Added SQLiteNumericBindings: bUInt() and bUIntArray() stop at 9223372036854775807, SQLite's integer maximum, since SQLite reads larger numbers as floats and can't tell them apart.
* MySQLNumericBindings' unsigned maximum is now the protected UINT_MAX constant, so subclasses can lower it.
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ With GLPDO2:
composer require geeklab/glpdo2
```

Requires PHP 8.3 or newer, with the `pdo_mysql` extension for MySQL and MariaDB, `pdo_pgsql` for PostgreSQL, or `pdo_sqlite` for SQLite 3. PHP 8.4 or newer is recommended for PostgreSQL; see [PostgreSQL](#postgresql).
Requires PHP 8.4 or newer, with the `pdo_mysql` extension for MySQL and MariaDB, `pdo_pgsql` for PostgreSQL, or `pdo_sqlite` for SQLite 3.

## Quick start

Expand Down Expand Up @@ -330,10 +330,7 @@ With it, `sql()` reads the text by PostgreSQL's rules rather than MySQL's:

`#` isn't a comment in PostgreSQL, so operators like `#>` and `#>>` work. For the jsonb operators, write `??` where you mean a literal `?`: `"data" ?? ?` checks whether the bound key exists. PDO turns `??` back into `?`, and `getComputed()` shows it as `?`.

PDO scans the SQL again before sending it, and its scanner doesn't follow all of PostgreSQL's rules:

- **PHP 8.3:** PDO doesn't recognise dollar-quoted strings, so a `?` or `:name` inside `$$...$$` fails with "mixed named and positional parameters". PHP 8.4 and newer handle them.
- **Nested comments:** PDO ends a comment at the first `*/`. Don't put `?`, `:name` or quotes in the outer comment after a nested one closes.
PDO scans the SQL again before sending it, and its scanner doesn't nest comments: it ends a comment at the first `*/`. Don't put `?`, `:name` or quotes in the outer comment after a nested one closes.

The value bindings are the same as for MySQL. PostgreSQL is stricter about types, so add a cast where it can't infer one, such as `?::date`, `?::jsonb` or `?::int` in a select list. `bBoolInt()` binds `0` or `1`, which a PostgreSQL `boolean` column won't accept; use `bBool()` there.

Expand Down Expand Up @@ -365,7 +362,7 @@ With it, `sql()` reads the text by SQLite's rules:

`#` and `$` have no special meaning, and `??` is two placeholders, since SQLite has no `?` operator.

SQLite handles PDO placeholders itself, so none of the PDO limits described under [PostgreSQL](#postgresql) apply. SQLite has no boolean type: `bBool()` stores `1` or `0`. Dates from `bDate()` and `bDateTime()` are stored as text, which SQLite's date functions read. For unsigned integers above 2⁶³−1, see [Unsigned integers](#unsigned-integers).
SQLite handles PDO placeholders itself, so the PDO limit described under [PostgreSQL](#postgresql) doesn't apply. SQLite has no boolean type: `bBool()` stores `1` or `0`. Dates from `bDate()` and `bDateTime()` are stored as text, which SQLite's date functions read. For unsigned integers above 2⁶³−1, see [Unsigned integers](#unsigned-integers).

## Custom bindings

Expand Down Expand Up @@ -406,7 +403,7 @@ $bindings = new Bindings(

## Limitations

- **MySQL, MariaDB, PostgreSQL and SQLite 3.** Other databases may work for simple queries, but aren't tested. See [PostgreSQL](#postgresql) for limits that come from PDO.
- **MySQL, MariaDB, PostgreSQL and SQLite 3.** Other databases may work for simple queries, but aren't tested. See [PostgreSQL](#postgresql) for a limit that comes from PDO.
- **Invalid dates don't throw.** `bDate()` and `bDateTime()` bind `1970-01-01` (`1970-01-01 00:00:00`) for a value that isn't in the expected format, and only accept years 1900–2099. Validate dates first if that matters.
- **`bLike()` doesn't escape wildcards.** A `%` or `_` in the value acts as a wildcard.
- **`getComputed()` is approximate.** It shows string values in quotes without escaping them.
Expand All @@ -430,7 +427,7 @@ docker run -d --rm --name glpdo2-mysql -p 3306:3306 \
MYSQLHOST=127.0.0.1 MYSQLDB=glpdo2 MYSQLUSER=root MYSQLPASS=root composer test
```

[CI](.github/workflows/ci.yml) runs the tests on PHP 8.3–8.5 against MySQL 8.4.
[CI](.github/workflows/ci.yml) runs the tests on PHP 8.4–8.5 against MySQL 8.4, PostgreSQL 17 and SQLite.

## Changelog and license

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require" : {
"php" : ">=8.3"
"php" : ">=8.4"
},
"autoload" : {
"psr-4" : {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions tests/GLPDO2PostgreSQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GeekLab\GLPDO2\Bindings\PostgreSQL\PostgreSQLBindingFactory;
use PDO;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -111,10 +110,6 @@ public function testLiteralsAndCommentsKeepTheirQuestionMarks(): void
$this->assertSame(['a' => 'Why?', 'b' => "it's?", 'c' => 1, 'd' => 7], $row);
}

/**
* Before PHP 8.4, PDO's own scanner doesn't know dollar quoting and reads a "?" in one as a placeholder.
*/
#[RequiresPhp('>= 8.4.0')]
public function testDollarQuotedStringKeepsItsQuestionMarks(): void
{
$row = $this->db->selectRow(
Expand All @@ -124,7 +119,6 @@ public function testDollarQuotedStringKeepsItsQuestionMarks(): void
$this->assertSame(['a' => 'ok? %%', 'b' => "it's? \$\$ ", 'c' => 7], $row);
}

#[RequiresPhp('>= 8.4.0')]
public function testDollarQuotedFunctionBody(): void
{
$this->db->queryUpdate(
Expand Down