2 from sqlparse.sql import Statement
3 from sqlparse.tokens import Name, Error, Punctuation
6 def requote_names(token_list):
7 """Remove backticks, quote non-lowercase identifiers"""
8 for token in token_list.flatten():
9 if token.ttype is Name:
11 if (value[0] == "`") and (value[-1] == "`"):
14 token.normalized = token.value = value
16 token.normalized = token.value = '"%s"' % value
19 def find_error(token_list):
21 for token in token_list.flatten():
22 if token.ttype is Error:
27 class StatementGrouper(object):
32 def get_statements(self):
33 for statement in self.statements:
37 def process(self, tokens):
39 self.tokens.append(token)
40 if (token.ttype == Punctuation) and (token.value == ';'):
41 self.statements.append(Statement(self.tokens))
46 raise ValueError("Incomplete SQL statement")