#716006: schema tests fail on SQLite.

From: Damien Tournoud <damien@tournoud.net>


---
 database/sqlite/schema.inc |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git includes/database/sqlite/schema.inc includes/database/sqlite/schema.inc
index 3a226fd..8edd630 100644
--- includes/database/sqlite/schema.inc
+++ 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'] . "'";
@@ -269,7 +276,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();
@@ -434,7 +441,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() != '');
   }
 
   /**
