diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-06-25 19:37:04 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-06-25 23:02:05 +0300 |
commit | 1254db42ba8d1967c6e2d71cc4711f933ef853d0 (patch) | |
tree | c130476953adca99d9ea2d666a9ca073ec76498c /src/Statements | |
parent | 8bfff84044f750d32e2c8e4a7c6ec668d435d409 (diff) | |
download | sql-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 'src/Statements')
-rw-r--r-- | src/Statements/AlterStatement.php | 48 | ||||
-rw-r--r-- | src/Statements/AnalyzeStatement.php | 50 | ||||
-rw-r--r-- | src/Statements/BackupStatement.php | 51 | ||||
-rw-r--r-- | src/Statements/CheckStatement.php | 53 | ||||
-rw-r--r-- | src/Statements/ChecsumStatement.php | 49 | ||||
-rw-r--r-- | src/Statements/CreateStatement.php | 26 | ||||
-rw-r--r-- | src/Statements/DropStatement.php | 57 | ||||
-rw-r--r-- | src/Statements/ExplainStatement.php | 19 | ||||
-rw-r--r-- | src/Statements/OptimizeStatement.php | 50 | ||||
-rw-r--r-- | src/Statements/RepairStatement.php | 55 | ||||
-rw-r--r-- | src/Statements/RestoreStatement.php | 48 | ||||
-rw-r--r-- | src/Statements/SelectStatement.php | 14 | ||||
-rw-r--r-- | src/Statements/ShowStatement.php | 76 |
13 files changed, 587 insertions, 9 deletions
diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php new file mode 100644 index 0000000..47d34bb --- /dev/null +++ b/src/Statements/AlterStatement.php @@ -0,0 +1,48 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `ALTER` statement. + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class AlterStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'DATABASE' => 1, + 'EVENT' => 1, + 'FUNCTION' => 1, + 'INDEX' => 1, + 'LOGFILE' => 1, + 'PROCEDURE' => 1, + 'SCHEMA' => 1, + 'SERVER' => 1, + 'TABLE' => 1, + 'TABLESPACE' => 1, + 'TRIGGER' => 1, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + +} diff --git a/src/Statements/AnalyzeStatement.php b/src/Statements/AnalyzeStatement.php new file mode 100644 index 0000000..abe872c --- /dev/null +++ b/src/Statements/AnalyzeStatement.php @@ -0,0 +1,50 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `ANALYZE` statement. + * + * ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE + * tbl_name [, tbl_name] ... + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class AnalyzeStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'NO_WRITE_TO_BINLOG' => 2, + 'LOCAL' => 3, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Analyzed tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php new file mode 100644 index 0000000..bca4be7 --- /dev/null +++ b/src/Statements/BackupStatement.php @@ -0,0 +1,51 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `BACKUP` statement. + * + * BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory' + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class BackupStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'NO_WRITE_TO_BINLOG' => 2, + 'LOCAL' => 3, + + 'TO' => array(4, 'var'), + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Backup tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php new file mode 100644 index 0000000..fa54591 --- /dev/null +++ b/src/Statements/CheckStatement.php @@ -0,0 +1,53 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `CHECK` statement. + * + * CHECK TABLE tbl_name [, tbl_name] ... [option] ... + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class CheckStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'FOR UPGRADE' => 2, + 'QUICK' => 3, + 'FAST' => 4, + 'MEDIUM' => 5, + 'EXTENDED' => 6, + 'CHANGED' => 7, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Checked tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/ChecsumStatement.php b/src/Statements/ChecsumStatement.php new file mode 100644 index 0000000..ff879c2 --- /dev/null +++ b/src/Statements/ChecsumStatement.php @@ -0,0 +1,49 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `CHECKSUM` statement. + * + * CHECKSUM TABLE tbl_name [, tbl_name] ... [ QUICK | EXTENDED ] + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class ChecksumStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'QUICK' => 2, + 'EXTENDED' => 3, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Checked tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index edb87ea..69e3f7f 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -57,20 +57,14 @@ class CreateStatement extends Statement public $options; /** - * The parameters of this routine. - * - * @var ParamDefFragment[] - */ - public $parameters; - - /** - * The options of the table. + * The options of the entity (table, procedure, function, etc.). * * @var OptionsFragment * * @see CreateDefFragment::$TABLE_OPTIONS + * @see CreateDefFragment::$FUNC_OPTIONS */ - public $tableOptions; + public $entityOptions; /** * Field created by this statement. @@ -80,6 +74,20 @@ class CreateStatement extends Statement public $fields; /** + * The return data type of this routine. + * + * @var DataTypeFragment + */ + public $return; + + /** + * The parameters of this routine. + * + * @var ParamDefFragment[] + */ + public $parameters; + + /** * The body of this function or procedure. * * @var Token[] diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php new file mode 100644 index 0000000..00d1591 --- /dev/null +++ b/src/Statements/DropStatement.php @@ -0,0 +1,57 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `DROP` statement. + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class DropStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'DATABASE' => 1, + 'EVENT' => 1, + 'FUNCTION' => 1, + 'INDEX' => 1, + 'LOGFILE' => 1, + 'PROCEDURE' => 1, + 'SCHEMA' => 1, + 'SERVER' => 1, + 'TABLE' => 1, + 'TABLESPACE' => 1, + 'TRIGGER' => 1, + + 'TEMPORARY' => 2, + 'IF EXISTS' => 3, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Dropped elements. + * + * @var FromKeyworrd[] + */ + public $name; +} diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php new file mode 100644 index 0000000..1983413 --- /dev/null +++ b/src/Statements/ExplainStatement.php @@ -0,0 +1,19 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `EXPLAIN` statement. + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class ExplainStatement extends Statement +{ + +} diff --git a/src/Statements/OptimizeStatement.php b/src/Statements/OptimizeStatement.php new file mode 100644 index 0000000..cb90f08 --- /dev/null +++ b/src/Statements/OptimizeStatement.php @@ -0,0 +1,50 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `OPTIMIZE` statement. + * + * OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE + * tbl_name [, tbl_name] ... + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class OptimizeStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'NO_WRITE_TO_BINLOG' => 2, + 'LOCAL' => 3, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Optimized tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php new file mode 100644 index 0000000..a3f1afe --- /dev/null +++ b/src/Statements/RepairStatement.php @@ -0,0 +1,55 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `REPAIR` statement. + * + * REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE + * tbl_name [, tbl_name] ... + * [QUICK] [EXTENDED] [USE_FRM] + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class RepairStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'NO_WRITE_TO_BINLOG' => 2, + 'LOCAL' => 3, + + 'QUICK' => 4, + 'EXTENDED' => 5, + 'USE_FRM' => 6, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Repaired tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/RestoreStatement.php b/src/Statements/RestoreStatement.php new file mode 100644 index 0000000..e8c46f8 --- /dev/null +++ b/src/Statements/RestoreStatement.php @@ -0,0 +1,48 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `RESTORE` statement. + * + * RESTORE TABLE tbl_name [, tbl_name] ... FROM '/path/to/backup/directory' + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class RestoreStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + + 'TABLE' => 1, + + 'FROM' => array(2, 'var'), + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; + + /** + * Restored tables. + * + * @var FieldFragment[] + */ + public $tables; +} diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index 50ce281..d8c9baa 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -127,6 +127,20 @@ class SelectStatement extends Statement public $limit; /** + * Procedure that should process the data in the result set. + * + * @var CallKeyword + */ + public $procedure; + + /** + * Destination of this result set. + * + * @var IntoKeyword + */ + public $into; + + /** * Joins. * * @var JoinKeyword diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php new file mode 100644 index 0000000..962a7a3 --- /dev/null +++ b/src/Statements/ShowStatement.php @@ -0,0 +1,76 @@ +<?php + +namespace SqlParser\Statements; + +use SqlParser\Statement; + +/** + * `SHOW` statement. + * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class ShowStatement extends Statement +{ + + /** + * Options of this statement. + * + * @var array + */ + public static $OPTIONS = array( + 'CREATE' => 1, + 'AUTHORS' => 2, + 'BINARY' => 2, + 'BINLOG' => 2, + 'CHARACTER' => 2, + 'CODE' => 2, + 'COLLATION' => 2, + 'COLUMNS' => 2, + 'CONTRIBUTORS' => 2, + 'DATABASE' => 2, + 'DATABASES' => 2, + 'ENGINE' => 2, + 'ENGINES' => 2, + 'ERRORS' => 2, + 'EVENT' => 2, + 'EVENTS' => 2, + 'FUNCTION' => 2, + 'GRANTS' => 2, + 'HOSTS' => 2, + 'INDEX' => 2, + 'INNODB' => 2, + 'LOGS' => 2, + 'MASTER' => 2, + 'OPEN' => 2, + 'PLUGINS' => 2, + 'PRIVILEGES' => 2, + 'PROCEDURE' => 2, + 'PROCESSLIST' => 2, + 'PROFILE' => 2, + 'PROFILES' => 2, + 'SCHEDULER' => 2, + 'SET' => 2, + 'SLAVE' => 2, + 'STATUS' => 2, + 'TABLE' => 2, + 'TABLES' => 2, + 'TRIGGER' => 2, + 'TRIGGERS' => 2, + 'VARIABLES' => 2, + 'VIEW' => 2, + 'WARNINGS' => 2, + ); + + /** + * The options of this query. + * + * @var OptionsFragment + * + * @see static::$OPTIONS + */ + public $options; +} |