Skip to content

Commit

Permalink
Merge pull request #90 from WebFiori/dev
Browse files Browse the repository at this point in the history
test: Added New Test Case
  • Loading branch information
usernane authored Oct 28, 2024
2 parents f428be2 + 7c6a5c1 commit ffa11a1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
16 changes: 15 additions & 1 deletion tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public function testRight07() {
/**
* @test
*/
public function testSelectWithWhere000() {
public function testSelectWithWhere013() {
$schema = new MSSQLTestSchema();
$bulder = $schema->table('users')->select()->where('id', 66);
$this->assertEquals('select * from [users] where [users].[id] = ?', $schema->getLastQuery());
Expand Down Expand Up @@ -1022,6 +1022,20 @@ public function testSelectWithWhere012() {
// Expr(Expr(Cond) Cond)
$this->assertEquals('select * from [users] where [users].[id] is null and [users].[id] is not null', $schema->getLastQuery());
}
/**
* @test
*/
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) 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());
}
/**
* @test
*
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 ffa11a1

Please sign in to comment.