1 from sqlparse import parse
2 from sqlobject.tests.dbtest import getConnection
5 from sqlconvert.print_tokens import tlist2str
6 from sqlconvert.process_mysql import unescape_strings
7 from sqlconvert.process_tokens import escape_strings
9 connection = getConnection()
10 pytestmark = pytest.mark.skipif(connection.dbName != "sqlite",
11 reason="This test requires SQLite")
13 create_sqlite_test_table = """
15 id INTEGER PRIMARY KEY AUTOINCREMENT,
16 test_str VARCHAR(255) NOT NULL
21 def test_mysql2sqlite_string():
22 connection.query(create_sqlite_test_table)
23 parsed = parse("insert into test (id, test_str) values "
24 "(1, '\"te\\'st\\\"\\n')")[0]
25 unescape_strings(parsed)
26 escape_strings(parsed, 'sqlite')
27 query = tlist2str(parsed)
28 assert query == u"INSERT INTO test (id, test_str) VALUES " \
29 u"(1, '\"te''st\"\n')"
30 connection.query(query)
31 test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0]
32 assert test_str == u"\"te'st\"\n"