updated core to 7.80
This commit is contained in:
@@ -107,9 +107,21 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
$this->sqliteCreateFunction('substring_index', array($this, 'sqlFunctionSubstringIndex'), 3);
|
||||
$this->sqliteCreateFunction('rand', array($this, 'sqlFunctionRand'));
|
||||
|
||||
// Enable the Write-Ahead Logging (WAL) option for SQLite if supported.
|
||||
// @see https://www.drupal.org/node/2348137
|
||||
// @see https://sqlite.org/wal.html
|
||||
if (version_compare($version, '3.7') >= 0) {
|
||||
$connection_options += array(
|
||||
'init_commands' => array(),
|
||||
);
|
||||
$connection_options['init_commands'] += array(
|
||||
'wal' => "PRAGMA journal_mode=WAL",
|
||||
);
|
||||
}
|
||||
|
||||
// Execute sqlite init_commands.
|
||||
if (isset($connection_options['init_commands'])) {
|
||||
$this->exec(implode('; ', $connection_options['init_commands']));
|
||||
$this->connection->exec(implode('; ', $connection_options['init_commands']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,10 +140,10 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
$count = $this->query('SELECT COUNT(*) FROM ' . $prefix . '.sqlite_master WHERE type = :type AND name NOT LIKE :pattern', array(':type' => 'table', ':pattern' => 'sqlite_%'))->fetchField();
|
||||
|
||||
// We can prune the database file if it doesn't have any tables.
|
||||
if ($count == 0) {
|
||||
// Detach the database.
|
||||
$this->query('DETACH DATABASE :schema', array(':schema' => $prefix));
|
||||
// Destroy the database file.
|
||||
if ($count == 0 && $this->connectionOptions['database'] != ':memory:') {
|
||||
// Detaching the database fails at this point, but no other queries
|
||||
// are executed after the connection is destructed so we can simply
|
||||
// remove the database file.
|
||||
unlink($this->connectionOptions['database'] . '-' . $prefix);
|
||||
}
|
||||
}
|
||||
@@ -143,6 +155,18 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the attached databases.
|
||||
*
|
||||
* @return array
|
||||
* An array of attached database names.
|
||||
*
|
||||
* @see DatabaseConnection_sqlite::__construct().
|
||||
*/
|
||||
public function getAttachedDatabases() {
|
||||
return $this->attachedDatabases;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite compatibility implementation for the IF() SQL function.
|
||||
*/
|
||||
@@ -235,7 +259,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
* expose this function to the world.
|
||||
*/
|
||||
public function PDOPrepare($query, array $options = array()) {
|
||||
return parent::prepare($query, $options);
|
||||
return $this->connection->prepare($query, $options);
|
||||
}
|
||||
|
||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
@@ -326,7 +350,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
}
|
||||
}
|
||||
if ($this->supportsTransactions()) {
|
||||
PDO::rollBack();
|
||||
$this->connection->rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +365,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
throw new DatabaseTransactionNameNonUniqueException($name . " is already in use.");
|
||||
}
|
||||
if (!$this->inTransaction()) {
|
||||
PDO::beginTransaction();
|
||||
$this->connection->beginTransaction();
|
||||
}
|
||||
$this->transactionLayers[$name] = $name;
|
||||
}
|
||||
@@ -366,9 +390,9 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
||||
// If there was any rollback() we should roll back whole transaction.
|
||||
if ($this->willRollback) {
|
||||
$this->willRollback = FALSE;
|
||||
PDO::rollBack();
|
||||
$this->connection->rollBack();
|
||||
}
|
||||
elseif (!PDO::commit()) {
|
||||
elseif (!$this->connection->commit()) {
|
||||
throw new DatabaseTransactionCommitFailedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class InsertQuery_sqlite extends InsertQuery {
|
||||
if (!$this->preExecute()) {
|
||||
return NULL;
|
||||
}
|
||||
if (count($this->insertFields)) {
|
||||
if (count($this->insertFields) || !empty($this->fromQuery)) {
|
||||
return parent::execute();
|
||||
}
|
||||
else {
|
||||
@@ -36,7 +36,10 @@ class InsertQuery_sqlite extends InsertQuery {
|
||||
$comments = $this->connection->makeComment($this->comments);
|
||||
|
||||
// Produce as many generic placeholders as necessary.
|
||||
$placeholders = array_fill(0, count($this->insertFields), '?');
|
||||
$placeholders = array();
|
||||
if (!empty($this->insertFields)) {
|
||||
$placeholders = array_fill(0, count($this->insertFields), '?');
|
||||
}
|
||||
|
||||
// If we're selecting from a SelectQuery, finish building the query and
|
||||
// pass it back, as any remaining options are irrelevant.
|
||||
|
||||
@@ -668,6 +668,9 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
|
||||
$this->alterTable($table, $old_schema, $new_schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findTables($table_expression) {
|
||||
// Don't add the prefix, $table_expression already includes the prefix.
|
||||
$info = $this->getPrefixInfo($table_expression, FALSE);
|
||||
@@ -680,4 +683,32 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
|
||||
));
|
||||
return $result->fetchAllKeyed(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findTablesD8($table_expression) {
|
||||
$tables = array();
|
||||
|
||||
// The SQLite implementation doesn't need to use the same filtering strategy
|
||||
// as the parent one because individually prefixed tables live in their own
|
||||
// schema (database), which means that neither the main database nor any
|
||||
// attached one will contain a prefixed table name, so we just need to loop
|
||||
// over all known schemas and filter by the user-supplied table expression.
|
||||
$attached_dbs = $this->connection->getAttachedDatabases();
|
||||
foreach ($attached_dbs as $schema) {
|
||||
// Can't use query placeholders for the schema because the query would
|
||||
// have to be :prefixsqlite_master, which does not work. We also need to
|
||||
// ignore the internal SQLite tables.
|
||||
$result = db_query("SELECT name FROM " . $schema . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", array(
|
||||
':type' => 'table',
|
||||
':table_name' => $table_expression,
|
||||
':pattern' => 'sqlite_%',
|
||||
));
|
||||
$tables += $result->fetchAllKeyed(0, 0);
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user