SimpleDB: Allow selecting arrays

This commit is contained in:
Jakub Vrana 2013-08-06 14:55:56 -07:00
parent 076a0a2634
commit 9ffca2f6e6
5 changed files with 95 additions and 65 deletions

View 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) {

View 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

View 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]);
}
$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, "<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";
}
}
}

View 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; }

View file

@ -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()