function Tasks::checkStandardConformingStrings
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php \Drupal\Core\Database\Driver\pgsql\Install\Tasks::checkStandardConformingStrings()
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks::checkStandardConformingStrings()
- 11.x core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks::checkStandardConformingStrings()
Ensures standard_conforming_strings setting is 'on'.
When standard_conforming_strings setting is 'on' string literals ('...') treat backslashes literally, as specified in the SQL standard. This allows Drupal to convert between bytea, text and varchar columns.
File
-
core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Install/ Tasks.php, line 196
Class
- Tasks
- Specifies installation tasks for PostgreSQL databases.
Namespace
Drupal\pgsql\Driver\Database\pgsql\InstallCode
public function checkStandardConformingStrings() {
$database_connection = Database::getConnection();
if (!$this->checkStandardConformingStringsSuccess()) {
// First try to alter the database. If it fails, raise an error telling
// the user to do it themselves.
$connection_options = $database_connection->getConnectionOptions();
// It is safe to include the database name directly here, because this
// code is only called when a connection to the database is already
// established, thus the database name is guaranteed to be a correct
// value.
$query = "ALTER DATABASE \"" . $connection_options['database'] . "\" SET standard_conforming_strings = 'on';";
try {
$database_connection->query($query);
} catch (\Exception $e) {
// Ignore possible errors when the user doesn't have the necessary
// privileges to ALTER the database.
}
// Close the database connection so that the configuration parameter
// is applied to the current connection.
Database::closeConnection();
// Recheck, if it fails, finally just rely on the end user to do the
// right thing.
if (!$this->checkStandardConformingStringsSuccess()) {
$replacements = [
'%setting' => 'standard_conforming_strings',
'%current_value' => 'off',
'%needed_value' => 'on',
'@query' => $query,
];
$this->fail(t("The %setting setting is currently set to '%current_value', but needs to be '%needed_value'. Change this by running the following query: <code>@query</code>", $replacements));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.