diff --git a/tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php b/tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php index b5c8572..3c6e337 100644 --- a/tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php +++ b/tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php @@ -1029,7 +1029,11 @@ public function testSelectWithWhere000() { $schema = new MSSQLTestSchema(); $bulder = $schema->table('users')->select()->where('id', 66); $this->assertEquals('select * from [users] where [users].[id] = ?', $schema->getLastQuery()); - $bulder->getTable()->getSelect()->addWhere(new Expression('year(x)'), new Expression('in(300)')); + $bulder->getTable()->getSelect()->addWhere(new Expression('year(x) in(300)')); + $bulder->groupBy([ + 'first-name', + 'last-name' + ]); $this->assertEquals('select * from [users] where [users].[id] = ? and year(x) in(300) group by [users].[first_name], [users].[last_name]', $schema->getLastQuery()); } /** diff --git a/webfiori/database/Condition.php b/webfiori/database/Condition.php index aa059e0..0ffa767 100644 --- a/webfiori/database/Condition.php +++ b/webfiori/database/Condition.php @@ -59,9 +59,10 @@ class Condition { * * @since 1.0 */ - public function __construct($leftOperand, $rightOperand, string $condition) { + public function __construct($leftOperand, $rightOperand, string $condition = null) { $this->setLeftOperand($leftOperand); $this->setRightOperand($rightOperand); + $this->condition = ''; $this->setCondition($condition); } /** @@ -143,8 +144,8 @@ public function getRightOperand() { * * @since 1.0.2 */ - public function setCondition(string $cond) { - $conditionT = trim($cond); + public function setCondition(string $cond = null) { + $conditionT = trim($cond.''); if (strlen($conditionT) != 0) { $this->condition = $conditionT; diff --git a/webfiori/database/SelectExpression.php b/webfiori/database/SelectExpression.php index 71fe724..d6649b0 100644 --- a/webfiori/database/SelectExpression.php +++ b/webfiori/database/SelectExpression.php @@ -225,7 +225,9 @@ public function addWhere($leftOpOrExp, $rightOp = null, string $cond = null, str $this->whereExp = $parentWhere; } else { - if ($rightOp === null) { + if ($leftOpOrExp instanceof Expression && $rightOp === null) { + $this->whereExp->addCondition($leftOpOrExp, $join); + } else if ($rightOp === null) { $this->addWhereNull($leftOpOrExp, $join, !($cond == '=')); } else { if ($this->whereExp === null) {