From: Oleg Broytman Date: Wed, 28 Sep 2016 23:47:30 +0000 (+0300) Subject: Make process_statement() a generator X-Git-Tag: 0.0.8~16 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=6f433a4531f0e301f3534de7f0278afbcf79d50e;p=sqlconvert.git Make process_statement() a generator Prepare for process_statement() to yield a list of statements: extended INSERT will be split into a list of plain INSERTs. --- diff --git a/demo/demo-process.py b/demo/demo-process.py index 2c93338..a81f93e 100755 --- a/demo/demo-process.py +++ b/demo/demo-process.py @@ -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: diff --git a/scripts/mysql2sql b/scripts/mysql2sql index f06234a..3766c97 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -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: diff --git a/sqlconvert/process_mysql.py b/sqlconvert/process_mysql.py index 91ef98d..9bfef92 100644 --- a/sqlconvert/process_mysql.py +++ b/sqlconvert/process_mysql.py @@ -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 diff --git a/tests/test_process_tokens.py b/tests/test_process_tokens.py index e561667..2d30dc9 100644 --- a/tests/test_process_tokens.py +++ b/tests/test_process_tokens.py @@ -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"'