public function assembleNotEqualPredicate(NotEqualPredicate $predicate)
 {
     if ($predicate->isNullValue()) {
         return $this->assembleSegment($predicate->getField()) . ' IS NOT NULL';
     }
     return $this->assembleOperator($predicate);
 }
 public function testAssemble()
 {
     $this->assertEquals('', QueryAssembler::stringify(PredicateSet::create()));
     $eq = new EqualPredicate();
     $eq->setField("first")->setExpression(ValueExpression::create('val1'));
     $neq = new NotEqualPredicate();
     $neq->setField("second")->setExpression(ValueExpression::create('val1'));
     $set = PredicateSet::create($eq, $neq);
     $this->assertEquals('(first = "val1" AND second <> "val1")', QueryAssembler::stringify($set));
 }
 public function testAssemble()
 {
     $predicate = new NotEqualPredicate();
     $predicate->setField('field');
     $this->assertEquals('field IS NOT NULL', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new NumericExpression())->setValue(1));
     $this->assertEquals('field <> 1', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new NumericExpression())->setValue('1'));
     $this->assertEquals('field <> 1', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new StringExpression())->setValue('abc'));
     $this->assertEquals('field <> "abc"', QueryAssembler::stringify($predicate));
 }
 public function testAssemble()
 {
     $clause = new FinalAbstractPredicateClause();
     $eq = new EqualPredicate();
     $string = (new StringExpression())->setValue('val');
     $eq->setField('one')->setExpression($string);
     $neq = new NotEqualPredicate();
     $neq->setField('two')->setExpression($string);
     $clause->addPredicate($eq);
     $this->assertEquals('T one = "val"', QueryAssembler::stringify($clause));
     $clause->clearPredicates();
     $clause->setPredicates([$eq, $neq]);
     $this->assertEquals('T one = "val" AND two <> "val"', QueryAssembler::stringify($clause));
 }
Example #5
0
 public function testAssemblerPrepare()
 {
     $stm = new QueryStatement();
     $stm->addClause(new SelectClause())->from('mytable');
     $stm->where(EqualPredicate::create('field1', 'value1'));
     $assembler = new QueryAssembler($stm, false);
     $this->assertEmpty($assembler->getParameters());
     $this->assertFalse($assembler->isForPrepare());
     $this->assertEquals('SELECT * FROM mytable WHERE field1 = "value1"', (string) $assembler);
     $stm->andWhere(['AND' => [EqualPredicate::create('field2', null), NotEqualPredicate::create('field3', null)], 'OR' => BetweenPredicate::create('field4', 123, 456)]);
     $assembler = new QueryAssembler($stm, true);
     $this->assertNotEmpty($assembler->getParameters());
     $this->assertTrue($assembler->isForPrepare());
     $this->assertEquals('SELECT * FROM mytable WHERE field1 = ? AND ((field2 IS NULL AND field3 IS NOT NULL) AND field4 BETWEEN ? AND ?)', (string) $assembler);
     $this->assertEquals(['value1', 123, 456], $assembler->getParameters());
 }