From 80a352828850edb4089fd0fd5555dee5d17f384c Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 14 Aug 2016 15:04:58 +0300 Subject: [PATCH] Refactor identical code in the script --- scripts/print_subtree_from_cl.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/scripts/print_subtree_from_cl.py b/scripts/print_subtree_from_cl.py index 76ac675..f34178a 100755 --- a/scripts/print_subtree_from_cl.py +++ b/scripts/print_subtree_from_cl.py @@ -7,24 +7,6 @@ from mysql2sql.print_tokens import print_tokens from mysql2sql.process_tokens import requote_names, find_error -def test(): - for query in ( - "SELECT * FROM `mytable`; -- line-comment", - "INSERT into /* inline comment */ mytable VALUES (1, 'one')", - "/*! directive*/ INSERT INTO `MyTable` (`Id`, `Name`) " - "VALUES (1, 'one')" - ): - for parsed in parse(query): - print("----------") - if find_error(parsed): - print("ERRORS IN QUERY") - requote_names(parsed) - print_tokens(parsed) - print() - parsed._pprint_tree() - print("----------") - - def main(*queries): for query in queries: for parsed in parse(query): @@ -37,6 +19,16 @@ def main(*queries): parsed._pprint_tree() print("----------") + +def test(): + main( + "SELECT * FROM `mytable`; -- line-comment", + "INSERT into /* inline comment */ mytable VALUES (1, 'one')", + "/*! directive*/ INSERT INTO `MyTable` (`Id`, `Name`) " + "VALUES (1, 'one')" + ) + + if __name__ == '__main__': if len(sys.argv) <= 1: sys.exit("Usage: %s [-t | sql_query_string [; sql_query_string ...]]" % -- 2.39.5