Skip to content

Commit f8b9fd3

Browse files
committed
Driver: added getServerVersion()
1 parent 07d30be commit f8b9fd3

9 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/Database/Connection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ public function getDatabaseEngine(): Drivers\Engine
120120
}
121121

122122

123+
public function getServerVersion(): string
124+
{
125+
return $this->getConnectionDriver()->getServerVersion();
126+
}
127+
128+
123129
public function getReflection(): Reflection
124130
{
125131
return new Reflection($this->getDatabaseEngine());

src/Database/Drivers/Connection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ function rollBack(): void;
2828
function getInsertId(?string $sequence = null): int|string;
2929

3030
function quote(string $string): string;
31+
32+
function getServerVersion(): string;
3133
}

src/Database/Drivers/PDO/Connection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public function quote(string $string): string
7979
}
8080

8181

82+
public function getServerVersion(): string
83+
{
84+
return $this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
85+
}
86+
87+
8288
public function getNativeConnection(): PDO
8389
{
8490
return $this->pdo;

tests/Database/Engine.reflection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ $expectedColumns = [
9898

9999
switch ($driverName) {
100100
case 'mysql':
101-
$version = $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
101+
$version = $connection->getServerVersion();
102102
if (version_compare($version, '8.0', '>=')) {
103103
$expectedColumns[0]['size'] = null;
104104
}

tests/Database/Explorer/Explorer.limit.sqlsrv.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $connection = $explorer->getConnection();
1616

1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

19-
$version2008 = $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION) < 11;
19+
$version2008 = $connection->getServerVersion() < 11;
2020

2121
Assert::same(
2222
$version2008

tests/Database/Explorer/Selection.page().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require __DIR__ . '/../../bootstrap.php';
1414
$explorer = connectToDB();
1515
$connection = $explorer->getConnection();
1616

17-
if ($driverName === 'sqlsrv' && $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION) < 11) {
17+
if ($driverName === 'sqlsrv' && $connection->getServerVersion() < 11) {
1818
Tester\Environment::skip('Offset is supported since SQL Server 2012');
1919
}
2020

tests/Database/Explorer/bugs/bug1356.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ foreach ($books as $book) {
3131
}
3232

3333
Assert::same(reformat([
34-
'sqlsrv' => $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION) < 11
34+
'sqlsrv' => $connection->getServerVersion() < 11
3535
? 'SELECT TOP 1 * FROM [book] ORDER BY [book].[id]'
3636
: 'SELECT * FROM [book] ORDER BY [book].[id] OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY',
3737
'SELECT * FROM [book] ORDER BY [book].[id] LIMIT 1',

tests/Database/Reflection.columns.mysql.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $connection = connectToDB()->getConnection();
1515
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql');
1616

1717

18-
$version80 = version_compare($connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '8.0', '>=');
18+
$version80 = version_compare($connection->getServerVersion(), '8.0', '>=');
1919
$reflection = $connection->getReflection();
2020
$columns = $reflection->getTable('types')->columns;
2121

tests/Database/Reflection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ $expectedColumns = [
118118

119119
switch ($driverName) {
120120
case 'mysql':
121-
$version = $connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
121+
$version = $connection->getServerVersion();
122122
if (version_compare($version, '8.0', '>=')) {
123123
$expectedColumns['id']['size'] = null;
124124
}

0 commit comments

Comments
 (0)