]> git.joonet.de Git - adminer.git/commitdiff
Save bytes
authorJakub Vrana <jakub@vrana.cz>
Tue, 2 Aug 2011 15:46:13 +0000 (17:46 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 2 Aug 2011 15:46:13 +0000 (17:46 +0200)
adminer/create.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/foreign.inc.php
adminer/include/bootstrap.inc.php
adminer/include/editing.inc.php

index 68ef8746ad9f9d749bebe48b4acaa9b84c637d7f..e46c419ae393196acef2897a11de16ab9880b08b 100644 (file)
@@ -47,7 +47,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
                                        $fields[] = array($field["orig"], $process_field, $after);
                                }
                                if (isset($foreign_key)) {
-                                       $foreign[idf_escape($field["field"])] = ($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]" : "");
+                                       $foreign[idf_escape($field["field"])] = ($TABLE != "" ? "ADD" : " ") . " FOREIGN KEY (" . idf_escape($field["field"]) . ") REFERENCES " . table($foreign_keys[$field["type"]]) . " (" . idf_escape($type_field["field"]) . ")" . (ereg("^($on_actions)\$", $field["on_delete"]) ? " ON DELETE $field[on_delete]" : "");
                                }
                                $after = "AFTER " . idf_escape($field["field"]);
                        } elseif ($field["orig"] != "") {
index 2bf8b3081cd889a29a72dc15628aede5a0d73109..27345b9adbfea15b94ce018d89b0e7df3f107557 100644 (file)
@@ -444,7 +444,7 @@ if (!defined("DRIVER")) {
                $return = array();
                $create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1);
                if ($create_table) {
-                       preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY \\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER);
+                       preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY \\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($on_actions))?(?: ON UPDATE ($on_actions))?~", $create_table, $matches, PREG_SET_ORDER);
                        foreach ($matches as $match) {
                                preg_match_all("~$pattern~", $match[2], $source);
                                preg_match_all("~$pattern~", $match[5], $target);
index 940d7659c22a45768ed7b63f78e77d3351cb117c..9a3b7e64857f567563cb4d112f1c1636f3aaf1cf 100644 (file)
@@ -284,8 +284,8 @@ ORDER BY conkey, conname") as $row) {
                                        $row['table'] = $match2[2];
                                }
                                $row['target'] = array_map('trim', explode(',', $match[3]));
-                               $row['on_delete'] = (preg_match('~ON DELETE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
-                               $row['on_update'] = (preg_match('~ON UPDATE (' . implode('|', $on_actions) . ')~', $match[4], $match2) ? $match2[1] : '');
+                               $row['on_delete'] = (preg_match("~ON DELETE ($on_actions)~", $match[4], $match2) ? $match2[1] : '');
+                               $row['on_update'] = (preg_match("~ON UPDATE ($on_actions)~", $match[4], $match2) ? $match2[1] : '');
                                $return[$row['conname']] = $row;
                        }
                }
index b81bf3f797063be20c9946b9495c52d736245cf0..7009a9fb47c5b0884fd467a9068bd323b57ff07f 100644 (file)
@@ -13,8 +13,8 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
                query_redirect("ALTER TABLE " . table($TABLE)
                        . ($_GET["name"] != "" ? "\nDROP FOREIGN KEY " . idf_escape($_GET["name"]) . "," : "")
                        . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $_GET["name"] - check in older MySQL versions
-                       . (in_array($_POST["on_delete"], $on_actions) ? " ON DELETE $_POST[on_delete]" : "")
-                       . (in_array($_POST["on_update"], $on_actions) ? " ON UPDATE $_POST[on_update]" : "")
+                       . (ereg("^($on_actions)\$", $_POST["on_delete"]) ? " ON DELETE $_POST[on_delete]" : "")
+                       . (ereg("^($on_actions)\$", $_POST["on_update"]) ? " ON UPDATE $_POST[on_update]" : "")
                , ME . "table=" . urlencode($TABLE), ($_GET["name"] != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
                $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "<br>$error"; //! no partitioning
        }
@@ -67,8 +67,8 @@ foreach ($row["source"] as $key => $val) {
 ?>
 </table>
 <p>
-<?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + $on_actions, $row["on_delete"]); ?>
- <?php echo lang('ON UPDATE'); ?>: <?php echo html_select("on_update", array(-1 => "") + $on_actions, $row["on_update"]); ?>
+<?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + explode("|", $on_actions), $row["on_delete"]); ?>
+ <?php echo lang('ON UPDATE'); ?>: <?php echo html_select("on_update", array(-1 => "") + explode("|", $on_actions), $row["on_update"]); ?>
 <p>
 <input type="submit" value="<?php echo lang('Save'); ?>">
 <noscript><p><input type="submit" name="add" value="<?php echo lang('Add column'); ?>"></noscript>
index 6f2103519ce8a91f4ebc43947a51728ac783d87d..26379a3da15db396b745eb12ad699ab63c369251 100644 (file)
@@ -78,4 +78,4 @@ if (!ini_bool("session.use_cookies") || @ini_set("session.use_cookies", false) !
        session_write_close(); // improves concurrency if a user opens several pages at once, may be restarted later
 }
 
-$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION"); ///< @var array used in foreign_keys()
+$on_actions = "RESTRICT|CASCADE|SET NULL|NO ACTION"; ///< @var string used in foreign_keys()
index 9964448e621de3e778ad05af47cde1a6e8991811..df1ebe2e11678ed8f72b5f34ee148fb4e956dbdb 100644 (file)
@@ -145,7 +145,7 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) {
 <td><input name="<?php echo $key; ?>[length]" value="<?php echo h($field["length"]); ?>" size="3" onfocus="editingLengthFocus(this);"><td class="options"><?php
        echo "<select name='$key" . "[collation]'" . (ereg('(char|text|enum|set)$', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')' . optionlist($collations, $field["collation"]) . '</select>';
        echo ($unsigned ? "<select name='$key" . "[unsigned]'" . (!$field["type"] || ereg('(int|float|double|decimal)$', $field["type"]) ? "" : " class='hidden'") . '><option>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : '');
-       echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist($on_actions, $field["on_delete"]) . "</select> " : " "); // space for IE
+       echo ($foreign_keys ? "<select name='$key" . "[on_delete]'" . (ereg("`", $field["type"]) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE
 }
 
 /** Filter length value including enums