build() публичный статический Метод

public static build ( Expression | Expression[] $component, array $options = [] ) : string
$component Expression | Expression[] The component to be built.
$options array Parameters for building.
Результат string
Пример #1
0
 /**
  * @param OrderKeyword $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     if (is_array($component)) {
         $ret = array();
         foreach ($component as $c) {
             $ret[] = static::build($c);
         }
         return implode(", ", $ret);
     } else {
         return Expression::build($component->field) . ' ' . $component->type;
     }
 }
Пример #2
0
 /**
  * Gets a list of all tables used in this statement.
  *
  * @param Statement $statement Statement to be scanned.
  *
  * @return array
  */
 public static function getTables($statement)
 {
     $expressions = array();
     if ($statement instanceof InsertStatement || $statement instanceof ReplaceStatement) {
         $expressions = array($statement->into->dest);
     } elseif ($statement instanceof UpdateStatement) {
         $expressions = $statement->tables;
     } elseif ($statement instanceof SelectStatement || $statement instanceof DeleteStatement) {
         $expressions = $statement->from;
     } elseif ($statement instanceof AlterStatement || $statement instanceof TruncateStatement) {
         $expressions = array($statement->table);
     } elseif ($statement instanceof DropStatement) {
         if (!$statement->options->has('TABLE')) {
             // No tables are dropped.
             return array();
         }
         $expressions = $statement->fields;
     } elseif ($statement instanceof RenameStatement) {
         foreach ($statement->renames as $rename) {
             $expressions[] = $rename->old;
         }
     }
     $ret = array();
     foreach ($expressions as $expr) {
         if (!empty($expr->table)) {
             $expr->expr = null;
             // Force rebuild.
             $expr->alias = null;
             // Aliases are not required.
             $ret[] = Expression::build($expr);
         }
     }
     return $ret;
 }
Пример #3
0
 public function testBuild()
 {
     $component = array(new Expression('1 + 2', 'three'), new Expression('1 + 3', 'four'));
     $this->assertEquals(Expression::build($component), '1 + 2 AS `three`, 1 + 3 AS `four`');
 }
Пример #4
0
 /**
  * @return string
  */
 public function build()
 {
     $fields = '';
     if (!empty($this->fields)) {
         if (is_array($this->fields)) {
             $fields = CreateDefinition::build($this->fields) . ' ';
         } elseif ($this->fields instanceof ArrayObj) {
             $fields = ArrayObj::build($this->fields);
         }
     }
     if ($this->options->has('DATABASE')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions);
     } elseif ($this->options->has('TABLE')) {
         $partition = '';
         if (!empty($this->partitionBy)) {
             $partition .= "\nPARTITION BY " . $this->partitionBy;
         }
         if (!empty($this->partitionsNum)) {
             $partition .= "\nPARTITIONS " . $this->partitionsNum;
         }
         if (!empty($this->subpartitionBy)) {
             $partition .= "\nSUBPARTITION BY " . $this->subpartitionBy;
         }
         if (!empty($this->subpartitionsNum)) {
             $partition .= "\nSUBPARTITIONS " . $this->subpartitionsNum;
         }
         if (!empty($this->partitions)) {
             $partition .= "\n" . PartitionDefinition::build($this->partitions);
         }
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $fields . OptionsArray::build($this->entityOptions) . $partition;
     } elseif ($this->options->has('VIEW')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $fields . ' AS ' . TokensList::build($this->body) . ' ' . OptionsArray::build($this->entityOptions);
     } elseif ($this->options->has('TRIGGER')) {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions) . ' ' . 'ON ' . Expression::build($this->table) . ' ' . 'FOR EACH ROW ' . TokensList::build($this->body);
     } elseif ($this->options->has('PROCEDURE') || $this->options->has('FUNCTION')) {
         $tmp = '';
         if ($this->options->has('FUNCTION')) {
             $tmp = 'RETURNS ' . DataType::build($this->return);
         }
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . ParameterDefinition::build($this->parameters) . ' ' . $tmp . ' ' . TokensList::build($this->body);
     } else {
         return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . TokensList::build($this->body);
     }
     return '';
 }
Пример #5
0
 /**
  * @param AlterOperation $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     $ret = OptionsArray::build($component->options) . ' ';
     if (!empty($component->field)) {
         $ret .= Expression::build($component->field) . ' ';
     }
     $ret .= TokensList::build($component->unknown);
     return $ret;
 }
Пример #6
0
 /**
  * @return string
  */
 public function build()
 {
     $tmp = array();
     foreach ($this->altered as $altered) {
         $tmp[] = $altered::build($altered);
     }
     return 'ALTER ' . OptionsArray::build($this->options) . ' TABLE ' . Expression::build($this->table) . ' ' . implode(', ', $tmp);
 }
Пример #7
0
 /**
  * @param JoinKeyword[] $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     $ret = array();
     foreach ($component as $c) {
         $ret[] = ($c->type === 'JOIN' ? 'JOIN ' : $c->type . ' JOIN ') . Expression::build($c->expr) . ' ON ' . Condition::build($c->on);
     }
     return implode(' ', $ret);
 }
Пример #8
0
 /**
  * @param IntoKeyword $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     if ($component->dest instanceof Expression) {
         $columns = !empty($component->columns) ? '(' . implode(', ', $component->columns) . ')' : '';
         return Expression::build($component->dest) . $columns;
     } else {
         return 'OUTFILE "' . $component->dest . '"';
     }
 }
 /**
  * @param RenameOperation $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     if (is_array($component)) {
         $values = array();
         foreach ($component as $c) {
             $values[] = static::build($c);
         }
         return implode(', ', $values);
     } else {
         return Expression::build($component->old) . ' TO ' . Expression::build($component->new);
     }
 }