From 0cbe7e54224e2f0a60fbd91823d1dc5e4390a536 Mon Sep 17 00:00:00 2001 From: Klim Todrik Date: Thu, 9 May 2024 14:54:25 +0200 Subject: [PATCH] Alter table local option support (#7) * Alter table local option support --------- Co-authored-by: djklim87 --- src/PHPSQLParser/processors/TableProcessor.php | 3 ++- tests/cases/parser/manticoreCasesTest.php | 3 ++- tests/expected/parser/ms_alter_table_6.serialized | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/expected/parser/ms_alter_table_6.serialized diff --git a/src/PHPSQLParser/processors/TableProcessor.php b/src/PHPSQLParser/processors/TableProcessor.php index 155edf2c..35baf6d4 100644 --- a/src/PHPSQLParser/processors/TableProcessor.php +++ b/src/PHPSQLParser/processors/TableProcessor.php @@ -235,8 +235,9 @@ public function process($tokens) case 'TYPE': case 'STATS_AUTO_RECALC': case 'STATS_PERSISTENT': + case 'LOCAL': case 'KEY_BLOCK_SIZE': - if ($prevCategory === 'CREATE_DEF') { + if (in_array($prevCategory, ['CREATE_DEF', 'TABLE_NAME']) ) { $expr[] = $this->getReservedType($trim); $currCategory = $prevCategory = 'TABLE_OPTION'; continue 2; diff --git a/tests/cases/parser/manticoreCasesTest.php b/tests/cases/parser/manticoreCasesTest.php index e06841a3..18e1e979 100644 --- a/tests/cases/parser/manticoreCasesTest.php +++ b/tests/cases/parser/manticoreCasesTest.php @@ -129,7 +129,8 @@ public function manticoreQueryProvider(): array ["ALTER MV view_name suspended=1", 'ms_alter_table_3'], // End aliases ["ALTER TABLE old_table RENAME new_table", 'ms_alter_table_4'], - ["ALTER TABLE `old_table` RENAME `new_table`", 'ms_alter_table_5'] + ["ALTER TABLE `old_table` RENAME `new_table`", 'ms_alter_table_5'], + ["alter table `dist` local='t1' local='t3'", 'ms_alter_table_6'] ]; } diff --git a/tests/expected/parser/ms_alter_table_6.serialized b/tests/expected/parser/ms_alter_table_6.serialized new file mode 100644 index 00000000..ec4b6b2d --- /dev/null +++ b/tests/expected/parser/ms_alter_table_6.serialized @@ -0,0 +1 @@ +a:2:{s:5:"ALTER";a:3:{s:9:"expr_type";s:5:"table";s:9:"base_expr";s:5:"table";s:8:"sub_tree";a:1:{i:0;a:2:{s:9:"expr_type";s:8:"reserved";s:9:"base_expr";s:5:"table";}}}s:5:"TABLE";a:5:{s:9:"base_expr";s:6:"`dist`";s:4:"name";s:6:"`dist`";s:9:"no_quotes";a:2:{s:5:"delim";b:0;s:5:"parts";a:1:{i:0;s:4:"dist";}}s:10:"create-def";b:0;s:7:"options";a:2:{i:0;a:4:{s:9:"expr_type";s:10:"expression";s:9:"base_expr";s:10:"local='t1'";s:5:"delim";s:1:" ";s:8:"sub_tree";a:3:{i:0;a:2:{s:9:"expr_type";s:8:"reserved";s:9:"base_expr";s:5:"local";}i:1;a:2:{s:9:"expr_type";s:8:"operator";s:9:"base_expr";s:1:"=";}i:2;a:2:{s:9:"expr_type";s:5:"const";s:9:"base_expr";s:4:"'t1'";}}}i:1;a:4:{s:9:"expr_type";s:10:"expression";s:9:"base_expr";s:10:"local='t3'";s:5:"delim";s:1:" ";s:8:"sub_tree";a:3:{i:0;a:2:{s:9:"expr_type";s:8:"reserved";s:9:"base_expr";s:5:"local";}i:1;a:2:{s:9:"expr_type";s:8:"operator";s:9:"base_expr";s:1:"=";}i:2;a:2:{s:9:"expr_type";s:5:"const";s:9:"base_expr";s:4:"'t3'";}}}}}} \ No newline at end of file