]> git.phdru.name Git - sqlconvert.git/commitdiff
Parse many queries from command line
authorOleg Broytman <phd@phdru.name>
Wed, 3 Aug 2016 16:05:51 +0000 (19:05 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 3 Aug 2016 16:08:54 +0000 (19:08 +0300)
scripts/print_subtree.py

index f1da6de13caf4f515be588764e96e715124479aa..8a37d957f08b69bc2c0a5629a7e20822e06ddcef 100755 (executable)
@@ -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)