"; //
for easy styling
+ echo "";
+ echo "
\n";
+ }
+
+ /** Print text length box in select
+ * @param string result of selectLengthProcess()
+ * @return null
+ */
+ function selectLengthPrint($text_length) {
+ if (isset($text_length)) {
+ echo "
\n";
+ }
+ }
+
+ /** Print action box in select
+ * @return null
+ */
+ function selectActionPrint() {
+ echo "
\n";
+ }
+
+ /** Process columns box in select
+ * @param array selectable columns
+ * @return array (array(select_expressions), array(group_expressions))
+ */
+ function selectColumnsProcess($columns, $indexes) {
+ $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"], $this->functions) || in_array($val["fun"], $this->grouping)))) {
+ $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
+ if (!in_array($val["fun"], $this->grouping)) {
+ $group[] = $select[$key];
+ }
+ }
+ }
+ return array($select, $group);
+ }
+
+ /** Process search box in select
+ * @param array
+ * @param array
+ * @return array expressions to join by AND
+ */
+ function selectSearchProcess($indexes, $fields) {
+ global $dbh;
+ $return = array();
+ foreach ($indexes as $i => $index) {
+ if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
+ $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $dbh->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
+ }
+ }
+ foreach ((array) $_GET["where"] as $val) {
+ if (strlen("$val[col]$val[val]") && in_array($val["op"], $this->operators)) {
+ if ($val["op"] == "AGAINST") {
+ $return[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST (" . $dbh->quote($val["val"]) . " IN BOOLEAN MODE)";
+ } else {
+ $in = process_length($val["val"]);
+ $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $dbh->quote($val["val"])));
+ if (strlen($val["col"])) {
+ $return[] = idf_escape($val["col"]) . $cond;
+ } else {
+ // find anywhere
+ $cols = array();
+ foreach ($fields as $name => $field) {
+ if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
+ $cols[] = $name;
+ }
+ }
+ $return[] = ($cols ? "(" . implode("$cond OR ", array_map('idf_escape', $cols)) . "$cond)" : "0");
+ }
+ }
+ }
+ }
+ return $return;
+ }
+
+ /** Process order box in select
+ * @param array
+ * @param array result of selectColumnsProcess()
+ * @param array
+ * @return array expressions to join by comma
+ */
+ function selectOrderProcess($columns, $select, $indexes) {
+ $return = array();
+ foreach ((array) $_GET["order"] as $key => $val) {
+ if (isset($columns[$val]) || in_array($val, $select, true)) {
+ $return[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
+ }
+ }
+ return $return;
+ }
+
+ /** Process limit box in select
+ * @return string expression to use in LIMIT, will be escaped
+ */
+ function selectLimitProcess() {
+ return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
+ }
+
+ /** Process length box in select
+ * @return string number of characters to shorten texts, will be escaped
+ */
+ function selectLengthProcess() {
+ return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
+ }
+
/** Print extra text in the end of a select form
* @param array fields holding e-mails
* @return null
*/
- function selectExtraDisplay($emailFields) {
+ function selectExtraPrint($emailFields) {
}
/** Process extras in select form
diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php
index fb839941..3228b63f 100644
--- a/adminer/include/functions.inc.php
+++ b/adminer/include/functions.inc.php
@@ -1,4 +1,10 @@
", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
-if (eregi('^(MyISAM|Maria)$', $table_status["Engine"])) {
- $operators[] = "AGAINST";
-}
$fields = fields($_GET["select"]);
$rights = array(); // privilege => 0
$columns = array(); // selectable columns
@@ -22,10 +10,7 @@ foreach ($fields as $key => $field) {
if (isset($field["privileges"]["select"]) && strlen($name)) {
$columns[$key] = html_entity_decode(strip_tags($name));
if (ereg('text|blob', $field["type"])) {
- $text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
- }
- if (!$_GET["columns"]) {
- unset($primary[$key]);
+ $text_length = $adminer->selectLengthProcess();
}
}
$rights += $field["privileges"];
@@ -38,62 +23,27 @@ function apply_sql_function($function, $column) {
);
}
-$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 (!in_array($val["fun"], $grouping)) {
- $group[] = $select[$key];
- }
- if (!$val["fun"]) {
- unset($primary[$val["col"]]);
- }
- }
-}
-
-$where = array(); // where expressions - will be joined by AND
-foreach ($indexes as $i => $index) {
- if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
- $where[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $dbh->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
- }
-}
-foreach ((array) $_GET["where"] as $val) {
- if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
- if ($val["op"] == "AGAINST") {
- $where[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST (" . $dbh->quote($val["val"]) . " IN BOOLEAN MODE)";
- } else {
- $in = process_length($val["val"]);
- $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $dbh->quote($val["val"])));
- if (strlen($val["col"])) {
- $where[] = idf_escape($val["col"]) . $cond;
- } else {
- // find anywhere
- $cols = array();
- foreach ($fields as $name => $field) {
- if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
- $cols[] = $name;
- }
- }
- $where[] = ($cols ? "(" . implode("$cond OR ", array_map('idf_escape', $cols)) . "$cond)" : "0");
- }
- }
- }
-}
-
-$order = array(); // order expressions - will be joined by comma
-foreach ((array) $_GET["order"] as $key => $val) {
- if (isset($columns[$val]) || in_array($val, $select, true)) {
- $order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
- }
-}
-
-$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
+list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
+$where = $adminer->selectSearchProcess($indexes, $fields);
+$order = $adminer->selectOrderProcess($columns, $select, $indexes);
+$limit = $adminer->selectLimitProcess();
$from = ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "");
$group_by = ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "");
if ($_POST && !$error) {
$where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
+ $primary = null; // empty array means that all primary fields are selected
+ foreach ($indexes as $index) {
+ if ($index["type"] == "PRIMARY") {
+ $primary = ($select ? array_flip($index["columns"]) : array());
+ }
+ }
+ foreach ($select as $key => $val) {
+ $val = $_GET["columns"][$key];
+ if (!$val["fun"]) {
+ unset($primary[$val["col"]]);
+ }
+ }
if ($_POST["export"]) {
dump_headers($_GET["select"]);
dump_table($_GET["select"], "");
@@ -182,74 +132,17 @@ if (!$columns) {
echo "
" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".\n";
} else {
echo "