mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-29 06:38:52 +00:00
[ticket/10942] Add sql_conditional to dbal
PHPBB3-10942
This commit is contained in:
parent
419d6cd035
commit
71374078b9
1 changed files with 17 additions and 0 deletions
|
@ -283,6 +283,23 @@ class dbal
|
||||||
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
|
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Returns whether results of a query need to be buffered to run a transaction while iterating over them.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue