| 1 |
import sqlite3 |
| 2 |
|
| 3 |
con = sqlite3.connect(":memory:") |
| 4 |
cur = con.cursor() |
| 5 |
|
| 6 |
AUSTRIA = u"\xd6sterreich" |
| 7 |
|
| 8 |
|
| 9 |
cur.execute("select ?", (AUSTRIA,)) |
| 10 |
row = cur.fetchone() |
| 11 |
assert row[0] == AUSTRIA |
| 12 |
|
| 13 |
|
| 14 |
con.text_factory = str |
| 15 |
cur.execute("select ?", (AUSTRIA,)) |
| 16 |
row = cur.fetchone() |
| 17 |
assert type(row[0]) is str |
| 18 |
|
| 19 |
|
| 20 |
assert row[0] == AUSTRIA.encode("utf-8") |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
con.text_factory = lambda x: unicode(x, "utf-8", "ignore") |
| 26 |
cur.execute("select ?", ("this is latin1 and would normally create errors" + |
| 27 |
u"\xe4\xf6\xfc".encode("latin1"),)) |
| 28 |
row = cur.fetchone() |
| 29 |
assert type(row[0]) is unicode |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
con.text_factory = sqlite3.OptimizedUnicode |
| 34 |
cur.execute("select ?", (AUSTRIA,)) |
| 35 |
row = cur.fetchone() |
| 36 |
assert type(row[0]) is unicode |
| 37 |
|
| 38 |
cur.execute("select ?", ("Germany",)) |
| 39 |
row = cur.fetchone() |
| 40 |
assert type(row[0]) is str |