]> git.phdru.name Git - sqlconvert.git/blobdiff - scripts/mysql2sql
Add release script
[sqlconvert.git] / scripts / mysql2sql
index f06234aeaf3ef48ede0765eb2a1e9f9f1a85ed43..e63c1fd8f5942f0735256d5aae12e51e3ebd318a 100755 (executable)
@@ -31,8 +31,12 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style):
         if size is None:
             use_pbar = False
 
-    print("Converting: ", end='', file=sys.stderr)
-    sys.stderr.flush()
+    if use_pbar:
+        print("Converting", end='', file=sys.stderr)
+        if infile.name != '<stdin>':
+            print(' ' + infile.name, end='', file=sys.stderr)
+        print(": ", end='', file=sys.stderr)
+        sys.stderr.flush()
 
     if use_pbar:
         pbar = ttyProgressBar(0, size-1)
@@ -56,9 +60,9 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style):
             got_directive = is_directive_statement(statement)
             if got_directive:
                 continue
-            process_statement(statement, quoting_style)
-            print_tokens(statement, outfile=outfile,
-                         encoding=output_encoding)
+            for statement in process_statement(statement, quoting_style):
+                print_tokens(statement, outfile=outfile,
+                             encoding=output_encoding)
     tokens = grouper.close()
     if tokens:
         for token in tokens:
@@ -66,7 +70,7 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style):
 
     if use_pbar:
         pbar.erase()
-    print("done.")
+        print("done.")
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Convert MySQL to SQL')
@@ -90,7 +94,7 @@ if __name__ == '__main__':
     parser.add_argument('output_file', nargs='?', help='output file name')
     args = parser.parse_args()
 
-    if int(args.mysql) + int(args.postgres) + int(args.sqlite) > 1:
+    if int(args.mysql) + int(args.pg) + int(args.sqlite) > 1:
         print("Error: options -m/-p/-s are mutually incompatible, "
               "use only one of them",
               file=sys.stderr)
@@ -133,6 +137,7 @@ if __name__ == '__main__':
 
     if outfile == '-':
         outfile = sys.stdout
+        args.no_pbar = True
     else:
         try:
             outfile = open(outfile, 'wt', encoding=output_encoding)
@@ -143,7 +148,7 @@ if __name__ == '__main__':
 
     if args.mysql:
         quoting_style = 'mysql'
-    elif args.postgres:
+    elif args.pg:
         quoting_style = 'postgres'
     else:
         quoting_style = 'sqlite'