diff options
author | William Desportes <williamdes@wdes.fr> | 2019-10-29 00:03:10 +0100 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2019-10-29 00:05:38 +0100 |
commit | 1a073cd8f0ffa74124123475753a3752717339a8 (patch) | |
tree | 12b01e437d5c7e8b382b72512d911956a930fe96 /src | |
parent | 6de19aeb28a3e4f4ff7b35b9eb77b4848d374630 (diff) | |
parent | 49731d2db2e45f967d3b1c103958f6d9f189e543 (diff) | |
download | sql-parser-1a073cd8f0ffa74124123475753a3752717339a8.zip sql-parser-1a073cd8f0ffa74124123475753a3752717339a8.tar.gz sql-parser-1a073cd8f0ffa74124123475753a3752717339a8.tar.bz2 |
Merge branch 'QA'
This merge includes phpcs fixes
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/AlterOperation.php | 2 | ||||
-rw-r--r-- | src/Components/CreateDefinition.php | 5 | ||||
-rw-r--r-- | src/Components/Expression.php | 2 | ||||
-rw-r--r-- | src/Components/ExpressionArray.php | 2 | ||||
-rw-r--r-- | src/Statement.php | 14 | ||||
-rw-r--r-- | src/Statements/TruncateStatement.php | 10 | ||||
-rw-r--r-- | src/Utils/CLI.php | 9 |
7 files changed, 32 insertions, 12 deletions
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index 2b83ae5..2540521 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -339,7 +339,7 @@ class AlterOperation extends Component 'COMMENT', 'DEFAULT', 'CHARACTER SET', - 'COLLATE' + 'COLLATE', ]; // Since these options can be used for // both table as well as a specific column in the table diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index 388a080..03f8225 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -80,6 +80,11 @@ class CreateDefinition extends Component 'VIRTUAL' => 10, 'PERSISTENT' => 11, 'STORED' => 11, + 'CHECK' => [ + 12, + 'expr', + ['parenthesesDelimited' => true], + ] // Common entries. // // NOTE: Some of the common options are not in the same order which diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 9c21def..108f335 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -433,7 +433,7 @@ class Expression extends Component public static function build($component, array $options = []) { if (is_array($component)) { - return implode($component, ', '); + return implode(', ', $component); } if ($component->expr !== '' && ! is_null($component->expr)) { diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index 2f44d7a..eb05aac 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -122,6 +122,6 @@ class ExpressionArray extends Component $ret[] = $frag::build($frag); } - return implode($ret, ', '); + return implode(', ', $ret); } } diff --git a/src/Statement.php b/src/Statement.php index de94951..d2d0ed2 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 52f6347..519ffaf 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 . ';'; + } } diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index 4881c5b..cd27908 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -78,7 +78,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -134,7 +134,7 @@ class CLI if (isset($params['c'])) { Context::load($params['c']); } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -190,7 +190,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -218,7 +218,8 @@ class CLI return 1; } - private function readStdin() { + private function readStdin() + { stream_set_blocking(STDIN, false); $stdin = stream_get_contents(STDIN); // restore-default block-mode setting |