3
con = sqlite3.connect(":memory:")
6
AUSTRIA = "\xd6sterreich"
8
# by default, rows are returned as Unicode
9
cur.execute("select ?", (AUSTRIA,))
11
assert row[0] == AUSTRIA
13
# but we can make sqlite3 always return bytestrings ...
14
con.text_factory = bytes
15
cur.execute("select ?", (AUSTRIA,))
17
assert type(row[0]) is bytes
18
# the bytestrings will be encoded in UTF-8, unless you stored garbage in the
20
assert row[0] == AUSTRIA.encode("utf-8")
22
# we can also implement a custom text_factory ...
23
# here we implement one that appends "foo" to all strings
24
con.text_factory = lambda x: x.decode("utf-8") + "foo"
25
cur.execute("select ?", ("bar",))
27
assert row[0] == "barfoo"