diff options
author | brunoais <brunoaiss@gmail.com> | 2015-02-24 23:03:11 +0000 |
---|---|---|
committer | brunoais <brunoaiss@gmail.com> | 2015-03-16 11:13:49 +0000 |
commit | 5c77e4381945300ba9a1086b99fac12ae48c52a8 (patch) | |
tree | e5b93c79cc8799adb6c3021d5a18b7cc125bf5ad /phpBB/phpbb/db/driver/driver.php | |
parent | 24f26478c4bf20799ea610cd672a96af818a1be6 (diff) | |
download | forums-5c77e4381945300ba9a1086b99fac12ae48c52a8.tar forums-5c77e4381945300ba9a1086b99fac12ae48c52a8.tar.gz forums-5c77e4381945300ba9a1086b99fac12ae48c52a8.tar.bz2 forums-5c77e4381945300ba9a1086b99fac12ae48c52a8.tar.xz forums-5c77e4381945300ba9a1086b99fac12ae48c52a8.zip |
[feature/sql-bool-builder] First working version
PHPBB3-13652
Diffstat (limited to 'phpBB/phpbb/db/driver/driver.php')
-rw-r--r-- | phpBB/phpbb/db/driver/driver.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index 8d360fc3e2..5822adceab 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -792,6 +792,98 @@ abstract class driver implements driver_interface return $sql; } + + + protected function _process_boolean_tree_first($operations_ary) + { + if ($operations_ary[0] !== 'AND' && + $operations_ary[0] !== 'OR') + { + $operations_ary = array('AND', $operations_ary); + } + return $this->_process_boolean_tree($operations_ary) . "\n"; + } + + protected function _process_boolean_tree($operations_ary) + { + $operation = array_shift($operations_ary); + + foreach ($operations_ary AS &$condition) + { + switch ($condition[0]) + { + case 'AND': + case 'OR': + + $condition = ' ( ' . $this->_process_boolean_tree($condition) . ') '; + + break; + case 'NOT': + + $condition = ' NOT ' . $this->_process_boolean_tree($condition); + + break; + + default: + + switch (sizeof($condition)) + { + case 3: + + // Typical 3 element clause with {left hand} {operator} {right hand} + switch ($condition[1]) + { + case 'IN': + case 'NOT_IN': + + // As this is used with an IN, assume it is a set of elements for sql_in_set() + $condition = $this->sql_in_set($condition[0], $condition[2], $condition[1] === 'NOT_IN', true); + + break; + + default: + + $condition = implode(' ', $condition); + + break; + } + + break; + + case 5: + + // Subquery with {left hand} {operator} {compare kind} {SELECT Kind } {Sub Query} + + $condition = $condition[0] . ' ' . $condition[1] . ' ' . $condition[2] . ' ( '; + $condition .= $this->sql_build_query($condition[3], $condition[4]); + $condition .= ' )'; + + break; + + default: + // This is an unpredicted clause setup. Just join all elements. + $condition = implode(' ', $condition); + + break; + } + + break; + } + + } + + if($operation === 'NOT') + { + $operations_ary = implode("", $operations_ary); + } + else + { + $operations_ary = implode(" \n $operation ", $operations_ary); + } + + return $operations_ary; + } + /** * {@inheritDoc} |