diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2013-06-17 21:30:13 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2013-06-17 21:30:13 +0200 |
| commit | 4edfd2fe0ac4e6aca1ee014ea47f9d6b13bfcfbe (patch) | |
| tree | 487720bd9e968778db066d6dc01b76efb7785745 | |
| parent | b62b79f9550c1d36383c4bb41eb5dd1ca9474a59 (diff) | |
| download | sqlparse-4edfd2fe0ac4e6aca1ee014ea47f9d6b13bfcfbe.tar.gz | |
Code cleanup.
| -rw-r--r-- | examples/extract_table_names.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/examples/extract_table_names.py b/examples/extract_table_names.py index 891ff6f..d8d1698 100644 --- a/examples/extract_table_names.py +++ b/examples/extract_table_names.py @@ -13,6 +13,7 @@ import sqlparse from sqlparse.sql import IdentifierList, Identifier from sqlparse.tokens import Keyword, DML + def is_subselect(parsed): if not parsed.is_group(): return False @@ -21,6 +22,7 @@ def is_subselect(parsed): return True return False + def extract_from_part(parsed): from_seen = False for item in parsed.tokens: @@ -35,6 +37,7 @@ def extract_from_part(parsed): elif item.ttype is Keyword and item.value.upper() == 'FROM': from_seen = True + def extract_table_identifiers(token_stream): for item in token_stream: if isinstance(item, IdentifierList): @@ -47,9 +50,11 @@ def extract_table_identifiers(token_stream): elif item.ttype is Keyword: yield item.value + def extract_tables(): stream = extract_from_part(sqlparse.parse(sql)[0]) return list(extract_table_identifiers(stream)) + if __name__ == '__main__': print 'Tables: %s' % ', '.join(extract_tables()) |
