public function testBoolean()
 {
     $expression = new BooleanExpression();
     $expression->setValue(true);
     $this->assertEquals('true', QueryAssembler::stringify($expression));
     $expression->setValue(1);
     $this->assertEquals('true', QueryAssembler::stringify($expression));
     $expression->setValue('abc');
     $this->assertEquals('true', QueryAssembler::stringify($expression));
     $expression->setValue(false);
     $this->assertEquals('false', QueryAssembler::stringify($expression));
     $expression->setValue(0);
     $this->assertEquals('false', QueryAssembler::stringify($expression));
     $expression->setValue('');
     $this->assertEquals('false', QueryAssembler::stringify($expression));
     $stmt = QueryBuilder::update('tbl', ['field' => $expression]);
     $assembler = new QueryAssembler($stmt);
     $this->assertEquals('UPDATE tbl SET field = ?', $assembler->getQuery());
     $this->assertEquals([false], $assembler->getParameters());
 }
Пример #2
0
 public function assembleValueExpression(ValueExpression $expression)
 {
     $value = $expression->getValue();
     if ($value === null) {
         return $this->_assemblePrepared() ?: 'NULL';
     } else {
         if (is_scalar($value)) {
             if (!is_string($value) && is_numeric($value)) {
                 return $this->assembleNumericExpression(NumericExpression::create($value));
             } else {
                 if (is_bool($value)) {
                     return $this->assembleBooleanExpression(BooleanExpression::create($value));
                 }
             }
         } else {
             if (is_array($value)) {
                 return $this->assembleArrayExpression(ArrayExpression::create($value));
             }
         }
     }
     return $this->assembleStringExpression(StringExpression::create($value));
 }