From ea3f99aa44f47d1fcd7229f8c887541bfd09fffe Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 29 Apr 2017 15:18:41 -0700 Subject: Use generator expression to avoid unnecessary temporary list --- sqlparse/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/utils.py b/sqlparse/utils.py index ee3e982..ffa029b 100644 --- a/sqlparse/utils.py +++ b/sqlparse/utils.py @@ -95,9 +95,9 @@ def imt(token, i=None, m=None, t=None): return False elif clss and isinstance(token, clss): return True - elif mpatterns and any((token.match(*pattern) for pattern in mpatterns)): + elif mpatterns and any(token.match(*pattern) for pattern in mpatterns): return True - elif types and any([token.ttype in ttype for ttype in types]): + elif types and any(token.ttype in ttype for ttype in types): return True else: return False -- cgit v1.2.1 From 78d46de2430104e41ba8738609c0cdd744f3fda2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 11 May 2017 01:18:23 +0300 Subject: Add MySQL keywords: ENGINE, AUTO_INCREMENT, CHARSET These are keywords from table options: CREATE TABLE name ( column definitions, ... ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; --- sqlparse/keywords.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index f742598..6a214f1 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -114,6 +114,7 @@ KEYWORDS = { 'ATOMIC': tokens.Keyword, 'AUDIT': tokens.Keyword, 'AUTHORIZATION': tokens.Keyword, + 'AUTO_INCREMENT': tokens.Keyword, 'AVG': tokens.Keyword, 'BACKWARD': tokens.Keyword, @@ -142,6 +143,7 @@ KEYWORDS = { 'CHARACTER_SET_NAME': tokens.Keyword, 'CHARACTER_SET_SCHEMA': tokens.Keyword, 'CHAR_LENGTH': tokens.Keyword, + 'CHARSET': tokens.Keyword, 'CHECK': tokens.Keyword, 'CHECKED': tokens.Keyword, 'CHECKPOINT': tokens.Keyword, @@ -238,6 +240,7 @@ KEYWORDS = { 'ENCODING': tokens.Keyword, 'ENCRYPTED': tokens.Keyword, 'END-EXEC': tokens.Keyword, + 'ENGINE': tokens.Keyword, 'EQUALS': tokens.Keyword, 'ESCAPE': tokens.Keyword, 'EVERY': tokens.Keyword, -- cgit v1.2.1 From dc788ab5b1af2e2a4a988b31a09d8d6656853f76 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Thu, 25 May 2017 08:52:13 +0200 Subject: Recognize MySQL table names starting with digits (fixes #337). --- sqlparse/keywords.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 6a214f1..92da63e 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -60,7 +60,7 @@ SQL_REGEX = { (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal), (r'-?\d*(\.\d+)?E-?\d+', tokens.Number.Float), (r'-?\d*\.\d+', tokens.Number.Float), - (r'-?\d+', tokens.Number.Integer), + (r'-?\d+(?![_A-Z])', tokens.Number.Integer), (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single), # not a real string literal in ANSI SQL: @@ -77,7 +77,7 @@ SQL_REGEX = { (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL), (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), - (r'[_A-Z][_$#\w]*', is_keyword), + (r'[0-9_A-Z][_$#\w]*', is_keyword), (r'[;:()\[\],\.]', tokens.Punctuation), (r'[<>=~!]+', tokens.Operator.Comparison), -- cgit v1.2.1 From 113897280c612aa839fa9f8bd44bfd720d3729c7 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sat, 29 Jul 2017 10:16:34 +0200 Subject: Fix parsing of UNION ALL after WHERE (fixes #349). --- sqlparse/sql.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/sql.py b/sqlparse/sql.py index f190de8..f698782 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -526,8 +526,9 @@ class Comment(TokenList): class Where(TokenList): """A WHERE clause.""" M_OPEN = T.Keyword, 'WHERE' - M_CLOSE = T.Keyword, ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT', - 'HAVING', 'RETURNING', 'INTO') + M_CLOSE = T.Keyword, ( + 'ORDER', 'GROUP', 'LIMIT', 'UNION', 'UNION ALL', 'EXCEPT', + 'HAVING', 'RETURNING', 'INTO') class Case(TokenList): -- cgit v1.2.1 From 7d91d361ad8c26af3fe0a15b807db4cefa5d000a Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sat, 29 Jul 2017 10:28:18 +0200 Subject: Don't treat sysdate as a builtin (fixes #344). According to Oracle's developer documentation sysdate is a function that doesn't require any parameters. Hence it's different from other builtins like int or varchar. --- sqlparse/keywords.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 92da63e..40022b9 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -639,7 +639,7 @@ KEYWORDS = { 'SERIAL8': tokens.Name.Builtin, 'SIGNED': tokens.Name.Builtin, 'SMALLINT': tokens.Name.Builtin, - 'SYSDATE': tokens.Name.Builtin, + 'SYSDATE': tokens.Name, 'TEXT': tokens.Name.Builtin, 'TINYINT': tokens.Name.Builtin, 'UNSIGNED': tokens.Name.Builtin, -- cgit v1.2.1 From c48a221e72dfc0a6631a16e5e42e768249919090 Mon Sep 17 00:00:00 2001 From: Demetrio92 Date: Mon, 7 Aug 2017 18:02:51 +0200 Subject: add PL/pgSQL syntax tested with mxtr/SQLTools --- sqlparse/keywords.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 40022b9..c9b41d6 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -14,6 +14,7 @@ def is_keyword(value): val = value.upper() return (KEYWORDS_COMMON.get(val) or KEYWORDS_ORACLE.get(val) or + KEYWORDS_PLPGSQL.get(val) or KEYWORDS.get(val, tokens.Name)), value @@ -800,3 +801,18 @@ KEYWORDS_ORACLE = { 'UNLIMITED': tokens.Keyword, 'UNLOCK': tokens.Keyword, } + +# PostgreSQL Syntax +KEYWORDS_PLPGSQL = { + 'PARTITION': tokens.Keyword, + 'OVER': tokens.Keyword, + 'PERFORM': tokens.Keyword, + 'NOTICE': tokens.Keyword, + 'PLPGSQL': tokens.Keyword, + 'INHERIT': tokens.Keyword, + 'INDEXES': tokens.Keyword, + + 'FOR': tokens.Keyword, + 'IN': tokens.Keyword, + 'LOOP': tokens.Keyword, +} -- cgit v1.2.1 From 617d38908bb999018598e3cbbdd123a992a08ba9 Mon Sep 17 00:00:00 2001 From: mvbentes Date: Fri, 25 Aug 2017 21:22:42 -0300 Subject: Extend alphas with accented characters --- sqlparse/keywords.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 40022b9..086aae9 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -35,7 +35,7 @@ SQL_REGEX = { (r"`(``|[^`])*`", tokens.Name), (r"´(´´|[^´])*´", tokens.Name), - (r'(\$(?:[_A-Z]\w*)?\$)[\s\S]*?\1', tokens.Literal), + (r'(\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal), (r'\?', tokens.Name.Placeholder), (r'%(\(\w+\))?s', tokens.Name.Placeholder), @@ -47,20 +47,20 @@ SQL_REGEX = { # is never a functino, see issue183 (r'(CASE|IN|VALUES|USING)\b', tokens.Keyword), - (r'(@|##|#)[A-Z]\w+', tokens.Name), + (r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name), # see issue #39 # Spaces around period `schema . name` are valid identifier # TODO: Spaces before period not implemented - (r'[A-Z]\w*(?=\s*\.)', tokens.Name), # 'Name' . - (r'(?<=\.)[A-Z]\w*', tokens.Name), # .'Name' - (r'[A-Z]\w*(?=\()', tokens.Name), # side effect: change kw to func + (r'[A-ZÀ-Ü]\w*(?=\s*\.)', tokens.Name), # 'Name' . + (r'(?<=\.)[A-ZÀ-Ü]\w*', tokens.Name), # .'Name' + (r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name), # side effect: change kw to func # TODO: `1.` and `.1` are valid numbers (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal), (r'-?\d*(\.\d+)?E-?\d+', tokens.Number.Float), (r'-?\d*\.\d+', tokens.Number.Float), - (r'-?\d+(?![_A-Z])', tokens.Number.Integer), + (r'-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer), (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single), # not a real string literal in ANSI SQL: @@ -77,7 +77,7 @@ SQL_REGEX = { (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL), (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), - (r'[0-9_A-Z][_$#\w]*', is_keyword), + (r'[0-9_A-ZÀ-Ü][_$#\w]*', is_keyword), (r'[;:()\[\],\.]', tokens.Punctuation), (r'[<>=~!]+', tokens.Operator.Comparison), -- cgit v1.2.1 From b3dc9a6ac2dd7511ecb6712ed6aceb4d4ce359ac Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Thu, 14 Sep 2017 15:52:00 +0200 Subject: Code cleanup. --- sqlparse/keywords.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index c63f1cc..649b5cc 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -804,15 +804,15 @@ KEYWORDS_ORACLE = { # PostgreSQL Syntax KEYWORDS_PLPGSQL = { - 'PARTITION': tokens.Keyword, - 'OVER': tokens.Keyword, - 'PERFORM': tokens.Keyword, - 'NOTICE': tokens.Keyword, - 'PLPGSQL': tokens.Keyword, - 'INHERIT': tokens.Keyword, - 'INDEXES': tokens.Keyword, - - 'FOR': tokens.Keyword, - 'IN': tokens.Keyword, - 'LOOP': tokens.Keyword, + 'PARTITION': tokens.Keyword, + 'OVER': tokens.Keyword, + 'PERFORM': tokens.Keyword, + 'NOTICE': tokens.Keyword, + 'PLPGSQL': tokens.Keyword, + 'INHERIT': tokens.Keyword, + 'INDEXES': tokens.Keyword, + + 'FOR': tokens.Keyword, + 'IN': tokens.Keyword, + 'LOOP': tokens.Keyword, } -- cgit v1.2.1