From 77dbb9d37dfcca2a1287879f40cb781121eaeffb Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 3 Aug 2016 19:05:51 +0300 Subject: [PATCH] Parse many queries from command line --- scripts/print_subtree.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/print_subtree.py b/scripts/print_subtree.py index f1da6de..8a37d95 100755 --- a/scripts/print_subtree.py +++ b/scripts/print_subtree.py @@ -14,8 +14,8 @@ def test(): "/*! directive*/ INSERT INTO `MyTable` (`Id`, `Name`) " "VALUES (1, 'one')" ): - print("----------") for parsed in parse(query): + print("----------") requote_names(parsed) print_tokens(parsed) print() @@ -24,17 +24,20 @@ def test(): def main(query): - parsed = parse(query)[0] - requote_names(parsed) - print_tokens(parsed) - print() - parsed._pprint_tree() + for parsed in parse(query): + print("----------") + requote_names(parsed) + print_tokens(parsed) + print() + parsed._pprint_tree() + print("----------") if __name__ == '__main__': - if len(sys.argv) != 2: - sys.exit("Usage: %s [-t | sql_query_string]" % sys.argv[0]) + if len(sys.argv) <= 1: + sys.exit("Usage: %s [-t | sql_query_string [; sql_query_string ...]]" % + sys.argv[0]) if sys.argv[1] == '-t': test() else: - query = sys.argv[1] + query = ';'.join(sys.argv[1:]) main(query) -- 2.39.5