Example #1
0
 /**
  * create
  *
  * @param string $columns
  * @param array  $pks
  * @param array  $keys
  * @param int    $autoIncrement
  * @param bool   $ifNotExists
  * @param array  $options
  *
  * @return $this
  */
 public function doCreate($columns, $pks = array(), $keys = array(), $autoIncrement = null, $ifNotExists = true, $options = array())
 {
     $autoIncrement = isset($options['auto_increment']) ? $options['auto_increment'] : null;
     $engine = isset($options['engine']) ? $options['engine'] : 'InnoDB';
     $charset = isset($options['charset']) ? $options['charset'] : 'utf8';
     $query = MysqlQueryBuilder::createTable($this->table, $columns, $pks, $keys, $autoIncrement, $ifNotExists, $engine, $charset);
     $this->db->setQuery($query)->execute();
     return $this;
 }
    /**
     * Method to test createTable().
     *
     * @return void
     *
     * @covers Windwalker\Query\Mysql\MysqlQueryBuilder::createTable
     */
    public function testCreateTable()
    {
        $expected = <<<SQL
CREATE TABLE IF NOT EXISTS {$this->qn('foo')} (
  {$this->qn('id')} int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  {$this->qn('name')} varchar(255) NOT NULL COMMENT 'Member Name',
  {$this->qn('email')} varchar(255) NOT NULL COMMENT 'Member email',
  PRIMARY KEY ({$this->qn('id')}),
  KEY {$this->qn('idx_alias')} ({$this->qn('email')})
) ENGINE=InnoDB AUTO_INCREMENT=415 DEFAULT CHARSET=utf8
SQL;
        $columns = array('id' => 'int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT \'Primary Key\'', 'name' => array('varchar(255)', 'NOT NULL', 'COMMENT \'Member Name\''), 'email' => "varchar(255) NOT NULL COMMENT 'Member email'");
        $keys = array(array('type' => 'KEY', 'name' => 'idx_alias', 'columns' => 'email'));
        $actual = MysqlQueryBuilder::createTable('foo', $columns, 'id', $keys, 415, true, 'InnoDB');
        $this->assertEquals($this->format($expected), $this->format($actual));
        $expected = <<<SQL
CREATE TABLE {$this->qn('foo')} (
  {$this->qn('id')} int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  {$this->qn('name')} varchar(255) NOT NULL COMMENT 'Member Name',
  {$this->qn('email')} varchar(255) NOT NULL COMMENT 'Member email',
  PRIMARY KEY ({$this->qn('id')}, {$this->qn('email')}),
  UNIQUE KEY {$this->qn('idx_alias')} ({$this->qn('email')}, {$this->qn('id')})
) ENGINE=InnoDB AUTO_INCREMENT=415 DEFAULT CHARSET=utf8
SQL;
        $columns = array('id' => 'int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT \'Primary Key\'', 'name' => array('varchar(255)', 'NOT NULL', 'COMMENT \'Member Name\''), 'email' => "varchar(255) NOT NULL COMMENT 'Member email'");
        $keys = array(array('type' => 'UNIQUE KEY', 'name' => 'idx_alias', 'columns' => array('email', 'id')));
        $actual = MysqlQueryBuilder::createTable('foo', $columns, array('id', 'email'), $keys, 415, false, 'InnoDB');
        $this->assertEquals($this->format($expected), $this->format($actual));
    }
Example #3
0
 /**
  * create
  *
  * @param string $columns
  * @param array  $pks
  * @param array  $keys
  * @param int    $autoIncrement
  * @param bool   $ifNotExists
  * @param string $engine
  * @param string $defaultCharset
  *
  * @return  $this
  */
 public function doCreate($columns, $pks = array(), $keys = array(), $autoIncrement = null, $ifNotExists = true, $engine = 'InnoDB', $defaultCharset = 'utf8')
 {
     $query = MysqlQueryBuilder::createTable($this->table, $columns, $pks, $keys, $autoIncrement, $ifNotExists, $engine, $defaultCharset);
     $this->db->setQuery($query)->execute();
     return $this;
 }