示例#1
0
 /**
  * @inheritDoc
  */
 protected function compileBase(DriverInterface $driver)
 {
     if ($this->valuesBag->isEmpty()) {
         throw new CompileException('No values found for update query.');
     }
     return 'UPDATE ' . $this->table->compile($driver) . ' SET ' . $this->valuesBag->concat($driver, ', ');
 }
示例#2
0
 /**
  * @inheritDoc
  */
 protected function compileBase(DriverInterface $driver)
 {
     if ($this->columnsBag->isEmpty()) {
         throw new CompileException('Select query requires columns list.');
     }
     return 'SELECT ' . $this->columnsBag->concat($driver, ', ') . ' FROM ' . $this->table->compile($driver);
 }
示例#3
0
 /**
  * @inheritDoc
  */
 public function compile(DriverInterface $driver)
 {
     if ($this->columnsBag->isEmpty()) {
         throw new CompileException('The table definition requires columns list.');
     }
     return 'CREATE TABLE ' . $this->table->compile($driver) . '(' . $this->columnsBag->concat($driver, ', ') . ')';
 }
示例#4
0
 /**
  * @inheritDoc
  */
 public function compile(DriverInterface $driver)
 {
     if ($this->expressions->isEmpty()) {
         return '1';
     }
     $compiled = $this->expressions->concat($driver, ' ' . $this->operator . ' ');
     if ($this->expressions->count() > 1) {
         return '(' . $compiled . ')';
     }
     return $compiled;
 }
示例#5
0
/**
 * Creates UPDATE query.
 *
 * @param string $table A table name for the query.
 * @param array $values Expressions list for updating.
 * @return UpdateQuery
 */
function update($table, array $values)
{
    $valuesBag = new ExpressionBag();
    foreach ($values as $column => $value) {
        if ($value instanceof Assign) {
            $valuesBag->add($value);
        } else {
            $valuesBag->add(assign($column, $value));
        }
    }
    return new UpdateQuery(new Reference($table), $valuesBag);
}
示例#6
0
 /**
  * @inheritDoc
  */
 public function compile(DriverInterface $driver)
 {
     $compiled = $this->compileBase($driver);
     if ($this->condition) {
         $compiled .= ' WHERE ' . $this->condition->compile($driver);
     }
     if ($this->orderBy) {
         $compiled .= ' ORDER BY ' . $this->orderBy->concat($driver, ', ');
     }
     if ($this->limit) {
         $compiled .= ' LIMIT ' . (int) $this->limit;
         if ($this->offset) {
             $compiled .= ' OFFSET ' . (int) $this->offset;
         }
     }
     return $compiled;
 }
示例#7
0
 /**
  * @param DriverInterface $driver
  * @return string
  * @throws CompileException
  */
 private function compileFields(DriverInterface $driver)
 {
     if (empty($this->fields)) {
         throw new CompileException('No fields found for insert query.');
     }
     $fields = new ExpressionBag();
     foreach ($this->fields as $field) {
         $fields->add(new Reference($field));
     }
     return $fields->concat($driver, ', ');
 }