Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

BorisValgo
Copy link

@BorisValgo BorisValgo commented May 17, 2021

Fixes: #168

@williamdes
Copy link
Member

Hi @BorisValgo
Could you give or add test cases for that ?

@BorisValgo
Copy link
Author

BorisValgo commented May 18, 2021

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

@williamdes williamdes self-assigned this May 19, 2021
@williamdes williamdes added this to the 4.7.3 milestone May 19, 2021
@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #337 (ceddca0) into QA (998338c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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           
Impacted Files Coverage Δ Complexity Δ
src/Components/AlterOperation.php 100.00% <100.00%> (ø) 38.00 <0.00> (+3.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 998338c...ceddca0. Read the comment docs.

@williamdes williamdes linked an issue May 19, 2021 that may be closed by this pull request
@williamdes
Copy link
Member

I added two test cases for this in ded1fea

@williamdes williamdes changed the title fix error on test SET statment #168 fix #168 - error on test SET statement May 19, 2021
@williamdes
Copy link
Member

I changed the format of outputs in 9f16b24
And now I can see locally that your PR does fix the case 11 but not 12

The error still exists:

"errors": {
"lexer": [],
"parser": [
[
"A new statement was found, but no delimiter between it and the previous one.",
{
"@type": "@12"
},
0
]
]
}

@williamdes
Copy link
Member

Adding

                                || $list->tokens[$list->idx + 2]->value === 'DEFAULT'

Fixes it but does not make the tokens recognised

(cherry picked from commit 706a811)
@williamdes williamdes changed the base branch from master to QA May 19, 2021 23:37
@williamdes
Copy link
Member

Hi @BorisValgo
I added the case for DEFAULT keyword
I think if the user has 3 spaces the code will break
Maybe this is not done right, I will try to search further

@williamdes
Copy link
Member

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

@williamdes
Copy link
Member

Thank you for your work @BorisValgo
It is now fixed by #344

@williamdes williamdes removed this from the 4.7.3 milestone Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SET statement / SET type
2 participants