/** * Render a Union object * @param Query\Union $query * @return string */ public static function render(Query\Union $query) { return Compiler::withDb($query->getDb(), function () use($query) { return Compiler::expression(array(Arr::join(' UNION ', Arr::map(function (Query\Select $select) { return Compiler::braced(Select::render($select)); }, $query->getSelects())), Compiler::word('ORDER BY', Direction::combine($query->getOrder())), Compiler::word('LIMIT', $query->getLimit()))); }); }
/** * 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)); }); }
/** * Render SQL for Aliased * * @param SQL\Aliased $aliased * @return string */ public static function render(SQL\Aliased $aliased) { $content = $aliased->getContent(); if ($content instanceof Query\Select) { $content = "(" . Select::render($content) . ")"; } else { $content = Compiler::name($content); } return Compiler::expression(array($content, Compiler::word('AS', Compiler::name($aliased->getAlias())))); }
/** * Render Update object * @param Query\Update $query * @return string */ public static function render(Query\Update $query) { return Compiler::withDb($query->getDb(), function () use($query) { return Compiler::expression(array('UPDATE', $query->getType(), Aliased::combine($query->getTable()), Join::combine($query->getJoin()), Compiler::word('SET', Set::combine($query->getSet())), Compiler::word('WHERE', Condition::combine($query->getWhere())), Compiler::word('ORDER BY', Direction::combine($query->getOrder())), Compiler::word('LIMIT', $query->getLimit()))); }); }
/** * Render a Select object * @param Query\Select $query * @return string */ public static function render(Query\Select $query) { return Compiler::withDb($query->getDb(), function () use($query) { return Compiler::expression(array('SELECT', $query->getType(), Aliased::combine($query->getColumns()) ?: '*', Compiler::word('FROM', Aliased::combine($query->getFrom())), Join::combine($query->getJoin()), Compiler::word('WHERE', Condition::combine($query->getWhere())), Compiler::word('GROUP BY', Direction::combine($query->getGroup())), Compiler::word('HAVING', Condition::combine($query->getHaving())), Compiler::word('ORDER BY', Direction::combine($query->getOrder())), Compiler::word('LIMIT', $query->getLimit()), Compiler::word('OFFSET', $query->getOffset()))); }); }
/** * @dataProvider dataWord * @covers ::word */ public function testWord($word, $statement, $expected) { $this->assertEquals($expected, Compiler::word($word, $statement)); }