Expressions like SELECT DATABASE() will always return one row

parent e48861ec
...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\MySQL80Platform; ...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\MySqlSchemaManager; use Doctrine\DBAL\Schema\MySqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\DBAL\VersionAwarePlatformDriver;
use function assert;
use function preg_match; use function preg_match;
use function stripos; use function stripos;
use function version_compare; use function version_compare;
...@@ -197,7 +198,15 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -197,7 +198,15 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchColumn(); if (isset($params['dbname'])) {
return $params['dbname'];
}
$database = $conn->query('SELECT DATABASE()')->fetchColumn();
assert($database !== false);
return $database;
} }
/** /**
......
...@@ -13,6 +13,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform; ...@@ -13,6 +13,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\DBAL\VersionAwarePlatformDriver;
use function assert;
use function preg_match; use function preg_match;
use function strpos; use function strpos;
use function version_compare; use function version_compare;
...@@ -119,7 +120,15 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri ...@@ -119,7 +120,15 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn(); if (isset($params['dbname'])) {
return $params['dbname'];
}
$database = $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn();
assert($database !== false);
return $database;
} }
/** /**
......
...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; ...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager; use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\DBAL\VersionAwarePlatformDriver;
use function assert;
use function preg_match; use function preg_match;
use function version_compare; use function version_compare;
...@@ -119,7 +120,15 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr ...@@ -119,7 +120,15 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn(); if (isset($params['dbname'])) {
return $params['dbname'];
}
$database = $conn->query('SELECT DB_NAME()')->fetchColumn();
assert($database !== false);
return $database;
} }
/** /**
......
...@@ -11,6 +11,7 @@ use Doctrine\DBAL\Platforms\SQLServer2012Platform; ...@@ -11,6 +11,7 @@ use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Schema\SQLServerSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\DBAL\VersionAwarePlatformDriver;
use function assert;
use function preg_match; use function preg_match;
use function version_compare; use function version_compare;
...@@ -60,7 +61,15 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr ...@@ -60,7 +61,15 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn(); if (isset($params['dbname'])) {
return $params['dbname'];
}
$database = $conn->query('SELECT DB_NAME()')->fetchColumn();
assert($database !== false);
return $database;
} }
/** /**
......
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