From: Oleg Broytman Date: Sun, 25 Sep 2016 01:36:23 +0000 (+0300) Subject: Do not test statements in StatementGrouper X-Git-Tag: 0.0.6~5 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=aff066ceefb79333878baaf7c16e0a2206d26c5d;p=sqlconvert.git Do not test statements in StatementGrouper StatementGrouper simply raises StopIteration if there are no statements. --- diff --git a/demo/demo-group.py b/demo/demo-group.py index 888cb97..00daf43 100755 --- a/demo/demo-group.py +++ b/demo/demo-group.py @@ -10,14 +10,13 @@ def group_lines(*lines): grouper = StatementGrouper(encoding='utf-8') for line in lines: grouper.process_line(line) - if grouper.statements: - for statement in grouper.get_statements(): - print("----- -----") - if find_error(statement): - print("ERRORS IN QUERY") - print_tokens(statement, encoding='utf-8') - print() - statement._pprint_tree() + for statement in grouper.get_statements(): + print("----- -----") + if find_error(statement): + print("ERRORS IN QUERY") + print_tokens(statement, encoding='utf-8') + print() + statement._pprint_tree() print("-----/-----") tokens = grouper.close() if tokens: diff --git a/demo/demo-process.py b/demo/demo-process.py index 8d3ee5d..2c93338 100755 --- a/demo/demo-process.py +++ b/demo/demo-process.py @@ -11,15 +11,14 @@ def process_lines(*lines): grouper = StatementGrouper(encoding='utf-8') for line in lines: grouper.process_line(line) - if grouper.statements: - for statement in grouper.get_statements(): - 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 grouper.get_statements(): + print("----- -----") + if find_error(statement): + print("ERRORS IN QUERY") + 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 98c5f10..112130e 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -48,18 +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(): - 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) + 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: diff --git a/sqlconvert/process_tokens.py b/sqlconvert/process_tokens.py index 924ba4a..b1c2602 100644 --- a/sqlconvert/process_tokens.py +++ b/sqlconvert/process_tokens.py @@ -54,6 +54,7 @@ class StatementGrouper(object): for stmt in self.statements: yield stmt self.statements = [] + raise StopIteration def close(self): if not self.lines: