Exemplo n.º 1
0
 /**
  * create
  *
  * @param bool  $ifNotExists
  * @param array $options
  *
  * @return  static
  */
 public function create($ifNotExists = true, $options = array())
 {
     $defaultOptions = array('auto_increment' => 1, 'sequences' => array());
     $options = array_merge($defaultOptions, $options);
     $columns = array();
     $comments = array();
     foreach ($this->columns as $column) {
         $length = $column->getLength();
         $length = $length ? '(' . $length . ')' : null;
         if ($column->getAutoIncrement()) {
             $column->type(PostgresqlType::SERIAL);
             $options['sequences'][$column->getName()] = $this->table . '_' . $column->getName() . '_seq';
         }
         $columns[$column->getName()] = MysqlQueryBuilder::build($column->getType() . $length, $column->getAllowNull() ? null : 'NOT NULL', $column->getDefault() ? 'DEFAULT ' . $this->db->quote($column->getDefault()) : null);
         if ($column->getComment()) {
             $comments[$column->getName()] = $column->getComment();
         }
     }
     $keys = array();
     $keyComments = array();
     foreach ($this->indexes as $index) {
         $keys[$index->getName()] = array('type' => strtoupper($index->getType()), 'name' => $index->getName(), 'columns' => $index->getColumns());
         if ($index->getComment()) {
             $keyComments[$index->getName()] = $index->getComment();
         }
     }
     $options['comments'] = $comments;
     $options['key_comments'] = $keyComments;
     $this->doCreate($columns, $this->primary, $keys, $options['auto_increment'], $ifNotExists, $options);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * create
  *
  * @param bool  $ifNotExists
  * @param array $options
  *
  * @return  static
  */
 public function create($ifNotExists = true, $options = array())
 {
     $defaultOptions = array('auto_increment' => 1, 'engine' => 'InnoDB', 'charset' => 'utf8');
     $options = array_merge($defaultOptions, $options);
     $columns = array();
     foreach ($this->columns as $column) {
         $length = $column->getLength();
         $length = $length ? '(' . $length . ')' : null;
         $columns[$column->getName()] = MysqlQueryBuilder::build($column->getType() . $length, $column->getSigned() ? '' : 'UNSIGNED', $column->getAllowNull() ? '' : 'NOT NULL', $column->getDefault() ? 'DEFAULT ' . $this->db->quote($column->getDefault()) : '', $column->getAutoIncrement() ? 'AUTO_INCREMENT' : '', $column->getComment() ? 'COMMENT ' . $this->db->quote($column->getComment()) : '');
     }
     $keys = array();
     foreach ($this->indexes as $index) {
         $keys[$index->getName()] = array('type' => $index->getType(), 'name' => $index->getName(), 'columns' => $index->getColumns(), 'comment' => $index->getComment() ? 'COMMENT ' . $this->db->quote($index->getComment()) : '');
     }
     $this->doCreate($columns, $this->primary, $keys, $options['auto_increment'], $ifNotExists, $options);
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Method to test build().
  *
  * @return void
  *
  * @covers Windwalker\Query\Mysql\MysqlQueryBuilder::build
  */
 public function testBuild()
 {
     $expected = "FLOWER SAKURA SUNFLOWER OLIVE";
     $actual = MysqlQueryBuilder::build('FLOWER', 'SAKURA', 'SUNFLOWER', 'OLIVE');
     $this->assertEquals($this->format($expected), $this->format($actual));
 }