aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-06-20 01:50:00 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-06-20 01:50:00 +0200
commit71374078b969ab429f0efcdf99158c1d21b138b6 (patch)
tree41e0d68119e73bc4ebb44b5d827aa3ca4a67f86f
parent419d6cd0359ba07bd4b254a98282735a398faa7a (diff)
downloadforums-71374078b969ab429f0efcdf99158c1d21b138b6.tar
forums-71374078b969ab429f0efcdf99158c1d21b138b6.tar.gz
forums-71374078b969ab429f0efcdf99158c1d21b138b6.tar.bz2
forums-71374078b969ab429f0efcdf99158c1d21b138b6.tar.xz
forums-71374078b969ab429f0efcdf99158c1d21b138b6.zip
[ticket/10942] Add sql_conditional to dbal
PHPBB3-10942
-rw-r--r--phpBB/includes/db/dbal.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index cf54d455f7..bf0dc15fad 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -284,6 +284,23 @@ class dbal
}
/**
+ * Build a conditional SQL query
+ *
+ * @param string $condition The condition which must be true, to use action_true rather then action_else
+ * @param string $action_true SQL statement that is used, if the condition is true
+ * @param string $action_else SQL statement that is used, if the condition is false, optional
+ * @return string CASE expression including the condition and statements
+ */
+ function sql_conditional($condition, $action_true, $action_false = false)
+ {
+ $sql_condition = 'CASE WHEN ' . $condition;
+ $sql_condition .= ' THEN ' . $action_true;
+ $sql_condition .= ($action_false !== false) ? ' ELSE ' . $action_false : '';
+ $sql_condition .= ' END';
+ return $sql_condition;
+ }
+
+ /**
* Returns whether results of a query need to be buffered to run a transaction while iterating over them.
*
* @return bool Whether buffering is required.