From 33dce6f1fef727c057c3e55de359e5a93ed6f2b0 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 3 Jan 2019 18:10:02 +0530 Subject: [PATCH 1/2] Fix incorrect error on DEFAULT keyword in ALTER operation Signed-off-by: Deven Bansod --- src/Components/AlterOperation.php | 2 +- tests/Parser/AlterStatementTest.php | 1 + tests/data/parser/parseAlter8.in | 1 + tests/data/parser/parseAlter8.out | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/data/parser/parseAlter8.in create mode 100644 tests/data/parser/parseAlter8.out diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index b9e64d228..e3893f7f0 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -294,7 +294,7 @@ public static function build($component, array $options = array()) * @param string $tokenValue Value of current token */ private static function checkIfColumnDefinitionKeyword($tokenValue) { - $common_options = array('AUTO_INCREMENT', 'COMMENT'); + $common_options = array('AUTO_INCREMENT', 'COMMENT', 'DEFAULT'); // Since AUTO_INCREMENT and COMMENT can be used for // both table as well as a specific column in the table return in_array($tokenValue, $common_options); diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php index 6b7d4a2d7..3582bf353 100644 --- a/tests/Parser/AlterStatementTest.php +++ b/tests/Parser/AlterStatementTest.php @@ -26,6 +26,7 @@ public function testAlterProvider() array('parser/parseAlter5'), array('parser/parseAlter6'), array('parser/parseAlter7'), + array('parser/parseAlter8'), array('parser/parseAlterErr'), array('parser/parseAlterErr2'), ); diff --git a/tests/data/parser/parseAlter8.in b/tests/data/parser/parseAlter8.in new file mode 100644 index 000000000..17b72cbaf --- /dev/null +++ b/tests/data/parser/parseAlter8.in @@ -0,0 +1 @@ +ALTER TABLE `api_tab_user` CHANGE `rank_id` `rank_id` INT(4) NOT NULL DEFAULT '4'; \ No newline at end of file diff --git a/tests/data/parser/parseAlter8.out b/tests/data/parser/parseAlter8.out new file mode 100644 index 000000000..8766a08ab --- /dev/null +++ b/tests/data/parser/parseAlter8.out @@ -0,0 +1 @@ +a:4:{s:5:"query";s:82:"ALTER TABLE `api_tab_user` CHANGE `rank_id` `rank_id` INT(4) NOT NULL DEFAULT '4';";s:5:"lexer";O:26:"PhpMyAdmin\SqlParser\Lexer":8:{s:3:"str";s:82:"ALTER TABLE `api_tab_user` CHANGE `rank_id` `rank_id` INT(4) NOT NULL DEFAULT '4';";s:3:"len";i:82;s:4:"last";i:82;s:4:"list";O:31:"PhpMyAdmin\SqlParser\TokensList":3:{s:6:"tokens";a:24:{i:0;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"ALTER";s:5:"value";s:5:"ALTER";s:7:"keyword";s:5:"ALTER";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:0;}i:1;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:5;}i:2;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"TABLE";s:5:"value";s:5:"TABLE";s:7:"keyword";s:5:"TABLE";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:6;}i:3;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:11;}i:4;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:14:"`api_tab_user`";s:5:"value";s:12:"api_tab_user";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:12;}i:5;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:26;}i:6;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"CHANGE";s:5:"value";s:6:"CHANGE";s:7:"keyword";s:6:"CHANGE";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:27;}i:7;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:33;}i:8;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:9:"`rank_id`";s:5:"value";s:7:"rank_id";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:34;}i:9;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:43;}i:10;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:9:"`rank_id`";s:5:"value";s:7:"rank_id";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:44;}i:11;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:53;}i:12;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:3:"INT";s:5:"value";s:3:"INT";s:7:"keyword";s:3:"INT";s:4:"type";i:1;s:5:"flags";i:11;s:8:"position";i:54;}i:13;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"(";s:5:"value";s:1:"(";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:57;}i:14;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"4";s:5:"value";i:4;s:7:"keyword";N;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:58;}i:15;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:")";s:5:"value";s:1:")";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:59;}i:16;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:60;}i:17;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:8:"NOT NULL";s:5:"value";s:8:"NOT NULL";s:7:"keyword";s:8:"NOT NULL";s:4:"type";i:1;s:5:"flags";i:7;s:8:"position";i:61;}i:18;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:69;}i:19;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:7:"DEFAULT";s:5:"value";s:7:"DEFAULT";s:7:"keyword";s:7:"DEFAULT";s:4:"type";i:1;s:5:"flags";i:35;s:8:"position";i:70;}i:20;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:77;}i:21;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:3:"'4'";s:5:"value";s:1:"4";s:7:"keyword";N;s:4:"type";i:7;s:5:"flags";i:1;s:8:"position";i:78;}i:22;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:";";s:5:"value";s:1:";";s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";i:81;}i:23;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";N;s:5:"value";N;s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:24;s:3:"idx";i:24;}s:9:"delimiter";s:1:";";s:12:"delimiterLen";i:1;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"parser";O:27:"PhpMyAdmin\SqlParser\Parser":5:{s:4:"list";r:7;s:10:"statements";a:1:{i:0;O:46:"PhpMyAdmin\SqlParser\Statements\AlterStatement":5:{s:5:"table";O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";s:12:"api_tab_user";s:6:"column";N;s:4:"expr";s:14:"`api_tab_user`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}s:7:"altered";a:1:{i:0;O:46:"PhpMyAdmin\SqlParser\Components\AlterOperation":3:{s:7:"options";O:44:"PhpMyAdmin\SqlParser\Components\OptionsArray":1:{s:7:"options";a:1:{i:1;s:6:"CHANGE";}}s:5:"field";O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";N;s:6:"column";s:7:"rank_id";s:4:"expr";s:9:"`rank_id`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}s:7:"unknown";a:12:{i:0;r:79;i:1;r:86;i:2;r:93;i:3;r:100;i:4;r:107;i:5;r:114;i:6;r:121;i:7;r:128;i:8;r:135;i:9;r:142;i:10;r:149;i:11;r:156;}}}s:7:"options";O:44:"PhpMyAdmin\SqlParser\Components\OptionsArray":1:{s:7:"options";a:1:{i:3;s:5:"TABLE";}}s:5:"first";i:0;s:4:"last";i:22;}}s:8:"brackets";i:0;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"errors";a:2:{s:5:"lexer";a:0:{}s:6:"parser";a:0:{}}} \ No newline at end of file From f1623b05642a6e18d3b7c4ca974f819d7b10f6d9 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 3 Jan 2019 18:11:35 +0530 Subject: [PATCH 2/2] Add ChangeLog for Issue 218 Signed-off-by: Deven Bansod --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f97600c3..821ee495f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +* Fixed incorrect error thrown on DEFAULT keyword in ALTER statement (#218) + ## [4.3.0] - 2018-12-25 * Add support for aliases on CASE expressions (#162 and #192)