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 != "postgres",
11 reason="This test requires PostgreSQL")
13 create_postgres_test_table = """
15 id serial PRIMARY KEY,
16 test_str VARCHAR(255) NOT NULL
21 def test_mysql2postgres_string():
22 connection.query(create_postgres_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, 'postgres')
27 query = tlist2str(parsed)
28 assert query == u"INSERT INTO test (id, test_str) VALUES " \
29 u"(1, E'\"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"