Skip to content

Commit

Permalink
Merge tag '2.11.1' into oracle122
Browse files Browse the repository at this point in the history
Release [2.11.1](https://github.com/doctrine/dbal/milestone/80)

2.11.1
======

- Total issues resolved: **2**
- Total pull requests resolved: **8**
- Total contributors: **6**

Documentation
-------------

 - [4299: Link to contributing guide](doctrine#4299) thanks to @greg0ire

SQLite,Test Suite,pdo_sqlite
----------------------------

 - [4297: Fix ExceptionTest::testConnectionExceptionSqLite() on macOS](doctrine#4297) thanks to @morozov

 - [4296: Increase indent in definition lists](doctrine#4296) thanks to @greg0ire

Deprecation,Prepared Statements
-------------------------------

 - [4291: Deprecate Abstraction\Result](doctrine#4291) thanks to @morozov

BC Fix,Quoting
--------------

 - [4287: Restore PDOStatement::quote() for backward compatibility](doctrine#4287) thanks to @morozov and @Shahelm

BC Fix,Query
------------

 - [4286: Fix BC break: QueryBuilder::andWhere() etc. should ignore empty strings](doctrine#4286) thanks to @BenMorel and @infabo

Bug,Documentation,Prepared Statements
-------------------------------------

 - [4285: Fix phpdoc on deprecated functions](doctrine#4285) thanks to @qdequippe

Bug,PDO,Prepared Statements
---------------------------

 - [4173: Fix Third parameter not allowed for PDO::FETCH&doctrine#95;COLUMN](doctrine#4173) thanks to @BenMorel

# gpg: Signature made Sun Sep 27 06:35:40 2020
# gpg:                using DSA key 1BEDEE0A820BC30D858F9F0C2C3A645671828132
# gpg: Can't check signature: No public key
  • Loading branch information
rgrellmann committed Mar 7, 2021
2 parents 227efd4 + 6e6903c commit a5d5d66
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Doctrine has [general contributing guidelines][contributor workflow], make
sure you follow them.

[contributor workflow]: https://www.doctrine-project.org/contribute/index.html
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 2.11

## Deprecated `Abstraction\Result`

The usage of the `Doctrine\DBAL\Abstraction\Result` interface is deprecated. In DBAL 3.0, the statement result at the wrapper level will be represented by the `Doctrine\DBAL\Result` class.

## Deprecated the functionality of dropping client connections when dropping a database

The corresponding `getDisallowDatabaseConnectionsSQL()` and `getCloseActiveDatabaseConnectionsSQL` methods
Expand Down
6 changes: 3 additions & 3 deletions docs/en/explanation/implicit-indexes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ with names such as ``IDX_885DBAFAA76ED395``? In this document, we will
distinguish three types of indexes:

user-defined indexes
indexes you did ask for
indexes you did ask for

DBAL-defined indexes
indexes you did not ask for, created on your behalf by the DBAL
indexes you did not ask for, created on your behalf by the DBAL

RDBMS-defined indexes
indexes you did not ask for, created on your behalf by the RDBMS
indexes you did not ask for, created on your behalf by the RDBMS

RDBMS-defined indexes can be created by some database platforms when you
create a foreign key: they will create an index on the referencing
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Abstraction/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
/**
* Abstraction-level result statement execution result. Provides additional methods on top
* of the driver-level interface.
*
* @deprecated
*/
interface Result extends DriverResult
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function setFetchMode($fetchMode)
* Prepares and executes an SQL query and returns the first row of the result
* as an associative array.
*
* @deprecated Use fetchAllAssociative()
* @deprecated Use fetchAssociative()
*
* @param string $sql The query SQL
* @param mixed[] $params The query parameters
Expand All @@ -560,7 +560,7 @@ public function fetchAssoc($sql, array $params = [], array $types = [])
* Prepares and executes an SQL query and returns the first row of the result
* as a numerically indexed array.
*
* @deprecated Use fetchAllNumeric()
* @deprecated Use fetchNumeric()
*
* @param string $sql The query SQL
* @param mixed[] $params The query parameters
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\PDO\Statement;
use Doctrine\DBAL\ParameterType;
use PDO;
use PDOException;
use PDOStatement;
Expand Down Expand Up @@ -101,6 +102,14 @@ public function query()
}
}

/**
* {@inheritdoc}
*/
public function quote($value, $type = ParameterType::STRING)
{
return parent::quote($value, $type);
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Query\Expression\CompositeExpression;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;

use function array_filter;
use function array_key_exists;
use function array_keys;
use function array_unshift;
Expand Down Expand Up @@ -829,6 +830,7 @@ public function where($predicates)
public function andWhere($where)
{
$args = func_get_args();
$args = array_filter($args); // https://github.com/doctrine/dbal/issues/4282
$where = $this->getQueryPart('where');

if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_AND) {
Expand Down Expand Up @@ -862,6 +864,7 @@ public function andWhere($where)
public function orWhere($where)
{
$args = func_get_args();
$args = array_filter($args); // https://github.com/doctrine/dbal/issues/4282
$where = $this->getQueryPart('where');

if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_OR) {
Expand Down Expand Up @@ -1010,6 +1013,7 @@ public function having($having)
public function andHaving($having)
{
$args = func_get_args();
$args = array_filter($args); // https://github.com/doctrine/dbal/issues/4282
$having = $this->getQueryPart('having');

if ($having instanceof CompositeExpression && $having->getType() === CompositeExpression::TYPE_AND) {
Expand All @@ -1033,6 +1037,7 @@ public function andHaving($having)
public function orHaving($having)
{
$args = func_get_args();
$args = array_filter($args); // https://github.com/doctrine/dbal/issues/4282
$having = $this->getQueryPart('having');

if ($having instanceof CompositeExpression && $having->getType() === CompositeExpression::TYPE_OR) {
Expand Down
10 changes: 9 additions & 1 deletion lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
if ($ctorArgs !== null) {
return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
}

if ($fetchArgument !== null) {
return $this->stmt->fetchAll($fetchMode, $fetchArgument);
}

return $this->stmt->fetchAll($fetchMode);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Version
/**
* Current Doctrine Version.
*/
public const VERSION = '2.11.0';
public const VERSION = '2.11.1';

/**
* Compares a Doctrine version with the current one.
Expand Down
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<exclude-pattern>lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php</exclude-pattern>
</rule>

<!-- The override opts out the caller from the strict mode for backward compatibility -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod.Found">
<exclude-pattern>lib/Doctrine/DBAL/Driver/PDOConnection.php</exclude-pattern>
</rule>

<!-- See https://github.com/slevomat/coding-standard/issues/770 -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<exclude-pattern>lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php</exclude-pattern>
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\DBAL\Functional\Driver\PDO;

use Doctrine\DBAL\Driver\PDO\Connection;
Expand Down Expand Up @@ -100,4 +102,12 @@ public function testThrowsWrappedExceptionOnQuery(): void

$this->driverConnection->query('foo');
}

/**
* This test ensures backward compatibility with DBAL 2.x and should be removed in 3.0.
*/
public function testQuoteInteger(): void
{
self::assertSame("'1'", $this->connection->getWrappedConnection()->quote(1));
}
}
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use function version_compare;

use const PHP_OS;
use const PHP_OS_FAMILY;

class ExceptionTest extends DbalFunctionalTestCase
{
Expand Down Expand Up @@ -303,7 +304,7 @@ public function testConnectionExceptionSqLite(): void
}

// mode 0 is considered read-only on Windows
$mode = PHP_OS === 'Linux' ? 0444 : 0000;
$mode = PHP_OS_FAMILY === 'Windows' ? 0000 : 0444;

$filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_' . $mode . '.db');

Expand Down
70 changes: 70 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ExternalPDOInstanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as PDOSqliteDriver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\TestUtil;
use PDO;

class ExternalPDOInstanceTest extends DbalTestCase
{
/** @var Connection */
protected $connection;

protected function setUp(): void
{
if (! TestUtil::getConnection()->getDriver() instanceof PDOSqliteDriver) {
$this->markTestSkipped('External PDO instance tests are only run on PDO SQLite for now');
}

$pdo = new PDO('sqlite::memory:');

$this->connection = new Connection(['pdo' => $pdo], new PDOSqliteDriver());

$table = new Table('stmt_fetch_all');
$table->addColumn('a', 'integer');
$table->addColumn('b', 'integer');

$this->connection->getSchemaManager()->createTable($table);

$this->connection->insert('stmt_fetch_all', [
'a' => 1,
'b' => 2,
]);
}

public function testFetchAllWithOneArgument(): void
{
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all');
$stmt->execute();

self::assertEquals([[1, 2]], $stmt->fetchAll(FetchMode::NUMERIC));
}

public function testFetchAllWithTwoArguments(): void
{
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all');
$stmt->execute();

self::assertEquals([2], $stmt->fetchAll(FetchMode::COLUMN, 1));
}

public function testFetchAllWithThreeArguments(): void
{
$stmt = $this->connection->prepare('SELECT a, b FROM stmt_fetch_all');
$stmt->execute();

[$obj] = $stmt->fetchAll(FetchMode::CUSTOM_OBJECT, StatementTestModel::class, ['foo', 'bar']);

$this->assertInstanceOf(StatementTestModel::class, $obj);

self::assertEquals(1, $obj->a);
self::assertEquals(2, $obj->b);
self::assertEquals('foo', $obj->x);
self::assertEquals('bar', $obj->y);
}
}
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/StatementTestModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Doctrine\Tests\DBAL\Functional;

class StatementTestModel
{
public function __construct(string $x, string $y)
{
$this->x = $x;
$this->y = $y;
}

/** @var int */
public $a;

/** @var int */
public $b;

/** @var string */
public $x;

/** @var string */
public $y;
}
100 changes: 100 additions & 0 deletions tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,104 @@ public function testJoinWithNonUniqueAliasThrowsException(): void

$qb->getSQL();
}

public function testAndWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo');

$qb->andWhere('', 'a = b');

self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
}

public function testAndWhereEmptyStringStartingWithNonEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->where('a = b');

$qb->andWhere('', 'c = d');

self::assertSame('SELECT id FROM foo WHERE (a = b) AND (c = d)', $qb->getSQL());
}

public function testOrWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo');

$qb->orWhere('', 'a = b');

self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
}

public function testOrWhereEmptyStringStartingWithNonEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->where('a = b');

$qb->orWhere('', 'c = d');

self::assertSame('SELECT id FROM foo WHERE (a = b) OR (c = d)', $qb->getSQL());
}

public function testAndHavingEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo');

$qb->andHaving('', 'a = b');

self::assertSame('SELECT id FROM foo HAVING a = b', $qb->getSQL());
}

public function testAndHavingEmptyStringStartingWithNonEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->having('a = b');

$qb->andHaving('', 'c = d');

self::assertSame('SELECT id FROM foo HAVING (a = b) AND (c = d)', $qb->getSQL());
}

public function testOrHavingEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo');

$qb->orHaving('', 'a = b');

self::assertSame('SELECT id FROM foo HAVING a = b', $qb->getSQL());
}

public function testOrHavingEmptyStringStartingWithNonEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->having('a = b');

$qb->orHaving('', 'c = d');

self::assertSame('SELECT id FROM foo HAVING (a = b) OR (c = d)', $qb->getSQL());
}
}

0 comments on commit a5d5d66

Please sign in to comment.