Commit 17698412 authored by alexpott's avatar alexpott

Issue #2010322 by Damien Tournoud, dcrocks, amateescu: SQLite follow up to...

Issue #2010322 by Damien Tournoud, dcrocks, amateescu: SQLite follow up to #1953800 'Make the database connection serializable'.
parent 42daa83c
......@@ -229,7 +229,7 @@ public static function sqlFunctionSubstringIndex($string, $delimiter, $count) {
/**
* SQLite compatibility implementation for the RAND() SQL function.
*/
public function sqlFunctionRand($seed = NULL) {
public static function sqlFunctionRand($seed = NULL) {
if (isset($seed)) {
mt_srand($seed);
}
......@@ -243,24 +243,8 @@ public function sqlFunctionRand($seed = NULL) {
* a Statement object, that will create a PDOStatement
* using the semi-private PDOPrepare() method below.
*/
public function prepare($query, $options = array()) {
return new Statement($this, $query, $options);
}
/**
* NEVER CALL THIS FUNCTION: YOU MIGHT DEADLOCK YOUR PHP PROCESS.
*
* This is a wrapper around the parent PDO::prepare method. However, as
* the PDO SQLite driver only closes SELECT statements when the PDOStatement
* destructor is called and SQLite does not allow data change (INSERT,
* UPDATE etc) on a table which has open SELECT statements, you should never
* call this function and keep a PDOStatement object alive as that can lead
* to a deadlock. This really, really should be private, but as Statement
* needs to call it, we have no other choice but to expose this function to
* the world.
*/
public function PDOPrepare($query, array $options = array()) {
return $this->connection->prepare($query, $options);
public function prepare($statement, array $driver_options = array()) {
return new Statement($this->connection, $this, $statement, $driver_options);
}
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
......@@ -312,10 +296,6 @@ public function mapConditionOperator($operator) {
return isset($specials[$operator]) ? $specials[$operator] : NULL;
}
public function prepareQuery($query) {
return $this->prepare($this->prefixTables($query));
}
public function nextId($existing_id = 0) {
$transaction = $this->startTransaction();
// We can safely use literal queries here instead of the slower query
......@@ -382,7 +362,7 @@ public function pushTransaction($name) {
throw new TransactionNameNonUniqueException($name . " is already in use.");
}
if (!$this->inTransaction()) {
PDO::beginTransaction();
$this->connection->beginTransaction();
}
$this->transactionLayers[$name] = $name;
}
......
......@@ -16,10 +16,11 @@
/**
* Specific SQLite implementation of DatabaseConnection.
*
* See DatabaseConnection_sqlite::PDOPrepare() for reasons why we must prefetch
* the data instead of using PDOStatement.
*
* @see DatabaseConnection_sqlite::PDOPrepare()
* The PDO SQLite driver only closes SELECT statements when the PDOStatement
* destructor is called and SQLite does not allow data change (INSERT,
* UPDATE etc) on a table which has open SELECT statements. This is a
* user-space mock of PDOStatement that buffers all the data and doesn't
* have those limitations.
*/
class Statement extends StatementPrefetch implements Iterator, StatementInterface {
......@@ -86,7 +87,7 @@ protected function getStatement($query, &$args = array()) {
}
}
return $this->dbh->PDOPrepare($query);
return $this->dbh->prepare($query);
}
public function execute($args = array(), $options = array()) {
......
......@@ -37,12 +37,19 @@ class StatementPrefetch implements Iterator, StatementInterface {
/**
* Reference to the database connection object for this statement.
*
* The name $dbh is inherited from PDOStatement.
* This is part of the public interface of PDOStatement.
*
* @var Drupal\Core\Database\Connection
* @var PDO
*/
public $dbh;
/**
* Reference to the Drupal database connection object for this statement.
*
* @var Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Main data store.
*
......@@ -124,8 +131,9 @@ class StatementPrefetch implements Iterator, StatementInterface {
'column' => 0,
);
public function __construct(Connection $connection, $query, array $driver_options = array()) {
$this->dbh = $connection;
public function __construct(PDO $dbh, Connection $connection, $query, array $driver_options = array()) {
$this->dbh = $dbh;
$this->connection = $connection;
$this->queryString = $query;
$this->driverOptions = $driver_options;
}
......@@ -153,7 +161,7 @@ public function execute($args = array(), $options = array()) {
}
}
$logger = $this->dbh->getLogger();
$logger = $this->connection->getLogger();
if (!empty($logger)) {
$query_start = microtime(TRUE);
}
......
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