[submodule "jush"]
path = externals/jush
- url = git://jush.git.sourceforge.net/gitroot/jush/jush
+ url = git://git.code.sf.net/p/jush/git
[submodule "tinymce"]
path = externals/tinymce
url = git://github.com/tinymce/tinymce.git
}
$name = trim($row["name"]);
- queries_redirect(ME . "table=" . urlencode($name), $message, alter_table(
+ queries_redirect(ME . (support("table") ? "table=" : "select=") . urlencode($name), $message, alter_table(
$TABLE,
$name,
($jush == "sqlite" && ($use_all_fields || $foreign) ? $all_fields : $fields),
<form action="" method="post" id="form">
<p>
+<?php if (support("table") || $TABLE == "") { ?>
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>" autocapitalize="off">
<?php if ($TABLE == "" && !$_POST) { ?><script type='text/javascript'>focus(document.getElementById('form')['name']);</script><?php } ?>
<?php echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?>
<?php echo ($collations && !ereg("sqlite|mssql", $jush) ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
<input type="submit" value="<?php echo lang('Save'); ?>" formnovalidate>
+<?php } ?>
+
+<?php if (support("table")) { ?>
<table cellspacing="0" id="edit-fields" class="nowrap">
<?php
$comments = ($_POST ? $_POST["comments"] : $row["Comment"] != "");
; ?>
<p>
<input type="submit" value="<?php echo lang('Save'); ?>" formnovalidate>
+<?php } ?>
+
<?php if ($TABLE != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?> formnovalidate><?php } ?>
<?php
if (support("partitioning")) {
foreach ($tables_list as $name => $type) {
$view = ($type !== null && !eregi("table", $type));
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
- echo '<th><a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>';
+ echo '<th>' . (support("table") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
if ($view) {
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . lang('View') . '</a>';
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
"Auto_increment" => array("auto_increment=1&create", lang('Alter table')),
"Rows" => array("select", lang('Select data')),
) as $key => $link) {
- echo ($link ? "<td align='right'><a href='" . h(ME . "$link[0]=") . urlencode($name) . "' id='$key-" . h($name) . "' title='$link[1]'>?</a>" : "<td id='$key-" . h($name) . "'> ");
+ $id = " id='$key-" . h($name) . "'";
+ echo ($link ? "<td align='right'>" . (support("table") || $key == "Rows"
+ ? "<a href='" . h(ME . "$link[0]=") . urlencode($name) . "'$id title='$link[1]'>?</a>"
+ : "<span$id>?</span>"
+ ) : "<td id='$key-" . h($name) . "'> ");
}
}
echo (support("comment") ? "<td id='Comment-" . h($name) . "'> " : "");
echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
if (!information_schema(DB)) {
- echo "<p>" . (ereg('^(sql|sqlite|pgsql)$', $jush)
- ? ($jush != "sqlite" ? "<input type='submit' value='" . lang('Analyze') . "'> " : "")
- . "<input type='submit' name='optimize' value='" . lang('Optimize') . "'> " : ""
- ) . ($jush == "sql" ? "<input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)") . ">\n";
+ echo "<p>"
+ . (ereg('^(sql|sqlite|pgsql)$', $jush) ? ($jush != "sqlite" ? "<input type='submit' value='" . lang('Analyze') . "'> " : "") . "<input type='submit' name='optimize' value='" . lang('Optimize') . "'> " : "")
+ . ($jush == "sql" ? "<input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "")
+ . (support("table") ? "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> " : "")
+ . "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)") . ">\n";
$databases = (support("scheme") ? schemas() : $adminer->databases());
if (count($databases) != 1 && $jush != "sqlite") {
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
}
function support($feature) {
- return ereg('^(scheme|trigger|view|drop_col)$', $feature); //! routine|
+ return ereg('^(database|table|scheme|trigger|view|drop_col)$', $feature); //! routine|
}
$jush = "mssql";
}
/** Check whether a feature is supported
- * @param string "comment", "copy", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "trigger", "type", "variables", "view"
+ * @param string "comment", "copy", "database", "drop_col", "dump", "event", "kill", "partitioning", "privileges", "procedure", "processlist", "routine", "scheme", "sequence", "status", "table", "trigger", "type", "variables", "view"
* @return bool
*/
function support($feature) {
}
function support($feature) {
- return ereg("view|scheme|processlist|drop_col|variables|status", $feature); //!
+ return ereg("database|table|view|scheme|processlist|drop_col|variables|status", $feature); //!
}
$jush = "oracle";
}
function support($feature) {
- return ereg('^(comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
+ return ereg('^(database|table|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
}
$jush = "pgsql";
--- /dev/null
+<?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"])) {
+ $possible_drivers = array("SimpleXML");
+ define("DRIVER", "simpledb");
+
+ if (class_exists('SimpleXMLElement')) {
+ class Min_DB {
+ var $extension = "SimpleXML", $server_info = '2009-04-15', $error, $timeout, $next, $_result;
+
+ function select_db($database) {
+ return ($database == "domain");
+ }
+
+ function query($query, $unbuffered = false) {
+ $params = array('SelectExpression' => $query, 'ConsistentRead' => 'true');
+ if ($this->next) {
+ $params['NextToken'] = $this->next;
+ }
+ $result = sdb_request_all('Select', 'Item', $params, $this->timeout); //! respect $unbuffered
+ if ($result === false) {
+ return $result;
+ }
+ if (preg_match('~^\s*SELECT\s+COUNT\(~i', $query)) {
+ $sum = 0;
+ foreach ($result as $item) {
+ $sum += $item->Attribute->Value;
+ }
+ $result = array((object) array('Attribute' => array((object) array(
+ 'Name' => 'Count',
+ 'Value' => $sum,
+ ))));
+ }
+ return new Min_Result($result);
+ }
+
+ function multi_query($query) {
+ return $this->_result = $this->query($query);
+ }
+
+ function store_result() {
+ return $this->_result;
+ }
+
+ function next_result() {
+ return false;
+ }
+
+ function quote($string) {
+ return "'" . str_replace("'", "''", $string) . "'";
+ }
+
+ }
+
+ class Min_Result {
+ var $num_rows, $_rows = array(), $_offset = 0;
+
+ function Min_Result($result) {
+ foreach ($result as $item) {
+ $row = array();
+ if ($item->Name != '') { // SELECT COUNT(*)
+ $row['itemName()'] = (string) $item->Name;
+ }
+ foreach ($item->Attribute as $attribute) {
+ $name = $this->_processValue($attribute->Name);
+ $row[$name] .= ($row[$name] != '' ? ',' : '') . $this->_processValue($attribute->Value);
+ }
+ $this->_rows[] = $row;
+ foreach ($row as $key => $val) {
+ if (!isset($this->_rows[0][$key])) {
+ $this->_rows[0][$key] = null;
+ }
+ }
+ }
+ $this->num_rows = count($this->_rows);
+ }
+
+ function _processValue($element) {
+ return (is_object($element) && $element['encoding'] == 'base64' ? base64_decode($element) : (string) $element);
+ }
+
+ function fetch_assoc() {
+ $row = current($this->_rows);
+ if (!$row) {
+ return $row;
+ }
+ $return = array();
+ foreach ($this->_rows[0] as $key => $val) {
+ $return[$key] = $row[$key];
+ }
+ next($this->_rows);
+ return $return;
+ }
+
+ function fetch_row() {
+ $return = $this->fetch_assoc();
+ if (!$return) {
+ return $return;
+ }
+ return array_values($return);
+ }
+
+ function fetch_field() {
+ $keys = array_keys($this->_rows[0]);
+ return (object) array('name' => $keys[$this->_offset++]);
+ }
+
+ }
+ }
+
+
+
+ class Min_Driver {
+
+ function _chunkRequest($ids, $action, $params, $expand = array()) {
+ foreach (array_chunk($ids, 25) as $chunk) {
+ $params2 = $params;
+ foreach ($chunk as $i => $id) {
+ $params2["Item.$i.ItemName"] = $id;
+ foreach ($expand as $key => $val) {
+ $params2["Item.$i.$key"] = $val;
+ }
+ }
+ if (!sdb_request($action, $params2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function _extractIds($queryWhere, $limit) {
+ $return = array();
+ if (preg_match_all("~itemName\(\) = ('[^']*+')+~", $queryWhere, $matches)) {
+ $return = array_map('idf_unescape', $matches[1]);
+ } else {
+ foreach (sdb_request_all('Select', 'Item', array('SelectExpression' => 'SELECT itemName() FROM ' . table($table) . $queryWhere . ($limit ? " LIMIT 1" : ""))) as $item) {
+ $return[] = $item->Name;
+ }
+ }
+ return $return;
+ }
+
+ function delete($table, $queryWhere, $limit = 0) {
+ return $this->_chunkRequest(
+ $this->_extractIds($queryWhere, $limit),
+ 'BatchDeleteAttributes',
+ array('DomainName' => $table)
+ );
+ }
+
+ function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
+ $delete = array();
+ $insert = array();
+ $i = 0;
+ foreach ($set as $key => $val) {
+ $key = idf_unescape($key);
+ if ($val == "NULL") {
+ $delete["Attribute." . count($delete) . ".Name"] = $key;
+ } elseif ($key != "itemName()") {
+ $insert["Attribute.$i.Name"] = $key;
+ $insert["Attribute.$i.Value"] = idf_unescape($val);
+ $insert["Attribute.$i.Replace"] = "true";
+ $i++;
+ }
+ }
+ $ids = $this->_extractIds($queryWhere, $limit);
+ $params = array('DomainName' => $table);
+ return (!$insert || $this->_chunkRequest($ids, 'BatchPutAttributes', $params, $insert))
+ && (!$delete || $this->_chunkRequest($ids, 'BatchDeleteAttributes', $params, $delete))
+ ;
+ }
+
+ function insert($table, $set) {
+ $params = array("DomainName" => $table);
+ $i = 0;
+ foreach ($set as $name => $value) {
+ if ($value != "NULL") {
+ $name = idf_unescape($name);
+ $value = idf_unescape($value);
+ if ($name == "itemName()") {
+ $params["ItemName"] = $value;
+ } else {
+ $params["Attribute.$i.Name"] = $name;
+ $params["Attribute.$i.Value"] = $value;
+ $i++;
+ }
+ }
+ }
+ return sdb_request('PutAttributes', $params);
+ }
+
+ }
+
+
+
+ function connect() {
+ return new Min_DB;
+ }
+
+ function support($feature) {
+ return false;
+ }
+
+ function logged_user() {
+ global $adminer;
+ $credentials = $adminer->credentials();
+ return $credentials[1];
+ }
+
+ function get_databases() {
+ return array("domain");
+ }
+
+ function collations() {
+ return array();
+ }
+
+ function db_collation($db, $collations) {
+ }
+
+ function tables_list() {
+ global $connection;
+ $return = array();
+ foreach (sdb_request_all('ListDomains', 'DomainName') as $table) {
+ $return[(string) $table] = 'table';
+ }
+ if ($connection->error && defined("PAGE_HEADER")) {
+ echo "<p class='error'>" . error() . "\n";
+ }
+ return $return;
+ }
+
+ function table_status($name = "", $fast = false) {
+ $return = array();
+ foreach (($name != "" ? array($name => true) : tables_list()) as $table => $type) {
+ $row = array("Name" => $table, "Auto_increment" => "");
+ if (!$fast) {
+ $meta = sdb_request('DomainMetadata', array('DomainName' => $table));
+ if ($meta) {
+ foreach (array(
+ "Rows" => "ItemCount",
+ "Data_length" => "ItemNamesSizeBytes",
+ "Index_length" => "AttributeValuesSizeBytes",
+ "Data_free" => "AttributeNamesSizeBytes",
+ ) as $key => $val) {
+ $row[$key] = (string) $meta->$val;
+ }
+ }
+ }
+ if ($name != "") {
+ return $row;
+ }
+ $return[$table] = $row;
+ }
+ return $return;
+ }
+
+ function explain($connection, $query) {
+ }
+
+ function error() {
+ global $connection;
+ return h($connection->error);
+ }
+
+ function information_schema() {
+ }
+
+ function is_view($table_status) {
+ }
+
+ function indexes($table, $connection2 = null) {
+ return array(
+ array("type" => "PRIMARY", "columns" => array("itemName()")),
+ );
+ }
+
+ function fields($table) {
+ return array();
+ }
+
+ function foreign_keys($table) {
+ return array();
+ }
+
+ function table($idf) {
+ return idf_escape($idf);
+ }
+
+ function idf_escape($idf) {
+ return "`" . str_replace("`", "``", $idf) . "`";
+ }
+
+ function limit($query, $where, $limit, $offset = 0, $separator = " ") {
+ return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" : "");
+ }
+
+ function unconvert_field($field, $return) {
+ return $return;
+ }
+
+ function fk_support($table_status) {
+ return false;
+ }
+
+ function engines() {
+ return array();
+ }
+
+ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
+ return ($table == "" && sdb_request('CreateDomain', array('DomainName' => $name)));
+ }
+
+ function drop_tables($tables) {
+ foreach ($tables as $table) {
+ if (!sdb_request('DeleteDomain', array('DomainName' => $table))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function count_tables($databases) {
+ foreach ($databases as $db) {
+ return array($db => count(tables_list()));
+ }
+ }
+
+ function found_rows($table_status, $where) {
+ return ($where ? null : $table_status["Rows"]);
+ }
+
+ function last_id() {
+ }
+
+ function hmac($algo, $data, $key, $raw_output = false) {
+ // can use hash_hmac() since PHP 5.1.2
+ $blocksize = 64;
+ if (strlen($key) > $blocksize) {
+ $key = pack("H*", $algo($key));
+ }
+ $key = str_pad($key, $blocksize, "\0");
+ $k_ipad = $key ^ str_repeat("\x36", $blocksize);
+ $k_opad = $key ^ str_repeat("\x5C", $blocksize);
+ $return = $algo($k_opad . pack("H*", $algo($k_ipad . $data)));
+ if ($raw_output) {
+ $return = pack("H*", $return);
+ }
+ return $return;
+ }
+
+ function sdb_request($action, $params = array()) {
+ global $adminer, $connection;
+ list($host, $params['AWSAccessKeyId'], $secret) = $adminer->credentials();
+ $params['Action'] = $action;
+ $params['Timestamp'] = gmdate('Y-m-d\TH:i:s+00:00');
+ $params['Version'] = '2009-04-15';
+ $params['SignatureVersion'] = 2;
+ $params['SignatureMethod'] = 'HmacSHA1';
+ ksort($params);
+ $query = '';
+ foreach ($params as $key => $val) {
+ $query .= '&' . rawurlencode($key) . '=' . rawurlencode($val);
+ }
+ $query = str_replace('%7E', '~', substr($query, 1));
+ $query .= "&Signature=" . urlencode(base64_encode(hmac('sha1', "POST\n" . ereg_replace('^https?://', '', $host) . "\n/\n$query", $secret, true)));
+ @ini_set('track_errors', 1); // @ - may be disabled
+ $file = @file_get_contents((ereg('^https?://', $host) ? $host : "http://$host"), false, stream_context_create(array('http' => array(
+ 'method' => 'POST', // may not fit in URL with GET
+ 'content' => $query,
+ 'ignore_errors' => 1, // available since PHP 5.2.10
+ ))));
+ if (!$file || !($xml = simplexml_load_string($file))) {
+ $connection->error = $php_errormsg;
+ return false;
+ }
+ if ($xml->Errors) {
+ $error = $xml->Errors->Error;
+ $connection->error = "$error->Message ($error->Code)";
+ return false;
+ }
+ $connection->error = '';
+ $tag = $action . "Result";
+ return ($xml->$tag ? $xml->$tag : true);
+ }
+
+ function sdb_request_all($action, $tag, $params = array(), $timeout = 0) {
+ $return = array();
+ $start = ($timeout ? microtime(true) : 0);
+ $limit = (preg_match('~LIMIT\s+(\d+)\s*$~i', $params['SelectExpression'], $match) ? $match[1] : 0);
+ do {
+ $xml = sdb_request($action, $params);
+ if (!$xml) {
+ break;
+ }
+ foreach ($xml->$tag as $element) {
+ $return[] = $element;
+ }
+ if ($limit && count($return) >= $limit) {
+ $_GET["next"] = $xml->NextToken;
+ break;
+ }
+ if ($timeout && microtime(true) - $start > $timeout) {
+ return false;
+ }
+ $params['NextToken'] = $xml->NextToken;
+ if ($limit) {
+ $params['SelectExpression'] = preg_replace('~\d+\s*$~', $limit - count($return), $params['SelectExpression']);
+ }
+ } while ($xml->NextToken);
+ return $return;
+ }
+
+ $jush = "simpledb";
+ $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL");
+ $functions = array();
+ $grouping = array("count");
+ $edit_functions = array();
+}
}
function support($feature) {
- return ereg('^(view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
+ return ereg('^(database|table|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
}
$jush = "sqlite";
$unique_array = unique_array($_GET["where"], $indexes);
$query_where = "\nWHERE $where";
+ if (!support("table")) {
+ foreach ($_POST["field_keys"] as $key => $val) {
+ if ($val != "") {
+ $_POST["fields"][bracket_escape($val)] = $_POST["field_vals"][$key];
+ }
+ }
+ foreach ($_POST["fields"] as $key => $val) {
+ $name = bracket_escape($key, 1); // 1 - back
+ $fields[$name] = array("field" => $name);
+ if (isset($_POST["function"][$key])) {
+ $fields[$name]["null"] = true;
+ }
+ }
+ }
+
if (isset($_POST["delete"])) {
queries_redirect(
$location,
foreach ($fields as $name => $field) {
$val = process_input($field);
if ($val !== false && $val !== null) {
- $set[idf_escape($name)] = ($update ? "\n" . idf_escape($name) . " = $val" : $val);
+ $set[idf_escape($name)] = $val;
}
}
}
}
$row = array();
+ if (!support("table")) {
+ $select = array("*");
+ }
if ($select) {
$rows = get_rows("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
$row = (isset($_GET["select"]) && count($rows) != 1 ? null : reset($rows));
}
}
+if (!support("table") && !$fields) {
+ if (!$where) { // insert
+ $row = reset(get_rows("SELECT * FROM " . table($TABLE) . " LIMIT 1"));
+ if (!$row) {
+ $row = array("itemName()" => "");
+ }
+ }
+ if ($row) {
+ foreach ($row as $key => $val) {
+ if (!$_POST["save"] && !$where) {
+ $row[$key] = null;
+ }
+ $fields[$key] = array("field" => $key, "null" => ($key != "itemName()"));
+ }
+ }
+}
+
if ($row === false) {
echo "<p class='error'>" . lang('No rows.') . "\n";
}
echo "\n";
}
+ if (!support("table")) {
+ echo "<tr><th><input name='field_keys[]'><td class='function'> <td><input name='field_vals[]'>";
+ }
+
echo "</table>\n";
}
?>
*/
function selectLinks($tableStatus, $set = "") {
echo '<p class="links">';
- $links = array("select" => lang('Select data'), "table" => lang('Show structure'));
- if (is_view($tableStatus)) {
- $links["view"] = lang('Alter view');
- } else {
- $links["create"] = lang('Alter table');
+ $links = array("select" => lang('Select data'));
+ if (support("table")) {
+ $links["table"] = lang('Show structure');
+ if (is_view($tableStatus)) {
+ $links["view"] = lang('Alter view');
+ } else {
+ $links["create"] = lang('Alter table');
+ }
}
if ($set !== null) {
$links["edit"] = lang('New item');
global $functions, $grouping;
print_fieldset("select", lang('Select'), $select);
$i = 0;
- $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
+ $fun_group = array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping));
foreach ($select as $key => $val) {
$val = $_GET["columns"][$key];
echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
- echo "(<select name='columns[$i][col]' onchange='selectFieldChange(this.form);'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
+ echo "(" . select_input(" name='columns[$i][col]' onchange='selectFieldChange(this.form);'", $columns, $val["col"]) . ")</div>\n";
$i++;
}
echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
- echo "(<select name='columns[$i][col]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>)</div>\n";
+ echo "(" . select_input(" name='columns[$i][col]' onchange='selectAddRow(this);'", $columns) . ")</div>\n";
echo "</div></fieldset>\n";
}
for ($i = 0; $i <= count($_GET["where"]); $i++) {
list(, $val) = each($_GET["where"]);
if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
- echo "<div><select name='where[$i][col]' onchange='$change_next'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
+ echo "<div>" . select_input(" name='where[$i][col]' onchange='$change_next'", $columns, $val["col"], "(" . lang('anywhere') . ")");
echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next);
echo "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "' onchange='" . ($val ? "selectFieldChange(this.form)" : "selectAddRow(this)") . ";' onsearch='selectSearchSearch(this);'></div>\n";
}
print_fieldset("sort", lang('Sort'), $order);
$i = 0;
foreach ((array) $_GET["order"] as $key => $val) {
- if (isset($columns[$val])) {
- echo "<div><select name='order[$i]' onchange='selectFieldChange(this.form);'><option>" . optionlist($columns, $val, true) . "</select>";
+ if ($val != "") {
+ echo "<div>" . select_input(" name='order[$i]' onchange='selectFieldChange(this.form);'", $columns, $val);
echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
$i++;
}
}
- echo "<div><select name='order[$i]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>";
+ echo "<div>" . select_input(" name='order[$i]' onchange='selectAddRow(this);'", $columns);
echo checkbox("desc[$i]", 1, false, lang('descending')) . "</div>\n";
echo "</div></fieldset>\n";
}
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach ((array) $_GET["columns"] as $key => $val) {
- if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
- $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
+ if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
+ $select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*"));
if (!in_array($val["fun"], $grouping)) {
$group[] = $select[$key];
}
function selectOrderProcess($fields, $indexes) {
$return = array();
foreach ((array) $_GET["order"] as $key => $val) {
- if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val)) { //! MS SQL uses []
- $return[] = (isset($fields[$val]) ? idf_escape($val) : $val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
+ if ($val != "") {
+ $return[] = (preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val) ? $val : idf_escape($val)) //! MS SQL uses []
+ . (isset($_GET["desc"][$key]) ? " DESC" : "")
+ ;
}
}
return $return;
* @return bool whether to print default homepage
*/
function homepage() {
- echo '<p class="links">' . ($_GET["ns"] == "" ? '<a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n" : "");
+ echo '<p class="links">' . ($_GET["ns"] == "" && support("database") ? '<a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n" : "");
echo (support("scheme") ? "<a href='" . h(ME) . "scheme='>" . ($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema')) . "</a>\n" : "");
echo ($_GET["ns"] !== "" ? '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n" : "");
echo (support("privileges") ? "<a href='" . h(ME) . "privileges='>" . lang('Privileges') . "</a>\n" : "");
$links[] = preg_quote($table, '/');
}
echo "<script type='text/javascript'>\n";
- echo "var jushLinks = { $jush: [ '" . js_escape(ME) . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
+ echo "var jushLinks = { $jush: [ '" . js_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
echo "jushLinks.$val = jushLinks.$jush;\n";
}
echo "<p id='tables' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
foreach ($tables as $table => $status) {
echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '"' . bold($_GET["select"] == $table || $_GET["edit"] == $table) . ">" . lang('select') . "</a> ";
- echo '<a href="' . h(ME) . 'table=' . urlencode($table) . '"' . bold(in_array($table, array($_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"]))) . " title='" . lang('Show structure') . "'>" . $this->tableName($status) . "</a><br>\n";
+ $name = $this->tableName($status);
+ echo (support("table")
+ ? '<a href="' . h(ME) . 'table=' . urlencode($table) . '"' . bold(in_array($table, array($_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"]))) . " title='" . lang('Show structure') . "'>$name</a>"
+ : $name
+ ) . "<br>\n";
}
}
include "../adminer/drivers/pgsql.inc.php";
include "../adminer/drivers/oracle.inc.php";
include "../adminer/drivers/mssql.inc.php";
+include "../adminer/drivers/simpledb.inc.php";
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost
}
page_header(lang('Select database'), $error, false);
- echo "<p class='links'><a href='" . h(ME) . "database='>" . lang('Create new database') . "</a>\n";
+ echo "<p class='links'>\n";
foreach (array(
+ 'database' => lang('Create new database'),
'privileges' => lang('Privileges'),
'processlist' => lang('Process list'),
'variables' => lang('Variables'),
$collations = collations();
echo "<form action='' method='post'>\n";
echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
- echo "<thead><tr><td> <th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
+ echo "<thead><tr>" . (support("database") ? "<td> " : "") . "<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
foreach ($databases as $db) {
$root = h(ME) . "db=" . urlencode($db);
- echo "<tr" . odd() . "><td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"]));
+ echo "<tr" . odd() . ">" . (support("database") ? "<td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"])) : "");
echo "<th><a href='$root'>" . h($db) . "</a>";
- echo "<td><a href='$root" . ($scheme ? "&ns=" : "") . "&database=' title='" . lang('Alter database') . "'>" . nbsp(db_collation($db, $collations)) . "</a>";
+ $collation = nbsp(db_collation($db, $collations));
+ echo "<td>" . (support("database") ? "<a href='$root" . ($scheme ? "&ns=" : "") . "&database=' title='" . lang('Alter database') . "'>$collation</a>" : $collation);
echo "<td align='right'><a href='$root&schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>?</a>";
echo "\n";
}
echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
- echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)") . ">\n";
+ echo "<p>" . (support("database") ? "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)") . ">\n" : "");
echo "<input type='hidden' name='token' value='$token'>\n";
echo $refresh;
echo "</form>\n";
/** Update data in table
* @param string
- * @param array
+ * @param array escaped columns in keys, quoted data in values
* @param string " WHERE ..."
* @param int 0 or 1
+ * @param string
* @return bool
*/
- function update($table, $set, $queryWhere, $limit = 0) {
- $query = table($table) . " SET" . implode(",", $set);
+ function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
+ $values = array();
+ foreach ($set as $key => $val) {
+ $values[] = "$key = $val";
+ }
+ $query = table($table) . " SET$separator" . implode(",$separator", $values);
return queries("UPDATE" . ($limit ? limit1($query, $queryWhere) : " $query$queryWhere"));
}
/** Insert data into table
* @param string
- * @param array
+ * @param array escaped columns in keys, quoted data in values
* @return bool
*/
function insert($table, $set) {
- return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
+ return queries("INSERT INTO " . table($table) . ($set
+ ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"
+ : "DEFAULT VALUES"
+ ));
}
/** Insert or update data in table
return $return;
}
+/** Generate HTML <select> or <input> if $options are empty
+ * @param string
+ * @param array
+ * @param string
+ * @param string
+ * @return string
+ */
+function select_input($attrs, $options, $value = "", $placeholder = "") {
+ return ($options
+ ? "<select$attrs><option value=''>$placeholder" . optionlist($options, $value, true) . "</select>"
+ : "<input$attrs value='" . h($value) . "' placeholder='$placeholder'>"
+ );
+}
+
/** Get onclick confirmation
* @param string JavaScript expression
* @return string
/** Get keys from first column and values from second
* @param string
* @param Min_DB
+* @param float
* @return array
*/
-function get_key_vals($query, $connection2 = null) {
+function get_key_vals($query, $connection2 = null, $timeout = 0) {
global $connection;
if (!is_object($connection2)) {
$connection2 = $connection;
}
$return = array();
+ $connection2->timeout = $timeout;
$result = $connection2->query($query);
+ $connection2->timeout = 0;
if (is_object($result)) {
while ($row = $result->fetch_row()) {
$return[$row[0]] = $row[1];
function where($where, $fields = array()) {
global $jush;
$return = array();
- $function_pattern = '(^[\w\(]+' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . '\)+$)'; //! columns looking like functions
+ $function_pattern = '(^[\w\(]+(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')?\)+$)'; //! columns looking like functions
foreach ((array) $where["where"] as $key => $val) {
$key = bracket_escape($key, 1); // 1 - back
$column = (preg_match($function_pattern, $key) ? $key : idf_escape($key)); //! SQL injection
* @return string
*/
function pagination($page, $current) {
- return " " . ($page == $current ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
+ return " " . ($page == $current
+ ? $page + 1
+ : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" . ($_GET["next"] ? "&next=" . urlencode($_GET["next"]) : "") : "")) . '">' . ($page + 1) . "</a>"
+ );
}
/** Get file contents from $_FILES
function slow_query($query) {
global $adminer, $token;
$db = $adminer->database();
+ $timeout = $adminer->queryTimeout();
if (support("kill") && is_object($connection2 = connect()) && ($db == "" || $connection2->select_db($db))) {
$kill = $connection2->result("SELECT CONNECTION_ID()"); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
?>
var timeout = setTimeout(function () {
ajax('<?php echo js_escape(ME); ?>script=kill', function () {
}, 'token=<?php echo $token; ?>&kill=<?php echo $kill; ?>');
-}, <?php echo 1000 * $adminer->queryTimeout(); ?>);
+}, <?php echo 1000 * $timeout; ?>);
</script>
<?php
} else {
}
ob_flush();
flush();
- $return = @get_key_vals($query, $connection2); // @ - may be killed
+ $return = @get_key_vals($query, $connection2, $timeout); // @ - may be killed
if ($connection2) {
echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
ob_flush();
if (!$_POST["delete"]) {
foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
$val = process_input($fields[$name]);
- if ($val !== null) {
- if ($_POST["clone"]) {
- $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
- } elseif ($val !== false) {
- $set[] = "\n" . idf_escape($name) . " = $val";
- }
+ if ($val !== null && ($_POST["clone"] || $val !== false)) {
+ $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
}
}
}
$set = array();
foreach ($row as $key => $val) {
$key = bracket_escape($key, 1); // 1 - back
- $set[] = " " . idf_escape($key) . " = " . (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
+ $set[idf_escape($key)] = (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
}
$result = $driver->update(
$TABLE,
$set,
" WHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($unique_idf, $fields),
- !($is_group || $unselected === array())
+ !($is_group || $unselected === array()),
+ " "
);
if (!$result) {
break;
}
$set = null;
-if (isset($rights["insert"])) {
+if (isset($rights["insert"]) || !support("table")) {
$set = "";
foreach ((array) $_GET["where"] as $val) {
if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
}
$adminer->selectLinks($table_status, $set);
-if (!$columns) {
+if (!$columns && support("table")) {
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
} else {
echo "<form action='' id='form'>\n";
}
echo $adminer->selectQuery($query);
+ $connection->next = $_GET["next"];
$result = $connection->query($query);
+ $connection->next = 0;
if (!$result) {
echo "<p class='error'>" . error() . "\n";
} else {
if ($key != $oid) {
$val = $_GET["columns"][key($select)];
$field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
- $name = ($field ? $adminer->fieldName($field, $rank) : "*");
+ $name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : $key));
if ($name != "") {
$rank++;
$names[$key] = $name;
$desc = "&desc%5B0%5D=1";
echo '<th onmouseover="columnMouse(this);" onmouseout="columnMouse(this, \' hidden\');">';
echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
- echo (!$select || $val ? apply_sql_function($val["fun"], $name) : h(current($select))) . "</a>"; //! columns looking like functions
+ echo apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
echo "<span class='column hidden'>";
echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
if (!$val["fun"]) {
? $page + (count($rows) >= $limit ? 2 : 1)
: floor(($found_rows - 1) / $limit)
);
- echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
- echo pagination(0, $page) . ($page > 5 ? " ..." : "");
- for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
- echo pagination($i, $page);
- }
- if ($max_page > 0) {
- echo ($page + 5 < $max_page ? " ..." : "");
- echo ($exact_count && $found_rows !== false
- ? pagination($max_page, $page)
- : " <a href='" . h(remove_from_uri("page") . "&page=last") . "' title='~$max_page'>" . lang('last') . "</a>"
+ if (support("table")) {
+ echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
+ echo pagination(0, $page) . ($page > 5 ? " ..." : "");
+ for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
+ echo pagination($i, $page);
+ }
+ if ($max_page > 0) {
+ echo ($page + 5 < $max_page ? " ..." : "");
+ echo ($exact_count && $found_rows !== false
+ ? pagination($max_page, $page)
+ : " <a href='" . h(remove_from_uri("page") . "&page=last") . "' title='~$max_page'>" . lang('last') . "</a>"
+ );
+ }
+ echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit
+ ? ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore(this, ' . (+$limit) . ', \'' . lang('Loading') . '\');">' . lang('Load more data') . '</a>'
+ : ''
);
+ } else {
+ echo lang('Page') . ":";
+ echo pagination(0, $page) . ($page > 1 ? " ..." : "");
+ echo ($page ? pagination($page, $page) : "");
+ echo ($max_page > $page ? pagination($page + 1, $page) . ($max_page > $page + 1 ? " ..." : "") : "");
}
- echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit ? ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore(this, ' . (+$limit) . ', \'' . lang('Loading') . '\');">' . lang('Load more data') . '</a>' : '');
}
echo "<p>\n";
}
/** Get value of select
-* @param HTMLSelectElement
+* @param HTMLElement <select> or <input>
* @return string
*/
function selectValue(select) {
+ if (!select.selectedIndex) {
+ return select.value;
+ }
var selected = select.options[select.selectedIndex];
return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
}
selects[i].selectedIndex = 0;
}
var inputs = row.getElementsByTagName('input');
- if (inputs.length) {
- inputs[0].name = inputs[0].name.replace(/[a-z]\[\d+/, '$&1');
- inputs[0].value = '';
- inputs[0].className = '';
+ for (var i=0; i < inputs.length; i++) {
+ inputs[i].name = inputs[i].name.replace(/[a-z]\[\d+/, '$&1');
+ inputs[i].value = '';
+ inputs[i].className = '';
}
field.parentNode.parentNode.appendChild(row);
}
-Adminer 3.7.2-dev:
+Adminer 4.0.0-dev:
+Driver for SimpleDB
Save and continue edit by AJAX
Add a new column in alter table on key press
Mark length as required for strings
-Subproject commit e19e1fbd00de59d58c9ac0552f5048389ab5a9ff
+Subproject commit 85b6e1e9734eb01ebf4364d7f4ffdd18a8545d4d