summaryrefslogtreecommitdiffstats
path: root/tests/utils/QueryTest.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-06-25 19:37:04 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-06-25 23:02:05 +0300
commit1254db42ba8d1967c6e2d71cc4711f933ef853d0 (patch)
treec130476953adca99d9ea2d666a9ca073ec76498c /tests/utils/QueryTest.php
parent8bfff84044f750d32e2c8e4a7c6ec668d435d409 (diff)
downloadsql-parser-1254db42ba8d1967c6e2d71cc4711f933ef853d0.zip
sql-parser-1254db42ba8d1967c6e2d71cc4711f933ef853d0.tar.gz
sql-parser-1254db42ba8d1967c6e2d71cc4711f933ef853d0.tar.bz2
Added query utilities.
Included basic support for ANALYZE, BACKUP, CHECK, CHECKSUM, OPTIMIZE, REPAIR and RESTORE statements. Better parsing for fields, SELECT statement, INTO keyword. Improved contexts (included functions). Improved documentation. Refactoring and coding style fixes.
Diffstat (limited to 'tests/utils/QueryTest.php')
-rw-r--r--tests/utils/QueryTest.php128
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/utils/QueryTest.php b/tests/utils/QueryTest.php
new file mode 100644
index 0000000..021339e
--- /dev/null
+++ b/tests/utils/QueryTest.php
@@ -0,0 +1,128 @@
+<?php
+
+namespace SqlParser\Tests\Utils;
+
+use SqlParser\Parser;
+use SqlParser\Utils\Query;
+
+use SqlParser\Tests\TestCase;
+
+class QueryTest extends TestCase
+{
+
+ /**
+ * @dataProvider testGetFlagsProvider
+ */
+ public function testGetFlags($query, $expected)
+ {
+ $parser = new Parser($query);
+ $this->assertEquals(
+ $expected,
+ Query::getFlags($parser->statements[0])
+ );
+ }
+
+ public function testGetFlagsProvider()
+ {
+ return array(
+ array(
+ 'ALTER TABLE DROP col',
+ array('reload' => true)
+ ),
+ array(
+ 'CREATE TABLE tbl (id INT)',
+ array('reload' => true)
+ ),
+ array(
+ 'ANALYZE TABLE tbl',
+ array(
+ 'is_maint' => true,
+ 'is_analyze' => true
+ )
+ ),
+ array(
+ 'CHECK TABLE tbl',
+ array('is_maint' => true)
+ ),
+ array(
+ 'DELETE FROM tbl',
+ array(
+ 'is_delete' => true,
+ 'is_affected' => true
+ ),
+ ),
+ array(
+ 'DROP VIEW v',
+ array('reload' => true)
+ ),
+ array(
+ 'DROP DATABASE db',
+ array(
+ 'reload' => true,
+ 'drop_database' => true
+ )
+ ),
+ array(
+ 'EXPLAIN tbl',
+ array('is_explain' => true),
+ ),
+ array(
+ 'INSERT INTO tbl VALUES (1)',
+ array(
+ 'is_affected' => true,
+ 'is_insert' => true
+ )
+ ),
+ array(
+ 'REPLACE INTO tbl VALUES (2)',
+ array(
+ 'is_affected' => true,
+ 'is_replace' => true
+ )
+ ),
+ array(
+ 'SELECT 1',
+ array()
+ ),
+ array(
+ 'SELECT * FROM tbl',
+ array('select_from' => true)
+ ),
+ array(
+ 'SELECT DISTINCT * FROM tbl',
+ array(
+ 'select_from' => true,
+ 'distinct' => true
+ )
+ ),
+ array(
+ 'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"',
+ array(
+ 'select_from' => true,
+ 'is_export' => true
+ )
+ ),
+ array(
+ 'SELECT COUNT(id), SUM(id) FROM tbl',
+ array(
+ 'select_from' => true,
+ 'is_func' => true,
+ 'is_count' => true
+ )
+ ),
+ array(
+ 'SELECT (SELECT "foo")',
+ array('is_subquery' => true)
+ ),
+ array(
+ 'SHOW CREATE TABLE tbl',
+ array('is_show' => true)
+ ),
+ array(
+ 'UPDATE tbl SET id = 1',
+ array('is_affected' => true)
+ )
+ );
+ }
+
+}