/** * Method to test union(). * * @return void * * @covers Windwalker\Query\Query::union */ public function testUnionAll() { $query = $this->getQuery(); $query->unionAll($this->getQuery()->select('*')->from('foo')->where('a = b')->order('id'))->union($this->getQuery()->select('*')->from('foo')->where('a = b')->order('id')); $sql = '( SELECT * FROM foo WHERE a = b ORDER BY id) UNION ALL ( SELECT * FROM foo WHERE a = b ORDER BY id)'; $this->assertEquals(\SqlFormatter::compress($sql), \SqlFormatter::compress($query)); }
<tr> <th>Original</th> <th>Compressed</th> </tr> <?php foreach ($statements as $sql) { ?> <tr> <td> <pre><?php echo $sql; ?> </pre> </td> <td><pre><?php echo SqlFormatter::compress($sql); ?> </pre></td> </tr> <?php } ?> </table> <h1>Splitting SQL Strings Into Individual Queries</h1> <div> Usage: <pre> <?php
/** * Method to test replace(). * * @return void * * @covers Windwalker\Query\Postgresql\PostgresqlQueryBuilder::replace */ public function testReplace() { $expected = "REPLACE INTO {$this->qn}foo{$this->qn} (a,b) VALUES (c, d, e), (f, g, h)"; $actual = PostgresqlQueryBuilder::replace('foo', array('a', 'b'), array('c, d, e', 'f, g, h')); $this->assertEquals(\SqlFormatter::compress($expected), \SqlFormatter::compress($actual)); }
/** * @dataProvider compressData */ function testCompress($sql, $html) { $this->assertEquals(trim($html), trim(SqlFormatter::compress($sql))); }
function print_sql($query) { if ($GLOBALS['cli']) { print_vars($query); } else { if (class_exists('SqlFormatter')) { // Hide it under a "database icon" popup. #echo overlib_link('#', '<i class="oicon-databases"> </i>', SqlFormatter::highlight($query)); $query = SqlFormatter::compress($query); echo '<p>', SqlFormatter::highlight($query), '</p>'; } else { print_vars($query); } } }