Esempio n. 1
0
 /**
  * @covers ::columns
  * @covers ::getColumns
  * @covers ::setColumns
  * @covers ::clearColumns
  */
 public function testColumns()
 {
     $query = new Query\Insert(self::getDb());
     $query->columns(array('posts'));
     $expected = new SQL\Columns(array('posts'));
     $this->assertEquals($expected, $query->getColumns());
     $query->columns(array('col1', 'col2'));
     $expected = new SQL\Columns(array('col1', 'col2'));
     $this->assertEquals($expected, $query->getColumns());
     $query->clearColumns();
     $this->assertEmpty($query->getColumns());
     $query->setColumns($expected);
     $this->assertEquals($expected, $query->getColumns());
 }
Esempio n. 2
0
 /**
  * Render a Insert object
  * @param  Query\Insert $query
  * @return string
  */
 public static function render(Query\Insert $query)
 {
     return Compiler::withDb($query->getDb(), function () use($query) {
         $table = $query->getTable();
         $select = $query->getSelect();
         return Compiler::expression(array('INSERT', $query->getType(), Compiler::word('INTO', $table !== null ? Aliased::render($table) : null), Columns::render($query->getColumns()), Compiler::word('VALUES', Values::combine($query->getValues())), Compiler::word('SET', Set::combine($query->getSet())), $select !== null ? Select::render($select) : null));
     });
 }