diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-02-23 05:07:18 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-02-23 05:07:18 +0000 |
commit | 6192e19f60cd6e0a7f4c5841271ca9caf5eeafa4 (patch) | |
tree | 88f2bd86af7aafd6c36b869c7894f37ea1f4e314 /includes/database/sqlite | |
parent | fa02c4f4e931ba3fda37835971a8a0fd6de0365c (diff) | |
download | brdo-6192e19f60cd6e0a7f4c5841271ca9caf5eeafa4.tar.gz brdo-6192e19f60cd6e0a7f4c5841271ca9caf5eeafa4.tar.bz2 |
#720620 by andypost: Fixed indexExists() for pgsql and sqlite does not prefix tablename.
Diffstat (limited to 'includes/database/sqlite')
-rw-r--r-- | includes/database/sqlite/schema.inc | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/includes/database/sqlite/schema.inc b/includes/database/sqlite/schema.inc index ff3f35c68..974d014d7 100644 --- a/includes/database/sqlite/schema.inc +++ b/includes/database/sqlite/schema.inc @@ -135,9 +135,12 @@ class DatabaseSchema_sqlite extends DatabaseSchema { protected function createFieldSql($name, $spec) { if (!empty($spec['auto_increment'])) { $sql = $name . " INTEGER PRIMARY KEY AUTOINCREMENT"; + if (!empty($spec['unsigned'])) { + $sql .= ' CHECK (' . $name . '>= 0)'; + } } else { - $sql = $name . " " . $spec['sqlite_type']; + $sql = $name . ' ' . $spec['sqlite_type']; if (in_array($spec['type'], array('varchar', 'char', 'text')) && isset($spec['length'])) { $sql .= '(' . $spec['length'] . ')'; @@ -147,6 +150,10 @@ class DatabaseSchema_sqlite extends DatabaseSchema { $sql .= ' NOT NULL'; } + if (!empty($spec['unsigned'])) { + $sql .= ' CHECK (' . $name . '>= 0)'; + } + if (isset($spec['default'])) { if (is_string($spec['default'])) { $spec['default'] = "'" . $spec['default'] . "'"; @@ -220,7 +227,27 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * The new name for the table. */ public function renameTable($table, $new_name) { + $schema = $this->introspectSchema($table); + $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); + + // Drop the indexes, there is no RENAME INDEX command in SQLite. + if (!empty($schema['unique keys'])) { + foreach ($schema['unique keys'] as $key => $fields) { + $this->dropIndex($table, $key); + } + } + if (!empty($schema['indexes'])) { + foreach ($schema['indexes'] as $index => $fields) { + $this->dropIndex($table, $index); + } + } + + // Recreate the indexes. + $statements = $this->createIndexSql($new_name, $schema); + foreach ($statements as $statement) { + $this->connection->query($statement); + } } /** @@ -269,7 +296,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { $this->createTable($new_table, $new_schema); - $select = $this->connection->select($table)->fields($new_schema['fields']); + $select = $this->connection->select($table)->fields($table, array_keys($new_schema['fields'])); $this->connection->insert($new_table) ->from($select) ->execute(); @@ -340,9 +367,11 @@ class DatabaseSchema_sqlite extends DatabaseSchema { ); } } - $n = strlen($table) + 1; + // Get length of table name and underscore. + $n = strlen($this->connection->prefixTables('{' . $table . '}')) + 1; foreach ($indexes as $index) { $name = $index['name']; + // Get index name without prefix. $index_name = substr($name, $n); $result = $this->connection->query("PRAGMA index_info('$name')"); foreach ($result as $row) { @@ -434,7 +463,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { } public function indexExists($table, $name) { - return ($this->connection->query("PRAGMA index_info($name)")->fetchField() != ''); + return ($this->connection->query('PRAGMA index_info({' . $table . '}_' . $name . ')')->fetchField() != ''); } /** |