Used for parsing CREATE TABLE statement.
Author: Dan Ungureanu (udan1107@gmail.com)
Inheritance: extends SqlParser\Component
 public function testParse()
 {
     $component = PartitionDefinition::parse(new Parser(), $this->getTokensList('PARTITION p0 VALUES LESS THAN(1990)'));
     $this->assertFalse($component->isSubpartition);
     $this->assertEquals('p0', $component->name);
     $this->assertEquals('LESS THAN', $component->type);
     $this->assertEquals('(1990)', $component->expr->expr);
 }
 /**
  * @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 '';
 }
 /**
  * @param PartitionDefinition|PartitionDefinition[] $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 {
         if ($component->isSubpartition) {
             return 'SUBPARTITION ' . $component->name;
         } else {
             $subpartitions = empty($component->subpartitions) ? '' : ' ' . PartitionDefinition::build($component->subpartitions);
             return 'PARTITION ' . $component->name . ' VALUES ' . $component->type . ' ' . $component->expr . $subpartitions;
         }
     }
 }
 /**
  * @param PartitionDefinition|PartitionDefinition[] $component The component to be built.
  * @param array                                     $options   Parameters for building.
  *
  * @return string
  */
 public static function build($component, array $options = array())
 {
     if (is_array($component)) {
         return "(\n" . implode(",\n", $component) . "\n)";
     } else {
         if ($component->isSubpartition) {
             return trim('SUBPARTITION ' . $component->name . ' ' . $component->options);
         } else {
             $subpartitions = empty($component->subpartitions) ? '' : ' ' . PartitionDefinition::build($component->subpartitions);
             return trim('PARTITION ' . $component->name . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') . $component->options . $subpartitions);
         }
     }
 }