File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -964,12 +964,61 @@ def _flatten_attribute_list(primary_key, attrs):
964
964
:param attrs: list of attribute names, which may include "KEY", "KEY DESC" or "KEY ASC"
965
965
:return: generator of attributes where "KEY" is replaced with its component attributes
966
966
"""
967
+ sql_keywords = [
968
+ "SELECT" ,
969
+ "FROM" ,
970
+ "WHERE" ,
971
+ "AND" ,
972
+ "OR" ,
973
+ "INSERT" ,
974
+ "INTO" ,
975
+ "VALUES" ,
976
+ "UPDATE" ,
977
+ "SET" ,
978
+ "DELETE" ,
979
+ "CREATE" ,
980
+ "TABLE" ,
981
+ "ALTER" ,
982
+ "DROP" ,
983
+ "INDEX" ,
984
+ "JOIN" ,
985
+ "LEFT" ,
986
+ "RIGHT" ,
987
+ "INNER" ,
988
+ "OUTER" ,
989
+ "UNION" ,
990
+ "GROUP" ,
991
+ "BY" ,
992
+ "HAVING" ,
993
+ "ORDER" ,
994
+ "ASC" ,
995
+ "DESC" ,
996
+ "LIMIT" ,
997
+ "OFFSET" ,
998
+ "DISTINCT" ,
999
+ "CASE" ,
1000
+ "WHEN" ,
1001
+ "THEN" ,
1002
+ "ELSE" ,
1003
+ "END" ,
1004
+ "NULL" ,
1005
+ "NOT" ,
1006
+ "IN" ,
1007
+ "LIKE" ,
1008
+ "KEY" ,
1009
+ ]
1010
+ keyword_pattern = (
1011
+ r"\b(" + "|" .join (re .escape (keyword ) for keyword in sql_keywords ) + r")\b"
1012
+ )
1013
+
967
1014
for a in attrs :
968
1015
if re .match (r"^\s*KEY(\s+[aA][Ss][Cc])?\s*$" , a ):
969
1016
if primary_key :
970
1017
yield from primary_key
971
1018
elif re .match (r"^\s*KEY\s+[Dd][Ee][Ss][Cc]\s*$" , a ):
972
1019
if primary_key :
973
1020
yield from (q + " DESC" for q in primary_key )
1021
+ elif re .match (keyword_pattern , a , re .I ):
1022
+ yield f"`{ a } `"
974
1023
else :
975
1024
yield a
You can’t perform that action at this time.
0 commit comments