Unverified Commit 514dddd8 authored by Grégoire Paris's avatar Grégoire Paris

Merge remote-tracking branch 'origin/2.10' into 2.10.x

parents 96d10bd5 a0e23739
...@@ -88,20 +88,7 @@ final class DriverManager ...@@ -88,20 +88,7 @@ final class DriverManager
* *
* $params must contain at least one of the following. * $params must contain at least one of the following.
* *
* Either 'driver' with one of the following values: * Either 'driver' with one of the array keys of {@link $_driverMap},
*
* pdo_mysql
* pdo_sqlite
* pdo_pgsql
* pdo_oci (unstable)
* pdo_sqlsrv
* pdo_sqlsrv
* mysqli
* sqlanywhere
* sqlsrv
* ibm_db2 (unstable)
* drizzle_pdo_mysql
*
* OR 'driverClass' that contains the full class name (with namespace) of the * OR 'driverClass' that contains the full class name (with namespace) of the
* driver class to instantiate. * driver class to instantiate.
* *
......
...@@ -12,7 +12,7 @@ class DebugStack implements SQLLogger ...@@ -12,7 +12,7 @@ class DebugStack implements SQLLogger
/** /**
* Executed SQL queries. * Executed SQL queries.
* *
* @var mixed[][] * @var array<int, array<string, mixed>>
*/ */
public $queries = []; public $queries = [];
......
...@@ -367,7 +367,7 @@ SQL ...@@ -367,7 +367,7 @@ SQL
[$schema, $table] = explode('.', $table); [$schema, $table] = explode('.', $table);
$schema = $this->quoteStringLiteral($schema); $schema = $this->quoteStringLiteral($schema);
} else { } else {
$schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))"; $schema = 'ANY(current_schemas(false))';
} }
$table = new Identifier($table); $table = new Identifier($table);
......
...@@ -118,9 +118,9 @@ class QueryBuilder ...@@ -118,9 +118,9 @@ class QueryBuilder
private $firstResult = null; private $firstResult = null;
/** /**
* The maximum number of results to retrieve. * The maximum number of results to retrieve or NULL to retrieve all results.
* *
* @var int * @var int|null
*/ */
private $maxResults = null; private $maxResults = null;
...@@ -367,7 +367,6 @@ class QueryBuilder ...@@ -367,7 +367,6 @@ class QueryBuilder
/** /**
* Gets the position of the first result the query object was set to retrieve (the "offset"). * Gets the position of the first result the query object was set to retrieve (the "offset").
* Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder.
* *
* @return int The position of the first result. * @return int The position of the first result.
*/ */
...@@ -379,7 +378,7 @@ class QueryBuilder ...@@ -379,7 +378,7 @@ class QueryBuilder
/** /**
* Sets the maximum number of results to retrieve (the "limit"). * Sets the maximum number of results to retrieve (the "limit").
* *
* @param int $maxResults The maximum number of results to retrieve. * @param int|null $maxResults The maximum number of results to retrieve or NULL to retrieve all results.
* *
* @return $this This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
...@@ -393,7 +392,7 @@ class QueryBuilder ...@@ -393,7 +392,7 @@ class QueryBuilder
/** /**
* Gets the maximum number of results the query object was set to retrieve (the "limit"). * Gets the maximum number of results the query object was set to retrieve (the "limit").
* Returns NULL if {@link setMaxResults} was not applied to this query builder. * Returns NULL if all results will be returned.
* *
* @return int The maximum number of results. * @return int The maximum number of results.
*/ */
...@@ -1328,8 +1327,10 @@ class QueryBuilder ...@@ -1328,8 +1327,10 @@ class QueryBuilder
throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases)); throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases));
} }
$sql .= ' ' . strtoupper($join['joinType']) $sql .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'] . ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'];
. ' ON ' . ((string) $join['joinCondition']); if ($join['joinCondition'] !== null) {
$sql .= ' ON ' . $join['joinCondition'];
}
$knownAliases[$join['joinAlias']] = true; $knownAliases[$join['joinAlias']] = true;
} }
......
...@@ -31,9 +31,9 @@ class SQLParserUtils ...@@ -31,9 +31,9 @@ class SQLParserUtils
public const POSITIONAL_TOKEN = '\?'; public const POSITIONAL_TOKEN = '\?';
public const NAMED_TOKEN = '(?<!:):[a-zA-Z_][a-zA-Z0-9_]*'; public const NAMED_TOKEN = '(?<!:):[a-zA-Z_][a-zA-Z0-9_]*';
// Quote characters within string literals can be preceded by a backslash. // Quote characters within string literals can be preceded by a backslash.
public const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')"; public const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')";
public const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")'; public const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")';
public const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)'; public const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)';
/**#@-*/ /**#@-*/
private const ESCAPED_BRACKET_QUOTED_TEXT = '(?<!\b(?i:ARRAY))\[(?:[^\]])*\]'; private const ESCAPED_BRACKET_QUOTED_TEXT = '(?<!\b(?i:ARRAY))\[(?:[^\]])*\]';
......
...@@ -233,7 +233,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint ...@@ -233,7 +233,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
$position = strrpos($name, '.'); $position = strrpos($name, '.');
if ($position !== false) { if ($position !== false) {
$name = substr($name, $position); $name = substr($name, $position + 1);
} }
return strtolower($name); return strtolower($name);
......
...@@ -335,6 +335,18 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -335,6 +335,18 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertFalse($comparator->diffTable($offlineTable, $onlineTable)); self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
} }
public function testListTableDetailsWhenCurrentSchemaNameQuoted() : void
{
$this->connection->exec('CREATE SCHEMA "001_test"');
$this->connection->exec('SET search_path TO "001_test"');
try {
$this->testListQuotedTable();
} finally {
$this->connection->close();
}
}
public function testListTablesExcludesViews() : void public function testListTablesExcludesViews() : void
{ {
$this->createTestTable('list_tables_excludes_views'); $this->createTestTable('list_tables_excludes_views');
......
...@@ -92,11 +92,22 @@ class QueryBuilderTest extends DbalTestCase ...@@ -92,11 +92,22 @@ class QueryBuilderTest extends DbalTestCase
$qb->select('u.*', 'p.*') $qb->select('u.*', 'p.*')
->from('users', 'u') ->from('users', 'u')
->Join('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id')); ->join('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb); self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb);
} }
public function testSelectWithJoinNoCondition() : void
{
$qb = new QueryBuilder($this->conn);
$qb->select('u.*', 'p.*')
->from('users', 'u')
->join('u', 'phones', 'p');
self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p', (string) $qb);
}
public function testSelectWithInnerJoin() : void public function testSelectWithInnerJoin() : void
{ {
$qb = new QueryBuilder($this->conn); $qb = new QueryBuilder($this->conn);
...@@ -569,13 +580,27 @@ class QueryBuilderTest extends DbalTestCase ...@@ -569,13 +580,27 @@ class QueryBuilderTest extends DbalTestCase
self::assertEquals($sql1, $qb->getSQL()); self::assertEquals($sql1, $qb->getSQL());
} }
public function testSetMaxResults() : void /**
* @dataProvider maxResultsProvider
*/
public function testSetMaxResults(?int $maxResults) : void
{ {
$qb = new QueryBuilder($this->conn); $qb = new QueryBuilder($this->conn);
$qb->setMaxResults(10); $qb->setMaxResults($maxResults);
self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEquals(10, $qb->getMaxResults()); self::assertEquals($maxResults, $qb->getMaxResults());
}
/**
* @return mixed[][]
*/
public static function maxResultsProvider() : iterable
{
return [
'non-null' => [10],
'null' => [null],
];
} }
public function testSetFirstResult() : void public function testSetFirstResult() : void
......
...@@ -89,7 +89,7 @@ SQLDATA ...@@ -89,7 +89,7 @@ SQLDATA
['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']],
['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']],
['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']],
["SELECT * FROM Foo WHERE (foo.bar LIKE :condition_0 ESCAPE '\') AND (foo.baz = :condition_1) AND (foo.bak LIKE :condition_2 ESCAPE '\')", false, [38 => 'condition_0', 78 => 'condition_1', 110 => 'condition_2']],
]; ];
} }
......
...@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Schema; ...@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ForeignKeyConstraintTest extends TestCase class ForeignKeyConstraintTest extends TestCase
...@@ -56,4 +57,30 @@ class ForeignKeyConstraintTest extends TestCase ...@@ -56,4 +57,30 @@ class ForeignKeyConstraintTest extends TestCase
[['FOO'], true], [['FOO'], true],
]; ];
} }
/**
* @param string|Table $foreignTableName
*
* @group DBAL-1062
* @dataProvider getUnqualifiedForeignTableNameData
*/
public function testGetUnqualifiedForeignTableName($foreignTableName, string $expectedUnqualifiedTableName) : void
{
$foreignKey = new ForeignKeyConstraint(['foo', 'bar'], $foreignTableName, ['fk_foo', 'fk_bar']);
self::assertSame($expectedUnqualifiedTableName, $foreignKey->getUnqualifiedForeignTableName());
}
/**
* @return mixed[][]
*/
public static function getUnqualifiedForeignTableNameData() : iterable
{
return [
['schema.foreign_table', 'foreign_table'],
['foreign_table', 'foreign_table'],
[new Table('schema.foreign_table'), 'foreign_table'],
[new Table('foreign_table'), 'foreign_table'],
];
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment