Skip to content

Commit

Permalink
Connection: added getDriver() as alias for getSupplementalDriver()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 25, 2020
1 parent e28bf02 commit 5975a28
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 35 deletions.
8 changes: 8 additions & 0 deletions src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public function getPdo(): PDO
}


public function getDriver(): Driver
{
$this->connect();
return $this->driver;
}


/** @deprecated use getDriver() */
public function getSupplementalDriver(): Driver
{
$this->connect();
Expand Down
4 changes: 2 additions & 2 deletions src/Database/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(Connection $connection, string $queryString, array $
@$this->pdoStatement->execute(); // @ PHP generates warning when ATTR_ERRMODE = ERRMODE_EXCEPTION bug #73878
}
} catch (\PDOException $e) {
$e = $connection->getSupplementalDriver()->convertException($e);
$e = $connection->getDriver()->convertException($e);
$e->queryString = $queryString;
$e->params = $params;
throw $e;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function getTime(): float
public function normalizeRow(array $row): array
{
if ($this->types === null) {
$this->types = $this->connection->getSupplementalDriver()->getColumnTypes($this->pdoStatement);
$this->types = $this->connection->getDriver()->getColumnTypes($this->pdoStatement);
}

foreach ($this->types as $key => $type) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SqlPreprocessor
public function __construct(Connection $connection)
{
$this->connection = $connection;
$this->driver = $connection->getSupplementalDriver();
$this->driver = $connection->getDriver();
}


Expand Down
6 changes: 3 additions & 3 deletions src/Database/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getPrimaryKeySequence(string $table): ?string
$this->needStructure();
$table = $this->resolveFQTableName($table);

if (!$this->connection->getSupplementalDriver()->isSupported(Driver::SUPPORT_SEQUENCE)) {
if (!$this->connection->getDriver()->isSupported(Driver::SUPPORT_SEQUENCE)) {
return null;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ protected function needStructure(): void

protected function loadStructure(): array
{
$driver = $this->connection->getSupplementalDriver();
$driver = $this->connection->getDriver();

$structure = [];
$structure['tables'] = $driver->getTables();
Expand Down Expand Up @@ -241,7 +241,7 @@ protected function analyzeForeignKeys(array &$structure, string $table): void
{
$lowerTable = strtolower($table);

$foreignKeys = $this->connection->getSupplementalDriver()->getForeignKeys($table);
$foreignKeys = $this->connection->getDriver()->getForeignKeys($table);

$fksColumnsCounts = [];
foreach ($foreignKeys as $foreignKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ public function insert(iterable $data)

// First check sequence
if (!empty($primarySequenceName) && $primaryAutoincrementKey) {
$primaryKey[$primaryAutoincrementKey] = $this->explorer->getInsertId($this->explorer->getConnection()->getSupplementalDriver()->delimite($primarySequenceName));
$primaryKey[$primaryAutoincrementKey] = $this->explorer->getInsertId($this->explorer->getConnection()->getDriver()->delimite($primarySequenceName));

// Autoincrement primary without sequence
} elseif ($primaryAutoincrementKey) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/SqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SqlBuilder
public function __construct(string $tableName, Explorer $explorer)
{
$this->tableName = $tableName;
$this->driver = $explorer->getConnection()->getSupplementalDriver();
$this->driver = $explorer->getConnection()->getDriver();
$this->conventions = $explorer->getConventions();
$this->structure = $explorer->getStructure();
$tableNameParts = explode('.', $tableName);
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/Connection.lazy.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ test('connect & disconnect', function () {

// first connection
$pdo = $connection->getPdo();
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();
Assert::same(1, $connections);

// still first connection
$connection->connect();
Assert::same($pdo, $connection->getPdo());
Assert::same($driver, $connection->getSupplementalDriver());
Assert::same($driver, $connection->getDriver());
Assert::same(1, $connections);

// second connection
$connection->reconnect();
$pdo2 = $connection->getPdo();
$driver2 = $connection->getSupplementalDriver();
$driver2 = $connection->getDriver();

Assert::notSame($pdo, $pdo2);
Assert::notSame($driver, $driver2);
Expand All @@ -74,6 +74,6 @@ test('connect & disconnect', function () {
// third connection
$connection->disconnect();
Assert::notSame($pdo2, $connection->getPdo());
Assert::notSame($driver2, $connection->getSupplementalDriver());
Assert::notSame($driver2, $connection->getDriver());
Assert::same(3, $connections);
});
2 changes: 1 addition & 1 deletion tests/Database/Drivers/MySqlDriver.applyLimit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection


$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

$query = 'SELECT 1 FROM t';
$driver->applyLimit($query, 10, 20);
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Drivers/MySqlDriver.formatLike.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection


$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Drivers/PgSqlDriver.formatLike.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require __DIR__ . '/../connect.inc.php'; // create $connection


$tests = function ($connection) {
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Assert::true($connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Expand All @@ -27,7 +27,7 @@ $tests = function ($connection) {
Assert::true($connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField());
};

$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();
$connection->query('SET escape_string_warning TO off'); // do not log warnings

$connection->query('SET standard_conforming_strings TO on');
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Drivers/SqliteDriver.formatLike.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection


$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Drivers/SqlsrvDriver.formatLike.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection


$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField());
Assert::same(1, $connection->query("SELECT CASE WHEN 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField());
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Reflection.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");


$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();
$tables = $driver->getTables();
$tables = array_filter($tables, function ($t) { return in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true); });
usort($tables, function ($a, $b) { return strcmp($a['name'], $b['name']); });
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Reflection.postgre.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Nette\Database\Helpers::loadFromFile($connection, Tester\FileMock::create('
ALTER TABLE "one"."slave" ADD CONSTRAINT "one_slave_fk" FOREIGN KEY ("one_id") REFERENCES "one"."master"("one_id");
ALTER TABLE "two"."slave" ADD CONSTRAINT "two_slave_fk" FOREIGN KEY ("two_id") REFERENCES "two"."master"("two_id");
'));
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();


function filter($columns)
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Row.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection


test('numeric field', function () use ($connection) {
$row = $connection->fetch("SELECT 123 AS {$connection->getSupplementalDriver()->delimite('123')}, NULL as nullcol");
$row = $connection->fetch("SELECT 123 AS {$connection->getDriver()->delimite('123')}, NULL as nullcol");
Assert::same(123, $row->{123});
Assert::same(123, $row->{'123'});
Assert::true(isset($row->{123}));
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/Structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StructureTestCase extends TestCase
$this->storage = Mockery::mock(Nette\Caching\IStorage::class);

$this->connection->shouldReceive('getDsn')->once()->andReturn('');
$this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver);
$this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver);
$this->driver->shouldReceive('getTables')->once()->andReturn([
['name' => 'authors', 'view' => false],
['name' => 'Books', 'view' => false],
Expand Down Expand Up @@ -79,7 +79,7 @@ class StructureTestCase extends TestCase
['name' => 'id', 'primary' => false, 'autoincrement' => false, 'vendor' => []],
['name' => 'title', 'primary' => false, 'autoincrement' => false, 'vendor' => []],
]);
$this->connection->shouldReceive('getSupplementalDriver')->times(4)->andReturn($this->driver);
$this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver);
$this->driver->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn([]);
$this->driver->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn([
['local' => 'author_id', 'table' => 'authors', 'foreign' => 'id', 'name' => 'authors_fk1'],
Expand Down Expand Up @@ -136,7 +136,7 @@ class StructureTestCase extends TestCase

public function testGetPrimaryKeySequence()
{
$this->connection->shouldReceive('getSupplementalDriver')->times(4)->andReturn($this->driver);
$this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver);
$this->driver->shouldReceive('isSupported')->with('sequence')->once()->andReturn(false);
$this->driver->shouldReceive('isSupported')->with('sequence')->times(3)->andReturn(true);

Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Structure.schemas.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StructureSchemasTestCase extends TestCase
$this->storage = Mockery::mock(Nette\Caching\IStorage::class);

$this->connection->shouldReceive('getDsn')->once()->andReturn('');
$this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver);
$this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver);
$this->driver->shouldReceive('getTables')->once()->andReturn([
['name' => 'authors', 'view' => false, 'fullName' => 'authors.authors'],
['name' => 'books', 'view' => false, 'fullName' => 'books.books'],
Expand All @@ -65,7 +65,7 @@ class StructureSchemasTestCase extends TestCase
['name' => 'title', 'primary' => false, 'vendor' => []],
]);

$this->connection->shouldReceive('getSupplementalDriver')->times(2)->andReturn($this->driver);
$this->connection->shouldReceive('getDriver')->times(2)->andReturn($this->driver);
$this->driver->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn([]);
$this->driver->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn([
['local' => 'author_id', 'table' => 'authors.authors', 'foreign' => 'id', 'name' => 'authors_authors_fk1'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/SqlBuilder.addAlias().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SqlBuilderMock extends SqlBuilder
}
}

$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();


test('test duplicated table names throw exception', function () use ($explorer, $driver) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/SqlBuilder.addWhere().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('test more ActiveRow as a parameter', function () use ($explorer) {
test('test Selection with parameters as a parameter', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id', $explorer->table('book')->having('COUNT(:book_tag.tag_id) >', 1));
$schemaSupported = $explorer->getConnection()->getSupplementalDriver()->isSupported(Driver::SUPPORT_SCHEMA);
$schemaSupported = $explorer->getConnection()->getDriver()->isSupported(Driver::SUPPORT_SCHEMA);
Assert::equal(reformat([
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book] LEFT JOIN ' . ($schemaSupported ? '[public].[book_tag] ' : '') . '[book_tag] ON [book].[id] = [book_tag].[book_id] HAVING COUNT([book_tag].[tag_id]) > ?))',
]), $sqlBuilder->buildSelectQuery());
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/SqlBuilder.parseJoinConditions().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SqlBuilderMock extends SqlBuilder
}
}

$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();

test('test circular reference', function () use ($explorer) {
$sqlBuilder = new SqlBuilderMock('author', $explorer);
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Table/SqlBuilder.parseJoins().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SqlBuilderMock extends SqlBuilder

$conventions = new DiscoveredConventions($structure);
$sqlBuilder = new SqlBuilderMock('nUsers', $explorer);
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();


$joins = [];
Expand All @@ -42,7 +42,7 @@ $sqlBuilder->parseJoins($joins, $query);
$join = $sqlBuilder->buildQueryJoins($joins);
Assert::same('WHERE priorit.id IS NULL', $query);

$tables = $connection->getSupplementalDriver()->getTables();
$tables = $connection->getDriver()->getTables();
if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'], true)) {
if ($driver->isSupported(Driver::SUPPORT_SCHEMA)) {
Assert::same(
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/Table.backjoin.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection

Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();


test('', function () use ($explorer) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/Table.join-condition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection

Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();
test('', function () use ($explorer, $driver) {
$schema = $driver->isSupported(Driver::SUPPORT_SCHEMA)
? '[public].'
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/Table.join.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Tester\Assert;
require __DIR__ . '/../connect.inc.php'; // create $connection

Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();


test('', function () use ($explorer) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Table/bugs/view.bug.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('', function () use ($explorer) {
});

test('', function () use ($connection) {
$driver = $connection->getSupplementalDriver();
$driver = $connection->getDriver();
$columns = $driver->getColumns('books_view');
$columnsNames = array_map(function ($item) {
return $item['name'];
Expand Down

0 comments on commit 5975a28

Please sign in to comment.