X-Git-Url: https://git.phdru.name/?p=sqlconvert.git;a=blobdiff_plain;f=tests%2Ftest_mysql2sqlite.py;fp=tests%2Ftest_mysql2sqlite.py;h=b5ae10ff35dc788cfd305dcbc30a83fae59b945c;hp=0000000000000000000000000000000000000000;hb=26ca2f53d8fe333bb2448ea412e82be415cb3fd2;hpb=b8225ccc168f04789db1935a90462b5cb0bbd6a6 diff --git a/tests/test_mysql2sqlite.py b/tests/test_mysql2sqlite.py new file mode 100644 index 0000000..b5ae10f --- /dev/null +++ b/tests/test_mysql2sqlite.py @@ -0,0 +1,32 @@ +from sqlparse import parse +from sqlobject.tests.dbtest import getConnection +import pytest + +from sqlconvert.print_tokens import tlist2str +from sqlconvert.process_mysql import unescape_strings +from sqlconvert.process_tokens import escape_strings + +connection = getConnection() +pytestmark = pytest.mark.skipif(connection.dbName != "sqlite", + reason="This test requires SQLite") + +create_sqlite_test_table = """ +CREATE TABLE test ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + test_str VARCHAR(255) NOT NULL +); +""" + + +def test_mysql2sqlite_string(): + connection.query(create_sqlite_test_table) + parsed = parse("insert into test (id, test_str) values " + "(1, '\"te\\'st\\\"\\n')")[0] + unescape_strings(parsed) + escape_strings(parsed, 'sqlite') + query = tlist2str(parsed) + assert query == u"INSERT INTO test (id, test_str) VALUES " \ + u"(1, '\"te''st\"\n')" + connection.query(query) + test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0] + assert test_str == u"\"te'st\"\n"