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/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/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/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); }); 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([ 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. diff --git a/src/DatabaseDriver.php b/src/DatabaseDriver.php index 433d884f..497d9cc0 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 ); @@ -1718,7 +1718,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/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/DatabaseInterface.php b/src/DatabaseInterface.php index 508b9b95..9b65b24b 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. * @@ -232,9 +241,10 @@ public function getPrefix(); public function getNumRows(); /** - * Get the current query object or 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 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 * 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);