diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php
index 409ee29209..4491730f63 100644
--- a/libraries/TableSearch.class.php
+++ b/libraries/TableSearch.class.php
@@ -1362,40 +1362,81 @@ EOT;
}
}
$htmlOutput .= '';
+
+ $htmlOutput .= '
' . PMA_Util::getCheckbox('useRegex' , __('Use regular expression'), false, false);
return $htmlOutput;
}
/**
- * Returns HTML for previewing strings found and their replacements
+ * Finds and returns Regex pattern and their replacements
*
* @param int $columnIndex index of the column
* @param string $find string to find in the column
* @param string $replaceWith string to replace with
* @param string $charSet character set of the connection
*
- * @return string HTML for previewing strings found and their replacements
+ * @return array Array containing original values, replcaed values and count
*/
- function getReplacePreview($columnIndex, $find, $replaceWith, $charSet)
+ function _getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet)
{
$column = $this->_columnNames[$columnIndex];
$sql_query = "SELECT "
. PMA_Util::backquote($column) . ","
- . " REPLACE("
- . PMA_Util::backquote($column) . ", '" . $find . "', '" . $replaceWith
- . "'),"
+ . " 1," // to add an extra column that will have replaced value
. " COUNT(*)"
. " FROM " . PMA_Util::backquote($this->_db)
. "." . PMA_Util::backquote($this->_table)
. " WHERE " . PMA_Util::backquote($column)
- . " LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin"; // here we
+ . " RLIKE '" . PMA_Util::sqlAddSlashes($find) . "' COLLATE " . $charSet . "_bin"; // here we
// change the collation of the 2nd operand to a case sensitive
// binary collation to make sure that the comparison is case sensitive
$sql_query .= " GROUP BY " . PMA_Util::backquote($column)
. " ORDER BY " . PMA_Util::backquote($column) . " ASC";
- $resultSet = $GLOBALS['dbi']->query(
- $sql_query, null, PMA_DatabaseInterface::QUERY_STORE
- );
+ $result = $GLOBALS['dbi']->fetchResult($sql_query, 0);
+
+ if (is_array($result)) {
+ foreach ($result as $index=>$row) {
+ $result[$index][1] = preg_replace("/" . $find . "/" , $replaceWith, $row[0]);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Returns HTML for previewing strings found and their replacements
+ *
+ * @param int $columnIndex index of the column
+ * @param string $find string to find in the column
+ * @param string $replaceWith string to replace with
+ * @param boolean $useRegex to use Regex replace or not
+ * @param string $charSet character set of the connection
+ *
+ * @return string HTML for previewing strings found and their replacements
+ */
+ function getReplacePreview($columnIndex, $find, $replaceWith, $useRegex, $charSet)
+ {
+ $column = $this->_columnNames[$columnIndex];
+ if( $useRegex ) {
+ $result = $this->_getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet);
+ } else {
+ $sql_query = "SELECT "
+ . PMA_Util::backquote($column) . ","
+ . " REPLACE("
+ . PMA_Util::backquote($column) . ", '" . $find . "', '" . $replaceWith
+ . "'),"
+ . " COUNT(*)"
+ . " FROM " . PMA_Util::backquote($this->_db)
+ . "." . PMA_Util::backquote($this->_table)
+ . " WHERE " . PMA_Util::backquote($column)
+ . " LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin"; // here we
+ // change the collation of the 2nd operand to a case sensitive
+ // binary collation to make sure that the comparison is case sensitive
+ $sql_query .= " GROUP BY " . PMA_Util::backquote($column)
+ . " ORDER BY " . PMA_Util::backquote($column) . " ASC";
+
+ $result = $GLOBALS['dbi']->fetchResult($sql_query, 0);
+ }
$htmlOutput = '