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
8 connection = getConnection()
9 pytestmark = pytest.mark.skipif(connection.dbName != "postgres",
10 reason="This test requires PostgreSQL")
12 create_postgres_test_table = """
14 id serial PRIMARY KEY,
15 test_str VARCHAR(255) NOT NULL
20 def test_mysql2postgres_string():
21 connection.query(create_postgres_test_table)
22 parsed = parse("insert into test (id, test_str) "
23 "values (1, '\"te\\'st\\\"')")[0]
24 unescape_strings(parsed)
25 query = tlist2str(parsed)
26 assert query == u"INSERT INTO test (id, test_str) VALUES (1, '\"te''st\"')"
27 connection.query(query)
28 test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0]
29 assert test_str == u"\"te'st\""