-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #168 - error on test SET statement #337
Conversation
Hi @BorisValgo |
Hi, For a test case you can try this : ./bin/lint-query --query 'ALTER TABLE `table_name` ADD `new_column_name` SET ('value1','value2','value3') NOT NULL AFTER another_column' Or without space between "SET" and "(" : ./bin/lint-query --query 'ALTER TABLE `table_name` ADD `new_column_name` SET('value1','value2','value3') NOT NULL AFTER another_column' This tests might not display errors. See also SET statement / SET type or Delimiter error |
Codecov Report
@@ Coverage Diff @@
## QA #337 +/- ##
=========================================
Coverage 99.73% 99.73%
- Complexity 1911 1914 +3
=========================================
Files 63 63
Lines 4601 4608 +7
=========================================
+ Hits 4589 4596 +7
Misses 12 12
Continue to review full report at Codecov.
|
I added two test cases for this in ded1fea |
I changed the format of outputs in 9f16b24 The error still exists: sql-parser/tests/data/parser/parseAlter12.out Lines 673 to 684 in 9f16b24
|
Adding || $list->tokens[$list->idx + 2]->value === 'DEFAULT' Fixes it but does not make the tokens recognised |
(cherry picked from commit 706a811)
915c2f3
to
ceddca0
Compare
Hi @BorisValgo |
You can see on the diff the errors are removed but more not recognized tokens are added Here is the diff of a merge into master
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php
index b43a5e3f..717f465d 100644
--- a/src/Components/AlterOperation.php
+++ b/src/Components/AlterOperation.php
@@ -285,7 +285,16 @@ class AlterOperation extends Component
// We have reached the end of ALTER operation and suddenly found
// a start to new statement, but have not find a delimiter between them
- if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
+ if (
+ ! ($token->value === 'SET' &&
+ (
+ $list->tokens[$list->idx - 1]->value === 'CHARACTER'
+ || $list->tokens[$list->idx + 1]->value === '('
+ || $list->tokens[$list->idx + 2]->value === '('
+ || $list->tokens[$list->idx + 2]->value === 'DEFAULT'
+ )
+ )
+ ) {
$parser->error(
'A new statement was found, but no delimiter between it and the previous one.',
$token
diff --git a/tests/data/parser/parseAlter11.out b/tests/data/parser/parseAlter11.out
index af11cc94..e46f1359 100644
--- a/tests/data/parser/parseAlter11.out
+++ b/tests/data/parser/parseAlter11.out
@@ -719,259 +719,31 @@
"function": null,
"subquery": null
},
- "unknown": []
- },
- {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
- "DB_OPTIONS": {
- "CHARACTER SET": [
- 1,
- "var"
- ],
- "CHARSET": [
- 1,
- "var"
- ],
- "DEFAULT CHARACTER SET": [
- 1,
- "var"
- ],
- "DEFAULT CHARSET": [
- 1,
- "var"
- ],
- "UPGRADE": [
- 1,
- "var"
- ],
- "COLLATE": [
- 2,
- "var"
- ],
- "DEFAULT COLLATE": [
- 2,
- "var"
- ]
- },
- "TABLE_OPTIONS": {
- "ENGINE": [
- 1,
- "var="
- ],
- "AUTO_INCREMENT": [
- 1,
- "var="
- ],
- "AVG_ROW_LENGTH": [
- 1,
- "var"
- ],
- "MAX_ROWS": [
- 1,
- "var"
- ],
- "ROW_FORMAT": [
- 1,
- "var"
- ],
- "COMMENT": [
- 1,
- "var"
- ],
- "ADD": 1,
- "ALTER": 1,
- "ANALYZE": 1,
- "CHANGE": 1,
- "CHECK": 1,
- "COALESCE": 1,
- "CONVERT": 1,
- "DISABLE": 1,
- "DISCARD": 1,
- "DROP": 1,
- "ENABLE": 1,
- "IMPORT": 1,
- "MODIFY": 1,
- "OPTIMIZE": 1,
- "ORDER": 1,
- "PARTITION": 1,
- "REBUILD": 1,
- "REMOVE": 1,
- "RENAME": 1,
- "REORGANIZE": 1,
- "REPAIR": 1,
- "UPGRADE": 1,
- "COLUMN": 2,
- "CONSTRAINT": 2,
- "DEFAULT": 2,
- "TO": 2,
- "BY": 2,
- "FOREIGN": 2,
- "FULLTEXT": 2,
- "KEY": 2,
- "KEYS": 2,
- "PARTITIONING": 2,
- "PRIMARY KEY": 2,
- "SPATIAL": 2,
- "TABLESPACE": 2,
- "INDEX": 2
- },
- "VIEW_OPTIONS": {
- "AS": 1
- },
- "options": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
- "options": []
- },
- "field": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
- "ALLOWED_KEYWORDS": {
- "AS": 1,
- "DUAL": 1,
- "NULL": 1,
- "REGEXP": 1,
- "CASE": 1,
- "DIV": 1,
- "AND": 1,
- "OR": 1,
- "XOR": 1,
- "NOT": 1,
- "MOD": 1
+ "unknown": [
+ {
+ "@type": "@12"
},
- "database": null,
- "table": null,
- "column": "value2",
- "expr": "'value2'",
- "alias": null,
- "function": null,
- "subquery": null
- },
- "unknown": []
- },
- {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
- "DB_OPTIONS": {
- "CHARACTER SET": [
- 1,
- "var"
- ],
- "CHARSET": [
- 1,
- "var"
- ],
- "DEFAULT CHARACTER SET": [
- 1,
- "var"
- ],
- "DEFAULT CHARSET": [
- 1,
- "var"
- ],
- "UPGRADE": [
- 1,
- "var"
- ],
- "COLLATE": [
- 2,
- "var"
- ],
- "DEFAULT COLLATE": [
- 2,
- "var"
- ]
- },
- "TABLE_OPTIONS": {
- "ENGINE": [
- 1,
- "var="
- ],
- "AUTO_INCREMENT": [
- 1,
- "var="
- ],
- "AVG_ROW_LENGTH": [
- 1,
- "var"
- ],
- "MAX_ROWS": [
- 1,
- "var"
- ],
- "ROW_FORMAT": [
- 1,
- "var"
- ],
- "COMMENT": [
- 1,
- "var"
- ],
- "ADD": 1,
- "ALTER": 1,
- "ANALYZE": 1,
- "CHANGE": 1,
- "CHECK": 1,
- "COALESCE": 1,
- "CONVERT": 1,
- "DISABLE": 1,
- "DISCARD": 1,
- "DROP": 1,
- "ENABLE": 1,
- "IMPORT": 1,
- "MODIFY": 1,
- "OPTIMIZE": 1,
- "ORDER": 1,
- "PARTITION": 1,
- "REBUILD": 1,
- "REMOVE": 1,
- "RENAME": 1,
- "REORGANIZE": 1,
- "REPAIR": 1,
- "UPGRADE": 1,
- "COLUMN": 2,
- "CONSTRAINT": 2,
- "DEFAULT": 2,
- "TO": 2,
- "BY": 2,
- "FOREIGN": 2,
- "FULLTEXT": 2,
- "KEY": 2,
- "KEYS": 2,
- "PARTITIONING": 2,
- "PRIMARY KEY": 2,
- "SPATIAL": 2,
- "TABLESPACE": 2,
- "INDEX": 2
- },
- "VIEW_OPTIONS": {
- "AS": 1
- },
- "options": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
- "options": []
- },
- "field": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
- "ALLOWED_KEYWORDS": {
- "AS": 1,
- "DUAL": 1,
- "NULL": 1,
- "REGEXP": 1,
- "CASE": 1,
- "DIV": 1,
- "AND": 1,
- "OR": 1,
- "XOR": 1,
- "NOT": 1,
- "MOD": 1
+ {
+ "@type": "@13"
+ },
+ {
+ "@type": "@14"
+ },
+ {
+ "@type": "@15"
+ },
+ {
+ "@type": "@16"
+ },
+ {
+ "@type": "@17"
+ },
+ {
+ "@type": "@18"
+ },
+ {
+ "@type": "@19"
},
- "database": null,
- "table": null,
- "column": "value3",
- "expr": "'value3'",
- "alias": null,
- "function": null,
- "subquery": null
- },
- "unknown": [
{
"@type": "@20"
},
@@ -1027,28 +799,6 @@
},
"errors": {
"lexer": [],
- "parser": [
- [
- "A new statement was found, but no delimiter between it and the previous one.",
- {
- "@type": "@12"
- },
- 0
- ],
- [
- "Unrecognized alter operation.",
- {
- "@type": "@18"
- },
- 0
- ],
- [
- "Unrecognized alter operation.",
- {
- "@type": "@27"
- },
- 0
- ]
- ]
+ "parser": []
}
}
\ No newline at end of file
diff --git a/tests/data/parser/parseAlter12.out b/tests/data/parser/parseAlter12.out
index bdd0480c..360ab799 100644
--- a/tests/data/parser/parseAlter12.out
+++ b/tests/data/parser/parseAlter12.out
@@ -638,7 +638,23 @@
"function": null,
"subquery": null
},
- "unknown": []
+ "unknown": [
+ {
+ "@type": "@12"
+ },
+ {
+ "@type": "@13"
+ },
+ {
+ "@type": "@14"
+ },
+ {
+ "@type": "@15"
+ },
+ {
+ "@type": "@16"
+ }
+ ]
}
],
"OPTIONS": {
@@ -672,14 +688,6 @@
},
"errors": {
"lexer": [],
- "parser": [
- [
- "A new statement was found, but no delimiter between it and the previous one.",
- {
- "@type": "@12"
- },
- 0
- ]
- ]
+ "parser": []
}
}
\ No newline at end of file
diff --git a/tests/data/parser/parseAlter13.out b/tests/data/parser/parseAlter13.out
index 9677381a..eb8beca8 100644
--- a/tests/data/parser/parseAlter13.out
+++ b/tests/data/parser/parseAlter13.out
@@ -665,259 +665,31 @@
"function": null,
"subquery": null
},
- "unknown": []
- },
- {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
- "DB_OPTIONS": {
- "CHARACTER SET": [
- 1,
- "var"
- ],
- "CHARSET": [
- 1,
- "var"
- ],
- "DEFAULT CHARACTER SET": [
- 1,
- "var"
- ],
- "DEFAULT CHARSET": [
- 1,
- "var"
- ],
- "UPGRADE": [
- 1,
- "var"
- ],
- "COLLATE": [
- 2,
- "var"
- ],
- "DEFAULT COLLATE": [
- 2,
- "var"
- ]
- },
- "TABLE_OPTIONS": {
- "ENGINE": [
- 1,
- "var="
- ],
- "AUTO_INCREMENT": [
- 1,
- "var="
- ],
- "AVG_ROW_LENGTH": [
- 1,
- "var"
- ],
- "MAX_ROWS": [
- 1,
- "var"
- ],
- "ROW_FORMAT": [
- 1,
- "var"
- ],
- "COMMENT": [
- 1,
- "var"
- ],
- "ADD": 1,
- "ALTER": 1,
- "ANALYZE": 1,
- "CHANGE": 1,
- "CHECK": 1,
- "COALESCE": 1,
- "CONVERT": 1,
- "DISABLE": 1,
- "DISCARD": 1,
- "DROP": 1,
- "ENABLE": 1,
- "IMPORT": 1,
- "MODIFY": 1,
- "OPTIMIZE": 1,
- "ORDER": 1,
- "PARTITION": 1,
- "REBUILD": 1,
- "REMOVE": 1,
- "RENAME": 1,
- "REORGANIZE": 1,
- "REPAIR": 1,
- "UPGRADE": 1,
- "COLUMN": 2,
- "CONSTRAINT": 2,
- "DEFAULT": 2,
- "TO": 2,
- "BY": 2,
- "FOREIGN": 2,
- "FULLTEXT": 2,
- "KEY": 2,
- "KEYS": 2,
- "PARTITIONING": 2,
- "PRIMARY KEY": 2,
- "SPATIAL": 2,
- "TABLESPACE": 2,
- "INDEX": 2
- },
- "VIEW_OPTIONS": {
- "AS": 1
- },
- "options": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
- "options": []
- },
- "field": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
- "ALLOWED_KEYWORDS": {
- "AS": 1,
- "DUAL": 1,
- "NULL": 1,
- "REGEXP": 1,
- "CASE": 1,
- "DIV": 1,
- "AND": 1,
- "OR": 1,
- "XOR": 1,
- "NOT": 1,
- "MOD": 1
+ "unknown": [
+ {
+ "@type": "@12"
},
- "database": null,
- "table": null,
- "column": "value2",
- "expr": "'value2'",
- "alias": null,
- "function": null,
- "subquery": null
- },
- "unknown": []
- },
- {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
- "DB_OPTIONS": {
- "CHARACTER SET": [
- 1,
- "var"
- ],
- "CHARSET": [
- 1,
- "var"
- ],
- "DEFAULT CHARACTER SET": [
- 1,
- "var"
- ],
- "DEFAULT CHARSET": [
- 1,
- "var"
- ],
- "UPGRADE": [
- 1,
- "var"
- ],
- "COLLATE": [
- 2,
- "var"
- ],
- "DEFAULT COLLATE": [
- 2,
- "var"
- ]
- },
- "TABLE_OPTIONS": {
- "ENGINE": [
- 1,
- "var="
- ],
- "AUTO_INCREMENT": [
- 1,
- "var="
- ],
- "AVG_ROW_LENGTH": [
- 1,
- "var"
- ],
- "MAX_ROWS": [
- 1,
- "var"
- ],
- "ROW_FORMAT": [
- 1,
- "var"
- ],
- "COMMENT": [
- 1,
- "var"
- ],
- "ADD": 1,
- "ALTER": 1,
- "ANALYZE": 1,
- "CHANGE": 1,
- "CHECK": 1,
- "COALESCE": 1,
- "CONVERT": 1,
- "DISABLE": 1,
- "DISCARD": 1,
- "DROP": 1,
- "ENABLE": 1,
- "IMPORT": 1,
- "MODIFY": 1,
- "OPTIMIZE": 1,
- "ORDER": 1,
- "PARTITION": 1,
- "REBUILD": 1,
- "REMOVE": 1,
- "RENAME": 1,
- "REORGANIZE": 1,
- "REPAIR": 1,
- "UPGRADE": 1,
- "COLUMN": 2,
- "CONSTRAINT": 2,
- "DEFAULT": 2,
- "TO": 2,
- "BY": 2,
- "FOREIGN": 2,
- "FULLTEXT": 2,
- "KEY": 2,
- "KEYS": 2,
- "PARTITIONING": 2,
- "PRIMARY KEY": 2,
- "SPATIAL": 2,
- "TABLESPACE": 2,
- "INDEX": 2
- },
- "VIEW_OPTIONS": {
- "AS": 1
- },
- "options": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
- "options": []
- },
- "field": {
- "@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
- "ALLOWED_KEYWORDS": {
- "AS": 1,
- "DUAL": 1,
- "NULL": 1,
- "REGEXP": 1,
- "CASE": 1,
- "DIV": 1,
- "AND": 1,
- "OR": 1,
- "XOR": 1,
- "NOT": 1,
- "MOD": 1
+ {
+ "@type": "@13"
+ },
+ {
+ "@type": "@14"
+ },
+ {
+ "@type": "@15"
+ },
+ {
+ "@type": "@16"
+ },
+ {
+ "@type": "@17"
+ },
+ {
+ "@type": "@18"
+ },
+ {
+ "@type": "@19"
},
- "database": null,
- "table": null,
- "column": "value3",
- "expr": "'value3'",
- "alias": null,
- "function": null,
- "subquery": null
- },
- "unknown": [
{
"@type": "@20"
}
@@ -955,28 +727,6 @@
},
"errors": {
"lexer": [],
- "parser": [
- [
- "A new statement was found, but no delimiter between it and the previous one.",
- {
- "@type": "@12"
- },
- 0
- ],
- [
- "Unrecognized alter operation.",
- {
- "@type": "@18"
- },
- 0
- ],
- [
- "Unrecognized alter operation.",
- {
- "@type": "@21"
- },
- 0
- ]
- ]
+ "parser": []
}
}
\ No newline at end of file
diff --git a/tests/data/parser/parseAlterErr4.out b/tests/data/parser/parseAlterErr4.out
index c8ce4a94..e6cb5aa2 100644
--- a/tests/data/parser/parseAlterErr4.out
+++ b/tests/data/parser/parseAlterErr4.out
@@ -638,7 +638,26 @@
"function": null,
"subquery": null
},
- "unknown": []
+ "unknown": [
+ {
+ "@type": "@12"
+ },
+ {
+ "@type": "@13"
+ },
+ {
+ "@type": "@14"
+ },
+ {
+ "@type": "@15"
+ },
+ {
+ "@type": "@16"
+ },
+ {
+ "@type": "@17"
+ }
+ ]
}
],
"OPTIONS": {
@@ -679,14 +698,6 @@
0
]
],
- "parser": [
- [
- "A new statement was found, but no delimiter between it and the previous one.",
- {
- "@type": "@12"
- },
- 0
- ]
- ]
+ "parser": []
}
}
\ No newline at end of file |
Thank you for your work @BorisValgo |
Fixes: #168