Skip to content

Commit

Permalink
Merge pull request #6188 from alikon/regexp
Browse files Browse the repository at this point in the history
PostgreSQL - SQL error when search for module
  • Loading branch information
Kubik-Rubik committed Mar 2, 2015
2 parents 10836d2 + 9c43ca4 commit 97c048b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
5 changes: 2 additions & 3 deletions administrator/components/com_modules/models/modules.php
Expand Up @@ -329,9 +329,8 @@ protected function getListQuery()
}
else
{
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
$search = $db->quote($escapedSearchString);
$query->where('(' . 'a.title REGEXP ' . $search . ' OR a.note REGEXP ' . $search . ')');
$search = $db->quote('%' . strtolower($search) . '%');
$query->where('(' . ' LOWER(a.title) LIKE ' . $search . ' OR LOWER(a.note) LIKE ' . $search . ')');
}
}

Expand Down
5 changes: 2 additions & 3 deletions administrator/components/com_templates/models/styles.php
Expand Up @@ -152,9 +152,8 @@ protected function getListQuery()
}
else
{
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
$search = $db->quote($escapedSearchString);
$query->where('(' . 'a.template REGEXP ' . $search . ' OR a.title REGEXP ' . $search . ')');
$search = $db->quote('%' . strtolower($search) . '%');
$query->where('(' . ' LOWER(a.template) LIKE ' . $search . ' OR LOWER(a.title) LIKE ' . $search . ')');
}
}

Expand Down
5 changes: 2 additions & 3 deletions administrator/components/com_templates/models/templates.php
Expand Up @@ -110,9 +110,8 @@ protected function getListQuery()
}
else
{
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
$search = $db->quote($escapedSearchString);
$query->where('(' . 'a.element REGEXP ' . $search . ' OR a.name REGEXP ' . $search . ')');
$search = $db->quote('%' . strtolower($search) . '%');
$query->where('(' . ' LOWER(a.element) LIKE ' . $search . ' OR LOWER(a.name) LIKE ' . $search . ')');
}
}

Expand Down
19 changes: 19 additions & 0 deletions libraries/joomla/database/query/mysqli.php
Expand Up @@ -101,4 +101,23 @@ public function setLimit($limit = 0, $offset = 0)

return $this;
}

/**
* Return correct regexp operator for mysqli.
*
* Ensure that the regexp operator is mysqli compatible.
*
* Usage:
* $query->where('field ' . $query->regexp($search));
*
* @param string $value The regex pattern.
*
* @return string Returns the regex operator.
*
* @since 11.3
*/
public function regexp($value)
{
return ' REGEXP ' . $value;
}
}
19 changes: 19 additions & 0 deletions libraries/joomla/database/query/postgresql.php
Expand Up @@ -619,4 +619,23 @@ public function dateAdd($date, $interval, $datePart)
return "timestamp '" . $date . "' - interval '" . ltrim($interval, '-') . " " . $datePart . "'";
}
}

/**
* Return correct regexp operator for Postgresql.
*
* Ensure that the regexp operator is Postgresql compatible.
*
* Usage:
* $query->where('field ' . $query->regexp($search));
*
* @param string $value The regex pattern.
*
* @return string Returns the regex operator.
*
* @since 11.3
*/
public function regexp($value)
{
return ' ~* ' . $value;
}
}

0 comments on commit 97c048b

Please sign in to comment.