X-Git-Url: https://git.phdru.name/?p=sqlconvert.git;a=blobdiff_plain;f=mysql2sql%2Fprocess_tokens.py;h=94879cc555ea2bbbb399ecb655657dfead8ceab0;hp=ac9930eb81963b1e0c376ff67af035aaaca37679;hb=031cc0d6a41717d4c5d7c4659290e05810202eb9;hpb=7d813bbd88d3d206cadf5904a538a8c2db6aad0c diff --git a/mysql2sql/process_tokens.py b/mysql2sql/process_tokens.py index ac9930e..94879cc 100644 --- a/mysql2sql/process_tokens.py +++ b/mysql2sql/process_tokens.py @@ -1,6 +1,6 @@ -from sqlparse.sql import TokenList -from sqlparse.tokens import Name, Error +from sqlparse.sql import Statement +from sqlparse.tokens import Name, Error, Punctuation def requote_names(token_list): @@ -22,3 +22,25 @@ def find_error(token_list): if token.ttype is Error: return True return False + + +class StatementGrouper(object): + def __init__(self): + self.tokens = [] + self.statements = [] + + def get_statements(self): + for statement in self.statements: + yield statement + self.statements = [] + + def process(self, tokens): + for token in tokens: + self.tokens.append(token) + if (token.ttype == Punctuation) and (token.value == ';'): + self.statements.append(Statement(self.tokens)) + self.tokens = [] + + def close(self): + if self.tokens: + raise ValueError("Incomplete SQL statement")