X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=scripts%2Fmysql2sql;h=112130ea398c707878d6e78e16088a8e6a3628ba;hb=26ca2f53d8fe333bb2448ea412e82be415cb3fd2;hp=5ba8fd741e1f021e7133aa9f79393c108f161505;hpb=dbc9220a2b29725f94637607f8d8b00c762deb67;p=sqlconvert.git diff --git a/scripts/mysql2sql b/scripts/mysql2sql index 5ba8fd7..112130e 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -8,8 +8,8 @@ import sys from sqlparse.compat import text_type from sqlconvert.print_tokens import print_tokens -from sqlconvert.process_mysql import requote_names -from sqlconvert.process_tokens import 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 @@ -39,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): @@ -47,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: