]> git.phdru.name Git - sqlconvert.git/blob - tests/test_mysql2postgres.py
Add a test for unescaped strings for Postgres
[sqlconvert.git] / tests / test_mysql2postgres.py
1 from sqlparse import parse
2 from sqlobject.tests.dbtest import getConnection
3 import py.test
4
5 from sqlconvert.print_tokens import tlist2str
6 from sqlconvert.process_mysql import unescape_strings
7
8
9 create_postgres_test_table = """
10 CREATE TABLE test (
11     id serial PRIMARY KEY,
12     test_str VARCHAR(255) NOT NULL
13 );
14 """
15
16
17 def test_mysql2postgres_string():
18     connection = getConnection()
19     if connection.dbName != "postgres":
20         py.test.skip("This test requires PostgreSQL")
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\""