]> git.phdru.name Git - sqlconvert.git/blobdiff - sqlconvert/process_mysql.py
Unescape strings
[sqlconvert.git] / sqlconvert / process_mysql.py
index f91f516d2d9236f53dd320f5eb2a958545d54c9d..d72479e7111bfc0db29b12c7f6bdb1d8aa0561ed 100644 (file)
@@ -49,6 +49,21 @@ def requote_names(token_list):
                 token.normalized = token.value = '"%s"' % value
 
 
+def unescape_strings(token_list):
+    """Unescape strings"""
+    for token in token_list.flatten():
+        if token.ttype is T.String.Single:
+            value = token.value
+            for orig, repl in (
+                ('\\"', '"'),
+                ("\\'", "''"),
+                ('\\\032', '\032'),
+            ):
+                value = value.replace(orig, repl)
+            token.normalized = token.value = value
+
+
 def process_statement(statement):
     remove_directive_tokens(statement)
     requote_names(statement)
+    unescape_strings(statement)