Created
July 18, 2020 04:01
-
-
Save masayuki038/42a1fbc796059d4e6aa1e2b3cf86edf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlparse | |
import sys | |
import re | |
parsed = sqlparse.parse(sys.argv[1]) | |
print(parsed[0]) | |
for t in parsed[0].tokens: | |
print(type(t), t.ttype, t) | |
if t.ttype is None: | |
sub_query = str(t) | |
m = re.match(r"^\((.*)\) [^\s()]+$", sub_query) | |
if m: | |
sub_query = m.group(1) | |
sub_parsed = sqlparse.parse(sub_query) | |
print(sub_parsed[0]) | |
for sub_t in sub_parsed[0].tokens: | |
print(type(sub_t), sub_t.ttype, sub_t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
フィールドとテーブル名の区別はつかない。
ホワイトリストではなくブラックリストを作り、ブラックリストに Identifier が含まれていなければセーフ、とするか。