Exemplo n.º 1
0
 /**
  * Get SQL string for statement
  *
  * @param  null|PlatformInterface $platform If null, defaults to Sql92
  * @return string
  */
 public function getSqlString(PlatformInterface $platform = null)
 {
     $platform = $platform ?: $this->platform ?: new Sql92();
     list($table, $schema) = $this->table->getAll();
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $data = $this->data;
     if (is_array($data)) {
         $setSql = array();
         foreach ($data as $column => $value) {
             if ($value instanceof Expression) {
                 $expr = $this->processExpression($value, $platform);
                 $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $expr;
             } elseif ($value === null) {
                 $setSql[] = $platform->quoteIdentifier($column) . ' = NULL';
             } else {
                 $setSql[] = $platform->quoteIdentifier($column) . ' = ' . $platform->quoteValue($value);
             }
         }
         $data = implode(', ', $setSql);
     }
     $sql = sprintf($this->specifications[self::SPECIFICATION_UPDATE], $table, $data);
     if ($this->where->count() > 0) {
         $expr = $this->processExpression($this->where, $platform, null, 'where');
         $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $expr);
     }
     return $sql;
 }
Exemplo n.º 2
0
 /**
  * Get the SQL string, based on the platform
  * Platform defaults to Sql92 if none provided
  *
  * @param  null|PlatformInterface $platform
  * @return string
  */
 public function getSqlString(PlatformInterface $platform = null)
 {
     $platform = $platform ?: $this->platform ?: new Sql92();
     list($table, $schema) = $this->table->getAll();
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $sql = sprintf($this->specifications[self::SPECIFICATION_DELETE], $table);
     if ($this->where->count() > 0) {
         $part = $this->processExpression($this->where, $platform, null, 'where');
         $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $part);
     }
     return $sql;
 }
Exemplo n.º 3
0
 /**
  * Get SQL string for this statement
  *
  * @param  null|PlatformInterface $platform Defaults to Sql92 if none provided
  * @return string
  */
 public function getSqlString(PlatformInterface $platform = null)
 {
     $platform = $platform ?: $this->platform ?: new Sql92();
     list($table, $schema) = $this->table->getAll();
     $table = $platform->quoteIdentifier($table);
     if ($schema) {
         $table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
     }
     $columns = array_map(array($platform, 'quoteIdentifier'), $this->columns);
     $columns = implode(', ', $columns);
     $values = array();
     foreach ($this->values as $value) {
         if ($value instanceof Expression) {
             $values[] = $this->processExpression($value, $platform);
         } elseif ($value === null) {
             $values[] = 'NULL';
         } else {
             $values[] = $platform->quoteValue($value);
         }
     }
     $values = implode(', ', $values);
     return sprintf($this->specifications[self::SPECIFICATION_INSERT], $table, $columns, $values);
 }
Exemplo n.º 4
0
 protected function processSelect(PlatformInterface $platform, DriverInterface $driver = null, Parameters $parameters = null)
 {
     if (!$this->table) {
         return null;
     }
     $separator = $platform->getIdentifierSeparator();
     $table = $this->table;
     $alias = null;
     if (is_array($table)) {
         $alias = key($table);
         $table = current($table);
     }
     if ($table instanceof TableIdentifier) {
         list($table, $schema, $alias) = $this->table->getAll();
         $table = $platform->quoteIdentifier($table);
         if ($schema) {
             $table = $platform->quoteIdentifier($schema) . $separator . $table;
         }
     } else {
         if ($table instanceof self) {
             $table = '(' . $this->processSubselect($table, $platform, $driver, $parameters) . ')';
         } else {
             $table = $platform->quoteIdentifier($table);
         }
     }
     if ($alias) {
         $fromTable = $platform->quoteIdentifier($alias);
         $table .= ' AS ' . $fromTable;
     } else {
         $fromTable = $table;
     }
     $fromTable .= $separator;
     // process table columns
     $columns = array();
     foreach ($this->columns as $columnIndexOrAs => $column) {
         if ($column === self::SQL_STAR) {
             $columns[] = array($fromTable . self::SQL_STAR);
             continue;
         }
         $columnName = array();
         if ($column instanceof Expression) {
             $columnName[] = $this->processExpression($column, $platform, $driver, $this->processInfo['paramPrefix'] . (is_string($columnIndexOrAs) ? $columnIndexOrAs : 'column'), $parameters);
         } else {
             if (preg_match('/^(.+)\\s+as\\s+(.+)$/i', $column, $m)) {
                 $column = $m[1];
                 $columnIndexOrAs = $m[2];
             }
             if (preg_match('/\\(.*\\)/', $column)) {
                 $columnName[] = $column;
             } else {
                 $columnName[] = $fromTable . $platform->quoteIdentifier($column);
             }
         }
         if (is_string($columnIndexOrAs)) {
             $columnName[] = $platform->quoteIdentifier($columnIndexOrAs);
         }
         $columns[] = $columnName;
     }
     // process join columns
     foreach ($this->joins as $join) {
         $name = $this->processColumnPrefix($join['name'], $platform);
         if (empty($join['columns'])) {
             continue;
         }
         foreach ($join['columns'] as $jKey => $jColumn) {
             $jColumns = array();
             if ($jColumn instanceof ExpressionInterface) {
                 $jColumns[] = $this->processExpression($jColumn, $platform, $driver, $this->processInfo['paramPrefix'] . (is_string($jKey) ? $jKey : 'column'), $parameters);
             } else {
                 if (preg_match('/^(.+)\\s+as\\s+(.+)$/i', $jColumn, $m)) {
                     $jColumn = $m[1];
                     $jKey = $m[2];
                 }
                 $jColumns[] = $name . $separator . $platform->quoteIdentifierInFragment($jColumn);
             }
             if (is_string($jKey)) {
                 $jColumns[] = $platform->quoteIdentifier($jKey);
             }
             $columns[] = $jColumns;
         }
     }
     if ($this->quantifier) {
         if ($this->quantifier instanceof Expression) {
             $quantifier = $this->processExpression($this->quantifier, $platform, $driver, 'quantifier', $parameters);
         } else {
             $quantifier = $this->quantifier;
         }
     }
     if (isset($quantifier)) {
         return array($quantifier, $columns, $table);
     } else {
         return array($columns, $table);
     }
 }