1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/12671] Possibility to use NOT LIKE expression

PHPBB3-12671
This commit is contained in:
Geolim4
2014-08-08 15:06:12 +02:00
parent f6da266109
commit 6b60153ab4
11 changed files with 137 additions and 0 deletions

View File

@@ -369,6 +369,17 @@ abstract class driver implements driver_interface
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
}
/**
* {@inheritDoc}
*/
function sql_not_like_expression($expression)
{
$expression = utf8_str_replace(array('_', '%'), array("\_", "\%"), $expression);
$expression = utf8_str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
return $this->_sql_like_expression('NOT LIKE \'' . $this->sql_escape($expression) . '\'');
}
/**
* {@inheritDoc}
*/

View File

@@ -418,6 +418,16 @@ interface driver_interface
*/
public function sql_like_expression($expression);
/**
* Correctly adjust NOT LIKE expression for special characters
* Some DBMS are handling them in a different way
*
* @param string $expression The expression to use. Every wildcard is
* escaped, except $this->any_char and $this->one_char
* @return string A SQL statement like: "NOT LIKE 'bertie_%'"
*/
public function sql_not_like_expression($expression);
/**
* Explain queries
*

View File

@@ -417,6 +417,14 @@ class factory implements driver_interface
return $this->get_driver()->sql_like_expression($expression);
}
/**
* {@inheritdoc}
*/
public function sql_not_like_expression($expression)
{
return $this->get_driver()->sql_not_like_expression($expression);
}
/**
* {@inheritdoc}
*/

View File

@@ -350,6 +350,15 @@ class mssql extends \phpbb\db\driver\driver
return $expression . " ESCAPE '\\'";
}
/**
* Build NOT LIKE expression
* @access private
*/
function _sql_not_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
/**
* return sql error array
* @access private

View File

@@ -51,6 +51,15 @@ abstract class mssql_base extends \phpbb\db\driver\driver
return $expression . " ESCAPE '\\'";
}
/**
* Build NOT LIKE expression
* @access private
*/
function _sql_not_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
/**
* Build db-specific query data
* @access private

View File

@@ -111,6 +111,15 @@ abstract class mysql_base extends \phpbb\db\driver\driver
return $expression;
}
/**
* Build NOT LIKE expression
* @access private
*/
function _sql_not_like_expression($expression)
{
return $expression;
}
/**
* Build db-specific query data
* @access private

View File

@@ -645,6 +645,15 @@ class oracle extends \phpbb\db\driver\driver
return $expression . " ESCAPE '\\'";
}
/**
* Build NOT LIKE expression
* @access private
*/
function _sql_not_like_expression($expression)
{
return $expression . " ESCAPE '\\'";
}
function _sql_custom_build($stage, $data)
{
return $data;

View File

@@ -370,6 +370,15 @@ class postgres extends \phpbb\db\driver\driver
return $expression;
}
/**
* Build NOT LIKE expression
* @access private
*/
function _sql_not_like_expression($expression)
{
return $expression;
}
/**
* {@inheritDoc}
*/

View File

@@ -287,6 +287,23 @@ class sqlite extends \phpbb\db\driver\driver
return 'GLOB \'' . $this->sql_escape($expression) . '\'';
}
/**
* {@inheritDoc}
*
* For SQLite an underscore is a not-known character... this may change with SQLite3
*/
function sql_not_like_expression($expression)
{
// Unlike LIKE, GLOB is case sensitive (unfortunatly). SQLite users need to live with it!
// We only catch * and ? here, not the character map possible on file globbing.
$expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
$expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
$expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
return 'GLOB \'' . $this->sql_escape($expression) . '\'';
}
/**
* return sql error array
* @access private