diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 691a6ae..93a5529 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -176,6 +176,14 @@ public function __construct(\PDO $connection, array $connection_options) { // Initialize and prepare the connection prefix. $this->setPrefix(isset($connection_options['prefix']) ? $connection_options['prefix'] : ''); + if (!empty($connection_options['namespace'])) { + $this->setPrefix($connection_options['namespace']) + + } + else { + @trigger_error('calling \Drupal\Core\Database\Connection::__construct() without namespace key is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/project/drupal/issues/3112476', E_USER_DEPRECATED); + } + // Set a Statement class, unless the driver opted out. if (!empty($this->statementClass)) { $connection->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [$this->statementClass, [$this]]); @@ -638,14 +646,18 @@ public function query($query, array $args = [], $options = []) { switch ($options['return']) { case Database::RETURN_STATEMENT: return $stmt; + case Database::RETURN_AFFECTED: $stmt->allowRowCount = TRUE; return $stmt->rowCount(); + case Database::RETURN_INSERT_ID: $sequence_name = isset($options['sequence_name']) ? $options['sequence_name'] : NULL; return $this->connection->lastInsertId($sequence_name); + case Database::RETURN_NULL: return NULL; + default: throw new \PDOException('Invalid return directive: ' . $options['return']); } @@ -770,6 +782,7 @@ protected function expandArguments(&$query, &$args) { * * @param string $class * The class for which we want the potentially driver-specific class. + * * @return string * The name of the class that should be used for this driver. */ @@ -1469,7 +1482,7 @@ public function commit() { abstract public function nextId($existing_id = 0); /** - * Prepares a statement for execution and returns a statement object + * Prepares a statement for execution and returns a statement object. * * Emulated prepared statements does not communicate with the database server * so this method does not check the statement. @@ -1521,7 +1534,7 @@ public function quote($string, $parameter_type = \PDO::PARAM_STR) { * Extracts the SQLSTATE error from the PDOException. * * @param \Exception $e - * The exception + * The exception. * * @return string * The five character error code. diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php old mode 100644 new mode 100755 index d13ea80..12a78c9 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -365,8 +365,7 @@ throw new DriverNotSpecifiedException('Driver not specified for this database connection: ' . $key); } - $namespace = static::getDatabaseDriverNamespace(self::$databaseInfo[$key][$target]); - $driver_class = $namespace . '\\Connection'; + $driver_class = self::$databaseInfo[$key][$target]['namespace'] . '\\Connnection'; $pdo_connection = $driver_class::open(self::$databaseInfo[$key][$target]); $new_connection = new $driver_class($pdo_connection, self::$databaseInfo[$key][$target]); @@ -488,7 +487,8 @@ public static function getConnectionInfoAsUrl($key = 'default') { if (empty($db_info) || empty($db_info['default'])) { throw new \RuntimeException("Database connection $key not defined or missing the 'default' settings"); } - $connection_class = static::getDatabaseDriverNamespace($db_info['default']) . '\\Connection'; + + $connection_class = $db_info['default']['namespace'] . '\\Connection'; return $connection_class::createUrlFromConnectionOptions($db_info['default']); } @@ -502,8 +502,13 @@ public static function getConnectionInfoAsUrl($key = 'default') { * * @return string * The PHP namespace of the driver's database. + * + * @deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. + * $info['namespace] is always set now. + * @see https://www.drupal.org/project/drupal/issues/3112476 */ protected static function getDatabaseDriverNamespace(array $connection_info) { + @trigger_error("getDatabaseDriverNamespace() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. $info['namespace'] is always set now. See https://www.drupal.org/project/drupal/issues/3115388.", E_USER_DEPRECATED); if (isset($connection_info['namespace'])) { return $connection_info['namespace']; }