diff options
48 files changed, 734 insertions, 263 deletions
diff --git a/src/Context.php b/src/Context.php index 9d6927a..e46a047 100644 --- a/src/Context.php +++ b/src/Context.php @@ -4,6 +4,11 @@ namespace SqlParser; /** * Default MySQL context (based on MySQL 5.7). + * + * @category Contexts + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ abstract class Context { @@ -31,14 +36,14 @@ abstract class Context * * @var string */ - public static $defaultContext = '\\SqlParser\\Contexts\\Context_MySQL570'; + public static $defaultContext = '\\SqlParser\\Contexts\\Context_MySQL50700'; /** * The name of the loaded context. * * @var string */ - public static $loadedContext = '\\SqlParser\\Contexts\\Context_MySQL570'; + public static $loadedContext = '\\SqlParser\\Contexts\\Context_MySQL50700'; // ------------------------------------------------------------------------- // Keywords. @@ -424,10 +429,10 @@ abstract class Context /** * Checks if the given string is a keyword. * - * @param string $str - * @param bool $isReserved + * @param string $str String to be checked. + * @param bool $isReserved Checks if the keyword is reserved. * - * @return bool + * @return int */ public static function isKeyword($str, $isReserved = false) { @@ -451,7 +456,7 @@ abstract class Context /** * Checks if the given string is an operator. * - * @param string $str + * @param string $str String to be checked. * * @return int The appropriate flag for the operator. */ @@ -469,7 +474,7 @@ abstract class Context /** * Checks if the given character is a whitespace. * - * @param string $ch + * @param string $ch String to be checked. * * @return bool */ @@ -484,7 +489,7 @@ abstract class Context /** * Checks if the given string is the beginning of a whitespace. * - * @param string $str + * @param string $str String to be checked. * * @return int The appropriate flag for the comment type. */ @@ -514,7 +519,7 @@ abstract class Context * This actually check only for `TRUE` and `FALSE` because `1` or `0` are * actually numbers and are parsed by specific methods. * - * @param string $ch + * @param string $ch String to be checked. * * @return bool */ @@ -530,7 +535,7 @@ abstract class Context /** * Checks if the given character can be a part of a number. * - * @param string $ch + * @param string $ch String to be checked. * * @return bool */ @@ -547,7 +552,7 @@ abstract class Context * Checks if the given character is the beginning of a symbol. A symbol * can be either a variable or a field name. * - * @param string $ch + * @param string $ch String to be checked. * * @return int The appropriate flag for the symbol type. */ @@ -567,7 +572,7 @@ abstract class Context /** * Checks if the given character is the beginning of a string. * - * @param string $str + * @param string $str String to be checked. * * @return int The appropriate flag for the string type. */ @@ -587,7 +592,7 @@ abstract class Context /** * Checks if the given character can be a separator for two lexems. * - * @param string $ch + * @param string $ch String to be checked. * * @return bool */ @@ -601,9 +606,13 @@ abstract class Context * * Contexts may be used by accessing the context directly. * - * @param string $context + * @param string $context Name of the context or full class name that + * defines the context. + * + * @return void */ - public static function load($context = '') { + public static function load($context = '') + { if (empty($context)) { $context = self::$defaultContext; } @@ -617,5 +626,4 @@ abstract class Context static::$loadedContext = $context; static::$KEYWORDS = $context::$KEYWORDS; } - } diff --git a/src/Contexts/Context_MySQL500.php b/src/Contexts/Context_MySQL50000.php index 3a54e84..830399e 100644 --- a/src/Contexts/Context_MySQL500.php +++ b/src/Contexts/Context_MySQL50000.php @@ -4,7 +4,16 @@ namespace SqlParser\Contexts; use SqlParser\Context; -class Context_MySQL500 extends Context +/** + * Context for MySQL 5.0. + * + * @category Contexts + * @package SqlParser + * @subpackage Contexts + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class Context_MySQL50000 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL510.php b/src/Contexts/Context_MySQL50100.php index e5713ec..f70ecef 100644 --- a/src/Contexts/Context_MySQL510.php +++ b/src/Contexts/Context_MySQL50100.php @@ -4,7 +4,16 @@ namespace SqlParser\Contexts; use SqlParser\Context; -class Context_MySQL510 extends Context +/** + * Context for MySQL 5.1. + * + * @category Contexts + * @package SqlParser + * @subpackage Contexts + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class Context_MySQL50100 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL550.php b/src/Contexts/Context_MySQL50500.php index 6d1b8d1..6febe72 100644 --- a/src/Contexts/Context_MySQL550.php +++ b/src/Contexts/Context_MySQL50500.php @@ -4,7 +4,16 @@ namespace SqlParser\Contexts; use SqlParser\Context; -class Context_MySQL550 extends Context +/** + * Context for MySQL 5.5. + * + * @category Contexts + * @package SqlParser + * @subpackage Contexts + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class Context_MySQL50500 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL560.php b/src/Contexts/Context_MySQL50600.php index 18fff66..dfd114a 100644 --- a/src/Contexts/Context_MySQL560.php +++ b/src/Contexts/Context_MySQL50600.php @@ -4,7 +4,16 @@ namespace SqlParser\Contexts; use SqlParser\Context; -class Context_MySQL560 extends Context +/** + * Context for MySQL 5.6. + * + * @category Contexts + * @package SqlParser + * @subpackage Contexts + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class Context_MySQL50600 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL570.php b/src/Contexts/Context_MySQL50700.php index 7c97c8b..b795b2d 100644 --- a/src/Contexts/Context_MySQL570.php +++ b/src/Contexts/Context_MySQL50700.php @@ -4,7 +4,16 @@ namespace SqlParser\Contexts; use SqlParser\Context; -class Context_MySQL570 extends Context +/** + * Context for MySQL 5.7. + * + * @category Contexts + * @package SqlParser + * @subpackage Contexts + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ +class Context_MySQL50700 extends Context { public static $KEYWORDS = array( diff --git a/src/Exceptions/LexerException.php b/src/Exceptions/LexerException.php index 306c8b9..53327ed 100644 --- a/src/Exceptions/LexerException.php +++ b/src/Exceptions/LexerException.php @@ -6,6 +6,12 @@ use SqlParser\Token; /** * Exception thrown by the lexer. + * + * @category Exceptions + * @package SqlParser + * @subpackage Exceptions + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class LexerException extends \Exception { @@ -27,10 +33,10 @@ class LexerException extends \Exception /** * Constructor. * - * @param string $msg The message of this exception. - * @param string $ch The character that produced this exception. - * @param int $pos The position of the character. - * @param int $code The code of this error. + * @param string $msg The message of this exception. + * @param string $ch The character that produced this exception. + * @param int $pos The position of the character. + * @param int $code The code of this error. */ public function __construct($msg = '', $ch = '', $pos = 0, $code = 0) { diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index 7332674..06a6033 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -6,6 +6,12 @@ use SqlParser\Token; /** * Exception thrown by the parser. + * + * @category Exceptions + * @package SqlParser + * @subpackage Exceptions + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class ParserException extends \Exception { @@ -20,9 +26,9 @@ class ParserException extends \Exception /** * Constructor. * - * @param string $msg The message of this exception. - * @param Token $token The token that produced this exception. - * @param int $code The code of this error. + * @param string $msg The message of this exception. + * @param Token $token The token that produced this exception. + * @param int $code The code of this error. */ public function __construct($msg = '', Token $token = null, $code = 0) { diff --git a/src/Fragment.php b/src/Fragment.php index 63af280..51cec95 100644 --- a/src/Fragment.php +++ b/src/Fragment.php @@ -5,18 +5,26 @@ namespace SqlParser; /** * A fragment (of a statement) is a part of a statement that is common to * multiple query types. + * + * @category Fragments + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ abstract class Fragment { /** - * Parses the tokens given by the lexer in the context of the given parser. + * Parses the tokens contained in the given list in the context of the given + * parser. * - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * - * @return array + * @return mixed */ - abstract public static function parse(Parser $parser, TokensList $list, array $options = array()); + abstract public static function parse(Parser $parser, TokensList $list, + array $options = array() + ); } diff --git a/src/Fragments/ArrayFragment.php b/src/Fragments/ArrayFragment.php index 6436823..eb5a80b 100644 --- a/src/Fragments/ArrayFragment.php +++ b/src/Fragments/ArrayFragment.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses an array. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class ArrayFragment extends Fragment { @@ -29,9 +34,9 @@ class ArrayFragment extends Fragment public $raw = array(); /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return ArrayFragment */ @@ -56,7 +61,11 @@ class ArrayFragment extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/CallKeyword.php b/src/Fragments/CallKeyword.php index 6147cf4..db11120 100644 --- a/src/Fragments/CallKeyword.php +++ b/src/Fragments/CallKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses a function call. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class CallKeyword extends Fragment { @@ -29,9 +34,9 @@ class CallKeyword extends Fragment public $parameters = array(); /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return CallKeyword */ @@ -53,7 +58,11 @@ class CallKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/CreateDefFragment.php b/src/Fragments/CreateDefFragment.php index 675ad81..58eabaa 100644 --- a/src/Fragments/CreateDefFragment.php +++ b/src/Fragments/CreateDefFragment.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses the definition that follows the `CREATE` keyword. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class CreateDefFragment extends Fragment { @@ -70,9 +75,9 @@ class CreateDefFragment extends Fragment public $name; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return CreateDefFragment */ @@ -81,7 +86,11 @@ class CreateDefFragment extends Fragment $ret = new CreateDefFragment(); for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. @@ -90,11 +99,15 @@ class CreateDefFragment extends Fragment } // Skipping whitespaces and comments. - if (($token->type === Token::TYPE_WHITESPACE) || ($token->type === Token::TYPE_COMMENT)) { + if (($token->type === Token::TYPE_WHITESPACE) + || ($token->type === Token::TYPE_COMMENT) + ) { continue; } - if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { + if (($token->type === Token::TYPE_OPERATOR) + && ($token->value === '(') + ) { break; } diff --git a/src/Fragments/DataTypeFragment.php b/src/Fragments/DataTypeFragment.php index ca7cfaf..7baefdd 100644 --- a/src/Fragments/DataTypeFragment.php +++ b/src/Fragments/DataTypeFragment.php @@ -4,13 +4,18 @@ namespace SqlParser\Fragments; use SqlParser\Context; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses a data type. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class DataTypeFragment extends Fragment { @@ -46,9 +51,9 @@ class DataTypeFragment extends Fragment public $options = array(); /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return DataTypeFragment[] */ @@ -70,7 +75,11 @@ class DataTypeFragment extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // Skipping whitespaces and comments. diff --git a/src/Fragments/FieldDefFragment.php b/src/Fragments/FieldDefFragment.php index 3079681..ba4b6dc 100644 --- a/src/Fragments/FieldDefFragment.php +++ b/src/Fragments/FieldDefFragment.php @@ -4,7 +4,6 @@ namespace SqlParser\Fragments; use SqlParser\Context; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; @@ -13,6 +12,12 @@ use SqlParser\TokensList; * Parses the definition of a field. * * Used for parsing `CREATE TABLE` statement. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class FieldDefFragment extends Fragment { @@ -64,9 +69,9 @@ class FieldDefFragment extends Fragment public $options; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return FieldDefFragment[] */ @@ -105,7 +110,11 @@ class FieldDefFragment extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/FieldFragment.php b/src/Fragments/FieldFragment.php index 9a69a2e..4adbba5 100644 --- a/src/Fragments/FieldFragment.php +++ b/src/Fragments/FieldFragment.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses a reference to a field. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class FieldFragment extends Fragment { @@ -50,9 +55,9 @@ class FieldFragment extends Fragment public $alias; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return FieldFragment */ @@ -60,20 +65,36 @@ class FieldFragment extends Fragment { $ret = new FieldFragment(); - /** @var bool Whether current tokens make an expression or a table reference. */ + /** + * Whether current tokens make an expression or a table reference. + * @var bool + */ $isExpr = false; - /** @var bool Whether a period was previously found. */ + /** + * Whether a period was previously found. + * @var bool + */ $period = false; - /** @var int Whether an alias is expected. Is 2 if `AS` keyword was found. */ + /** + * Whether an alias is expected. Is 2 if `AS` keyword was found. + * @var int + */ $alias = 0; - /** @var int Counts brackets. */ + /** + * Counts brackets. + * @var int + */ $brackets = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. @@ -122,7 +143,8 @@ class FieldFragment extends Fragment if (($token->type === Token::TYPE_NUMBER) || ($token->type === Token::TYPE_BOOL) || (($token->type === Token::TYPE_SYMBOL) && ($token->flags & Token::FLAG_SYMBOL_VARIABLE)) - || (($token->type === Token::TYPE_OPERATOR)) && ($token->value !== '.')) { + || (($token->type === Token::TYPE_OPERATOR)) && ($token->value !== '.') + ) { // Numbers, booleans and operators are usually part of expressions. $isExpr = true; } @@ -159,7 +181,7 @@ class FieldFragment extends Fragment } if ($alias === 2) { - $parser->error('Alias was expected.', $token); + $parser->error('Alias was expected.'); } if (empty($ret->expr)) { diff --git a/src/Fragments/FromKeyword.php b/src/Fragments/FromKeyword.php index c7dc624..aea9c3e 100644 --- a/src/Fragments/FromKeyword.php +++ b/src/Fragments/FromKeyword.php @@ -3,21 +3,26 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `FROM` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class FromKeyword extends Fragment { /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return FieldFragment[] */ @@ -28,7 +33,11 @@ class FromKeyword extends Fragment $expr = new FieldFragment(); for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/IntoKeyword.php b/src/Fragments/IntoKeyword.php index d56293a..c4211fd 100644 --- a/src/Fragments/IntoKeyword.php +++ b/src/Fragments/IntoKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `INTO` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class IntoKeyword extends Fragment { @@ -29,9 +34,9 @@ class IntoKeyword extends Fragment public $fields; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return IntoKeyword */ @@ -55,7 +60,11 @@ class IntoKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/JoinKeyword.php b/src/Fragments/JoinKeyword.php index 411d227..b6b2c22 100644 --- a/src/Fragments/JoinKeyword.php +++ b/src/Fragments/JoinKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `JOIN` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class JoinKeyword extends Fragment { @@ -24,14 +29,14 @@ class JoinKeyword extends Fragment /** * Join conditions. * - * @var WhereKeyword + * @var WhereKeyword[] */ public $on; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return JoinKeyword */ @@ -55,7 +60,11 @@ class JoinKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/LimitKeyword.php b/src/Fragments/LimitKeyword.php index 3e6f592..2e5b819 100644 --- a/src/Fragments/LimitKeyword.php +++ b/src/Fragments/LimitKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `lIMIT` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class LimitKeyword extends Fragment { @@ -29,9 +34,9 @@ class LimitKeyword extends Fragment public $row_count; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return LimitKeyword */ @@ -42,7 +47,11 @@ class LimitKeyword extends Fragment $offset = false; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/OptionsFragment.php b/src/Fragments/OptionsFragment.php index 3317f10..f002f5b 100644 --- a/src/Fragments/OptionsFragment.php +++ b/src/Fragments/OptionsFragment.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * Parses a list of options. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class OptionsFragment extends Fragment { @@ -22,9 +27,9 @@ class OptionsFragment extends Fragment public $options = array(); /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return OptionsFragment */ @@ -32,17 +37,27 @@ class OptionsFragment extends Fragment { $ret = new OptionsFragment(); - /** @var int The ID that will be assigned to duplicate options. */ + /** + * The ID that will be assigned to duplicate options. + * @var int + */ $lastAssignedId = count($options) + 1; - /** @var array The option that was processed last time. */ + /** + * The option that was processed last time. + * @var array + */ $lastOption = null; $lastOptionId = 0; $brackets = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/OrderKeyword.php b/src/Fragments/OrderKeyword.php index 4cebc1c..224a573 100644 --- a/src/Fragments/OrderKeyword.php +++ b/src/Fragments/OrderKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `ORDER BY` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class OrderKeyword extends Fragment { @@ -29,9 +34,9 @@ class OrderKeyword extends Fragment public $type = 'ASC'; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return OrderKeyword[] */ @@ -42,7 +47,11 @@ class OrderKeyword extends Fragment $expr = new OrderKeyword(); for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/ParamDefFragment.php b/src/Fragments/ParamDefFragment.php index 132898f..4756120 100644 --- a/src/Fragments/ParamDefFragment.php +++ b/src/Fragments/ParamDefFragment.php @@ -4,13 +4,18 @@ namespace SqlParser\Fragments; use SqlParser\Context; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * The definition of a parameter of a function or procedure. + * + * @category Fragments + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class ParamDefFragment extends Fragment { @@ -37,9 +42,9 @@ class ParamDefFragment extends Fragment public $type; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return ParamDefFragment[] */ @@ -69,7 +74,11 @@ class ParamDefFragment extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/RenameKeyword.php b/src/Fragments/RenameKeyword.php index c38dae6..9e9969c 100644 --- a/src/Fragments/RenameKeyword.php +++ b/src/Fragments/RenameKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `RENAME TABLE` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class RenameKeyword extends Fragment { @@ -29,9 +34,9 @@ class RenameKeyword extends Fragment public $new; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return RenameKeyword */ @@ -60,7 +65,11 @@ class RenameKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/SelectKeyword.php b/src/Fragments/SelectKeyword.php index 8848815..fc59aa0 100644 --- a/src/Fragments/SelectKeyword.php +++ b/src/Fragments/SelectKeyword.php @@ -3,21 +3,26 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `SELECT` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class SelectKeyword extends Fragment { /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return FieldFragment[] */ @@ -28,7 +33,11 @@ class SelectKeyword extends Fragment $expr = null; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/SetKeyword.php b/src/Fragments/SetKeyword.php index 284173e..82f9965 100644 --- a/src/Fragments/SetKeyword.php +++ b/src/Fragments/SetKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `SET` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class SetKeyword extends Fragment { @@ -29,9 +34,9 @@ class SetKeyword extends Fragment public $value; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return SetKeyword[] */ @@ -56,7 +61,11 @@ class SetKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/ValuesKeyword.php b/src/Fragments/ValuesKeyword.php index db8c5fd..cb470dd 100644 --- a/src/Fragments/ValuesKeyword.php +++ b/src/Fragments/ValuesKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `VALUES` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class ValuesKeyword extends Fragment { @@ -22,9 +27,9 @@ class ValuesKeyword extends Fragment public $values; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return ValuesKeyword */ @@ -54,7 +59,11 @@ class ValuesKeyword extends Fragment $state = 0; for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Fragments/WhereKeyword.php b/src/Fragments/WhereKeyword.php index c9ce460..0bc60a7 100644 --- a/src/Fragments/WhereKeyword.php +++ b/src/Fragments/WhereKeyword.php @@ -3,13 +3,18 @@ namespace SqlParser\Fragments; use SqlParser\Fragment; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Token; use SqlParser\TokensList; /** * `WHERE` keyword parser. + * + * @category Keywords + * @package SqlParser + * @subpackage Fragments + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class WhereKeyword extends Fragment { @@ -19,7 +24,7 @@ class WhereKeyword extends Fragment * * @var array */ - private static $OPERATORS = array('&&', '(', ')', 'AND', 'OR', 'XOR', '||'); + public static $OPERATORS = array('&&', '(', ')', 'AND', 'OR', 'XOR', '||'); /** * Whether this fragment is an operator. @@ -36,9 +41,9 @@ class WhereKeyword extends Fragment public $condition; /** - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. * * @return WhereKeyword[] */ @@ -49,7 +54,11 @@ class WhereKeyword extends Fragment $expr = new WhereKeyword(); for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. diff --git a/src/Lexer.php b/src/Lexer.php index e7cb64a..33e7337 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -10,7 +10,11 @@ use SqlParser\Exceptions\LexerException; * * The output of the lexer is affected by the context of the SQL statement. * - * @see Context + * @category Lexer + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @see Context */ class Lexer { @@ -123,8 +127,8 @@ class Lexer /** * Constructor. * - * @param string|UtfString $str The query to be lexed. - * @param bool $strict Whether strict mode should be enabled or not. + * @param string|UtfString $str The query to be lexed. + * @param bool $strict Whether strict mode should be enabled or not. */ public function __construct($str, $strict = false) { @@ -137,6 +141,8 @@ class Lexer /** * Parses the string and extracts lexems. + * + * @return void */ public function lex() { @@ -153,7 +159,11 @@ class Lexer $lastToken = null; for ($this->last = 0, $lastIdx = 0; $this->last < $this->len; $lastIdx = ++$this->last) { - /** @var Token The new token. */ + + /** + * The new token. + * @var Token + */ $token = null; foreach (static::$PARSER_METHODS as $method) { @@ -188,7 +198,6 @@ class Lexer // Handling delimiters. if (($token->type === Token::TYPE_NONE) && ($token->value === 'DELIMITER')) { - if ($this->last + 1 >= $this->len) { $this->error('Expected whitespace(s) before delimiter.', '', $this->last + 1); continue; @@ -236,10 +245,12 @@ class Lexer /** * Creates a new error log. * - * @param string $msg The error message. - * @param string $ch The character that produced the error. - * @param int $pos The position of the character. - * @param int $code The code of the error. + * @param string $msg The error message. + * @param string $str The character that produced the error. + * @param int $pos The position of the character. + * @param int $code The code of the error. + * + * @return void */ public function error($msg = '', $str = '', $pos = 0, $code = 0) { @@ -259,10 +270,16 @@ class Lexer { $token = ''; - /** @var Token Value to be returned. */ + /** + * Value to be returned. + * @var Token + */ $ret = null; - /** @var int The value of `$this->last` where `$token` ends in `$this->str`. */ + /** + * The value of `$this->last` where `$token` ends in `$this->str`. + * @var int + */ $iEnd = $this->last; for ($j = 1; $j < Context::KEYWORD_MAX_LENGTH && $this->last < $this->len; ++$j, ++$this->last) { @@ -291,10 +308,16 @@ class Lexer { $token = ''; - /** @var Token|bool Value to be returned. */ - $ret = false; + /** + * Value to be returned. + * @var Token|bool + */ + $ret = null; - /** @var int The value of `$this->last` where `$token` ends in `$this->str`. */ + /** + * The value of `$this->last` where `$token` ends in `$this->str`. + * @var int + */ $iEnd = $this->last; for ($j = 1; $j < Context::OPERATOR_MAX_LENGTH && $this->last < $this->len; ++$j, ++$this->last) { @@ -508,8 +531,9 @@ class Lexer } } elseif ($state === 5) { $flags |= Token::FLAG_NUMBER_APPROXIMATE; - if (($this->str[$this->last] === '+') || ($this->str[$this->last] === '-') || - ((($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9')))) { + if (($this->str[$this->last] === '+') || ($this->str[$this->last] === '-') + || ((($this->str[$this->last] >= '0') && ($this->str[$this->last] <= '9'))) + ) { $state = 6; } else { break; diff --git a/src/Parser.php b/src/Parser.php index 059faa5..2973a03 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -7,6 +7,11 @@ use SqlParser\Exceptions\ParserException; /** * Takes multiple tokens (contained in a Lexer instance) as input and builds a * parse tree. + * + * @category Parser + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class Parser { @@ -119,8 +124,8 @@ class Parser /** * Constructor. * - * @param mixed $list The list of tokens to be parsed. - * @param bool $strict Whether strict mode should be enabled or not. + * @param mixed $list The list of tokens to be parsed. + * @param bool $strict Whether strict mode should be enabled or not. */ public function __construct($list = null, $strict = false) { @@ -140,6 +145,8 @@ class Parser /** * Builds the parse trees. + * + * @return void */ public function parse() { @@ -148,7 +155,11 @@ class Parser $last = &$this->list->idx; for (; $last < $count; ++$last) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $tokens[$last]; // Statements can start with keywords only. @@ -160,17 +171,23 @@ class Parser // Checking if it is a known statement that can be parsed. if (empty(static::$STATEMENT_PARSERS[$token->value])) { $this->error( - 'Unrecognized statement type "' . $token->value .'".', + 'Unrecognized statement type "' . $token->value . '".', $token ); // TODO: Skip to first delimiter. continue; } - /** @var string The name of the class that is used for parsing. */ + /** + * The name of the class that is used for parsing. + * @var string + */ $class = static::$STATEMENT_PARSERS[$token->value]; - /** @var Statement Processed statement. */ + /** + * Processed statement. + * @var Statement + */ $stmt = new $class(); $stmt->parse($this, $this->list); @@ -181,13 +198,13 @@ class Parser /** * Creates a new error log. * - * @param string $msg The error message. - * @param Token $token The token that produced the error. - * @param int $code The code of the error. + * @param string $msg The error message. + * @param Token $token The token that produced the error. + * @param int $code The code of the error. */ - public function error($str = '', Token $token = null, $code = 0) + public function error($msg = '', Token $token = null, $code = 0) { - $error = new ParserException($str, $token, $code); + $error = new ParserException($msg, $token, $code); if ($this->strict) { throw $error; } diff --git a/src/Statement.php b/src/Statement.php index b1dc2c1..13002f4 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -2,11 +2,9 @@ namespace SqlParser; -use SqlParser\Lexer; use SqlParser\Parser; use SqlParser\Statement; use SqlParser\Token; - use SqlParser\Fragments\CallKeyword; use SqlParser\Fragments\CreateDefFragment; use SqlParser\Fragments\DataTypeFragment; @@ -17,6 +15,14 @@ use SqlParser\Fragments\ParamDefFragment; use SqlParser\Fragments\RenameKeyword; use SqlParser\Fragments\SelectKeyword; +/** + * Abstract statement definition. + * + * @category Statements + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ abstract class Statement { @@ -37,13 +43,19 @@ abstract class Statement /** * Parses the statements defined by the tokens list. * - * @param Parser $parser - * @param TokensList $list + * @param Parser $parser The instance that requests parsing. + * @param TokensList $list The list of tokens to be parsed. + * + * @return void */ public function parse(Parser $parser, TokensList $list) { for (; $list->idx < $list->count; ++$list->idx) { - /** @var Token Token parsed at this moment. */ + + /** + * Token parsed at this moment. + * @var Token + */ $token = $list->tokens[$list->idx]; // End of statement. @@ -57,7 +69,10 @@ abstract class Statement continue; } - /** @var string The name of the class that is used for parsing. */ + /** + * The name of the class that is used for parsing. + * @var string + */ $class = null; if (!empty(Parser::$KEYWORD_PARSERS[$token->value])) { @@ -73,13 +88,19 @@ abstract class Statement continue; } - /** @var string The name of the field where the result is stored. */ + /** + * The name of the field where the result is stored. + * @var string + */ $field = strtolower($token->value); // Parsing options. if (($class == null) && (isset(static::$OPTIONS))) { ++$list->idx; // Skipping keyword. - $this->options = OptionsFragment::parse($parser, $list, static::$OPTIONS); + $this->options = OptionsFragment::parse( + $parser, $list, + static::$OPTIONS + ); } // Keyword specific code. @@ -93,33 +114,53 @@ abstract class Statement ++$list->idx; $this->fields = FieldDefFragment::parse($parser, $list); ++$list->idx; - $this->tableOptions = OptionsFragment::parse($parser, $list, CreateDefFragment::$TABLE_OPTIONS); - } elseif (($this->options->has('PROCEDURE')) || ($this->options->has('FUNCTION'))) { + $this->tableOptions = OptionsFragment::parse( + $parser, + $list, + CreateDefFragment::$TABLE_OPTIONS + ); + } elseif (($this->options->has('PROCEDURE')) + || ($this->options->has('FUNCTION')) + ) { ++$list->idx; $this->parameters = ParamDefFragment::parse($parser, $list); if ($this->options->has('FUNCTION')) { $token = $list->getNextOfType(Token::TYPE_KEYWORD); if ($token->value !== 'RETURNS') { - $parser->error('\'RETURNS\' keyword was expected.', $token); + $parser->error( + '\'RETURNS\' keyword was expected.', + $token + ); } else { ++$list->idx; - $this->return = DataTypeFragment::parse($parser, $list); + $this->return = DataTypeFragment::parse( + $parser, + $list + ); } } ++$list->idx; - $this->funcOptions = OptionsFragment::parse($parser, $list, CreateDefFragment::$FUNC_OPTIONS); + $this->funcOptions = OptionsFragment::parse( + $parser, + $list, + CreateDefFragment::$FUNC_OPTIONS + ); ++$list->idx; $this->body = array(); for (; $list->idx < $list->count; ++$list->idx) { $token = $list->tokens[$list->idx]; $this->body[] = $token; - if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'END')) { + if (($token->type === Token::TYPE_KEYWORD) + && ($token->value === 'END') + ) { break; } } $class = null; // The statement has been processed here. } - } elseif (($token->value === 'GROUP') || ($token->value === 'ORDER')) { + } elseif (($token->value === 'GROUP') + || ($token->value === 'ORDER') + ) { $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'BY'); } elseif ($token->value === 'RENAME') { $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'TABLE'); diff --git a/src/Statements/CallStatement.php b/src/Statements/CallStatement.php index 76681b5..162f50e 100644 --- a/src/Statements/CallStatement.php +++ b/src/Statements/CallStatement.php @@ -6,6 +6,18 @@ use SqlParser\Statement; /** * `CALL` statement. + * + * CALL sp_name([parameter[,...]]) + * + * or + * + * CALL sp_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 CallStatement extends Statement { diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index 00561f5..7a248e9 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -6,6 +6,12 @@ use SqlParser\Statement; /** * `CREATE` 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 CreateStatement extends Statement { diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 01dd8ad..0e88fed 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -13,6 +13,11 @@ use SqlParser\Statement; * [ORDER BY ...] * [LIMIT row_count] * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class DeleteStatement extends Statement { diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index f24634a..db88b42 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -37,6 +37,11 @@ use SqlParser\Statement; * col_name=expr * [, col_name=expr] ... ] * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class InsertStatement extends Statement { diff --git a/src/Statements/RenameStatement.php b/src/Statements/RenameStatement.php index bd3c767..88607ea 100644 --- a/src/Statements/RenameStatement.php +++ b/src/Statements/RenameStatement.php @@ -10,6 +10,11 @@ use SqlParser\Statement; * RENAME TABLE tbl_name TO new_tbl_name * [, tbl_name2 TO new_tbl_name2] ... * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class RenameStatement extends Statement { diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index 8e69207..577f72c 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -17,6 +17,11 @@ use SqlParser\Statement; * [INTO] tbl_name * SET col_name={expr | DEFAULT}, ... * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class ReplaceStatement extends Statement { diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index d17450e..50ce281 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -32,6 +32,11 @@ use SqlParser\Statement; * | INTO var_name [, var_name]] * [FOR UPDATE | LOCK IN SHARE MODE]] * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class SelectStatement extends Statement { diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php index cdeab03..8dcc6f0 100644 --- a/src/Statements/UpdateStatement.php +++ b/src/Statements/UpdateStatement.php @@ -19,6 +19,11 @@ use SqlParser\Statement; * SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... * [WHERE where_condition] * + * @category Statements + * @package SqlParser + * @subpackage Statements + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class UpdateStatement extends Statement { diff --git a/src/Token.php b/src/Token.php index 7563d77..5a378ca 100644 --- a/src/Token.php +++ b/src/Token.php @@ -5,6 +5,11 @@ namespace SqlParser; /** * A structure representing a lexeme that explicitly indicates its * categorization for the purpose of parsing. + * + * @category Tokens + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class Token { @@ -179,10 +184,9 @@ class Token /** * Constructor. * - * @param string $token - * @param int $type - * @param int $flags - * @param int $position + * @param string $token The value of the token. + * @param int $type The type of the token. + * @param int $flags The flags of the token. */ public function __construct($token, $type = 0, $flags = 0) { @@ -202,47 +206,50 @@ class Token public function extract() { switch ($this->type) { - case Token::TYPE_KEYWORD: - if ($this->flags & Token::FLAG_KEYWORD_RESERVED) { - return strtoupper($this->token); - } - return $this->token; - case Token::TYPE_WHITESPACE: - return ' '; - case Token::TYPE_BOOL: - return strtoupper($this->token) === 'TRUE'; - case Token::TYPE_NUMBER: - $ret = str_replace('--', '', $this->token); // e.g. ---42 === -42 - if ($this->flags & Token::FLAG_NUMBER_HEX) { - if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) { - $ret = str_replace('-', '', $this->token); - sscanf($ret, "%x", $ret); - $ret = -$ret; - } else { - sscanf($ret, "%x", $ret); - } - } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE) || - ($this->flags & Token::FLAG_NUMBER_FLOAT)) { - sscanf($ret, "%f", $ret); + case Token::TYPE_KEYWORD: + if ($this->flags & Token::FLAG_KEYWORD_RESERVED) { + return strtoupper($this->token); + } + return $this->token; + case Token::TYPE_WHITESPACE: + return ' '; + case Token::TYPE_BOOL: + return strtoupper($this->token) === 'TRUE'; + case Token::TYPE_NUMBER: + $ret = str_replace('--', '', $this->token); // e.g. ---42 === -42 + if ($this->flags & Token::FLAG_NUMBER_HEX) { + if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) { + $ret = str_replace('-', '', $this->token); + sscanf($ret, "%x", $ret); + $ret = -$ret; } else { - sscanf($ret, "%d", $ret); - } - return $ret; - case Token::TYPE_STRING: - $quote = $this->token[0]; - $str = str_replace($quote . $quote, $quote, $this->token); - return mb_substr($str, 1, -1); // trims quotes - case Token::TYPE_SYMBOL: - $str = $this->token; - if ((isset($str[0])) && ($str[0] === '@')) { - $str = mb_substr($str, 1); - } - if ((isset($str[0])) && (($str[0] === '`') || ($str[0] === '"') || ($str[0] === '\''))) { - $quote = $str[0]; - $str = str_replace($quote . $quote, $quote, $str); - $str = mb_substr($str, 1, -1); + sscanf($ret, "%x", $ret); } - return $str; + } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE) + || ($this->flags & Token::FLAG_NUMBER_FLOAT) + ) { + sscanf($ret, "%f", $ret); + } else { + sscanf($ret, "%d", $ret); + } + return $ret; + case Token::TYPE_STRING: + $quote = $this->token[0]; + $str = str_replace($quote . $quote, $quote, $this->token); + return mb_substr($str, 1, -1); // trims quotes + case Token::TYPE_SYMBOL: + $str = $this->token; + if ((isset($str[0])) && ($str[0] === '@')) { + $str = mb_substr($str, 1); + } + if ((isset($str[0])) && (($str[0] === '`') + || ($str[0] === '"') || ($str[0] === '\'')) + ) { + $quote = $str[0]; + $str = str_replace($quote . $quote, $quote, $str); + $str = mb_substr($str, 1, -1); + } + return $str; } return $this->token; } diff --git a/src/TokensList.php b/src/TokensList.php index 405f4a1..533fb0b 100644 --- a/src/TokensList.php +++ b/src/TokensList.php @@ -2,6 +2,14 @@ namespace SqlParser; +/** + * A structure representing a list of tokens. + * + * @category Tokens + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ class TokensList implements \ArrayAccess { @@ -29,7 +37,9 @@ class TokensList implements \ArrayAccess /** * Adds a new token. * - * @param Token $token + * @param Token $token Token to be added in list. + * + * @return void */ public function add(Token $token) { @@ -37,7 +47,7 @@ class TokensList implements \ArrayAccess } /** - * Gets next token in list. + * Gets the next token. * * @return Token */ @@ -50,9 +60,9 @@ class TokensList implements \ArrayAccess } /** - * Gets next token of a specified type. + * Gets the next token. * - * @param int $type + * @param int $type The type. * * @return Token */ @@ -67,26 +77,33 @@ class TokensList implements \ArrayAccess } /** - * Gets next token of a specified type. + * Gets the next token. * - * @param int $type - * @param string $value + * @param int $type The type of the token. + * @param string $value The value of the token. * * @return Token */ public function getNextOfTypeAndValue($type, $value) { for (; $this->idx < $this->count; ++$this->idx) { - if (($this->tokens[$this->idx]->type === $type) && - ($this->tokens[$this->idx]->value === $value)) { + if (($this->tokens[$this->idx]->type === $type) + && ($this->tokens[$this->idx]->value === $value) + ) { return $this->tokens[$this->idx++]; } } return null; } - // ArrayAccess methods. - + /** + * Sets an value inside the container. + * + * @param int $offset The offset to be set. + * @param Token $value The token to be saved. + * + * @return void + */ public function offsetSet($offset, $value) { if ($offset === null) { @@ -96,16 +113,37 @@ class TokensList implements \ArrayAccess } } + /** + * Gets a value from the container. + * + * @param int $offset The offset to be returned. + * + * @return Token + */ public function offsetGet($offset) { return $offset < $this->count ? $this->tokens[$offset] : null; } + /** + * Checks if an offset was previously set. + * + * @param int $offset The offset to be checked. + * + * @return bool + */ public function offsetExists($offset) { return $offset < $this->count; } + /** + * Unsets the value of an offset. + * + * @param int $offset The offset to be unset. + * + * @return void + */ public function offsetUnset($offset) { unset($this->tokens[$offset]); diff --git a/src/UtfString.php b/src/UtfString.php index 0f68cfe..e98ee3f 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -6,6 +6,11 @@ namespace SqlParser; * Implements array-like access for UTF-8 strings. * * In this library, this class should be used to parse UTF-8 queries. + * + * @category Misc + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ class UtfString implements \ArrayAccess { @@ -15,7 +20,7 @@ class UtfString implements \ArrayAccess * * @var string */ - private $str = ''; + public $str = ''; /** * The index of current byte. @@ -24,7 +29,7 @@ class UtfString implements \ArrayAccess * * @var int */ - private $byteIdx = 0; + public $byteIdx = 0; /** * The index of current character. @@ -34,26 +39,26 @@ class UtfString implements \ArrayAccess * * @var int */ - private $charIdx = 0; + public $charIdx = 0; /** * The length of the string (in bytes). * * @var int */ - private $buffLen = 0; + public $byteLen = 0; /** * The length of the string (in characters). * * @var int */ - private $charLen = 0; + public $charLen = 0; /** * Constructor. * - * @param string $str + * @param string $str The string. */ public function __construct($str) { @@ -70,19 +75,19 @@ class UtfString implements \ArrayAccess /** * Checks if the given offset exists. * - * @param int $offset + * @param int $offset The offset to be checked. * * @return bool */ public function offsetExists($offset) { - return $offset < $charLen; + return $offset < $this->charLen; } /** * Gets the character at given offset. * - * @param int $offset + * @param int $offset The offset to be returned. * * @return string */ @@ -123,8 +128,10 @@ class UtfString implements \ArrayAccess /** * Sets the value of a character. * - * @param int $offset - * @param string $value + * @param int $offset The offset to be set. + * @param string $value The value to be set. + * + * @return void */ public function offsetSet($offset, $value) { @@ -134,7 +141,9 @@ class UtfString implements \ArrayAccess /** * Unsets an index. * - * @param int $offset + * @param int $offset The value to be unset. + * + * @return void */ public function offsetUnset($offset) { @@ -148,9 +157,9 @@ class UtfString implements \ArrayAccess * However, this implemenation supports UTF-8 characters containing up to 6 * bytes. * - * @see http://tools.ietf.org/html/rfc3629 + * @param string $byte The byte to be analyzed. * - * @param string $byte + * @see http://tools.ietf.org/html/rfc3629 * * @return int */ @@ -197,8 +206,10 @@ class UtfString implements \ArrayAccess /** * Gets the values of the indexes. * - * @param int &$byte - * @param int &$char + * @param int &$byte Reference to the byte index. + * @param int &$char Reference to the character index. + * + * @return void */ public function getIndexes(&$byte, &$char) { @@ -209,8 +220,10 @@ class UtfString implements \ArrayAccess /** * Sets the values of the indexes. * - * @param int $byte - * @param int $char + * @param int $byte The byte index. + * @param int $char The character index. + * + * @return void */ public function setIndexes($byte = 0, $char = 0) { diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index 473bf9b..a29951e 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -4,6 +4,15 @@ namespace SqlParser\Utils; use SqlParser\Statements\SelectStatement; +/** + * Miscellaneous utilities. + * + * @category Misc + * @package SqlParser + * @subpackage Utils + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ class Misc { @@ -11,7 +20,7 @@ class Misc * Gets a list of all aliases and their original names. * * @param SelectStatement $tree The tree that was generated after parsing. - * @param string $db + * @param string $db The name of the database. * * @return array */ @@ -21,7 +30,9 @@ class Misc $tables = array(); - if ((!empty($tree->join->expr->table)) && (!empty($tree->join->expr->alias))) { + if ((!empty($tree->join->expr->table)) + && (!empty($tree->join->expr->alias)) + ) { $thisDb = empty($tree->join->expr->database) ? $db : $tree->join->expr->database; @@ -81,7 +92,8 @@ class Misc } else { $thisTable = isset($tables[$thisDb][$expr->table]) ? $tables[$thisDb][$expr->table] : $expr->table; - $retval[$thisDb]['tables'][$thisTable]['columns'][$expr->column] = $expr->alias; + $retval[$thisDb]['tables'] + [$thisTable]['columns'][$expr->column] = $expr->alias; } } diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 36511ca..f234d97 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -8,6 +8,15 @@ use SqlParser\Fragments\DataTypeFragment; use SqlParser\Fragments\ParamDefFragment; use SqlParser\Statements\CreateStatement; +/** + * Routine utilities. + * + * @category Routines + * @package SqlParser + * @subpackage Utils + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + */ class Routine { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 18dc3e2..0e55e02 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ namespace SqlParser\Tests; -require('vendor/autoload.php'); +require 'vendor/autoload.php'; use SqlParser\Lexer; use SqlParser\Parser; diff --git a/tests/data/parseSelectErr1.out b/tests/data/parseSelectErr1.out index de76724..7adbc3a 100644 --- a/tests/data/parseSelectErr1.out +++ b/tests/data/parseSelectErr1.out @@ -11,4 +11,4 @@ a:2:{s:6:"parser";O:16:"SqlParser\Parser":4:{s:4:"list";O:20:"SqlParser\TokensLi ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:164;}i:58;O:15:"SqlParser\Token":5:{s:5:"token";s:5:"ORDER";s:5:"value";s:5:"ORDER";s:4:"type";i:1;s:5:"flags";i:1;s:8:"position";i:165;}i:59;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:170;}i:60;O:15:"SqlParser\Token":5:{s:5:"token";s:2:"BY";s:5:"value";s:2:"BY";s:4:"type";i:1;s:5:"flags";i:1;s:8:"position";i:171;}i:61;O:15:"SqlParser\Token":5:{s:5:"token";s:5:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:173;}i:62;O:15:"SqlParser\Token":5:{s:5:"token";s:8:"username";s:5:"value";s:8:"username";s:4:"type";i:0;s:5:"flags";i:0;s:8:"position";i:178;}i:63;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:186;}i:64;O:15:"SqlParser\Token":5:{s:5:"token";s:4:"DESC";s:5:"value";s:4:"DESC";s:4:"type";i:1;s:5:"flags";i:1;s:8:"position";i:187;}i:65;O:15:"SqlParser\Token":5:{s:5:"token";s:1:",";s:5:"value";s:1:",";s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:191;}i:66;O:15:"SqlParser\Token":5:{s:5:"token";s:5:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:192;}i:67;O:15:"SqlParser\Token":5:{s:5:"token";s:2:"id";s:5:"value";s:2:"id";s:4:"type";i:0;s:5:"flags";i:0;s:8:"position";i:197;}i:68;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" -";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:199;}i:69;O:15:"SqlParser\Token":5:{s:5:"token";s:5:"LIMIT";s:5:"value";s:5:"LIMIT";s:4:"type";i:1;s:5:"flags";i:1;s:8:"position";i:200;}i:70;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:205;}i:71;O:15:"SqlParser\Token":5:{s:5:"token";s:1:"2";s:5:"value";i:2;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:206;}i:72;O:15:"SqlParser\Token":5:{s:5:"token";s:1:",";s:5:"value";s:1:",";s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:207;}i:73;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:208;}i:74;O:15:"SqlParser\Token":5:{s:5:"token";s:1:"3";s:5:"value";i:3;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:209;}i:75;O:15:"SqlParser\Token":5:{s:5:"token";s:1:";";s:5:"value";s:1:";";s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";i:210;}i:76;O:15:"SqlParser\Token":5:{s:5:"token";N;s:5:"value";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:77;s:3:"idx";i:77;}s:6:"strict";b:0;s:6:"errors";a:0:{}s:10:"statements";a:1:{i:0;O:36:"SqlParser\Statements\SelectStatement":12:{s:7:"options";O:35:"SqlParser\Fragments\OptionsFragment":1:{s:7:"options";a:2:{i:1;s:3:"ALL";i:3;a:2:{s:4:"name";s:18:"MAX_STATEMENT_TIME";s:5:"value";s:2:"10";}}}s:4:"expr";a:4:{i:0;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";N;s:4:"expr";s:6:"1 + 2 ";s:5:"alias";s:6:"result";}i:1;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";N;s:4:"expr";s:4:"@idx";s:5:"alias";N;}i:2;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";s:2:"id";s:4:"expr";s:2:"id";s:5:"alias";N;}i:3;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";s:4:"test";s:5:"table";s:5:"users";s:6:"column";s:8:"username";s:4:"expr";s:21:"test.`users`.username";s:5:"alias";N;}}s:4:"from";a:1:{i:0;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";s:4:"test";s:5:"table";s:5:"users";s:6:"column";N;s:4:"expr";s:12:"`test`.users";s:5:"alias";N;}}s:9:"partition";O:33:"SqlParser\Fragments\ArrayFragment":2:{s:5:"array";a:2:{i:0;s:2:"p1";i:1;s:2:"p2";}s:3:"raw";a:2:{i:0;s:2:"p1";i:1;s:2:"p2";}}s:5:"where";a:1:{i:0;O:32:"SqlParser\Fragments\WhereKeyword":2:{s:10:"isOperator";b:0;s:9:"condition";s:4:"id>0";}}s:5:"group";N;s:6:"having";N;s:5:"order";a:2:{i:0;O:32:"SqlParser\Fragments\OrderKeyword":2:{s:6:"column";s:8:"username";s:4:"type";s:4:"DESC";}i:1;O:32:"SqlParser\Fragments\OrderKeyword":2:{s:6:"column";s:2:"id";s:4:"type";s:3:"ASC";}}s:5:"limit";O:32:"SqlParser\Fragments\LimitKeyword":2:{s:6:"offset";i:2;s:9:"row_count";i:3;}s:4:"join";N;s:5:"first";N;s:4:"last";i:74;}}}s:6:"errors";a:1:{i:0;a:3:{i:0;s:19:"Alias was expected.";i:1;r:215;i:2;i:0;}}}
\ No newline at end of file +";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:199;}i:69;O:15:"SqlParser\Token":5:{s:5:"token";s:5:"LIMIT";s:5:"value";s:5:"LIMIT";s:4:"type";i:1;s:5:"flags";i:1;s:8:"position";i:200;}i:70;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:205;}i:71;O:15:"SqlParser\Token":5:{s:5:"token";s:1:"2";s:5:"value";i:2;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:206;}i:72;O:15:"SqlParser\Token":5:{s:5:"token";s:1:",";s:5:"value";s:1:",";s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:207;}i:73;O:15:"SqlParser\Token":5:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:208;}i:74;O:15:"SqlParser\Token":5:{s:5:"token";s:1:"3";s:5:"value";i:3;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:209;}i:75;O:15:"SqlParser\Token":5:{s:5:"token";s:1:";";s:5:"value";s:1:";";s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";i:210;}i:76;O:15:"SqlParser\Token":5:{s:5:"token";N;s:5:"value";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:77;s:3:"idx";i:77;}s:6:"strict";b:0;s:6:"errors";a:0:{}s:10:"statements";a:1:{i:0;O:36:"SqlParser\Statements\SelectStatement":12:{s:7:"options";O:35:"SqlParser\Fragments\OptionsFragment":1:{s:7:"options";a:2:{i:1;s:3:"ALL";i:3;a:2:{s:4:"name";s:18:"MAX_STATEMENT_TIME";s:5:"value";s:2:"10";}}}s:4:"expr";a:4:{i:0;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";N;s:4:"expr";s:6:"1 + 2 ";s:5:"alias";s:6:"result";}i:1;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";N;s:4:"expr";s:4:"@idx";s:5:"alias";N;}i:2;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";N;s:5:"table";N;s:6:"column";s:2:"id";s:4:"expr";s:2:"id";s:5:"alias";N;}i:3;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";s:4:"test";s:5:"table";s:5:"users";s:6:"column";s:8:"username";s:4:"expr";s:21:"test.`users`.username";s:5:"alias";N;}}s:4:"from";a:1:{i:0;O:33:"SqlParser\Fragments\FieldFragment":5:{s:8:"database";s:4:"test";s:5:"table";s:5:"users";s:6:"column";N;s:4:"expr";s:12:"`test`.users";s:5:"alias";N;}}s:9:"partition";O:33:"SqlParser\Fragments\ArrayFragment":2:{s:5:"array";a:2:{i:0;s:2:"p1";i:1;s:2:"p2";}s:3:"raw";a:2:{i:0;s:2:"p1";i:1;s:2:"p2";}}s:5:"where";a:1:{i:0;O:32:"SqlParser\Fragments\WhereKeyword":2:{s:10:"isOperator";b:0;s:9:"condition";s:4:"id>0";}}s:5:"group";N;s:6:"having";N;s:5:"order";a:2:{i:0;O:32:"SqlParser\Fragments\OrderKeyword":2:{s:6:"column";s:8:"username";s:4:"type";s:4:"DESC";}i:1;O:32:"SqlParser\Fragments\OrderKeyword":2:{s:6:"column";s:2:"id";s:4:"type";s:3:"ASC";}}s:5:"limit";O:32:"SqlParser\Fragments\LimitKeyword":2:{s:6:"offset";i:2;s:9:"row_count";i:3;}s:4:"join";N;s:5:"first";N;s:4:"last";i:74;}}}s:6:"errors";a:1:{i:0;a:3:{i:0;s:19:"Alias was expected.";i:1;N;i:2;i:0;}}}
\ No newline at end of file diff --git a/tests/lexer/ContextTest.php b/tests/lexer/ContextTest.php index 54938f3..cb52e1d 100644 --- a/tests/lexer/ContextTest.php +++ b/tests/lexer/ContextTest.php @@ -12,18 +12,18 @@ class ContextTest extends TestCase public function testLoad() { // Default context is 5.7.0. - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL570', Context::$loadedContext); + $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50700', Context::$loadedContext); $this->assertTrue(isset(Context::$KEYWORDS['STORED'])); $this->assertFalse(isset(Context::$KEYWORDS['AUTHORS'])); - Context::load('MySQL560'); - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL560', Context::$loadedContext); + Context::load('MySQL50600'); + $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50600', Context::$loadedContext); $this->assertFalse(isset(Context::$KEYWORDS['STORED'])); $this->assertTrue(isset(Context::$KEYWORDS['AUTHORS'])); // Restoring context. Context::load(''); - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL570', Context::$defaultContext); + $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50700', Context::$defaultContext); $this->assertTrue(isset(Context::$KEYWORDS['STORED'])); $this->assertFalse(isset(Context::$KEYWORDS['AUTHORS'])); } diff --git a/tests/lexer/LexerTest.php b/tests/lexer/LexerTest.php index 9978565..4db57a7 100644 --- a/tests/lexer/LexerTest.php +++ b/tests/lexer/LexerTest.php @@ -17,10 +17,12 @@ class LexerTest extends TestCase $lexer->error('error #1', 'foo', 1, 2); $lexer->error('error #2', 'bar', 3, 4); - $this->assertEquals($lexer->errors, array( + $this->assertEquals( + $lexer->errors, array( new LexerException('error #1', 'foo', 1, 2), new LexerException('error #2', 'bar', 3, 4), - )); + ) + ); } /** diff --git a/tests/parser/ParserTest.php b/tests/parser/ParserTest.php index dc3475b..954222a 100644 --- a/tests/parser/ParserTest.php +++ b/tests/parser/ParserTest.php @@ -49,10 +49,12 @@ class ParserTest extends TestCase $parser->error('error #1', new Token('foo'), 1); $parser->error('error #2', new Token('bar'), 2); - $this->assertEquals($parser->errors, array( + $this->assertEquals( + $parser->errors, array( new ParserException('error #1', new Token('foo'), 1), new ParserException('error #2', new Token('bar'), 2), - )); + ) + ); } /** |