]> git.phdru.name Git - sqlconvert.git/commitdiff
Refactor identical code in the script
authorOleg Broytman <phd@phdru.name>
Sun, 14 Aug 2016 12:04:58 +0000 (15:04 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 14 Aug 2016 12:04:58 +0000 (15:04 +0300)
scripts/print_subtree_from_cl.py

index 76ac675ce9f5086652b785d89d1c8359640c350b..f34178a706b5c894f7bead750561c0e6ed1efe31 100755 (executable)
@@ -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 ...]]" %