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

public static build ( OptionsArray $component, array $options = [] ) : string
$component OptionsArray The component to be built.
$options array Parameters for building.
Результат string
 /**
  * @return string
  */
 public function build()
 {
     $ret = OptionsArray::build($this->options);
     if ($this->type === TransactionStatement::TYPE_BEGIN) {
         foreach ($this->statements as $statement) {
             $ret .= ';' . $statement->build();
         }
         $ret .= ';' . $this->end->build();
     }
     return $ret;
 }
Пример #2
0
 /**
  * @return string
  */
 public function build()
 {
     $ret = 'DELETE ' . OptionsArray::build($this->options);
     if ($this->columns != NULL && count($this->columns) > 0) {
         $ret .= ' ' . ExpressionArray::build($this->columns);
     }
     if ($this->from != NULL && count($this->from) > 0) {
         $ret .= ' FROM ' . ExpressionArray::build($this->from);
     }
     if ($this->using != NULL && count($this->using) > 0) {
         $ret .= ' USING ' . ExpressionArray::build($this->using);
     }
     if ($this->where != NULL && count($this->where) > 0) {
         $ret .= ' WHERE ' . Condition::build($this->where);
     }
     if ($this->order != NULL && count($this->order) > 0) {
         $ret .= ' ORDER BY ' . ExpressionArray::build($this->order);
     }
     if ($this->limit != NULL && count($this->limit) > 0) {
         $ret .= ' LIMIT ' . Limit::build($this->limit);
     }
     return $ret;
 }
Пример #3
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 '';
 }
Пример #4
0
 public function testBuild()
 {
     $component = new OptionsArray(array('ALL', 'SQL_CALC_FOUND_ROWS', array('name' => 'MAX_STATEMENT_TIME', 'value' => '42', 'equals' => true)));
     $this->assertEquals(OptionsArray::build($component), 'ALL SQL_CALC_FOUND_ROWS MAX_STATEMENT_TIME=42');
 }
Пример #5
0
 /**
  * @param FieldDefinition|FieldDefinition[] $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 "(\n" . implode(",\n", $ret) . "\n)";
     } else {
         $tmp = '';
         if ($component->isConstraint) {
             $tmp .= 'CONSTRAINT ';
         }
         if (!empty($component->name)) {
             $tmp .= Context::escape($component->name) . ' ';
         }
         if (!empty($component->type)) {
             $tmp .= DataType::build($component->type) . ' ';
         }
         if (!empty($component->key)) {
             $tmp .= Key::build($component->key) . ' ';
         }
         if (!empty($component->references)) {
             $tmp .= 'REFERENCES ' . Reference::build($component->references) . ' ';
         }
         $tmp .= OptionsArray::build($component->options);
         return trim($tmp);
     }
 }
Пример #6
0
 /**
  * @param Key $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     $ret = $component->type . ' ';
     if (!empty($component->name)) {
         $ret .= Context::escape($component->name) . ' ';
     }
     $ret .= '(' . implode(',', Context::escape($component->columns)) . ')';
     $ret .= OptionsArray::build($component->options);
     return trim($ret);
 }
Пример #7
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;
 }
Пример #8
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);
 }
Пример #9
0
 /**
  * @param DataType $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     $tmp = '';
     if (!empty($component->parameters)) {
         $tmp = '(' . implode(',', $component->parameters) . ')';
     }
     return trim(strtolower($component->name) . $tmp . ' ' . OptionsArray::build($component->options));
 }
Пример #10
0
 /**
  * @param Reference $component The component to be built.
  *
  * @return string
  */
 public static function build($component)
 {
     return trim(Context::escape($component->table) . ' (' . implode(', ', Context::escape($component->columns)) . ') ' . OptionsArray::build($component->options));
 }
Пример #11
0
 /**
  * @return string
  */
 public function build()
 {
     return 'SET ' . OptionsArray::build($this->options) . ' ' . SetOperation::build($this->set);
 }