]> git.phdru.name Git - sqlconvert.git/blobdiff - tests/test_tokens.py
Use SQLObject for string quoting
[sqlconvert.git] / tests / test_tokens.py
index d537d73f068291c2eb3d9a13773ba31c9cccf5ef..4e48ab040e00c4212225f4415c467a776c8ac00a 100644 (file)
@@ -6,6 +6,7 @@ from sqlconvert.print_tokens import tlist2str
 from sqlconvert.process_mysql import remove_directive_tokens, \
         is_directive_statement, requote_names, unescape_strings, \
         process_statement
+from sqlconvert.process_tokens import escape_strings
 
 
 def test_encoding():
@@ -42,10 +43,26 @@ def test_requote():
     assert query == u'SELECT * FROM "T"'
 
 
-def test_string():
+def test_unescape_string():
     parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0]
     unescape_strings(parsed)
     query = tlist2str(parsed)
+    assert query == u"INSERT INTO test VALUES ('\"te'st\"\n')"
+
+
+def test_escape_string_postgres():
+    parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0]
+    unescape_strings(parsed)
+    escape_strings(parsed, 'postgres')
+    query = tlist2str(parsed)
+    assert query == u"INSERT INTO test VALUES (E'\"te''st\"\\n')"
+
+
+def test_escape_string_sqlite():
+    parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0]
+    unescape_strings(parsed)
+    escape_strings(parsed, 'sqlite')
+    query = tlist2str(parsed)
     assert query == u"INSERT INTO test VALUES ('\"te''st\"\n')"