コード例 #1
0
 /**
  * update
  *
  * @return  static
  */
 public function update()
 {
     foreach ($this->columns as $column) {
         $length = $column->getLength();
         $length = $length ? '(' . $length . ')' : null;
         $sequence = null;
         if ($column->getAutoIncrement()) {
             $column->type(PostgresqlType::SERIAL);
         }
         $query = PostgresqlQueryBuilder::addColumn($this->table, $column->getName(), $column->getType() . $length, $column->getAllowNull(), $column->getDefault());
         $this->db->setQuery($query)->execute();
         if ($column->getComment()) {
             $query = PostgresqlQueryBuilder::comment('COLUMN', $this->table, $column->getName(), $column->getComment());
             $this->db->setQuery($query)->execute();
         }
     }
     foreach ($this->indexes as $index) {
         $query = PostgresqlQueryBuilder::addIndex($this->table, $index->getType(), $index->getName(), $index->getColumns());
         $this->db->setQuery($query)->execute();
         if ($index->getComment()) {
             $query = PostgresqlQueryBuilder::comment('INDEX', 'public', $index->getName(), $index->getComment());
             $this->db->setQuery($query)->execute();
         }
     }
     return $this;
 }
コード例 #2
0
 /**
  * Method to test addIndex().
  *
  * @return void
  *
  * @covers Windwalker\Query\Postgresql\PostgresqlQueryBuilder::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 = PostgresqlQueryBuilder::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 = PostgresqlQueryBuilder::addIndex('foo', 'KEY', 'idx_alias', 'alias', 'Test Index');
     $this->assertEquals(\SqlFormatter::compress($expected), \SqlFormatter::compress($actual));
 }
コード例 #3
0
 /**
  * Method to test addIndex().
  *
  * @return void
  *
  * @covers Windwalker\Query\Postgresql\PostgresqlQueryBuilder::addIndex
  */
 public function testAddIndex()
 {
     $expected = "CREATE INDEX {$this->qn('idx_alias')} ON {$this->qn('foo')} ({$this->qn('alias')}, {$this->qn('name')})";
     $actual = PostgresqlQueryBuilder::addIndex('foo', 'INDEX', 'idx_alias', array('alias', 'name'));
     $this->assertEquals($this->format($expected), $this->format($actual));
     $expected = "CREATE INDEX {$this->qn('idx_alias')} ON {$this->qn('foo')} ({$this->qn('alias')})";
     $actual = PostgresqlQueryBuilder::addIndex('foo', 'INDEX', 'idx_alias', 'alias');
     $this->assertEquals($this->format($expected), $this->format($actual));
 }