diff options
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | sqlparse/keywords.py | 2 | ||||
| -rw-r--r-- | tests/files/mysql_handler.sql | 10 | ||||
| -rw-r--r-- | tests/test_split.py | 6 |
4 files changed, 18 insertions, 1 deletions
@@ -21,6 +21,7 @@ Bug Fixes * Improved parsing of IN(...) statements (issue566, pr567 by hurcy). * Preserve line breaks when removing comments (issue484). * Fix parsing error when using square bracket notation (issue583). +* Fix splitting when using DECLARE ... HANDLER (issue581). Release 0.3.1 (Feb 29, 2020) diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 933b323..bb69843 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -84,6 +84,7 @@ SQL_REGEX = { (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), (r'GROUP\s+BY\b', tokens.Keyword), (r'ORDER\s+BY\b', tokens.Keyword), + (r'HANDLER\s+FOR\b', tokens.Keyword), (r'(LATERAL\s+VIEW\s+)' r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b', tokens.Keyword), @@ -294,7 +295,6 @@ KEYWORDS = { 'GRANTED': tokens.Keyword, 'GROUPING': tokens.Keyword, - 'HANDLER': tokens.Keyword, 'HAVING': tokens.Keyword, 'HIERARCHY': tokens.Keyword, 'HOLD': tokens.Keyword, diff --git a/tests/files/mysql_handler.sql b/tests/files/mysql_handler.sql new file mode 100644 index 0000000..702374e --- /dev/null +++ b/tests/files/mysql_handler.sql @@ -0,0 +1,10 @@ +create procedure proc1() +begin + declare handler for foo begin end; + select 1; +end; + +create procedure proc2() +begin + select 1; +end; diff --git a/tests/test_split.py b/tests/test_split.py index c073298..f69e3d2 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -154,3 +154,9 @@ def test_split_quotes_with_new_line(): stmts = sqlparse.split("select 'foo\n\bar'") assert len(stmts) == 1 assert stmts[0] == "select 'foo\n\bar'" + + +def test_split_mysql_handler_for(load_file): + # see issue581 + stmts = sqlparse.split(load_file('mysql_handler.sql')) + assert len(stmts) == 2 |
