]> git.phdru.name Git - sqlconvert.git/commitdiff
Make process_statement() a generator
authorOleg Broytman <phd@phdru.name>
Wed, 28 Sep 2016 23:47:30 +0000 (02:47 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 28 Sep 2016 23:47:30 +0000 (02:47 +0300)
Prepare for process_statement() to yield a list of statements:
extended INSERT will be split into a list of plain INSERTs.

demo/demo-process.py
scripts/mysql2sql
sqlconvert/process_mysql.py
tests/test_process_tokens.py

index 2c93338c8e454064cb3b8d4747d0c5d38ea5bce9..a81f93ef1787cf1bae3658fa1a82a1ac757e8365 100755 (executable)
@@ -15,10 +15,10 @@ def process_lines(*lines):
             print("----- -----")
             if find_error(statement):
                 print("ERRORS IN QUERY")
-            process_statement(statement)
-            print_tokens(statement, encoding='utf-8')
-            print()
-            statement._pprint_tree()
+            for statement in process_statement(statement):
+                print_tokens(statement, encoding='utf-8')
+                print()
+                statement._pprint_tree()
             print("-----/-----")
     tokens = grouper.close()
     if tokens:
index f06234aeaf3ef48ede0765eb2a1e9f9f1a85ed43..3766c971ba0499fb49c9ef6d54273a7a314673a2 100755 (executable)
@@ -56,9 +56,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:
index 91ef98d66c65cd86ce93baddec518ccb980eb7f6..9bfef92de598c09c68f99623d1b2cdd1de157273 100644 (file)
@@ -75,3 +75,5 @@ def process_statement(statement, quoting_style='sqlite'):
     requote_names(statement)
     unescape_strings(statement)
     escape_strings(statement, quoting_style)
+    yield statement
+    return
index e561667d3c36de8a3d2a6ded7718743f9cee3d9e..2d30dc9b86561806d0c4b38f25e82171e3fc5724 100644 (file)
@@ -69,8 +69,8 @@ def test_escape_string_sqlite():
 
 def test_process():
     parsed = parse("select /*! test */ * from /* test */ `T`")[0]
-    process_statement(parsed)
-    query = tlist2str(parsed)
+    statement = next(process_statement(parsed))
+    query = tlist2str(statement)
     assert query == u'SELECT * FROM /* test */ "T"'