diff --git a/lib/sqlparser/sqlparser.class.php b/lib/sqlparser/sqlparser.class.php index 7a7e3be8f0..f8fef2ebed 100644 --- a/lib/sqlparser/sqlparser.class.php +++ b/lib/sqlparser/sqlparser.class.php @@ -301,7 +301,7 @@ class sqlparser * @access public * @return object */ - public function getCondition($tableA = null, $columnA = null, $operator = '', $tableB = null, $columnB = null, $group = 1) + public function getCondition($tableA = null, $columnA = null, $operator = '', $tableB = null, $columnB = null, $group = 1, $quote = true) { if(is_array($tableA)) return call_user_func_array(array($this, 'getCondition'), $tableA); @@ -324,7 +324,7 @@ class sqlparser if(empty($tableB)) $columnB = $this->trimExpr($columnB, "'"); $exprA = empty($tableA) ? "`$columnA`" : "`$tableA`.`$columnA`"; - $exprB = empty($tableB) ? "'$columnB'" : "`$tableB`.`$columnB`"; + $exprB = empty($tableB) ? ($quote ? "'$columnB'" : "$columnB") : "`$tableB`.`$columnB`"; $operator = strtoupper($operator); $expr = "$exprA $operator $exprB"; diff --git a/module/bi/model.php b/module/bi/model.php index 0d8234e722..7848ae212b 100644 --- a/module/bi/model.php +++ b/module/bi/model.php @@ -1459,12 +1459,12 @@ class biModel extends model * @access public * @return object */ - public function getCondition(mixed $tableA = null, mixed $columnA = null, string $operator = '', mixed $tableB = null, mixed $columnB = null, int $group = 1): object + public function getCondition(mixed $tableA = null, mixed $columnA = null, string $operator = '', mixed $tableB = null, mixed $columnB = null, int $group = 1, bool $quote = true): object { $this->app->loadClass('sqlparser', true); $parser = new sqlparser(null); - return $parser->getCondition($tableA, $columnA, $operator, $tableB, $columnB, $group); + return $parser->getCondition($tableA, $columnA, $operator, $tableB, $columnB, $group, $quote); } /** diff --git a/module/bi/test/lib/bi.unittest.class.php b/module/bi/test/lib/bi.unittest.class.php index e20e5751a3..03c52abe33 100644 --- a/module/bi/test/lib/bi.unittest.class.php +++ b/module/bi/test/lib/bi.unittest.class.php @@ -60,9 +60,9 @@ class biTest * @access public * @return string */ - public function getConditionTest(mixed $tableA = null, mixed $columnA = null, string $operator = '', mixed $tableB = null, mixed $columnB = null, int $group = 1): string + public function getConditionTest(mixed $tableA = null, mixed $columnA = null, string $operator = '', mixed $tableB = null, mixed $columnB = null, int $group = 1, bool $quote = true): string { - $condition = $this->objectModel->getCondition($tableA, $columnA, $operator, $tableB, $columnB, $group); + $condition = $this->objectModel->getCondition($tableA, $columnA, $operator, $tableB, $columnB, $group, $quote); return $condition->build($condition); } diff --git a/module/bi/test/model/getcondition.php b/module/bi/test/model/getcondition.php index b69ea3dd98..f6370f5dc8 100755 --- a/module/bi/test/model/getcondition.php +++ b/module/bi/test/model/getcondition.php @@ -24,14 +24,14 @@ cid=1 */ $bi = new biTest(); -r($bi->getConditionTest(null, 'deleted', '=', null, "'0'")) && p('') && e("`deleted` = '0'"); // 测试 `deleted` = '0' -r($bi->getConditionTest('t1', 'deleted', '=', null, "'0'")) && p('') && e("`t1`.`deleted` = '0'"); // 测试 `t1`.`deleted` = '0' +r($bi->getConditionTest(null, 'deleted', '=', null, "0")) && p('') && e("`deleted` = '0'"); // 测试 `deleted` = '0' +r($bi->getConditionTest('t1', 'deleted', '=', null, "0")) && p('') && e("`t1`.`deleted` = '0'"); // 测试 `t1`.`deleted` = '0' r($bi->getConditionTest('t1', 'project', '=', 't2', 'id')) && p('') && e("`t1`.`project` = `t2`.`id`"); // 测试 `t1`.`project` = `t2`.`id` r($bi->getConditionTest('`t1`', '`project`', '=', 't2', 'id')) && p('') && e("`t1`.`project` = `t2`.`id`"); // 测试 `t1`.`project` = `t2`.`id` r($bi->getConditionTest('`t1`', '`project` ', '=', 't2', 'id')) && p('') && e("`t1`.`project` = `t2`.`id`"); // 测试 `t1`.`project` = `t2`.`id` -r($bi->getConditionTest('t1', 'type', 'in', null, "('sprint', 'stage', 'kanban')")) && p('') && e("`t1`.`type` IN ('sprint', 'stage', 'kanban')"); // 测试 `t1`.`type` IN ('sprint', 'stage', 'kanban') -r($bi->getConditionTest('t1', 'type', 'not in', null, "('sprint', 'stage', 'kanban')")) && p('') && e("`t1`.`type` NOT IN ('sprint', 'stage', 'kanban')"); // 测试 `t1`.`type` NOT IN ('sprint', 'stage', 'kanban') +r($bi->getConditionTest('t1', 'type', 'in', null, "('sprint', 'stage', 'kanban')", 1, false)) && p('') && e("`t1`.`type` IN ('sprint', 'stage', 'kanban')"); // 测试 `t1`.`type` IN ('sprint', 'stage', 'kanban') +r($bi->getConditionTest('t1', 'type', 'not in', null, "('sprint', 'stage', 'kanban')", 1, false)) && p('') && e("`t1`.`type` NOT IN ('sprint', 'stage', 'kanban')"); // 测试 `t1`.`type` NOT IN ('sprint', 'stage', 'kanban') -r($bi->getConditionTest('t1', 'name', 'is', null, 'not null')) && p('') && e("`t1`.`name` IS not null"); // 测试 `t1`.`name` IS not null -r($bi->getConditionTest('t1', 'name', 'is', null, 'null')) && p('') && e("`t1`.`name` IS null"); // 测试 `t1`.`name` IS not null`t1`.`name` IS null \ No newline at end of file +r($bi->getConditionTest('t1', 'name', 'is', null, 'not null', 1, false)) && p('') && e("`t1`.`name` IS not null"); // 测试 `t1`.`name` IS not null +r($bi->getConditionTest('t1', 'name', 'is', null, 'null', 1, false)) && p('') && e("`t1`.`name` IS null"); // 测试 `t1`.`name` IS not null`t1`.`name` IS null \ No newline at end of file