Skip to content

Commit 689c298

Browse files
committed
Connection: added getDriver() as alias for getSupplementalDriver()
1 parent bfa92a7 commit 689c298

25 files changed

+43
-35
lines changed

src/Database/Connection.php

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public function getPdo(): PDO
106106
}
107107

108108

109+
public function getDriver(): Driver
110+
{
111+
$this->connect();
112+
return $this->driver;
113+
}
114+
115+
116+
/** @deprecated use getDriver() */
109117
public function getSupplementalDriver(): Driver
110118
{
111119
$this->connect();

src/Database/ResultSet.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct(Connection $connection, string $queryString, array $
7070
@$this->pdoStatement->execute(); // @ PHP generates warning when ATTR_ERRMODE = ERRMODE_EXCEPTION bug #73878
7171
}
7272
} catch (\PDOException $e) {
73-
$e = $connection->getSupplementalDriver()->convertException($e);
73+
$e = $connection->getDriver()->convertException($e);
7474
$e->queryString = $queryString;
7575
$e->params = $params;
7676
throw $e;
@@ -130,7 +130,7 @@ public function getTime(): float
130130
public function normalizeRow(array $row): array
131131
{
132132
if ($this->types === null) {
133-
$this->types = $this->connection->getSupplementalDriver()->getColumnTypes($this->pdoStatement);
133+
$this->types = $this->connection->getDriver()->getColumnTypes($this->pdoStatement);
134134
}
135135

136136
foreach ($this->types as $key => $type) {

src/Database/SqlPreprocessor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SqlPreprocessor
7575
public function __construct(Connection $connection)
7676
{
7777
$this->connection = $connection;
78-
$this->driver = $connection->getSupplementalDriver();
78+
$this->driver = $connection->getDriver();
7979
}
8080

8181

src/Database/Structure.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getPrimaryKeySequence(string $table): ?string
100100
$this->needStructure();
101101
$table = $this->resolveFQTableName($table);
102102

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

@@ -183,7 +183,7 @@ protected function needStructure(): void
183183

184184
protected function loadStructure(): array
185185
{
186-
$driver = $this->connection->getSupplementalDriver();
186+
$driver = $this->connection->getDriver();
187187

188188
$structure = [];
189189
$structure['tables'] = $driver->getTables();
@@ -241,7 +241,7 @@ protected function analyzeForeignKeys(array &$structure, string $table): void
241241
{
242242
$lowerTable = strtolower($table);
243243

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

246246
$fksColumnsCounts = [];
247247
foreach ($foreignKeys as $foreignKey) {

src/Database/Table/Selection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public function insert(iterable $data)
827827

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

832832
// Autoincrement primary without sequence
833833
} elseif ($primaryAutoincrementKey) {

src/Database/Table/SqlBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class SqlBuilder
9696
public function __construct(string $tableName, Explorer $explorer)
9797
{
9898
$this->tableName = $tableName;
99-
$this->driver = $explorer->getConnection()->getSupplementalDriver();
99+
$this->driver = $explorer->getConnection()->getDriver();
100100
$this->conventions = $explorer->getConventions();
101101
$this->structure = $explorer->getStructure();
102102
$tableNameParts = explode('.', $tableName);

tests/Database/Connection.lazy.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ test('connect & disconnect', function () {
5353

5454
// first connection
5555
$pdo = $connection->getPdo();
56-
$driver = $connection->getSupplementalDriver();
56+
$driver = $connection->getDriver();
5757
Assert::same(1, $connections);
5858

5959
// still first connection
6060
$connection->connect();
6161
Assert::same($pdo, $connection->getPdo());
62-
Assert::same($driver, $connection->getSupplementalDriver());
62+
Assert::same($driver, $connection->getDriver());
6363
Assert::same(1, $connections);
6464

6565
// second connection
6666
$connection->reconnect();
6767
$pdo2 = $connection->getPdo();
68-
$driver2 = $connection->getSupplementalDriver();
68+
$driver2 = $connection->getDriver();
6969

7070
Assert::notSame($pdo, $pdo2);
7171
Assert::notSame($driver, $driver2);
@@ -74,6 +74,6 @@ test('connect & disconnect', function () {
7474
// third connection
7575
$connection->disconnect();
7676
Assert::notSame($pdo2, $connection->getPdo());
77-
Assert::notSame($driver2, $connection->getSupplementalDriver());
77+
Assert::notSame($driver2, $connection->getDriver());
7878
Assert::same(3, $connections);
7979
});

tests/Database/Drivers/MySqlDriver.applyLimit.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Tester\Assert;
1111
require __DIR__ . '/../connect.inc.php'; // create $connection
1212

1313

14-
$driver = $connection->getSupplementalDriver();
14+
$driver = $connection->getDriver();
1515

1616
$query = 'SELECT 1 FROM t';
1717
$driver->applyLimit($query, 10, 20);

tests/Database/Drivers/MySqlDriver.formatLike.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Tester\Assert;
1111
require __DIR__ . '/../connect.inc.php'; // create $connection
1212

1313

14-
$driver = $connection->getSupplementalDriver();
14+
$driver = $connection->getDriver();
1515

1616
Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
1717
Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());

tests/Database/Drivers/PgSqlDriver.formatLike.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require __DIR__ . '/../connect.inc.php'; // create $connection
1212

1313

1414
$tests = function ($connection) {
15-
$driver = $connection->getSupplementalDriver();
15+
$driver = $connection->getDriver();
1616

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

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

3333
$connection->query('SET standard_conforming_strings TO on');

tests/Database/Drivers/SqliteDriver.formatLike.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Tester\Assert;
1111
require __DIR__ . '/../connect.inc.php'; // create $connection
1212

1313

14-
$driver = $connection->getSupplementalDriver();
14+
$driver = $connection->getDriver();
1515

1616
Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());
1717
Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField());

tests/Database/Drivers/SqlsrvDriver.formatLike.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Tester\Assert;
1111
require __DIR__ . '/../connect.inc.php'; // create $connection
1212

1313

14-
$driver = $connection->getSupplementalDriver();
14+
$driver = $connection->getDriver();
1515

1616
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());
1717
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());

tests/Database/Reflection.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1515
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1616

1717

18-
$driver = $connection->getSupplementalDriver();
18+
$driver = $connection->getDriver();
1919
$tables = $driver->getTables();
2020
$tables = array_filter($tables, function ($t) { return in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true); });
2121
usort($tables, function ($a, $b) { return strcmp($a['name'], $b['name']); });

tests/Database/Reflection.postgre.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Nette\Database\Helpers::loadFromFile($connection, Tester\FileMock::create('
3030
ALTER TABLE "one"."slave" ADD CONSTRAINT "one_slave_fk" FOREIGN KEY ("one_id") REFERENCES "one"."master"("one_id");
3131
ALTER TABLE "two"."slave" ADD CONSTRAINT "two_slave_fk" FOREIGN KEY ("two_id") REFERENCES "two"."master"("two_id");
3232
'));
33-
$driver = $connection->getSupplementalDriver();
33+
$driver = $connection->getDriver();
3434

3535

3636
function filter($columns)

tests/Database/Row.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1313

1414

1515
test('numeric field', function () use ($connection) {
16-
$row = $connection->fetch("SELECT 123 AS {$connection->getSupplementalDriver()->delimite('123')}, NULL as nullcol");
16+
$row = $connection->fetch("SELECT 123 AS {$connection->getDriver()->delimite('123')}, NULL as nullcol");
1717
Assert::same(123, $row->{123});
1818
Assert::same(123, $row->{'123'});
1919
Assert::true(isset($row->{123}));

tests/Database/Structure.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class StructureTestCase extends TestCase
5151
$this->storage = Mockery::mock(Nette\Caching\IStorage::class);
5252

5353
$this->connection->shouldReceive('getDsn')->once()->andReturn('');
54-
$this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver);
54+
$this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver);
5555
$this->driver->shouldReceive('getTables')->once()->andReturn([
5656
['name' => 'authors', 'view' => false],
5757
['name' => 'Books', 'view' => false],
@@ -79,7 +79,7 @@ class StructureTestCase extends TestCase
7979
['name' => 'id', 'primary' => false, 'autoincrement' => false, 'vendor' => []],
8080
['name' => 'title', 'primary' => false, 'autoincrement' => false, 'vendor' => []],
8181
]);
82-
$this->connection->shouldReceive('getSupplementalDriver')->times(4)->andReturn($this->driver);
82+
$this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver);
8383
$this->driver->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn([]);
8484
$this->driver->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn([
8585
['local' => 'author_id', 'table' => 'authors', 'foreign' => 'id', 'name' => 'authors_fk1'],
@@ -136,7 +136,7 @@ class StructureTestCase extends TestCase
136136

137137
public function testGetPrimaryKeySequence()
138138
{
139-
$this->connection->shouldReceive('getSupplementalDriver')->times(4)->andReturn($this->driver);
139+
$this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver);
140140
$this->driver->shouldReceive('isSupported')->with('sequence')->once()->andReturn(false);
141141
$this->driver->shouldReceive('isSupported')->with('sequence')->times(3)->andReturn(true);
142142

tests/Database/Structure.schemas.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class StructureSchemasTestCase extends TestCase
5151
$this->storage = Mockery::mock(Nette\Caching\IStorage::class);
5252

5353
$this->connection->shouldReceive('getDsn')->once()->andReturn('');
54-
$this->connection->shouldReceive('getSupplementalDriver')->once()->andReturn($this->driver);
54+
$this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver);
5555
$this->driver->shouldReceive('getTables')->once()->andReturn([
5656
['name' => 'authors', 'view' => false, 'fullName' => 'authors.authors'],
5757
['name' => 'books', 'view' => false, 'fullName' => 'books.books'],
@@ -65,7 +65,7 @@ class StructureSchemasTestCase extends TestCase
6565
['name' => 'title', 'primary' => false, 'vendor' => []],
6666
]);
6767

68-
$this->connection->shouldReceive('getSupplementalDriver')->times(2)->andReturn($this->driver);
68+
$this->connection->shouldReceive('getDriver')->times(2)->andReturn($this->driver);
6969
$this->driver->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn([]);
7070
$this->driver->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn([
7171
['local' => 'author_id', 'table' => 'authors.authors', 'foreign' => 'id', 'name' => 'authors_authors_fk1'],

tests/Database/Table/SqlBuilder.addAlias().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SqlBuilderMock extends SqlBuilder
2929
}
3030
}
3131

32-
$driver = $connection->getSupplementalDriver();
32+
$driver = $connection->getDriver();
3333

3434

3535
test('test duplicated table names throw exception', function () use ($explorer, $driver) {

tests/Database/Table/SqlBuilder.addWhere().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test('test more ActiveRow as a parameter', function () use ($explorer) {
7575
test('test Selection with parameters as a parameter', function () use ($explorer) {
7676
$sqlBuilder = new SqlBuilder('book', $explorer);
7777
$sqlBuilder->addWhere('id', $explorer->table('book')->having('COUNT(:book_tag.tag_id) >', 1));
78-
$schemaSupported = $explorer->getConnection()->getSupplementalDriver()->isSupported(Driver::SUPPORT_SCHEMA);
78+
$schemaSupported = $explorer->getConnection()->getDriver()->isSupported(Driver::SUPPORT_SCHEMA);
7979
Assert::equal(reformat([
8080
'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]) > ?))',
8181
]), $sqlBuilder->buildSelectQuery());

tests/Database/Table/SqlBuilder.parseJoinConditions().phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SqlBuilderMock extends SqlBuilder
4141
}
4242
}
4343

44-
$driver = $connection->getSupplementalDriver();
44+
$driver = $connection->getDriver();
4545

4646
test('test circular reference', function () use ($explorer) {
4747
$sqlBuilder = new SqlBuilderMock('author', $explorer);

tests/Database/Table/SqlBuilder.parseJoins().phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SqlBuilderMock extends SqlBuilder
3333

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

3838

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

45-
$tables = $connection->getSupplementalDriver()->getTables();
45+
$tables = $connection->getDriver()->getTables();
4646
if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'], true)) {
4747
if ($driver->isSupported(Driver::SUPPORT_SCHEMA)) {
4848
Assert::same(

tests/Database/Table/Table.backjoin.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Tester\Assert;
1313
require __DIR__ . '/../connect.inc.php'; // create $connection
1414

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

1818

1919
test('', function () use ($explorer) {

tests/Database/Table/Table.join-condition.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Tester\Assert;
1313
require __DIR__ . '/../connect.inc.php'; // create $connection
1414

1515
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
16-
$driver = $connection->getSupplementalDriver();
16+
$driver = $connection->getDriver();
1717
test('', function () use ($explorer, $driver) {
1818
$schema = $driver->isSupported(Driver::SUPPORT_SCHEMA)
1919
? '[public].'

tests/Database/Table/Table.join.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Tester\Assert;
1313
require __DIR__ . '/../connect.inc.php'; // create $connection
1414

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

1818

1919
test('', function () use ($explorer) {

tests/Database/Table/bugs/view.bug.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('', function () use ($explorer) {
2020
});
2121

2222
test('', function () use ($connection) {
23-
$driver = $connection->getSupplementalDriver();
23+
$driver = $connection->getDriver();
2424
$columns = $driver->getColumns('books_view');
2525
$columnsNames = array_map(function ($item) {
2626
return $item['name'];

0 commit comments

Comments
 (0)