mirror of
https://github.com/vrana/adminer.git
synced 2025-08-16 11:34:10 +02:00
Select columns, aggregation
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@437 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -41,6 +41,8 @@ if (isset($_GET["download"])) {
|
|||||||
$unsigned = array("", "unsigned", "zerofill", "unsigned zerofill");
|
$unsigned = array("", "unsigned", "zerofill", "unsigned zerofill");
|
||||||
$enum_length = '\'(?:\'\'|[^\'\\\\]+|\\\\.)*\'|"(?:""|[^"\\\\]+|\\\\.)*"';
|
$enum_length = '\'(?:\'\'|[^\'\\\\]+|\\\\.)*\'|"(?:""|[^"\\\\]+|\\\\.)*"';
|
||||||
$inout = array("IN", "OUT", "INOUT");
|
$inout = array("IN", "OUT", "INOUT");
|
||||||
|
$functions = array("char_length", "from_unixtime", "hex", "lower", "round", "sec_to_time", "time_to_sec", "unix_timestamp", "upper");
|
||||||
|
$grouping = array("avg", "count", "distinct", "group_concat", "max", "min", "sum");
|
||||||
|
|
||||||
$error = "";
|
$error = "";
|
||||||
if (isset($_GET["table"])) {
|
if (isset($_GET["table"])) {
|
||||||
|
@@ -154,7 +154,7 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => array('Byl smazán %d záznam.', 'Byly smazány %d záznamy.', 'Bylo smazáno %d záznamů.'),
|
'%d item(s) have been deleted.' => array('Byl smazán %d záznam.', 'Byly smazány %d záznamy.', 'Bylo smazáno %d záznamů.'),
|
||||||
'all' => 'vše',
|
'all' => 'vše',
|
||||||
'Delete selected' => 'Smazat označené',
|
'Delete selected' => 'Smazat označené',
|
||||||
'Truncate table' => 'Promazat tabulku',
|
'Truncate result' => 'Promazat výsledek',
|
||||||
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".',
|
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".',
|
||||||
'Logged as: %s' => 'Přihlášen jako: %s',
|
'Logged as: %s' => 'Přihlášen jako: %s',
|
||||||
'Move up' => 'Přesunout nahoru',
|
'Move up' => 'Přesunout nahoru',
|
||||||
|
@@ -152,7 +152,6 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => array('%d Artikel gelöscht.', '%d Artikel gelöscht.'),
|
'%d item(s) have been deleted.' => array('%d Artikel gelöscht.', '%d Artikel gelöscht.'),
|
||||||
'all' => 'alle',
|
'all' => 'alle',
|
||||||
'Delete selected' => 'Markierte löschen',
|
'Delete selected' => 'Markierte löschen',
|
||||||
'Truncate table' => 'Tabelleninhalt löschen (truncate)',
|
|
||||||
'MySQL version: %s through PHP extension %s' => 'Version MySQL: %s, Zugriff unter Benutzung der PHP-Erweiterung %s',
|
'MySQL version: %s through PHP extension %s' => 'Version MySQL: %s, Zugriff unter Benutzung der PHP-Erweiterung %s',
|
||||||
'around %d row(s)' => array('ungefähren %d Datensatz', 'ungefähren %d Datensätze'),
|
'around %d row(s)' => array('ungefähren %d Datensatz', 'ungefähren %d Datensätze'),
|
||||||
'Logged as: %s' => 'Angemeldet als: %s',
|
'Logged as: %s' => 'Angemeldet als: %s',
|
||||||
|
@@ -152,7 +152,6 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => array('%d item eliminado.', '%d itemes eliminados.'),
|
'%d item(s) have been deleted.' => array('%d item eliminado.', '%d itemes eliminados.'),
|
||||||
'all' => 'todos',
|
'all' => 'todos',
|
||||||
'Delete selected' => 'Eliminar seleccionados',
|
'Delete selected' => 'Eliminar seleccionados',
|
||||||
'Truncate table' => 'Vaciar tabla (truncate)',
|
|
||||||
'MySQL version: %s through PHP extension %s' => 'Versión MySQL: %s a través de extensión PHP %s',
|
'MySQL version: %s through PHP extension %s' => 'Versión MySQL: %s a través de extensión PHP %s',
|
||||||
'around %d row(s)' => array('acaso %d fila', 'acaso %d filas'),
|
'around %d row(s)' => array('acaso %d fila', 'acaso %d filas'),
|
||||||
'Logged as: %s' => 'Logeado como: %s',
|
'Logged as: %s' => 'Logeado como: %s',
|
||||||
|
@@ -154,7 +154,6 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => array('%d item werd verwijderd.', '%d items warden verwijderd.'),
|
'%d item(s) have been deleted.' => array('%d item werd verwijderd.', '%d items warden verwijderd.'),
|
||||||
'all' => 'alle',
|
'all' => 'alle',
|
||||||
'Delete selected' => 'Geselecteerde verwijderen',
|
'Delete selected' => 'Geselecteerde verwijderen',
|
||||||
'Truncate table' => 'Tabel leegmaken',
|
|
||||||
'Logged as: %s' => 'Aangemeld als: %s',
|
'Logged as: %s' => 'Aangemeld als: %s',
|
||||||
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'POST-data is te groot. Verklein de hoeveelheid data of verhoog de "post_max_size" configuratie.',
|
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'POST-data is te groot. Verklein de hoeveelheid data of verhoog de "post_max_size" configuratie.',
|
||||||
'Move up' => 'Omhoog',
|
'Move up' => 'Omhoog',
|
||||||
|
@@ -154,7 +154,6 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => array('%d záznam bol zmazaný.', '%d záznamy boli zmazané.', '%d záznamov bolo zmazaných.'),
|
'%d item(s) have been deleted.' => array('%d záznam bol zmazaný.', '%d záznamy boli zmazané.', '%d záznamov bolo zmazaných.'),
|
||||||
'all' => 'všetko',
|
'all' => 'všetko',
|
||||||
'Delete selected' => 'Zmazať označené',
|
'Delete selected' => 'Zmazať označené',
|
||||||
'Truncate table' => 'Vyprázdniť tabuľku',
|
|
||||||
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Príliš veľké POST dáta. Zmenšite dáta alebo zvýšte hodnotu konfiguračej direktívy "post_max_size".',
|
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Príliš veľké POST dáta. Zmenšite dáta alebo zvýšte hodnotu konfiguračej direktívy "post_max_size".',
|
||||||
'Logged as: %s' => 'Prihlásený ako: %s',
|
'Logged as: %s' => 'Prihlásený ako: %s',
|
||||||
'Move up' => 'Presunúť hore',
|
'Move up' => 'Presunúť hore',
|
||||||
|
@@ -154,7 +154,6 @@ $translations = array(
|
|||||||
'%d item(s) have been deleted.' => '%d 个项目被删除',
|
'%d item(s) have been deleted.' => '%d 个项目被删除',
|
||||||
'all' => '全部',
|
'all' => '全部',
|
||||||
'Delete selected' => '删除选中',
|
'Delete selected' => '删除选中',
|
||||||
'Truncate table' => '截断表',
|
|
||||||
'Logged as: %s' => '登录为: %s',
|
'Logged as: %s' => '登录为: %s',
|
||||||
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => '太大的 POST 数据. 减少数据或者增加 "post_max_size" 配置指令.',
|
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => '太大的 POST 数据. 减少数据或者增加 "post_max_size" 配置指令.',
|
||||||
'Move up' => '上移',
|
'Move up' => '上移',
|
||||||
|
@@ -19,6 +19,16 @@ foreach ($fields as $key => $field) {
|
|||||||
$rights += $field["privileges"];
|
$rights += $field["privileges"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$select = array();
|
||||||
|
$group = array();
|
||||||
|
foreach ((array) $_GET["columns"] as $key => $val) {
|
||||||
|
if ($val["fun"] == "count" || (in_array($val["col"], $columns, true) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
|
||||||
|
$select[$key] = (in_array($val["col"], $columns, true) ? (!$val["fun"] ? idf_escape($val["col"]) : ($val["fun"] == "distinct" ? "COUNT(DISTINCT " : strtoupper("$val[fun](")) . idf_escape($val["col"]) . ")") : "COUNT(*)");
|
||||||
|
if (!in_array($val["fun"], $grouping)) {
|
||||||
|
$group[] = $select[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$where = array();
|
$where = array();
|
||||||
foreach ($indexes as $i => $index) {
|
foreach ($indexes as $i => $index) {
|
||||||
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
|
if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
|
||||||
@@ -39,12 +49,12 @@ foreach ((array) $_GET["where"] as $val) {
|
|||||||
}
|
}
|
||||||
$order = array();
|
$order = array();
|
||||||
foreach ((array) $_GET["order"] as $key => $val) {
|
foreach ((array) $_GET["order"] as $key => $val) {
|
||||||
if (in_array($val, $columns, true)) {
|
if (in_array($val, $columns, true)) { //! respect functions
|
||||||
$order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
|
$order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
|
$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
|
||||||
$from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
|
$from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
|
||||||
|
|
||||||
if ($_POST && !$error) {
|
if ($_POST && !$error) {
|
||||||
$result = true;
|
$result = true;
|
||||||
@@ -93,14 +103,46 @@ if (isset($rights["insert"])) {
|
|||||||
if (!$columns) {
|
if (!$columns) {
|
||||||
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($mysql->error)) . ".</p>\n";
|
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($mysql->error)) . ".</p>\n";
|
||||||
} else {
|
} else {
|
||||||
echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\n";
|
echo "<form action='' id='form'>\n";
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function add_row(field) {
|
||||||
|
var row = field.parentNode.cloneNode(true);
|
||||||
|
var selects = row.getElementsByTagName('select');
|
||||||
|
for (var i=0; i < selects.length; i++) {
|
||||||
|
selects[i].name = selects[i].name.replace(/[a-z]\[[0-9]+/, '$&1');
|
||||||
|
selects[i].selectedIndex = 0;
|
||||||
|
}
|
||||||
|
var inputs = row.getElementsByTagName('input');
|
||||||
|
if (inputs.length) {
|
||||||
|
inputs[0].name = inputs[0].name.replace(/[a-z]\[[0-9]+/, '$&1');
|
||||||
|
inputs[0].value = '';
|
||||||
|
}
|
||||||
|
field.parentNode.parentNode.appendChild(row);
|
||||||
|
field.onchange = function () { };
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
echo "<fieldset><legend>" . lang('Select') . "</legend>\n";
|
||||||
if (strlen($_GET["server"])) {
|
if (strlen($_GET["server"])) {
|
||||||
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
|
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
|
||||||
}
|
}
|
||||||
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
|
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
|
||||||
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
|
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
$i = 0;
|
||||||
|
$fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
|
||||||
|
foreach ($select as $key => $val) {
|
||||||
|
$val = $_GET["columns"][$key];
|
||||||
|
echo "<div><select name='columns[$i][fun]'><option></option>" . optionlist($fun_group, $val["fun"]) . "</select>";
|
||||||
|
echo "<select name='columns[$i][col]'><option></option>" . optionlist($columns, $val["col"]) . "</select></div>\n";
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
echo "<div><select name='columns[$i][fun]' onchange='this.nextSibling.onchange();'><option></option>" . optionlist($fun_group) . "</select>";
|
||||||
|
echo "<select name='columns[$i][col]' onchange='add_row(this);'><option></option>" . optionlist($columns) . "</select></div>\n";
|
||||||
|
echo "</fieldset>\n";
|
||||||
|
|
||||||
|
echo "<fieldset><legend>" . lang('Search') . "</legend>\n";
|
||||||
foreach ($indexes as $i => $index) {
|
foreach ($indexes as $i => $index) {
|
||||||
if ($index["type"] == "FULLTEXT") {
|
if ($index["type"] == "FULLTEXT") {
|
||||||
echo "(<i>" . implode("</i>, <i>", array_map('htmlspecialchars', $index["columns"])) . "</i>) AGAINST";
|
echo "(<i>" . implode("</i>, <i>", array_map('htmlspecialchars', $index["columns"])) . "</i>) AGAINST";
|
||||||
@@ -128,20 +170,6 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
|
|||||||
document.getElementById('form')['where[' + i + '][op]'].onchange();
|
document.getElementById('form')['where[' + i + '][op]'].onchange();
|
||||||
}
|
}
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
function add_row(field) {
|
|
||||||
var row = field.parentNode.cloneNode(true);
|
|
||||||
var selects = row.getElementsByTagName('select');
|
|
||||||
for (var i=0; i < selects.length; i++) {
|
|
||||||
selects[i].name = selects[i].name.replace(/[a-z]\[[0-9]+/, '$&1');
|
|
||||||
selects[i].selectedIndex = 0;
|
|
||||||
}
|
|
||||||
var input = row.getElementsByTagName('input')[0];
|
|
||||||
input.name = input.name.replace(/[a-z]\[[0-9]+/, '$&1');
|
|
||||||
input.value = '';
|
|
||||||
field.parentNode.parentNode.appendChild(row);
|
|
||||||
field.onchange = function () { };
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
echo "<div><select name='where[$i][col]' onchange='add_row(this);'><option></option>" . optionlist($columns) . "</select>";
|
echo "<div><select name='where[$i][col]' onchange='add_row(this);'><option></option>" . optionlist($columns) . "</select>";
|
||||||
@@ -176,7 +204,7 @@ function add_row(field) {
|
|||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
echo "<div style='clear: left;'> </div>\n";
|
echo "<div style='clear: left;'> </div>\n";
|
||||||
|
|
||||||
$result = $mysql->query("SELECT * $from");
|
$result = $mysql->query("SELECT " . ($select ? (count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) : "*") . " $from");
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
echo "<p class='error'>" . htmlspecialchars($mysql->error) . "</p>\n";
|
echo "<p class='error'>" . htmlspecialchars($mysql->error) . "</p>\n";
|
||||||
} else {
|
} else {
|
||||||
@@ -194,14 +222,14 @@ function add_row(field) {
|
|||||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
||||||
for ($j=0; $row = $result->fetch_assoc(); $j++) {
|
for ($j=0; $row = $result->fetch_assoc(); $j++) {
|
||||||
if (!$j) {
|
if (!$j) {
|
||||||
echo '<thead><tr><td><label><input type="checkbox" name="delete_selected" value="1" onclick="var elems = this.form.elements; for (var i=0; i < elems.length; i++) if (elems[i].name == \'delete[]\') elems[i].checked = this.checked;" />' . lang('all') . '</label></td>';
|
echo '<thead><tr>' . (count($select) == count($group) ? '<td><label><input type="checkbox" name="delete_selected" value="1" onclick="var elems = this.form.elements; for (var i=0; i < elems.length; i++) if (elems[i].name == \'delete[]\') elems[i].checked = this.checked;" />' . lang('all') . '</label></td>' : '');
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
echo '<th><a href="' . remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . htmlspecialchars($key) . ($_GET["order"][0] === $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '') . '">' . htmlspecialchars($key) . "</a></th>";
|
echo '<th><a href="' . remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . htmlspecialchars($key) . ($_GET["order"][0] === $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '') . '">' . htmlspecialchars($key) . "</a></th>";
|
||||||
}
|
}
|
||||||
echo "</tr></thead>\n";
|
echo "</tr></thead>\n";
|
||||||
}
|
}
|
||||||
$unique_idf = implode('&', unique_idf($row, $indexes));
|
$unique_idf = implode('&', unique_idf($row, $indexes));
|
||||||
echo '<tr><td><input type="checkbox" name="delete[]" value="' . $unique_idf . '" /> <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('edit') . "</a></td>";
|
echo '<tr>' . (count($select) == count($group) ? '<td><input type="checkbox" name="delete[]" value="' . $unique_idf . '" /> <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('edit') . '</a></td>' : '');
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
if (!isset($val)) {
|
if (!isset($val)) {
|
||||||
$val = "<i>NULL</i>";
|
$val = "<i>NULL</i>";
|
||||||
@@ -234,9 +262,9 @@ function add_row(field) {
|
|||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
echo "<p><input type='hidden' name='token' value='$token' /><input type='submit' value='" . lang('Delete selected') . "' /> <input type='submit' name='truncate' value='" . lang('Truncate table') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\" /></p>\n";
|
echo "<p><input type='hidden' name='token' value='$token' />" . (count($group) == count($select) ? "<input type='submit' value='" . lang('Delete selected') . "' /> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate result') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\" /></p>\n";
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
if (intval($limit) && ($found_rows = $mysql->result($mysql->query("SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")))) > $limit) {
|
if (intval($limit) && ($found_rows = $mysql->result($mysql->query(count($group) < count($select) ? " SELECT FOUND_ROWS()" : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")))) > $limit) {
|
||||||
$max_page = floor(($found_rows - 1) / $limit);
|
$max_page = floor(($found_rows - 1) / $limit);
|
||||||
echo "<p>" . lang('Page') . ":";
|
echo "<p>" . lang('Page') . ":";
|
||||||
print_page(0);
|
print_page(0);
|
||||||
|
Reference in New Issue
Block a user