Esempio n. 1
0
 /**
  * @param mixed ...$params expressions to pass to where clause
  *
  * @return $this
  */
 public function loadWhere(...$params)
 {
     $this->resetQuery();
     $this->clear();
     if (func_num_args() > 0) {
         $this->_query->where(...$params);
     }
     $this->load();
     return $this;
 }
Esempio n. 2
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());
 }