summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-12-08 22:32:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-12-08 22:33:04 +0000
commit842d00c02c61edb3d9cfc9869f1b683ba1f44065 (patch)
tree6fe07f59a3ba83ce06fc40ca9632b8326a1d0368
parentReleasing progress-linux version 4.3.2-3~progress5+u1. (diff)
downloadphpmyadmin-sql-parser-842d00c02c61edb3d9cfc9869f1b683ba1f44065.tar.xz
phpmyadmin-sql-parser-842d00c02c61edb3d9cfc9869f1b683ba1f44065.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--CHANGELOG.md7
-rw-r--r--src/Components/CreateDefinition.php7
-rw-r--r--src/Components/Expression.php2
-rw-r--r--src/Components/ExpressionArray.php2
-rw-r--r--src/Components/PartitionDefinition.php14
-rw-r--r--src/Statement.php14
-rw-r--r--src/Statements/TruncateStatement.php10
-rw-r--r--tests/Components/CreateDefinitionTest.php16
-rw-r--r--tests/Components/PartitionDefinitionTest.php12
9 files changed, 72 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97b30e2..8face3d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Change Log
+## [4.4.0] - 2019-11-12
+
+* Fix for PHP deprecations messages about implode for php 7.4+ (#258)
+* Parse CHECK keyword on table definition (#264)
+* Parse truncate statement (#221)
+* Fix wrong parsing of partitions (#265)
+
## [4.3.2] - 2019-06-03
* Fix redundant whitespaces in build() outputs (#228)
diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php
index ed79af7..0f44e09 100644
--- a/src/Components/CreateDefinition.php
+++ b/src/Components/CreateDefinition.php
@@ -79,7 +79,12 @@ class CreateDefinition extends Component
),
'VIRTUAL' => 10,
'PERSISTENT' => 11,
- 'STORED' => 11
+ 'STORED' => 11,
+ 'CHECK' => array(
+ 12,
+ 'expr',
+ array('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 8eff735..67767dc 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 = array())
{
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 ab6988d..cdec66b 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/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php
index 71f73b8..53da148 100644
--- a/src/Components/PartitionDefinition.php
+++ b/src/Components/PartitionDefinition.php
@@ -170,10 +170,16 @@ class PartitionDefinition extends Component
$ret->name = $token->value;
// Looking ahead for a 'VALUES' keyword.
- $idx = $list->idx;
- $list->getNext();
- $nextToken = $list->getNext();
- $list->idx = $idx;
+ // Loop until the end of the partition name (delimited by a whitespace)
+ while ($nextToken = $list->tokens[++$list->idx]) {
+ if ($nextToken->type !== Token::TYPE_NONE) {
+ break;
+ }
+ $ret->name .= $nextToken->value;
+ }
+ $idx = $list->idx--;
+ // Get the first token after the white space.
+ $nextToken = $list->tokens[++$idx];
$state = ($nextToken->type === Token::TYPE_KEYWORD)
&& ($nextToken->value === 'VALUES')
diff --git a/src/Statement.php b/src/Statement.php
index d9027d9..f9e0902 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, array('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 . ';';
+ }
}
diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php
index 3683e29..d00feea 100644
--- a/tests/Components/CreateDefinitionTest.php
+++ b/tests/Components/CreateDefinitionTest.php
@@ -63,4 +63,20 @@ class CreateDefinitionTest extends TestCase
CreateDefinition::build($parser->statements[0]->fields[1])
);
}
+
+ public function testBuild2()
+ {
+ $parser = new Parser(
+ 'CREATE TABLE `payment` (' .
+ '-- snippet' . "\n" .
+ '`customer_id` smallint(5) unsigned NOT NULL,' .
+ '`customer_data` longtext CHARACTER SET utf8mb4 CHARSET utf8mb4_bin NOT NULL CHECK (json_valid(customer_data)),' .
+ 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' .
+ ') ENGINE=InnoDB"'
+ );
+ $this->assertEquals(
+ 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
+ CreateDefinition::build($parser->statements[0]->fields[2])
+ );
+ }
}
diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php
index 7edc21e..3c9a847 100644
--- a/tests/Components/PartitionDefinitionTest.php
+++ b/tests/Components/PartitionDefinitionTest.php
@@ -19,4 +19,16 @@ class PartitionDefinitionTest extends TestCase
$this->assertEquals('LESS THAN', $component->type);
$this->assertEquals('(1990)', $component->expr->expr);
}
+
+ public function testParseNameWithUnderscore()
+ {
+ $component = PartitionDefinition::parse(
+ new Parser(),
+ $this->getTokensList('PARTITION 2017_12 VALUES LESS THAN (\'2018-01-01 00:00:00\') ENGINE = MyISAM')
+ );
+ $this->assertFalse($component->isSubpartition);
+ $this->assertEquals('2017_12', $component->name);
+ $this->assertEquals('LESS THAN', $component->type);
+ $this->assertEquals('(\'2018-01-01 00:00:00\')', $component->expr->expr);
+ }
}