X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=sqlconvert%2Fprocess_mysql.py;h=9e342c2e04ec7c5ad4ba1796731932320762e5f3;hb=d33677c7a57a955f59e46f2abe03e9f5a192d883;hp=d72479e7111bfc0db29b12c7f6bdb1d8aa0561ed;hpb=b83ec9eaf7e388f4061c5e13dd930fd108e4bd77;p=sqlconvert.git diff --git a/sqlconvert/process_mysql.py b/sqlconvert/process_mysql.py index d72479e..9e342c2 100644 --- a/sqlconvert/process_mysql.py +++ b/sqlconvert/process_mysql.py @@ -1,6 +1,7 @@ from sqlparse.sql import Comment from sqlparse import tokens as T +from .process_tokens import escape_strings, is_comment_or_space def _is_directive_token(token): @@ -56,14 +57,30 @@ def unescape_strings(token_list): 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_directive_tokens(statement) +def is_insert(statement): + for token in statement.tokens: + if is_comment_or_space(token): + continue + return (token.ttype is T.DML) and (token.normalized == 'INSERT') + + +def process_statement(statement, quoting_style='sqlite'): requote_names(statement) unescape_strings(statement) + remove_directive_tokens(statement) + escape_strings(statement, quoting_style) + yield statement + return