From 4edfd2fe0ac4e6aca1ee014ea47f9d6b13bfcfbe Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Mon, 17 Jun 2013 21:30:13 +0200 Subject: Code cleanup. --- examples/extract_table_names.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'examples') 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()) -- cgit v1.2.1