]> git.joonet.de Git - adminer.git/commitdiff
SimpleDB: Allow selecting arrays
authorJakub Vrana <jakub@vrana.cz>
Tue, 6 Aug 2013 21:55:56 +0000 (14:55 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 8 Aug 2013 20:52:04 +0000 (13:52 -0700)
adminer/drivers/simpledb.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
adminer/static/default.css
todo.txt

index 2b81afacc8f11c26743f7319836dde165e026136..6810a5ae63a6687a95bd6fdd8308e09b188a1d4b 100644 (file)
@@ -1,12 +1,4 @@
 <?php
-/* //!
-invalid user or password
-report API calls instead of queries
-multi-value attributes
-select: clone
-update: delete + insert when changing itemName()
-*/
-
 $drivers["simpledb"] = "SimpleDB";
 
 if (isset($_GET["simpledb"])) {
@@ -72,7 +64,13 @@ if (isset($_GET["simpledb"])) {
                                        }
                                        foreach ($item->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) {
index 8d8117ca68ec63418264244d5a22accf750727d0..5b42df9f7cf8d2941166867e19226bb25f9029ae 100644 (file)
@@ -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 .= "<tr>"
+                               . ($val != array_values($val) ? "<th>" . h($k) : "")
+                               . "<td>" . select_value($v, $link, $field, $text_length)
+                       ;
+               }
+               return "<table cellspacing='0'>$return</table>";
+       }
+       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 = "&nbsp;";
+               } 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
index 46be3c83834d78ee3751ffa71e2cc3c0a315d390..4e59429f0a0b2fabf8546d2f3054d99b332bf761 100644 (file)
@@ -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 = "&nbsp;";
-                                                       } 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]);
                                                                        }
-                                                               }
-                                                       }
-
-                                                       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"]);
+                                                                       $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;
                                                                        }
                                                                }
-                                                               foreach ($unique_array as $k => $v) {
-                                                                       $link .= where_link($i++, $k, $v);
-                                                               }
                                                        }
-
                                                }
-
-                                               if (!$link && ($link = $adminer->selectLink($row[$key], $field)) === null) {
-                                                       if (is_mail($row[$key])) {
-                                                               $link = "mailto:$row[$key]";
+                                               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 ($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, "<i>...</i>");
-                                               $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
-                                                       ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
-                                                       : "<td id='$id' onclick=\"selectClick(this, event, " . ($long ? 2 : ($text ? 1 : 0)) . ($editable ? "" : ", '" . h(lang('Use edit link to modify this value.')) . "'") . ");\">" . $adminer->selectVal($val, $link, $field)
-                                               );
+                                               if (($_GET["modify"] && $editable) || $value !== null) {
+                                                       $h_value = h($value !== null ? $value : $row[$key]);
+                                                       echo "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>");
+                                               } else {
+                                                       $long = strpos($val, "<i>...</i>");
+                                                       echo "<td id='$id' onclick=\"selectClick(this, event, " . ($long ? 2 : ($text ? 1 : 0)) . ($editable ? "" : ", '" . h(lang('Use edit link to modify this value.')) . "'") . ");\">$val";
+                                               }
                                        }
                                }
 
index 2b531a699bfd067bc77bc1c39f370e904024bee2..d81c4f7fb55e0de28308a40bb8c28c258fa2db3e 100644 (file)
@@ -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; }
index 0e30e42a30bbef47651f1e7a8ff2c5bbeedc9244..8f848d01e4917dfe1acc8a35858e862c5e11552c 100644 (file)
--- 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()