]> git.phdru.name Git - sqlconvert.git/commitdiff
Find an error in parse tree
authorOleg Broytman <phd@phdru.name>
Thu, 4 Aug 2016 17:01:09 +0000 (20:01 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 4 Aug 2016 17:05:41 +0000 (20:05 +0300)
mysql2sql/process_tokens.py
scripts/print_subtree.py

index 70dadb23bf6080b7764154e8ef3356763e552e37..2e39a2a7d8a4677de1052fa64639c088beaa579e 100644 (file)
@@ -1,6 +1,6 @@
 
 from sqlparse.sql import TokenList
-from sqlparse.tokens import Name
+from sqlparse.tokens import Name, Error
 
 
 def requote_names(token_list):
@@ -16,3 +16,14 @@ def requote_names(token_list):
                 token.normalized = token.value = value
             else:
                 token.normalized = token.value = '"%s"' % value
+
+
+def find_error(token_list):
+    """Find an error"""
+    for token in token_list:
+        if isinstance(token, TokenList):
+            if find_error(token):
+                return True
+        elif token.ttype is Error:
+            return True
+    return False
index 100fa649c313a2713cda1e9b753e1bc565831bef..76ac675ce9f5086652b785d89d1c8359640c350b 100755 (executable)
@@ -3,8 +3,8 @@ from __future__ import print_function
 
 import sys
 from sqlparse import parse
-from mysql2sql.process_tokens import requote_names
 from mysql2sql.print_tokens import print_tokens
+from mysql2sql.process_tokens import requote_names, find_error
 
 
 def test():
@@ -16,6 +16,8 @@ def test():
     ):
         for parsed in parse(query):
             print("----------")
+            if find_error(parsed):
+                print("ERRORS IN QUERY")
             requote_names(parsed)
             print_tokens(parsed)
             print()
@@ -27,6 +29,8 @@ def main(*queries):
     for query in queries:
         for parsed in parse(query):
             print("----------")
+            if find_error(parsed):
+                print("ERRORS IN QUERY")
             requote_names(parsed)
             print_tokens(parsed)
             print()