From 8e75d54e44e350398dfc52bdb6da13c5827170cc Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 2 Aug 2011 17:46:13 +0200 Subject: [PATCH] Save bytes --- adminer/create.inc.php | 2 +- adminer/drivers/mysql.inc.php | 2 +- adminer/drivers/pgsql.inc.php | 4 ++-- adminer/foreign.inc.php | 8 ++++---- adminer/include/bootstrap.inc.php | 2 +- adminer/include/editing.inc.php | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 68ef8746..e46c419a 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -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"] != "") { diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 2bf8b308..27345b9a 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -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); diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 940d7659..9a3b7e64 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -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; } } diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index b81bf3f7..7009a9fb 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -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.') . "
$error"; //! no partitioning } @@ -67,8 +67,8 @@ foreach ($row["source"] as $key => $val) { ?>

-: "") + $on_actions, $row["on_delete"]); ?> - : "") + $on_actions, $row["on_update"]); ?> +: "") + explode("|", $on_actions), $row["on_delete"]); ?> + : "") + explode("|", $on_actions), $row["on_update"]); ?>

diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index 6f210351..26379a3d 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -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() diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 9964448e..df1ebe2e 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -145,7 +145,7 @@ function edit_type($key, $field, $collations, $foreign_keys = array()) { " size="3" onfocus="editingLengthFocus(this);">