X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=sqlconvert%2Fprocess_mysql.py;h=ad4d422b4c13fa0ca2f1821009038b0e512c9214;hb=7c6cbe51aaef47343ecd26f5979fdaa942579eb0;hp=34565316e93b62f0f6092df7950fb597ef405f93;hpb=294acc7e0f294eca2ca6d7f09b5fd63e31ccaf80;p=sqlconvert.git diff --git a/sqlconvert/process_mysql.py b/sqlconvert/process_mysql.py index 3456531..ad4d422 100644 --- a/sqlconvert/process_mysql.py +++ b/sqlconvert/process_mysql.py @@ -29,7 +29,7 @@ def is_directive_statement(statement): def remove_directive_tokens(statement): - """Remove /\*! directives \*/ from the first-level""" + """Remove /\*! directives \*/ from the first-level""" # noqa: W605: \* new_tokens = [] for token in statement.tokens: if _is_directive_token(token): @@ -71,11 +71,14 @@ def unescape_strings(token_list): token.normalized = token.value = value -def is_insert(statement): +def get_DML_type(statement): for token in statement.tokens: if is_comment_or_space(token): continue - return (token.ttype is T.DML) and (token.normalized == 'INSERT') + if (token.ttype is T.DML): + return token.normalized + break + raise ValueError("Not a DML statement") def split_ext_insert(statement): @@ -131,19 +134,23 @@ def split_ext_insert(statement): if i == len(values_tokens) - 1: # Last but one statement # Insert newlines only between split statements but not after new_lines = [] - # The statemnt sets `parent` attribute of the every token to self + # The statement sets `parent` attribute of the every token to self # but we don't care. statement = Statement(insert_tokens + [values] + end_tokens + new_lines) yield statement -def process_statement(statement, quoting_style='sqlite'): +def process_statement(statement, dbname='sqlite'): requote_names(statement) unescape_strings(statement) remove_directive_tokens(statement) - escape_strings(statement, quoting_style) - if is_insert(statement): + escape_strings(statement, dbname) + try: + dml_type = get_DML_type(statement) + except ValueError: + dml_type = 'UNKNOWN' + if dml_type == 'INSERT': for statement in split_ext_insert(statement): yield statement else: