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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mysql/MysqlExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mysql/MysqlImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions Tests/Mysql/MysqlPreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mysqli/MysqliExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mysqli/MysqliImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion Tests/Pgsql/PgsqlExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion Tests/Pgsql/PgsqlImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions Tests/Pgsql/PgsqlPreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down
4 changes: 2 additions & 2 deletions Tests/Sqlite/SqlitePreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down
4 changes: 2 additions & 2 deletions Tests/Sqlsrv/SqlsrvPreparedStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand Down
5 changes: 5 additions & 0 deletions docs/v3-to-v4-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions src/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
);

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/DatabaseExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
Expand Down
14 changes: 12 additions & 2 deletions src/DatabaseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/Pgsql/PgsqlExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down