FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Doc/includes/sqlite3/text_factory.py at master · python-emscripten/cpython · GitHub
python-emscripten
cpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Doc
/
includes
/
sqlite3
/
text_factory.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (23 loc) · 781 Bytes
Breadcrumbs
cpython
/
Doc
/
includes
/
sqlite3
/
text_factory.py
Copy path
File metadata and controls
29 lines (23 loc) · 781 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import
sqlite3
con
=
sqlite3
.
connect
(
":memory:"
)
cur
=
con
.
cursor
()
AUSTRIA
=
"
\xd6
sterreich"
# by default, rows are returned as Unicode
cur
.
execute
(
"select ?"
, (
AUSTRIA
,))
row
=
cur
.
fetchone
()
assert
row
[
0
]
==
AUSTRIA
# but we can make sqlite3 always return bytestrings ...
con
.
text_factory
=
bytes
cur
.
execute
(
"select ?"
, (
AUSTRIA
,))
row
=
cur
.
fetchone
()
assert
type
(
row
[
0
])
is
bytes
# the bytestrings will be encoded in UTF-8, unless you stored garbage in the
# database ...
assert
row
[
0
]
==
AUSTRIA
.
encode
(
"utf-8"
)
# we can also implement a custom text_factory ...
# here we implement one that appends "foo" to all strings
con
.
text_factory
=
lambda
x
:
x
.
decode
(
"utf-8"
)
+
"foo"
cur
.
execute
(
"select ?"
, (
"bar"
,))
row
=
cur
.
fetchone
()
assert
row
[
0
]
==
"barfoo"
con
.
close
()
Back
|
FazBrowse Home
|
New Git URL