- if isinstance(token, Comment):
- subtokens = token.tokens
- if subtokens:
- comment = subtokens[0]
- if comment.ttype is T.Comment.Multiline and \
- comment.value.startswith('/*!'):
+ if is_comment_or_space(token):
+ continue
+ if (token.ttype is T.DML):
+ return token.normalized
+ break
+ raise ValueError("Not a DML statement")
+
+
+def split_ext_insert(statement):
+ """Split extended INSERT into multiple standard INSERTs"""
+ insert_tokens = []
+ values_tokens = []
+ end_tokens = []
+ expected = 'INSERT'
+ for token in statement.tokens:
+ if is_comment_or_space(token):
+ if expected == 'END':
+ end_tokens.append(token)
+ else:
+ insert_tokens.append(token)
+ continue
+ elif expected == 'INSERT':
+ if (token.ttype is T.DML) and (token.normalized == 'INSERT'):
+ insert_tokens.append(token)
+ expected = 'INTO'
+ continue
+ elif expected == 'INTO':
+ if (token.ttype is T.Keyword) and (token.normalized == 'INTO'):
+ insert_tokens.append(token)
+ expected = 'TABLE_NAME'
+ continue
+ elif expected == 'TABLE_NAME':
+ if isinstance(token, (Function, Identifier)):
+ insert_tokens.append(token)
+ expected = 'VALUES'
+ continue
+ elif expected == 'VALUES':
+ if (token.ttype is T.Keyword) and (token.normalized == 'VALUES'):
+ insert_tokens.append(token)
+ expected = 'VALUES_OR_SEMICOLON'
+ continue
+ elif expected == 'VALUES_OR_SEMICOLON':
+ if isinstance(token, Parenthesis):
+ values_tokens.append(token)
+ continue
+ elif token.ttype is T.Punctuation:
+ if token.value == ',':