From 1c157c90116bb791f83e47f457c397e723268f9a Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:50:55 +0100 Subject: [PATCH 1/8] [4.x] add createQuery to DatabaseInterface --- README.md | 2 +- src/DatabaseDriver.php | 2 +- src/DatabaseInterface.php | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ebc552d..84143f08 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ The `Database\DatabaseIterator` class allows iteration over database results ```php $db = DatabaseDriver::getInstance($options); $iterator = $db->setQuery( - $db->getQuery(true)->select('*')->from('#__content') + $db->createQuery()->select('*')->from('#__content') )->getIterator(); foreach ($iterator as $row) diff --git a/src/DatabaseDriver.php b/src/DatabaseDriver.php index 25b25677..9bed4ce5 100644 --- a/src/DatabaseDriver.php +++ b/src/DatabaseDriver.php @@ -1748,7 +1748,7 @@ public function setQuery($query, $offset = 0, $limit = 0) if (\is_string($query)) { // Allows taking advantage of bound variables in a direct query: - $query = $this->getQuery(true)->setQuery($query); + $query = $this->createQuery()->setQuery($query); } elseif (!($query instanceof QueryInterface)) { throw new \InvalidArgumentException( sprintf( diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 508b9b95..3a8d8815 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -48,6 +48,15 @@ public function connected(); */ public function createDatabase($options, $utf = true); + /** + * Create a new DatabaseQuery object. + * + * @return QueryInterface + * + * @since 4.0.0 + */ + public function createQuery(): QueryInterface; + /** * Replace special placeholder representing binary field with the original string. * From 03f6cd66c88dad93ed41cca4cc608c4fa6140b41 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:51:31 +0100 Subject: [PATCH 2/8] extend getQuery($new) to 5.0 --- src/DatabaseDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DatabaseDriver.php b/src/DatabaseDriver.php index 9bed4ce5..f42db819 100644 --- a/src/DatabaseDriver.php +++ b/src/DatabaseDriver.php @@ -979,7 +979,7 @@ public function getImporter() * Get the current query object or a new DatabaseQuery object. * * @param boolean $new False to return the current query object, True to return a new DatabaseQuery object. - * The $new parameter is deprecated in 2.2 and will be removed in 4.0, use createQuery() instead. + * The $new parameter is deprecated in 2.2 and will be removed in 5.0, use createQuery() instead. * * @return DatabaseQuery * @@ -991,7 +991,7 @@ public function getQuery($new = false) trigger_deprecation( 'joomla/database', '2.2.0', - 'The parameter $new is deprecated and will be removed in 4.0, use %s::createQuery() instead.', + 'The parameter $new is deprecated and will be removed in 5.0, use %s::createQuery() instead.', self::class ); From 3c31a3fce9f6a99b800a985ae188980ae1b27f2f Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:57:01 +0100 Subject: [PATCH 3/8] Revert "Revert usage of createQuery till interface has been updated" This reverts commit aca10d7b63ba989c63e2f7b62047d2de46057fca. --- src/DatabaseExporter.php | 2 +- src/Pgsql/PgsqlExporter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DatabaseExporter.php b/src/DatabaseExporter.php index fd26d110..dffedf18 100644 --- a/src/DatabaseExporter.php +++ b/src/DatabaseExporter.php @@ -269,7 +269,7 @@ protected function buildXmlData() } $this->db->setQuery( - $this->db->getQuery(true) + $this->db->createQuery() ->select($this->db->quoteName(array_keys($fields))) ->from($this->db->quoteName($table)) ); diff --git a/src/Pgsql/PgsqlExporter.php b/src/Pgsql/PgsqlExporter.php index 08d7d2a3..82d94e0d 100644 --- a/src/Pgsql/PgsqlExporter.php +++ b/src/Pgsql/PgsqlExporter.php @@ -126,7 +126,7 @@ protected function buildXmlData() } } - $query = $this->db->getQuery(true); + $query = $this->db->createQuery(); $query->select($query->quoteName(array_keys($fields))) ->from($query->quoteName($table)); $this->db->setQuery($query); From bc0a51fc0ad80856e8b7f5ff6f4dd88d6cf0d0bd Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 15 Mar 2025 14:58:23 +0100 Subject: [PATCH 4/8] update tests --- Tests/Mysql/MysqlPreparedStatementTest.php | 4 ++-- Tests/Pgsql/PgsqlPreparedStatementTest.php | 4 ++-- Tests/Sqlite/SqlitePreparedStatementTest.php | 4 ++-- Tests/Sqlsrv/SqlsrvPreparedStatementTest.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/Mysql/MysqlPreparedStatementTest.php b/Tests/Mysql/MysqlPreparedStatementTest.php index 6e177f90..f450db22 100644 --- a/Tests/Mysql/MysqlPreparedStatementTest.php +++ b/Tests/Mysql/MysqlPreparedStatementTest.php @@ -72,7 +72,7 @@ protected function tearDown(): void public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ @@ -93,7 +93,7 @@ public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; $dummyValue2 = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ diff --git a/Tests/Pgsql/PgsqlPreparedStatementTest.php b/Tests/Pgsql/PgsqlPreparedStatementTest.php index 17dd43e9..41b4fe18 100644 --- a/Tests/Pgsql/PgsqlPreparedStatementTest.php +++ b/Tests/Pgsql/PgsqlPreparedStatementTest.php @@ -75,7 +75,7 @@ protected function tearDown(): void public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ @@ -96,7 +96,7 @@ public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; $dummyValue2 = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ diff --git a/Tests/Sqlite/SqlitePreparedStatementTest.php b/Tests/Sqlite/SqlitePreparedStatementTest.php index e3ffd2a8..3ddb258c 100644 --- a/Tests/Sqlite/SqlitePreparedStatementTest.php +++ b/Tests/Sqlite/SqlitePreparedStatementTest.php @@ -82,7 +82,7 @@ function (string $table): bool { public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ @@ -103,7 +103,7 @@ public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; $dummyValue2 = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ diff --git a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php index 8625fdf7..f21e4b1f 100644 --- a/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php +++ b/Tests/Sqlsrv/SqlsrvPreparedStatementTest.php @@ -133,7 +133,7 @@ public function testPrepareParameterKeyMappingWithSingleKey() public function testPreparedStatementWithDuplicateKey() { $dummyValue = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ @@ -154,7 +154,7 @@ public function testPreparedStatementWithSingleKey() { $dummyValue = 'test'; $dummyValue2 = 'test'; - $query = static::$connection->getQuery(true); + $query = static::$connection->createQuery(); $query->select('*') ->from($query->quoteName('dbtest')) ->where([ From 7d947a8bd6783e5609798e30032499afcaa1073c Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 15 Mar 2025 15:14:26 +0100 Subject: [PATCH 5/8] fix test mock --- Tests/Mysql/MysqlExporterTest.php | 2 +- Tests/Mysql/MysqlImporterTest.php | 2 +- Tests/Mysqli/MysqliExporterTest.php | 2 +- Tests/Mysqli/MysqliImporterTest.php | 2 +- Tests/Pgsql/PgsqlExporterTest.php | 2 +- Tests/Pgsql/PgsqlImporterTest.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Mysql/MysqlExporterTest.php b/Tests/Mysql/MysqlExporterTest.php index 01484de0..f44d075c 100644 --- a/Tests/Mysql/MysqlExporterTest.php +++ b/Tests/Mysql/MysqlExporterTest.php @@ -43,7 +43,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new MysqlQuery($this->db); }); diff --git a/Tests/Mysql/MysqlImporterTest.php b/Tests/Mysql/MysqlImporterTest.php index 1b6cdf58..d9484a30 100644 --- a/Tests/Mysql/MysqlImporterTest.php +++ b/Tests/Mysql/MysqlImporterTest.php @@ -69,7 +69,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new MysqlQuery($this->db); }); diff --git a/Tests/Mysqli/MysqliExporterTest.php b/Tests/Mysqli/MysqliExporterTest.php index 4e96342a..429b41c8 100644 --- a/Tests/Mysqli/MysqliExporterTest.php +++ b/Tests/Mysqli/MysqliExporterTest.php @@ -43,7 +43,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new MysqliQuery($this->db); }); diff --git a/Tests/Mysqli/MysqliImporterTest.php b/Tests/Mysqli/MysqliImporterTest.php index a1763882..b5fb6c1d 100644 --- a/Tests/Mysqli/MysqliImporterTest.php +++ b/Tests/Mysqli/MysqliImporterTest.php @@ -69,7 +69,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new MysqliQuery($this->db); }); diff --git a/Tests/Pgsql/PgsqlExporterTest.php b/Tests/Pgsql/PgsqlExporterTest.php index 7d92d52c..ad83cc38 100644 --- a/Tests/Pgsql/PgsqlExporterTest.php +++ b/Tests/Pgsql/PgsqlExporterTest.php @@ -43,7 +43,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new PgsqlQuery($this->db); }); diff --git a/Tests/Pgsql/PgsqlImporterTest.php b/Tests/Pgsql/PgsqlImporterTest.php index d33a63e1..92750c88 100644 --- a/Tests/Pgsql/PgsqlImporterTest.php +++ b/Tests/Pgsql/PgsqlImporterTest.php @@ -69,7 +69,7 @@ protected function setUp(): void ->willReturn('jos_'); $this->db->expects($this->any()) - ->method('getQuery') + ->method('createQuery') ->willReturnCallback(function () { return new PgsqlQuery($this->db); }); From f05558c5a9ebaf7ea120c54e053047db47d1ca96 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Mon, 19 May 2025 22:49:57 +0200 Subject: [PATCH 6/8] copy doc from class --- src/DatabaseInterface.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 3a8d8815..4a514e92 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -241,9 +241,10 @@ public function getPrefix(); public function getNumRows(); /** - * Get the current query object or a new QueryInterface object. - * - * @param boolean $new False to return the current query object, True to return a new QueryInterface object. + * Get the current query object. (Deprecated: Or a new QueryInterface object). + * + * @param boolean $new False to return the current query object, True to return a new DatabaseQuery object. + * The $new parameter is deprecated in 2.2 and will be removed in 5.0, use createQuery() instead. * * @return QueryInterface * From 9ad4d58cb9b95fdab3d806e997acfdec25f8e3a1 Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 24 May 2025 07:39:13 +0200 Subject: [PATCH 7/8] fix cs --- src/DatabaseInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 4a514e92..9b65b24b 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -242,7 +242,7 @@ public function getNumRows(); /** * Get the current query object. (Deprecated: Or a new QueryInterface object). - * + * * @param boolean $new False to return the current query object, True to return a new DatabaseQuery object. * The $new parameter is deprecated in 2.2 and will be removed in 5.0, use createQuery() instead. * From 12972f1b62e8fbecd57038883c49f98a7c981b4a Mon Sep 17 00:00:00 2001 From: Christian Heel <66922325+heelc29@users.noreply.github.com> Date: Sat, 24 May 2025 07:52:23 +0200 Subject: [PATCH 8/8] doc --- docs/v3-to-v4-update.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/v3-to-v4-update.md b/docs/v3-to-v4-update.md index d70d6a00..1fecf5c9 100644 --- a/docs/v3-to-v4-update.md +++ b/docs/v3-to-v4-update.md @@ -17,3 +17,8 @@ The following are the minimum supported database versions: ### Removed quoteNameStr The deprecated method `quoteNameStr` has been removed. Use `quoteNameString` instead. + +### DatabaseInterface: `createQuery` method + +`DatabaseInterface` adds a `createQuery` method for creating query objects. Use `createQuery()` instead of `getQuery(true)`. +If you have a custom query class update your adapter's `createQuery()` method to return your custom query class.