X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=scripts%2Fmysql2sql;h=112130ea398c707878d6e78e16088a8e6a3628ba;hb=aff066ceefb79333878baaf7c16e0a2206d26c5d;hp=d3178e9936219dc0b4d1acb7faf0c3ce27adfcb1;hpb=159b4e3d7127e719a0dd12013dd54bf05b276ba9;p=sqlconvert.git diff --git a/scripts/mysql2sql b/scripts/mysql2sql index d3178e9..112130e 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -8,7 +8,8 @@ import sys from sqlparse.compat import text_type from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_tokens import requote_names, StatementGrouper +from sqlconvert.process_mysql import is_directive_statement, process_statement +from sqlconvert.process_tokens import is_newline_statement, StatementGrouper from m_lib.defenc import default_encoding from m_lib.pbar.tty_pbar import ttyProgressBar @@ -38,6 +39,7 @@ def main(infile, encoding, outfile, output_encoding, use_pbar): cur_pos = 0 grouper = StatementGrouper(encoding=encoding) + got_directive = False for line in infile: if use_pbar: if isinstance(line, text_type): @@ -46,11 +48,17 @@ def main(infile, encoding, outfile, output_encoding, use_pbar): cur_pos += len(line) pbar.display(cur_pos) grouper.process_line(line) - if grouper.statements: - for statement in grouper.get_statements(): - requote_names(statement) - print_tokens(statement, outfile=outfile, - encoding=output_encoding) + for statement in grouper.get_statements(): + if got_directive and is_newline_statement(statement): + # Condense a sequence of newlines after a /*! directive */; + got_directive = False + continue + got_directive = is_directive_statement(statement) + if got_directive: + continue + process_statement(statement) + print_tokens(statement, outfile=outfile, + encoding=output_encoding) tokens = grouper.close() if tokens: for token in tokens: