X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=sqlconvert%2Fprocess_mysql.py;h=218655aa976090c7af1a79c6881ca6d35b0311e0;hb=6d906e2f335699348bf44a653ca708b522a99d85;hp=3f2f6aa3c7dee8ad84f60c3a630050c8f3d413b6;hpb=ad12dfd9c03a4f6bbd03d22238b6399ab09962ed;p=sqlconvert.git diff --git a/sqlconvert/process_mysql.py b/sqlconvert/process_mysql.py index 3f2f6aa..218655a 100644 --- a/sqlconvert/process_mysql.py +++ b/sqlconvert/process_mysql.py @@ -26,7 +26,7 @@ def is_directive_statement(statement): return True -def remove_directives(statement): +def remove_directive_tokens(statement): """Remove /*! directives */ from the first-level""" new_tokens = [] for token in statement.tokens: @@ -49,6 +49,27 @@ 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 ( + ('\\"', '"'), + ("\\'", "'"), + ("''", "'"), + ('\\b', '\b'), + ('\\n', '\n'), + ('\\r', '\r'), + ('\\t', '\t'), + ('\\\032', '\032'), + ('\\\\', '\\'), + ): + value = value.replace(orig, repl) + token.normalized = token.value = value + + def process_statement(statement): - remove_directives(statement) + remove_directive_tokens(statement) requote_names(statement) + unescape_strings(statement)