]> git.joonet.de Git - adminer.git/commitdiff
SQLite: Don't treat multi-column primary key as auto_increment
authorJakub Vrana <jakub@vrana.cz>
Wed, 7 Aug 2013 22:31:15 +0000 (15:31 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 8 Aug 2013 20:52:23 +0000 (13:52 -0700)
adminer/drivers/sqlite.inc.php

index e8e6e12bfb6f99f7a6168e1ba2bcf6aba304c99e..caa65d3795b209cf057a649d35b889ae3c33145f 100644 (file)
@@ -292,19 +292,28 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
 
        function fields($table) {
                $return = array();
+               $primary = "";
                foreach (get_rows("PRAGMA table_info(" . table($table) . ")") as $row) {
+                       $name = $row["name"];
                        $type = strtolower($row["type"]);
                        $default = $row["dflt_value"];
-                       $return[$row["name"]] = array(
-                               "field" => $row["name"],
+                       $return[$name] = array(
+                               "field" => $name,
                                "type" => (preg_match('~int~i', $type) ? "integer" : (preg_match('~char|clob|text~i', $type) ? "text" : (preg_match('~blob~i', $type) ? "blob" : (preg_match('~real|floa|doub~i', $type) ? "real" : "numeric")))),
                                "full_type" => $type,
                                "default" => (preg_match("~'(.*)'~", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)),
                                "null" => !$row["notnull"],
-                               "auto_increment" => preg_match('~^integer$~i', $type) && $row["pk"], //! possible false positive
                                "privileges" => array("select" => 1, "insert" => 1, "update" => 1),
                                "primary" => $row["pk"],
                        );
+                       if ($row["pk"]) {
+                               if ($primary != "") {
+                                       $return[$primary]["auto_increment"] = false;
+                               } elseif (preg_match('~^integer$~i', $type)) {
+                                       $return[$name]["auto_increment"] = true;
+                                       $primary = $name;
+                               }
+                       }
                }
                return $return;
        }