]> git.phdru.name Git - sqlconvert.git/blobdiff - sqlconvert/process_tokens.py
Skip semicolons and newlines /*! directives */;
[sqlconvert.git] / sqlconvert / process_tokens.py
index 0bbf94cb703ecb8963d93eeac147ecff0c19f1d4..924ba4abd7ce2f00c8b5ecb477a081c023cc674d 100644 (file)
@@ -1,17 +1,24 @@
 
 from sqlparse import parse
 from sqlparse.compat import PY3
-from sqlparse.tokens import Error, Punctuation, Comment, Newline, Whitespace
+from sqlparse import tokens as T
 
 
 def find_error(token_list):
     """Find an error"""
     for token in token_list.flatten():
-        if token.ttype is Error:
+        if token.ttype is T.Error:
             return True
     return False
 
 
+def is_newline_statement(statement):
+    for token in statement.tokens[:]:
+        if token.ttype is not T.Newline:
+            return False
+    return True
+
+
 if PY3:
     xrange = range
 
@@ -33,10 +40,10 @@ class StatementGrouper(object):
         last_stmt = statements[-1]
         for i in xrange(len(last_stmt.tokens) - 1, 0, -1):
             token = last_stmt.tokens[i]
-            if token.ttype in (Comment.Single, Comment.Multiline,
-                               Newline, Whitespace):
+            if token.ttype in (T.Comment.Single, T.Comment.Multiline,
+                               T.Newline, T.Whitespace):
                 continue
-            if token.ttype is Punctuation and token.value == ';':
+            if token.ttype is T.Punctuation and token.value == ';':
                 break  # The last statement is complete
             # The last statement is still incomplete - wait for the next line
             return
@@ -53,8 +60,8 @@ class StatementGrouper(object):
             return
         tokens = parse(''.join(self.lines), encoding=self.encoding)
         for token in tokens:
-            if (token.ttype not in (Comment.Single, Comment.Multiline,
-                                    Newline, Whitespace)):
+            if (token.ttype not in (T.Comment.Single, T.Comment.Multiline,
+                                    T.Newline, T.Whitespace)):
                 raise ValueError("Incomplete SQL statement: %s" %
                                  tokens)
         return tokens