コード例 #1
0
ファイル: Cast.php プロジェクト: Hikariii/doctrine-extensions
 /**
  * {@inheritdoc}
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     /** @var Node $value */
     $value = $this->parameters[DqlFunction::PARAMETER_KEY];
     $type = $this->parameters[DqlFunction::TYPE_KEY];
     $type = strtolower($type);
     if ($type === 'datetime') {
         $timestampFunction = new Timestamp(array(SimpleFunction::PARAMETER_KEY => $value));
         return $timestampFunction->getSql($sqlWalker);
     }
     if ($type === 'json' && !$sqlWalker->getConnection()->getDatabasePlatform()->hasNativeJsonType()) {
         $type = 'text';
     }
     if ($type === 'bool') {
         $type = 'boolean';
     }
     /**
      * The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively.
      * character without length specifier is equivalent to character(1). If character varying is used
      * without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.
      * http://www.postgresql.org/docs/9.2/static/datatype-character.html
      */
     if ($type === 'string') {
         $type = 'varchar';
     }
     return 'CAST(' . $this->getExpressionValue($value, $sqlWalker) . ' AS ' . $type . ')';
 }
コード例 #2
0
ファイル: Cast.php プロジェクト: sergeyz/doctrine-extensions
 /**
  * {@inheritdoc}
  */
 public function getSql(SqlWalker $sqlWalker)
 {
     /** @var Node $value */
     $value = $this->parameters[DqlFunction::PARAMETER_KEY];
     $type = $this->parameters[DqlFunction::TYPE_KEY];
     if (strtolower($type) == 'datetime') {
         $timestampFunction = new Timestamp(array(SimpleFunction::PARAMETER_KEY => $value));
         return $timestampFunction->getSql($sqlWalker);
     }
     return 'CAST(' . $value->dispatch($sqlWalker) . ' AS ' . $type . ')';
 }
 /**
  * Get timestamp value for given expression.
  *
  * @param Node|string $expression
  * @param SqlWalker $sqlWalker
  * @return string
  */
 protected function getTimestampValue($expression, SqlWalker $sqlWalker)
 {
     $value = $this->getExpressionValue($expression, $sqlWalker);
     if ($expression instanceof Literal) {
         $value = trim(trim($value), '\'"');
         if (is_numeric(substr($value, 0, 1))) {
             $timestampFunction = new Timestamp(array(SimpleFunction::PARAMETER_KEY => "'{$value}'"));
             $value = $timestampFunction->getSql($sqlWalker);
         }
     }
     return $value;
 }
コード例 #4
0
 /**
  * @param Node $firstDateNode
  * @param Node $secondDateNode
  * @param SqlWalker $sqlWalker
  * @return string
  */
 protected function getDiffForDay(Node $firstDateNode, Node $secondDateNode, SqlWalker $sqlWalker)
 {
     $firstDateTimestampFunction = new Timestamp(array(SimpleFunction::PARAMETER_KEY => $firstDateNode));
     $secondDateTimestampFunction = new Timestamp(array(SimpleFunction::PARAMETER_KEY => $secondDateNode));
     return sprintf('EXTRACT(DAY FROM %s - %s)', $secondDateTimestampFunction->getSql($sqlWalker), $firstDateTimestampFunction->getSql($sqlWalker));
 }