diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index ead1d85..66a4722 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -101,6 +101,13 @@ protected $temporaryNameIndex = 0; /** + * The actual PDO connection. + * + * @var \PDO + */ + protected $connection; + + /** * The connection information for this connection object. * * @var array @@ -136,13 +143,6 @@ protected $prefixReplace = array(); /** - * The actual PDO connection. - * - * @var \PDO - */ - protected $connection; - - /** * Constructs a Connection object. */ public function __construct(PDO $connection, array $connection_options) { @@ -155,14 +155,19 @@ public function __construct(PDO $connection, array $connection_options) { } $this->connection = $connection; + $this->connectionOptions = $connection_options; } /** * Opens a PDO connection. + * + * @param array $connection_options + * The database connection settings array. + * + * @return \PDO + * A \PDO object. */ - public static function open(array &$connection_options = array()) { - // @TODO WHy is there no abstract for static methods. - } + public static function open(array &$connection_options = array()) { } /** * Destroys this Connection object. @@ -1192,12 +1197,42 @@ public function commit() { abstract public function nextId($existing_id = 0); /** + * 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. + * + * @param string $statement + * This must be a valid SQL statement for the target database server. + * @param array $driver_options + * (optional) This array holds one or more key=>value pairs to set + * attribute values for the PDOStatement object that this method returns. + * You would most commonly use this to set the \PDO::ATTR_CURSOR value to + * \PDO::CURSOR_SCROLL to request a scrollable cursor. Some drivers have + * driver specific options that may be set at prepare-time. + * + * @return \PDOStatement|false + * If the database server successfully prepares the statement, returns a + * \PDOStatement object. + * If the database server cannot successfully prepare the statement returns + * FALSE or emits \PDOException (depending on error handling). + * + * @throws \PDOException + * + * @see \PDO::prepare() + */ + public function prepare($statement, array $driver_options = NULL) { + return $this->connection->prepare($statement, $driver_options); + } + + /** * Quotes a string for use in a query. * * @param string $string * The string to be quoted. * @param int $parameter_type - * Provides a data type hint for drivers that have alternate quoting styles. + * (optional) Provides a data type hint for drivers that have alternate + * quoting styles. * * @return string|bool * A quoted string that is theoretically safe to pass into an SQL statement. @@ -1210,4 +1245,3 @@ public function quote($string, $parameter_type = \PDO::PARAM_STR) { } } - diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index e68bc94..0647c85 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -121,15 +121,15 @@ public static function open(array &$connection_options = array()) { $pdo = new PDO('sqlite:' . $connection_options['database'], '', '', $connection_options['pdo']); // Create functions needed by SQLite. - $pdo->sqliteCreateFunction('if', array($this, 'sqlFunctionIf')); - $pdo->sqliteCreateFunction('greatest', array($this, 'sqlFunctionGreatest')); + $pdo->sqliteCreateFunction('if', array(__CLASS__, 'sqlFunctionIf')); + $pdo->sqliteCreateFunction('greatest', array(__CLASS__, 'sqlFunctionGreatest')); $pdo->sqliteCreateFunction('pow', 'pow', 2); $pdo->sqliteCreateFunction('length', 'strlen', 1); $pdo->sqliteCreateFunction('md5', 'md5', 1); - $pdo->sqliteCreateFunction('concat', array($this, 'sqlFunctionConcat')); - $pdo->sqliteCreateFunction('substring', array($this, 'sqlFunctionSubstring'), 3); - $pdo->sqliteCreateFunction('substring_index', array($this, 'sqlFunctionSubstringIndex'), 3); - $pdo->sqliteCreateFunction('rand', array($this, 'sqlFunctionRand')); + $pdo->sqliteCreateFunction('concat', array(__CLASS__, 'sqlFunctionConcat')); + $pdo->sqliteCreateFunction('substring', array(__CLASS__, 'sqlFunctionSubstring'), 3); + $pdo->sqliteCreateFunction('substring_index', array(__CLASS__, 'sqlFunctionSubstringIndex'), 3); + $pdo->sqliteCreateFunction('rand', array(__CLASS__, 'sqlFunctionRand')); // Execute sqlite init_commands. if (isset($connection_options['init_commands'])) { @@ -173,14 +173,14 @@ public function __destruct() { /** * SQLite compatibility implementation for the IF() SQL function. */ - public function sqlFunctionIf($condition, $expr1, $expr2 = NULL) { + public static function sqlFunctionIf($condition, $expr1, $expr2 = NULL) { return $condition ? $expr1 : $expr2; } /** * SQLite compatibility implementation for the GREATEST() SQL function. */ - public function sqlFunctionGreatest() { + public static function sqlFunctionGreatest() { $args = func_get_args(); foreach ($args as $k => $v) { if (!isset($v)) { @@ -198,7 +198,7 @@ public function sqlFunctionGreatest() { /** * SQLite compatibility implementation for the CONCAT() SQL function. */ - public function sqlFunctionConcat() { + public static function sqlFunctionConcat() { $args = func_get_args(); return implode('', $args); } @@ -206,14 +206,14 @@ public function sqlFunctionConcat() { /** * SQLite compatibility implementation for the SUBSTRING() SQL function. */ - public function sqlFunctionSubstring($string, $from, $length) { + public static function sqlFunctionSubstring($string, $from, $length) { return substr($string, $from - 1, $length); } /** * SQLite compatibility implementation for the SUBSTRING_INDEX() SQL function. */ - public function sqlFunctionSubstringIndex($string, $delimiter, $count) { + public static function sqlFunctionSubstringIndex($string, $delimiter, $count) { // If string is empty, simply return an empty string. if (empty($string)) { return '';