Skip to content

Commit c801ff3

Browse files
committed
Driver: added getServerVersion()
1 parent 9cf4506 commit c801ff3

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
@@ -107,6 +107,12 @@ public function getEngine(): Drivers\Engine
107107
}
108108

109109

110+
public function getServerVersion(): string
111+
{
112+
return $this->getConnectionDriver()->getServerVersion();
113+
}
114+
115+
110116
public function getReflection(): Reflection
111117
{
112118
return new Reflection($this->getEngine());

src/Database/Drivers/Connection.php

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

3232
function quote(string $string): string;
33+
34+
function getServerVersion(): string;
3335
}

src/Database/Drivers/PDO/Connection.php

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

152152

153+
public function getServerVersion(): string
154+
{
155+
return $this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
156+
}
157+
158+
153159
public function getNativeConnection(): PDO
154160
{
155161
return $this->pdo;

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.driver.phpt

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

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

tests/Database/Reflection.phpt

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

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

0 commit comments

Comments
 (0)