X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=tests%2Ftest_mysql2postgres.py;fp=tests%2Ftest_mysql2postgres.py;h=37edb57aab0bab4ccc7a6c398343a5e45314513c;hb=00f0aef5739a19921ed06f0397b44ba336184424;hp=0000000000000000000000000000000000000000;hpb=3b92cf503ab42f2e3b040398a54d8b7d75838e8b;p=sqlconvert.git diff --git a/tests/test_mysql2postgres.py b/tests/test_mysql2postgres.py new file mode 100644 index 0000000..37edb57 --- /dev/null +++ b/tests/test_mysql2postgres.py @@ -0,0 +1,29 @@ +from sqlparse import parse +from sqlobject.tests.dbtest import getConnection +import py.test + +from sqlconvert.print_tokens import tlist2str +from sqlconvert.process_mysql import unescape_strings + + +create_postgres_test_table = """ +CREATE TABLE test ( + id serial PRIMARY KEY, + test_str VARCHAR(255) NOT NULL +); +""" + + +def test_mysql2postgres_string(): + connection = getConnection() + if connection.dbName != "postgres": + py.test.skip("This test requires PostgreSQL") + connection.query(create_postgres_test_table) + parsed = parse("insert into test (id, test_str) " + "values (1, '\"te\\'st\\\"')")[0] + unescape_strings(parsed) + query = tlist2str(parsed) + assert query == u"INSERT INTO test (id, test_str) VALUES (1, '\"te''st\"')" + connection.query(query) + test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0] + assert test_str == u"\"te'st\""