Skip to content

Commit

Permalink
PostgreSQL: Cast to string when searching using LIKE (bug vrana#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Feb 6, 2018
1 parent 197abdc commit d7f9b6b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion adminer/drivers/mysql.inc.php
Expand Up @@ -277,7 +277,7 @@ function insertUpdate($table, $rows, $primary) {
return queries($prefix . implode(",\n", $values) . $suffix);
}

function convertSearch($idf, $field) {
function convertSearch($idf, $val, $field) {
return (preg_match('~char|text|enum|set~', $field["type"]) && !preg_match("~^utf8~", $field["collation"])
? "CONVERT($idf USING " . charset($this->_conn) . ")"
: $idf
Expand Down
7 changes: 7 additions & 0 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -181,6 +181,13 @@ function insertUpdate($table, $rows, $primary) {
return true;
}

function convertSearch($idf, $val, $field) {
return (preg_match('~char|text' . (is_numeric($val["val"]) && !preg_match('~LIKE~', $val["op"]) ? '|' . number_type() : '') . '~', $field["type"])
? $idf
: "CAST($idf AS text)"
);
}

function warnings() {
return $this->_conn->warnings();
}
Expand Down
4 changes: 2 additions & 2 deletions adminer/include/adminer.inc.php
Expand Up @@ -534,15 +534,15 @@ function selectSearchProcess($fields, $indexes) {
$cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
}
if ($val["col"] != "") {
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $fields[$val["col"]]) . $cond;
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond;
} else {
// find anywhere
$cols = array();
foreach ($fields as $name => $field) {
if ((is_numeric($val["val"]) || !preg_match('~' . number_type() . '|bit~', $field["type"]))
&& (!preg_match("~[\x80-\xFF]~", $val["val"]) || preg_match('~char|text|enum|set~', $field["type"]))
) {
$cols[] = $prefix . $driver->convertSearch(idf_escape($name), $field) . $cond;
$cols[] = $prefix . $driver->convertSearch(idf_escape($name), $val, $field) . $cond;
}
}
$return[] = ($cols ? "(" . implode(" OR ", $cols) . ")" : "1 = 0");
Expand Down
5 changes: 3 additions & 2 deletions adminer/include/driver.inc.php
Expand Up @@ -114,11 +114,12 @@ function rollback() {
}

/** Convert column to be searchable
* @param string escaped name
* @param string escaped column name
* @param array array("op" => , "val" => )
* @param array
* @return string
*/
function convertSearch($idf, $field) {
function convertSearch($idf, $val, $field) {
return $idf;
}

Expand Down
1 change: 1 addition & 0 deletions changes.txt
@@ -1,6 +1,7 @@
Adminer 4.6.1-dev:
MySQL: Support non-utf8 charset in search in column
MySQL: Support geometry in MySQL 8 (bug #574)
PostgreSQL: Cast to string when searching using LIKE (bug #325)
PostgreSQL: Don't treat interval type as number (bug #474)
PostgreSQL: Fix condition for selecting no rows

Expand Down

0 comments on commit d7f9b6b

Please sign in to comment.