from sqlparse.sql import Statement
-from sqlparse.tokens import Name, Error, Punctuation
+from sqlparse.tokens import Name, Error, Punctuation, Comment, Newline, \
+ Whitespace
def requote_names(token_list):
self.tokens = []
def close(self):
- if self.tokens:
- raise ValueError("Incomplete SQL statement")
+ for token in self.tokens:
+ if (token.ttype not in (Comment.Single, Comment.Multiline,
+ Newline, Whitespace)):
+ raise ValueError("Incomplete SQL statement: %s" % self.tokens)
+ return self.tokens
INSERT into /* inline comment */ mytable VALUES (1, 'one');
/*! directive*/ INSERT INTO `MyTable` (`Id`, `Name`)
VALUES (1, 'one');
+
+-- The end
print()
statement._pprint_tree()
print("----------")
- grouper.close()
+ tokens = grouper.close()
+ for token in tokens:
+ print_tokens(token)
+ print(repr(token))
if __name__ == '__main__':
print()
statement._pprint_tree()
print("----------")
- grouper.close()
+ tokens = grouper.close()
+ for token in tokens:
+ print_tokens(token)
+ print(repr(token))
def test():
self.assertEqual(query, 'SELECT * FROM "T";')
self.assertRaises(StopIteration, next, g)
self.assertEqual(len(grouper.statements), 0)
- self.assertIsNone(grouper.close())
+ self.assertEqual(grouper.close(), [])
if __name__ == "__main__":
main()