]> git.phdru.name Git - sqlconvert.git/blobdiff - sqlconvert/process_mysql.py
Build(GHActions): Use `checkout@v4` instead of outdated `v2`
[sqlconvert.git] / sqlconvert / process_mysql.py
index e99ea79edc2816c57787f0578589a38bacea6173..c89d6d190940dad18230043b6ae77da89bfababf 100644 (file)
@@ -1,6 +1,6 @@
 
 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
 
@@ -29,7 +29,7 @@ def is_directive_statement(statement):
 
 
 def remove_directive_tokens(statement):
-    """Remove /\*! directives \*/ from the first-level"""
+    """Remove /*! directives */ from the first-level"""
     new_tokens = []
     for token in statement.tokens:
         if _is_directive_token(token):
@@ -110,6 +110,14 @@ def split_ext_insert(statement):
                 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'
@@ -147,10 +155,10 @@ def process_statement(statement, dbname='sqlite'):
     remove_directive_tokens(statement)
     escape_strings(statement, dbname)
     try:
-        is_insert = get_DML_type(statement) == 'INSERT'
+        dml_type = get_DML_type(statement)
     except ValueError:
-        is_insert = False
-    if is_insert:
+        dml_type = 'UNKNOWN'
+    if dml_type == 'INSERT':
         for statement in split_ext_insert(statement):
             yield statement
     else: