diff options
author | Sinri Edogawa <e.joshua.s.e@gmail.com> | 2019-01-16 16:59:30 +0800 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2019-10-28 23:55:04 +0100 |
commit | 04da59b51db477a9caaf3e755df414cf1b3c09c3 (patch) | |
tree | 51cc6212186c68171c38ad8534a81a556bc919ba /src | |
parent | dedb5d5236a384963de97ce25f2e90355d5216ac (diff) | |
download | sql-parser-04da59b51db477a9caaf3e755df414cf1b3c09c3.zip sql-parser-04da59b51db477a9caaf3e755df414cf1b3c09c3.tar.gz sql-parser-04da59b51db477a9caaf3e755df414cf1b3c09c3.tar.bz2 |
Fix #221 - parse truncate statement
Fixes: #221
Pull-request: #222
Co-authored-by: Sinri Edogawa <e.joshua.s.e@gmail.com>
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'src')
-rw-r--r-- | src/Statement.php | 14 | ||||
-rw-r--r-- | src/Statements/TruncateStatement.php | 10 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/Statement.php b/src/Statement.php index d9027d9..2e7fc49 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -320,11 +320,15 @@ abstract class Statement } // Checking if this is the beginning of a clause. - if (! empty(Parser::$KEYWORD_PARSERS[$token->value]) && $list->idx < $list->count) { - $class = Parser::$KEYWORD_PARSERS[$token->value]['class']; - $field = Parser::$KEYWORD_PARSERS[$token->value]['field']; - if (! empty(Parser::$KEYWORD_PARSERS[$token->value]['options'])) { - $options = Parser::$KEYWORD_PARSERS[$token->value]['options']; + // Fix Issue #221: As `truncate` is not a keyword + // but it might be the beginning of a statement of truncate, + // so let the value use the keyword field for truncate type. + $token_value = in_array($token->keyword, ['TRUNCATE']) ? $token->keyword : $token->value; + if (! empty(Parser::$KEYWORD_PARSERS[$token_value]) && $list->idx < $list->count) { + $class = Parser::$KEYWORD_PARSERS[$token_value]['class']; + $field = Parser::$KEYWORD_PARSERS[$token_value]['field']; + if (! empty(Parser::$KEYWORD_PARSERS[$token_value]['options'])) { + $options = Parser::$KEYWORD_PARSERS[$token_value]['options']; } } diff --git a/src/Statements/TruncateStatement.php b/src/Statements/TruncateStatement.php index eb791d0..13a4d21 100644 --- a/src/Statements/TruncateStatement.php +++ b/src/Statements/TruncateStatement.php @@ -33,4 +33,14 @@ class TruncateStatement extends Statement * @var Expression */ public $table; + + /** + * Special build method for truncate statement as Statement::build would return empty string. + * + * @return string + */ + public function build() + { + return 'TRUNCATE TABLE ' . $this->table . ';'; + } } |