Ejemplo n.º 1
0
 public function testNestedFunctions()
 {
     $func1 = new Func('CHAR', ['0x65 USING utf8' => Func::LITERAL]);
     $func2 = new Func('CHARSET', $func1);
     $this->assertEquals('CHARSET', $func2->getName());
     $this->assertEquals(', ', $func2->getSeparator());
     $this->assertEquals([['type' => null, 'value' => $func1]], $func2->getArguments());
 }
Ejemplo n.º 2
0
 /**
  * Format a database function.
  *
  * @param \Titon\Db\Query\Func $func
  * @return string
  */
 public function formatFunction(Func $func)
 {
     $arguments = [];
     foreach ($func->getArguments() as $arg) {
         $type = $arg['type'];
         $value = $arg['value'];
         if ($value instanceof Func) {
             $value = $this->formatFunction($value);
         } else {
             if ($value instanceof SubQuery) {
                 $value = $this->formatSubQuery($value);
             } else {
                 if ($type === Func::FIELD) {
                     $value = $this->quote($value);
                 } else {
                     if ($type === Func::LITERAL) {
                         // Do nothing
                     } else {
                         if (is_string($value) || $value === null) {
                             $value = $this->getDriver()->escape($value);
                         }
                     }
                 }
             }
         }
         $arguments[] = $value;
     }
     $output = sprintf($this->getClause(self::FUNC), $func->getName(), implode($func->getSeparator(), $arguments));
     if ($alias = $func->getAlias()) {
         $output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
     }
     return $output;
 }