summaryrefslogtreecommitdiffstatshomepage
path: root/includes/database/sqlite
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-04-07 15:07:59 +0000
committerDries Buytaert <dries@buytaert.net>2010-04-07 15:07:59 +0000
commitdde5c67ba041dc65588377808b1943fdd3b57bf6 (patch)
tree133c901b2517a88d36060da686dd95903e84d079 /includes/database/sqlite
parent626e64025eb85faf819b9d17298df505e9d0526a (diff)
downloaddrupal-dde5c67ba041dc65588377808b1943fdd3b57bf6.tar.gz
drupal-dde5c67ba041dc65588377808b1943fdd3b57bf6.zip
- Patch #302327 by Josh Waihi, noahb, Crell, hswong3i: support cross-schema/database prefixing like we claim to.
Diffstat (limited to 'includes/database/sqlite')
-rw-r--r--includes/database/sqlite/schema.inc28
1 files changed, 22 insertions, 6 deletions
diff --git a/includes/database/sqlite/schema.inc b/includes/database/sqlite/schema.inc
index 894d51c632e..f8f18eb7428 100644
--- a/includes/database/sqlite/schema.inc
+++ b/includes/database/sqlite/schema.inc
@@ -14,6 +14,11 @@
class DatabaseSchema_sqlite extends DatabaseSchema {
+ /**
+ * Override DatabaseSchema::$defaultSchema
+ */
+ protected $defaultSchema = 'main';
+
public function tableExists($table) {
// Don't use {} around sqlite_master table.
return (bool) $this->connection->query("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '{" . $table . "}'", array(), array())->fetchField();
@@ -45,14 +50,19 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
*/
protected function createIndexSql($tablename, $schema) {
$sql = array();
+ $info = $this->getPrefixInfo($tablename);
if (!empty($schema['unique keys'])) {
foreach ($schema['unique keys'] as $key => $fields) {
- $sql[] = 'CREATE UNIQUE INDEX "{' . $tablename . '}_' . $key . '" ON {' . $tablename . '} (' . $this->createKeySql($fields) . "); \n";
+ // Normally we don't escape double quotes (we use single quotes) but
+ // describing the index name like this is faster and is readable.
+ $index = "\"{$info['schema']}\".\"{$info['table']}_$key\"";
+ $sql[] = 'CREATE UNIQUE INDEX ' . $index . ' ON ' . $info['table'] . ' (' . $this->createKeySql($fields) . "); \n";
}
}
if (!empty($schema['indexes'])) {
- foreach ($schema['indexes'] as $index => $fields) {
- $sql[] = 'CREATE INDEX "{' . $tablename . '}_' . $index . '" ON {' . $tablename . '} (' . $this->createKeySql($fields) . "); \n";
+ foreach ($schema['indexes'] as $key => $fields) {
+ $index = "\"{$info['schema']}\".\"{$info['table']}_$key\"";
+ $sql[] = 'CREATE INDEX ' . $index . ' ON ' . $info['table'] . ' (' . $this->createKeySql($fields) . "); \n";
}
}
return $sql;
@@ -228,7 +238,13 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
$schema = $this->introspectSchema($table);
- $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
+ // SQLite doesn't allow you to rename tables outside of the current
+ // database. So the syntax '...RENAME TO database.table' would fail.
+ // So we must determine the full table name here rather than surrounding
+ // the table with curly braces incase the db_prefix contains a reference
+ // to a database outside of our existsing database.
+ $info = $this->getPrefixInfo($new_name);
+ $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO ' . $info['table']);
// Drop the indexes, there is no RENAME INDEX command in SQLite.
if (!empty($schema['unique keys'])) {
@@ -445,7 +461,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
return FALSE;
}
- $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
+ $this->connection->query('DROP INDEX ' . $this->prefixNonTable($table, $name));
return TRUE;
}
@@ -469,7 +485,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
return FALSE;
}
- $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name);
+ $this->connection->query('DROP INDEX ' . $this->prefixNonTable($table, $name));
return TRUE;
}