]> git.joonet.de Git - adminer.git/commitdiff
MS SQL: Foreign key in create table
authorJakub Vrana <jakub@vrana.cz>
Sun, 28 Nov 2010 15:28:15 +0000 (16:28 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 29 Nov 2010 21:02:10 +0000 (22:02 +0100)
adminer/create.inc.php
adminer/drivers/mssql.inc.php
todo.txt

index 6b7e5287f14b7ddea3d5d675dd58f3058f3f86cc..4c63a376159af2d89d51fb1523e09d98373efda5 100644 (file)
@@ -44,7 +44,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
                                        $fields[] = array($field["orig"], $process_field, $after);
                                }
                                if (isset($foreign_key)) {
-                                       $foreign[] = ($TABLE != "" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . idf_escape($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (in_array($field["on_delete"], $on_actions) ? " ON DELETE $field[on_delete]" : "");
+                                       $foreign[] = ($TABLE != "" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (in_array($field["on_delete"], $on_actions) ? " ON DELETE $field[on_delete]" : "");
                                }
                                $after = "AFTER " . idf_escape($field["field"]);
                        } elseif ($field["orig"] != "") {
index e3bd6f31a7dffafa1d2a50ec9601a96f2f8842b2..2ee9ecb509bcdbc5d9636b52aa4d8dd6ecc0e648 100644 (file)
@@ -425,6 +425,9 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
                if ($table != $name) {
                        queries("EXEC sp_rename " . q(table($table)) . ", " . q($name));
                }
+               if ($foreign) {
+                       $alter[""] = $foreign;
+               }
                foreach ($alter as $key => $val) {
                        if (!queries("ALTER TABLE " . idf_escape($name) . " $key" . implode(",", $val))) {
                                return false;
index 46ad70bc111f3920d2a1ea4a6cc020e19cc9c113..b5d554febea84fce50a1c88386b84366ee9833e2 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -42,6 +42,7 @@ Column rights - http://www.postgresql.org/docs/8.4/static/functions-info.html
 bool in Editor
 
 MS SQL:
+Edit of AI column
 Non UTF-8 character sets
 Detection of table collation
 PDO_MSSQL and PDO_SQLSRV driver with seek