Browse files

SQLite: Fix creating table and altering primary key (bug #373)

  • Loading branch information...
1 parent 147957c commit d5a2afeef7976ffaf6a9f89d4fae6b26aa5be21d @vrana committed Jan 30, 2014
Showing with 7 additions and 5 deletions.
  1. +6 −5 adminer/drivers/sqlite.inc.php
  2. +1 −0 changes.txt
View
11 adminer/drivers/sqlite.inc.php
@@ -497,7 +497,6 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
}
function recreate_table($table, $name, $fields, $originals, $foreign, $indexes = array()) {
- queries("BEGIN");
if ($table != "") {
if (!$fields) {
foreach (fields($table) as $key => $field) {
@@ -506,11 +505,10 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes =
}
}
$primary_key = false;
- foreach ($fields as $key => $field) {
+ foreach ($fields as $field) {
if ($field[6]) {
$primary_key = true;
}
- $fields[$key] = " " . implode($field);
}
$drop_indexes = array();
foreach ($indexes as $key => $val) {
@@ -527,7 +525,6 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes =
}
$columns[] = $originals[$column] . ($index["descs"][$key] ? " DESC" : "");
}
- $columns = "(" . implode(", ", $columns) . ")";
if (!$drop_indexes[$key_name]) {
if ($index["type"] != "PRIMARY" || !$primary_key) {
$indexes[] = array($index["type"], $key_name, $columns);
@@ -537,7 +534,7 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes =
foreach ($indexes as $key => $val) {
if ($val[0] == "PRIMARY") {
unset($indexes[$key]);
- $foreign[] = " PRIMARY KEY $val[2]";
+ $foreign[] = " PRIMARY KEY (" . implode(", ", $val[2]) . ")";
}
}
foreach (foreign_keys($table) as $key_name => $foreign_key) {
@@ -551,6 +548,10 @@ function recreate_table($table, $name, $fields, $originals, $foreign, $indexes =
$foreign[] = " " . format_foreign_key($foreign_key);
}
}
+ queries("BEGIN");
+ }
+ foreach ($fields as $key => $field) {
+ $fields[$key] = " " . implode($field);
}
$fields = array_merge($fields, array_filter($foreign));
if (!queries("CREATE TABLE " . table($table != "" ? "adminer_$name" : $name) . " (\n" . implode(",\n", $fields) . "\n)")) {
View
1 changes.txt
@@ -1,6 +1,7 @@
Adminer 4.0.3-dev:
MongoDB: insert, truncate, indexes
SimpleDB, MongoDB: insert more fields at once
+SQLite: Fix creating table and altering primary key, bug since Adminer 4.0.0
Norweigan translation
Adminer 4.0.2 (released 2014-01-11):

0 comments on commit d5a2afe

Please sign in to comment.