From 643a86504a30f6b9fbe0f073bb03009b4fbd0f43 Mon Sep 17 00:00:00 2001 From: Andreas Fischer <bantu@phpbb.com> Date: Thu, 31 May 2012 11:44:41 +0200 Subject: [ticket/10751] Add sql_lower_text() to database abstraction layer. On MSSQL, LOWER() can only be called on bounded strings (i.e. varchar or char). So, in order to use it on a text column, we have to convert it to an appropriate type. We do so using the SUBSTRING function. PHPBB3-10751 --- phpBB/includes/db/dbal.php | 12 ++++++++++++ phpBB/includes/db/mssql.php | 8 ++++++++ phpBB/includes/db/mssql_odbc.php | 8 ++++++++ phpBB/includes/db/mssqlnative.php | 8 ++++++++ 4 files changed, 36 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 358df50402..9cc337955b 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -500,6 +500,18 @@ class dbal return $column_name . ' | ' . (1 << $bit) . (($compare) ? ' ' . $compare : ''); } + /** + * Run LOWER() on DB column of type text (i.e. neither varchar nor char). + * + * @param string $column_name The column name to use + * + * @return string A SQL statement like "LOWER($column_name)" + */ + function sql_lower_text($column_name) + { + return "LOWER($column_name)"; + } + /** * Run more than one insert statement. * diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 6899a73902..b7178593dc 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -332,6 +332,14 @@ class dbal_mssql extends dbal return str_replace(array("'", "\0"), array("''", ''), $msg); } + /** + * {@inheritDoc} + */ + function sql_lower_text($column_name) + { + return "LOWER(SUBSTRING($column_name, 1, DATALENGTH($column_name)))"; + } + /** * Build LIKE expression * @access private diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 34f7a87337..2ecc42cadf 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -310,6 +310,14 @@ class dbal_mssql_odbc extends dbal return str_replace(array("'", "\0"), array("''", ''), $msg); } + /** + * {@inheritDoc} + */ + function sql_lower_text($column_name) + { + return "LOWER(SUBSTRING($column_name, 1, DATALENGTH($column_name)))"; + } + /** * Build LIKE expression * @access private diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 92ac9b1fb9..c91cc188b0 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -492,6 +492,14 @@ class dbal_mssqlnative extends dbal return str_replace(array("'", "\0"), array("''", ''), $msg); } + /** + * {@inheritDoc} + */ + function sql_lower_text($column_name) + { + return "LOWER(SUBSTRING($column_name, 1, DATALENGTH($column_name)))"; + } + /** * Build LIKE expression * @access private -- cgit v1.2.1