from sqlparse.sql import Comment
from sqlparse import tokens as T
-from .process_tokens import escape_strings
+from .process_tokens import escape_strings, is_comment_or_space
def _is_directive_token(token):
token.normalized = token.value = value
+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)
from sqlconvert.print_tokens import tlist2str
from sqlconvert.process_mysql import remove_directive_tokens, \
is_directive_statement, requote_names, unescape_strings, \
- process_statement
+ is_insert, process_statement
from sqlconvert.process_tokens import escape_strings
assert query == u"INSERT INTO test VALUES ('\"te''st\"\n')"
+def test_is_insert():
+ parsed = parse("select /*! test */ * from /* test */ `T`")[0]
+ statement = next(process_statement(parsed))
+ assert not is_insert(statement)
+ parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0]
+ statement = next(process_statement(parsed))
+ assert is_insert(statement)
+
+
def test_process():
parsed = parse("select /*! test */ * from /* test */ `T`")[0]
statement = next(process_statement(parsed))