示例#1
0
 /**
  * update
  *
  * @return  static
  */
 public function update()
 {
     foreach ($this->columns as $column) {
         $length = $column->getLength();
         $length = $length ? '(' . $length . ')' : null;
         $query = MysqlQueryBuilder::addColumn($this->table, $column->getName(), $column->getType() . $length, $column->getSigned(), $column->getAllowNull(), $column->getDefault(), $column->getPosition(), $column->getComment());
         $this->db->setQuery($query)->execute();
     }
     foreach ($this->indexes as $index) {
         $query = MysqlQueryBuilder::addIndex($this->table, $index->getType(), $index->getName(), $index->getColumns(), $index->getComment());
         $this->db->setQuery($query)->execute();
     }
     return $this;
 }
 /**
  * Method to test addIndex().
  *
  * @return void
  *
  * @covers Windwalker\Query\Mysql\MysqlQueryBuilder::addIndex
  */
 public function testAddIndex()
 {
     $expected = "ALTER TABLE {$this->qn('foo')} ADD KEY {$this->qn('idx_alias')} ({$this->qn('alias')}, {$this->qn('name')}) COMMENT 'Test Index'";
     $actual = MysqlQueryBuilder::addIndex('foo', 'KEY', 'idx_alias', array('alias', 'name'), 'Test Index');
     $this->assertEquals($this->format($expected), $this->format($actual));
     $expected = "ALTER TABLE {$this->qn('foo')} ADD KEY {$this->qn('idx_alias')} ({$this->qn('alias')}) COMMENT 'Test Index'";
     $actual = MysqlQueryBuilder::addIndex('foo', 'KEY', 'idx_alias', 'alias', 'Test Index');
     $this->assertEquals($this->format($expected), $this->format($actual));
 }
 /**
  * Method to test addIndex().
  *
  * @return void
  *
  * @covers Windwalker\Query\Mysql\MysqlQueryBuilder::addIndex
  */
 public function testAddIndex()
 {
     $expected = "ALTER TABLE {$this->qn}foo{$this->qn} ADD KEY {$this->qn}idx_alias{$this->qn} ({$this->qn}alias{$this->qn}, {$this->qn}name{$this->qn}) COMMENT 'Test Index'";
     $actual = MysqlQueryBuilder::addIndex('foo', 'KEY', 'idx_alias', array('alias', 'name'), 'Test Index');
     $this->assertEquals(\SqlFormatter::compress($expected), \SqlFormatter::compress($actual));
     $expected = "ALTER TABLE {$this->qn}foo{$this->qn} ADD KEY {$this->qn}idx_alias{$this->qn} ({$this->qn}alias{$this->qn}) COMMENT 'Test Index'";
     $actual = MysqlQueryBuilder::addIndex('foo', 'KEY', 'idx_alias', 'alias', 'Test Index');
     $this->assertEquals(\SqlFormatter::compress($expected), \SqlFormatter::compress($actual));
 }