From c71f604327653bde3eea1b5d7150f5cc9c58a712 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 23:30:31 +0200 Subject: [ticket/10942] Add a comment why we cast to sql_case() PHPBB3-10942 --- phpBB/includes/db/mssql.php | 1 + phpBB/includes/db/mssql_odbc.php | 1 + phpBB/includes/db/mssqlnative.php | 1 + phpBB/includes/db/oracle.php | 1 + phpBB/includes/db/postgres.php | 1 + 5 files changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 0345e4f8f8..8888bb3939 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -96,6 +96,7 @@ class dbal_mssql extends dbal */ function sql_case($condition, $action_true, $action_false = false) { + // To ensure, that both expressions have the same type, we cast them to varchar manually $sql_case = 'CASE WHEN ' . $condition; $sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)'; $sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : ''; diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 07da14bd53..a14d6adb14 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -114,6 +114,7 @@ class dbal_mssql_odbc extends dbal */ function sql_case($condition, $action_true, $action_false = false) { + // To ensure, that both expressions have the same type, we cast them to varchar manually $sql_case = 'CASE WHEN ' . $condition; $sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)'; $sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : ''; diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 835b86f8c3..0001bc4ba7 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -262,6 +262,7 @@ class dbal_mssqlnative extends dbal */ function sql_case($condition, $action_true, $action_false = false) { + // To ensure, that both expressions have the same type, we cast them to varchar manually $sql_case = 'CASE WHEN ' . $condition; $sql_case .= ' THEN CAST(' . $action_true . ' AS VARCHAR)'; $sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS VARCHAR)' : ''; diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 9e08979bc1..dc405ab08a 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -94,6 +94,7 @@ class dbal_oracle extends dbal */ function sql_case($condition, $action_true, $action_false = false) { + // To ensure, that both expressions have the same type, we cast them to clob manually $sql_case = 'CASE WHEN ' . $condition; $sql_case .= ' THEN CAST(' . $action_true . ' AS clob)'; $sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS clob)' : ''; diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 1ceb0ed0a2..c3116601ae 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -159,6 +159,7 @@ class dbal_postgres extends dbal */ function sql_case($condition, $action_true, $action_false = false) { + // To ensure, that both expressions have the same type, we cast them to text manually $sql_case = 'CASE WHEN ' . $condition; $sql_case .= ' THEN CAST(' . $action_true . ' AS TEXT)'; $sql_case .= ($action_false !== false) ? ' ELSE CAST(' . $action_false . ' AS TEXT)' : ''; -- cgit v1.2.1