]> git.joonet.de Git - adminer.git/commitdiff
SQLite: Fix primary key handling
authorJakub Vrana <jakub@vrana.cz>
Fri, 9 Aug 2013 02:20:27 +0000 (19:20 -0700)
committerJakub Vrana <jakub@vrana.cz>
Fri, 9 Aug 2013 02:20:27 +0000 (19:20 -0700)
adminer/drivers/sqlite.inc.php

index 7fce6e34cbfc616cb25efa3f4566ed42f34557a5..dbfc14c70437217481332fae8120e812403bd9df 100644 (file)
@@ -336,7 +336,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                if (!$return) {
                        foreach (fields($table) as $name => $field) {
                                if ($field["primary"]) {
-                                       $return[""] = array("type" => "PRIMARY", "columns" => array($name), "lengths" => array(), "descs" => array());
+                                       $return[""] = array("type" => "PRIMARY", "columns" => array($name), "lengths" => array(), "descs" => array(null));
                                }
                        }
                }
@@ -509,13 +509,17 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
                                }
                                $columns = "(" . implode(", ", $columns) . ")";
                                if (!$drop_indexes[$key_name]) {
-                                       if ($index["type"] != "PRIMARY") {
+                                       if ($index["type"] != "PRIMARY" || !$primary_key) {
                                                $indexes[] = array($index["type"], $key_name, $columns);
-                                       } elseif (!$primary_key) {
-                                               $foreign[] = "  PRIMARY KEY $columns";
                                        }
                                }
                        }
+                       foreach ($indexes as $key => $val) {
+                               if ($val[0] == "PRIMARY") {
+                                       unset($indexes[$key]);
+                                       $foreign[] = "  PRIMARY KEY $val[2]";
+                               }
+                       }
                        foreach (foreign_keys($table) as $foreign_key) {
                                $columns = array();
                                foreach ($foreign_key["source"] as $column) {