`VALUES` is now a separate object that contains a lists of value tuples.
from sqlparse.sql import Comment, Function, Identifier, Parenthesis, \
- Statement, Token
+ Statement, Token, Values
from sqlparse import tokens as T
from .process_tokens import escape_strings, is_comment_or_space
expected = 'VALUES'
continue
elif expected == 'VALUES':
+ if isinstance(token, Values):
+ for subtoken in token.tokens:
+ if isinstance(subtoken, Parenthesis):
+ values_tokens.append(subtoken)
+ insert_tokens.append(Token(T.Keyword, 'VALUES'))
+ insert_tokens.append(Token(T.Whitespace, ' '))
+ expected = 'VALUES_OR_SEMICOLON'
+ continue
if (token.ttype is T.Keyword) and (token.normalized == 'VALUES'):
insert_tokens.append(token)
expected = 'VALUES_OR_SEMICOLON'
INSERT INTO "MyTable" ("Id", "Name")
VALUES (1, 'one');
-INSERT INTO mytable VALUES (1, 'one');
-INSERT INTO mytable VALUES (2, 'two');
+INSERT INTO mytable VALUES (1, 'one');
+INSERT INTO mytable VALUES (2, 'two');
-INSERT INTO mytable (id, name) VALUES (1, 'one');
-INSERT INTO mytable (id, name) VALUES (2, 'two');
+INSERT INTO mytable (id, name) VALUES (1, 'one');
+INSERT INTO mytable (id, name) VALUES (2, 'two');
-- The end
stiter = process_statement(parsed)
statement = next(stiter)
query = tlist2str(statement)
- assert query == u"INSERT INTO test VALUES (1, 2);\n"
+ assert query == u"INSERT INTO test VALUES (1, 2);\n"
statement = next(stiter)
query = tlist2str(statement)
- assert query == u"INSERT INTO test VALUES (3, 4);"
+ assert query == u"INSERT INTO test VALUES (3, 4);"
parsed = parse("insert into test (age, salary) values (1, 2), (3, 4)")[0]
stiter = process_statement(parsed)
statement = next(stiter)
query = tlist2str(statement)
- assert query == u"INSERT INTO test (age, salary) VALUES (1, 2)\n"
+ assert query == u"INSERT INTO test (age, salary) VALUES (1, 2)\n"
statement = next(stiter)
query = tlist2str(statement)
- assert query == u"INSERT INTO test (age, salary) VALUES (3, 4)"
+ assert query == u"INSERT INTO test (age, salary) VALUES (3, 4)"
def test_process():