From 9ffca2f6e6501118a74ff40f8be988af14473795 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 6 Aug 2013 14:55:56 -0700 Subject: [PATCH] SimpleDB: Allow selecting arrays --- adminer/drivers/simpledb.inc.php | 16 +++--- adminer/include/functions.inc.php | 49 ++++++++++++++++- adminer/select.inc.php | 87 ++++++++++++------------------- adminer/static/default.css | 1 + todo.txt | 7 +++ 5 files changed, 95 insertions(+), 65 deletions(-) diff --git a/adminer/drivers/simpledb.inc.php b/adminer/drivers/simpledb.inc.php index 2b81afac..6810a5ae 100644 --- a/adminer/drivers/simpledb.inc.php +++ b/adminer/drivers/simpledb.inc.php @@ -1,12 +1,4 @@ Attribute as $attribute) { $name = $this->_processValue($attribute->Name); - $row[$name] .= ($row[$name] != '' ? ',' : '') . $this->_processValue($attribute->Value); + $value = $this->_processValue($attribute->Value); + if (isset($row[$name])) { + $row[$name] = (array) $row[$name]; + $row[$name][] = $value; + } else { + $row[$name] = $value; + } } $this->_rows[] = $row; foreach ($row as $key => $val) { diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 8d8117ca..5b42df9f 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -975,6 +975,53 @@ function password_file($create) { return $return; } +/** Format value to use in select +* @param string +* @param string +* @param array +* @param int +* @return string HTML +*/ +function select_value($val, $link, $field, $text_length) { + global $adminer, $HTTPS; + if (is_array($val)) { + $return = ""; + foreach ($val as $k => $v) { + $return .= "" + . ($val != array_values($val) ? "" . h($k) : "") + . "" . select_value($v, $link, $field, $text_length) + ; + } + return "$return
"; + } + if (!$link) { + $link = $adminer->selectLink($val, $field); + } + if ($link === null) { + if (is_mail($val)) { + $link = "mailto:$val"; + } + if ($protocol = is_url($val)) { + $link = ($protocol == "http" && $HTTPS + ? $val // HTTP links from HTTPS pages don't receive Referer automatically + : "$protocol://www.adminer.org/redirect/?url=" . urlencode($val) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5 + ); + } + } + $val = $adminer->editVal($val, $field); + if ($val !== null) { + if ($val === "") { // === - may be int + $val = " "; + } elseif ($text_length != "" && is_shortable($field)) { + $val = shorten_utf8($val, max(0, +$text_length)); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network + } else { + $val = h($val); + } + } + $val = $adminer->selectVal($val, $link, $field); + return $val; +} + /** Check whether the string is e-mail address * @param string * @return bool @@ -983,7 +1030,7 @@ function is_mail($email) { $atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component $pattern = "$atom+(\\.$atom+)*@($domain?\\.)+$domain"; - return preg_match("(^$pattern(,\\s*$pattern)*\$)i", $email); + return is_string($email) && preg_match("(^$pattern(,\\s*$pattern)*\$)i", $email); } /** Check whether the string is URL address diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 46be3c83..4e59429f 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -362,71 +362,48 @@ if (!$columns && support("table")) { } $link = ""; - $val = $adminer->editVal($val, $field); - if ($val !== null) { - if (preg_match('~blob|bytea|raw|file~', $field["type"]) && $val != "") { - $link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf; - } - if ($val === "") { // === - may be int - $val = " "; - } elseif ($text_length != "" && is_shortable($field)) { - $val = shorten_utf8($val, max(0, +$text_length)); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network - } else { - $val = h($val); - } - - if (!$link) { // link related items - foreach ((array) $foreign_keys[$key] as $foreign_key) { - if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) { - $link = ""; - foreach ($foreign_key["source"] as $i => $source) { - $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]); - } - $link = ($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link; // InnoDB supports non-UNIQUE keys - if (count($foreign_key["source"]) == 1) { - break; - } + if (preg_match('~blob|bytea|raw|file~', $field["type"]) && $val != "") { + $link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf; + } + if (!$link) { // link related items + foreach ((array) $foreign_keys[$key] as $foreign_key) { + if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) { + $link = ""; + foreach ($foreign_key["source"] as $i => $source) { + $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]); + } + $link = ($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link; // InnoDB supports non-UNIQUE keys + if (count($foreign_key["source"]) == 1) { + break; } } } - - if ($key == "COUNT(*)") { //! columns looking like functions - $link = ME . "select=" . urlencode($TABLE); - $i = 0; - foreach ((array) $_GET["where"] as $v) { - if (!array_key_exists($v["col"], $unique_array)) { - $link .= where_link($i++, $v["col"], $v["val"], $v["op"]); - } - } - foreach ($unique_array as $k => $v) { - $link .= where_link($i++, $k, $v); + } + if ($key == "COUNT(*)") { //! columns looking like functions + $link = ME . "select=" . urlencode($TABLE); + $i = 0; + foreach ((array) $_GET["where"] as $v) { + if (!array_key_exists($v["col"], $unique_array)) { + $link .= where_link($i++, $v["col"], $v["val"], $v["op"]); } } - - } - - if (!$link && ($link = $adminer->selectLink($row[$key], $field)) === null) { - if (is_mail($row[$key])) { - $link = "mailto:$row[$key]"; - } - if ($protocol = is_url($row[$key])) { - $link = ($protocol == "http" && $HTTPS - ? $row[$key] // HTTP links from HTTPS pages don't receive Referer automatically - : "$protocol://www.adminer.org/redirect/?url=" . urlencode($row[$key]) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5 - ); + foreach ($unique_array as $k => $v) { + $link .= where_link($i++, $k, $v); } } - + + $val = select_value($val, $link, $field, $text_length); $id = h("val[$unique_idf][" . bracket_escape($key) . "]"); $value = $_POST["val"][$unique_idf][bracket_escape($key)]; - $h_value = h($value !== null ? $value : $row[$key]); - $long = strpos($val, "..."); - $editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key]; + $editable = !is_array($row[$key]) && is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key]; $text = preg_match('~text|lob~', $field["type"]); - echo (($_GET["modify"] && $editable) || $value !== null - ? "" . ($text ? "" : "") - : "" . $adminer->selectVal($val, $link, $field) - ); + if (($_GET["modify"] && $editable) || $value !== null) { + $h_value = h($value !== null ? $value : $row[$key]); + echo "" . ($text ? "" : ""); + } else { + $long = strpos($val, "..."); + echo "$val"; + } } } diff --git a/adminer/static/default.css b/adminer/static/default.css index 2b531a69..d81c4f7f 100644 --- a/adminer/static/default.css +++ b/adminer/static/default.css @@ -9,6 +9,7 @@ h1 { font-size: 150%; margin: 0; padding: .8em 1em; border-bottom: 1px solid #99 h2 { font-size: 150%; margin: 0 0 20px -18px; padding: .8em 1em; border-bottom: 1px solid #000; color: #000; font-weight: normal; background: #ddf; } h3 { font-weight: normal; font-size: 130%; margin: 1em 0 0; } form { margin: 0; } +td table { width: 100%; margin: 0; } table { margin: 1em 20px 0 0; border: 0; border-top: 1px solid #999; border-left: 1px solid #999; font-size: 90%; } td, th { border: 0; border-right: 1px solid #999; border-bottom: 1px solid #999; padding: .2em .3em; } th { background: #eee; text-align: left; } diff --git a/todo.txt b/todo.txt index 0e30e42a..8f848d01 100644 --- a/todo.txt +++ b/todo.txt @@ -43,3 +43,10 @@ PDO_MSSQL and PDO_SQLSRV driver with seek Oracle: clob comparable with string + +SimpleDB: +Report invalid user or password +Report API calls instead of queries +Edit multi-value attributes +Select: clone +Update: delete + insert when changing itemName()