From 68e7f8bd78bb8f410e393bac700a357dbb2a3636 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:05:35 +0200 Subject: [PATCH 1/3] [4.x] use PDO::connect to get driver-specific subclass https://www.php.net/manual/en/migration84.new-features.php#migration84.new-features.pdo https://www.php.net/manual/en/pdo.connect.php --- src/Pdo/PdoDriver.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Pdo/PdoDriver.php b/src/Pdo/PdoDriver.php index cfb3d109..71d90e1e 100644 --- a/src/Pdo/PdoDriver.php +++ b/src/Pdo/PdoDriver.php @@ -361,12 +361,21 @@ public function connect() $connectionString = str_replace($replace, $with, $format); try { - $this->connection = new \PDO( - $connectionString, - $this->options['user'], - $this->options['password'], - $this->options['driverOptions'] - ); + if (PHP_VERSION_ID >= 80400) { + $this->connection = \PDO::connect( + $connectionString, + $this->options['user'], + $this->options['password'], + $this->options['driverOptions'] + ); + } else { + $this->connection = new \PDO( + $connectionString, + $this->options['user'], + $this->options['password'], + $this->options['driverOptions'] + ); + } } catch (\PDOException $e) { throw new ConnectionFailureException('Could not connect to PDO: ' . $e->getMessage(), $e->getCode(), $e); } From 11b47f09239e4d03e9c4a30ae8c5da8ca0a1e09b Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 19 Oct 2026 18:10:29 +0200 Subject: [PATCH 2/3] [4.x][PHP8.5] driver specific methods in the PDO class have been deprecated https://www.php.net/manual/en/migration85.deprecated.php#migration85.deprecated.pdo https://www.php.net/manual/en/pdo.sqlitecreatefunction.php --- src/Sqlite/SqliteDriver.php | 51 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Sqlite/SqliteDriver.php b/src/Sqlite/SqliteDriver.php index eac39f70..100b9317 100644 --- a/src/Sqlite/SqliteDriver.php +++ b/src/Sqlite/SqliteDriver.php @@ -79,33 +79,42 @@ public function connect() parent::connect(); - $this->connection->sqliteCreateFunction( - 'ROW_NUMBER', - function ($init = null) { - static $rownum, $partition; + $rownumberfn = function ($init = null) { + static $rownum, $partition; - if ($init !== null) { - $rownum = $init; - $partition = null; + if ($init !== null) { + $rownum = $init; + $partition = null; - return $rownum; - } - - $args = \func_get_args(); - array_shift($args); + return $rownum; + } - $partitionBy = $args ? implode(',', $args) : null; + $args = \func_get_args(); + array_shift($args); - if ($partitionBy === null || $partitionBy === $partition) { - $rownum++; - } else { - $rownum = 1; - $partition = $partitionBy; - } + $partitionBy = $args ? implode(',', $args) : null; - return $rownum; + if ($partitionBy === null || $partitionBy === $partition) { + $rownum++; + } else { + $rownum = 1; + $partition = $partitionBy; } - ); + + return $rownum; + }; + + if ($this->connection instanceof \Pdo\Sqlite) { + $this->connection->createFunction( + 'ROW_NUMBER', + $rownumberfn + ); + } else { + $this->connection->sqliteCreateFunction( + 'ROW_NUMBER', + $rownumberfn + ); + } } /** From 4c546d31691b8e0aeaf45ba8259374e3fa567a01 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 19 Oct 2026 19:05:39 +0200 Subject: [PATCH 3/3] add test --- Tests/Sqlite/SqliteDriverTest.php | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Tests/Sqlite/SqliteDriverTest.php b/Tests/Sqlite/SqliteDriverTest.php index 927156e0..c9717294 100644 --- a/Tests/Sqlite/SqliteDriverTest.php +++ b/Tests/Sqlite/SqliteDriverTest.php @@ -630,4 +630,45 @@ public function testQuoteAndDecodeBinary() $this->assertEquals($expected, $result); } + + #[TestDox('The custom ROW_NUMBER function correctly numbers rows')] + public function testRowNumberCustomFunction() + { + $this->loadExampleData(); + + static::$connection->setQuery('SELECT ROW_NUMBER(0)')->execute(); + + $query = static::$connection->createQuery() + ->select('ROW_NUMBER() AS row_num, title') + ->from('#__dbtest'); + + $results = static::$connection->setQuery($query)->loadObjectList(); + + $this->assertCount(4, $results); + $this->assertEquals(1, $results[0]->row_num); + $this->assertEquals(2, $results[1]->row_num); + $this->assertEquals(3, $results[2]->row_num); + $this->assertEquals(4, $results[3]->row_num); + + $query = static::$connection->createQuery() + ->update('#__dbtest') + ->set('start_date = ' . static::$connection->quote('2019-10-19 00:00:00')) + ->where('id = 4'); + + static::$connection->setQuery($query)->execute(); + + static::$connection->setQuery('SELECT ROW_NUMBER(0)')->execute(); + + $query = static::$connection->createQuery() + ->select('ROW_NUMBER(NULL, start_date) AS row_num, title') + ->from('#__dbtest'); + + $results = static::$connection->setQuery($query)->loadObjectList(); + + $this->assertCount(4, $results); + $this->assertEquals(1, $results[0]->row_num); + $this->assertEquals(2, $results[1]->row_num); + $this->assertEquals(3, $results[2]->row_num); + $this->assertEquals(1, $results[3]->row_num); + } }