Skip to content

Commit

Permalink
fix: Added Fix to Custom Expression
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Oct 28, 2024
1 parent cc08e19 commit 7c6a5c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
/**
Expand Down
7 changes: 4 additions & 3 deletions webfiori/database/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
/**
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion webfiori/database/SelectExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7c6a5c1

Please sign in to comment.