summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-02-15 20:22:34 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-02-15 20:22:34 (GMT)
commitbe2cf338e9baef1f2479a33a8c7b5552bf9bd86f (patch)
treead5bfa3bbfe0db0e65b25eb5ef805fbf0e0b226b
parent482ee66cb7075b917a0a93051536ed0c10586447 (diff)
parent1ca93954e17e4f6f1230306997badbda3e5c68bc (diff)
downloadcpython-be2cf338e9baef1f2479a33a8c7b5552bf9bd86f.zip
cpython-be2cf338e9baef1f2479a33a8c7b5552bf9bd86f.tar.gz
cpython-be2cf338e9baef1f2479a33a8c7b5552bf9bd86f.tar.bz2
Merge branch '3.2'
Issue #13491.
-rw-r--r--Doc/includes/sqlite3/converter_point.py4
-rw-r--r--Doc/includes/sqlite3/execute_1.py11
-rw-r--r--Doc/includes/sqlite3/execute_2.py12
-rw-r--r--Doc/includes/sqlite3/executemany_2.py4
-rw-r--r--Doc/includes/sqlite3/md5func.py2
-rw-r--r--Doc/includes/sqlite3/rowclass.py8
-rw-r--r--Doc/includes/sqlite3/text_factory.py17
-rw-r--r--Doc/library/sqlite3.rst8
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
10 files changed, 29 insertions, 41 deletions
diff --git a/Doc/includes/sqlite3/converter_point.py b/Doc/includes/sqlite3/converter_point.py
index a8861bc..5df828e 100644
--- a/Doc/includes/sqlite3/converter_point.py
+++ b/Doc/includes/sqlite3/converter_point.py
@@ -8,10 +8,10 @@ class Point:
return "(%f;%f)" % (self.x, self.y)
def adapt_point(point):
- return "%f;%f" % (point.x, point.y)
+ return ("%f;%f" % (point.x, point.y)).encode('ascii')
def convert_point(s):
- x, y = list(map(float, s.split(";")))
+ x, y = list(map(float, s.split(b";")))
return Point(x, y)
# Register the adapter
diff --git a/Doc/includes/sqlite3/execute_1.py b/Doc/includes/sqlite3/execute_1.py
index 3d08840..f864a89 100644
--- a/Doc/includes/sqlite3/execute_1.py
+++ b/Doc/includes/sqlite3/execute_1.py
@@ -1,11 +1,16 @@
import sqlite3
-con = sqlite3.connect("mydb")
-
+con = sqlite3.connect(":memory:")
cur = con.cursor()
+cur.execute("create table people (name_last, age)")
who = "Yeltsin"
age = 72
-cur.execute("select name_last, age from people where name_last=? and age=?", (who, age))
+# This is the qmark style:
+cur.execute("insert into people values (?, ?)", (who, age))
+
+# And this is the named style:
+cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
+
print(cur.fetchone())
diff --git a/Doc/includes/sqlite3/execute_2.py b/Doc/includes/sqlite3/execute_2.py
deleted file mode 100644
index 84734f9..0000000
--- a/Doc/includes/sqlite3/execute_2.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import sqlite3
-
-con = sqlite3.connect("mydb")
-
-cur = con.cursor()
-
-who = "Yeltsin"
-age = 72
-
-cur.execute("select name_last, age from people where name_last=:who and age=:age",
- {"who": who, "age": age})
-print(cur.fetchone())
diff --git a/Doc/includes/sqlite3/executemany_2.py b/Doc/includes/sqlite3/executemany_2.py
index 518cd94..527358e 100644
--- a/Doc/includes/sqlite3/executemany_2.py
+++ b/Doc/includes/sqlite3/executemany_2.py
@@ -1,8 +1,8 @@
import sqlite3
+import string
def char_generator():
- import string
- for c in string.letters[:26]:
+ for c in string.ascii_lowercase:
yield (c,)
con = sqlite3.connect(":memory:")
diff --git a/Doc/includes/sqlite3/md5func.py b/Doc/includes/sqlite3/md5func.py
index b7bc05b..0056b2d 100644
--- a/Doc/includes/sqlite3/md5func.py
+++ b/Doc/includes/sqlite3/md5func.py
@@ -7,5 +7,5 @@ def md5sum(t):
con = sqlite3.connect(":memory:")
con.create_function("md5", 1, md5sum)
cur = con.cursor()
-cur.execute("select md5(?)", ("foo",))
+cur.execute("select md5(?)", (b"foo",))
print(cur.fetchone()[0])
diff --git a/Doc/includes/sqlite3/rowclass.py b/Doc/includes/sqlite3/rowclass.py
index 3fa0b87..92b5ad6 100644
--- a/Doc/includes/sqlite3/rowclass.py
+++ b/Doc/includes/sqlite3/rowclass.py
@@ -1,12 +1,12 @@
import sqlite3
-con = sqlite3.connect("mydb")
+con = sqlite3.connect(":memory:")
con.row_factory = sqlite3.Row
cur = con.cursor()
-cur.execute("select name_last, age from people")
+cur.execute("select 'John' as name, 42 as age")
for row in cur:
- assert row[0] == row["name_last"]
- assert row["name_last"] == row["nAmE_lAsT"]
+ assert row[0] == row["name"]
+ assert row["name"] == row["nAmE"]
assert row[1] == row["age"]
assert row[1] == row["AgE"]
diff --git a/Doc/includes/sqlite3/text_factory.py b/Doc/includes/sqlite3/text_factory.py
index bdffd36..5f96cdb 100644
--- a/Doc/includes/sqlite3/text_factory.py
+++ b/Doc/includes/sqlite3/text_factory.py
@@ -3,9 +3,6 @@ import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
-# Create the table
-con.execute("create table person(lastname, firstname)")
-
AUSTRIA = "\xd6sterreich"
# by default, rows are returned as Unicode
@@ -14,19 +11,17 @@ row = cur.fetchone()
assert row[0] == AUSTRIA
# but we can make sqlite3 always return bytestrings ...
-con.text_factory = str
+con.text_factory = bytes
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
-assert type(row[0]) == str
+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 will ignore Unicode characters that cannot be
-# decoded from UTF-8
-con.text_factory = lambda x: str(x, "utf-8", "ignore")
-cur.execute("select ?", ("this is latin1 and would normally create errors" +
- "\xe4\xf6\xfc".encode("latin1"),))
+# 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 type(row[0]) == str
+assert row[0] == "barfoo"
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 6fd239e..2eb4614 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -484,14 +484,10 @@ Cursor Objects
kinds of placeholders: question marks (qmark style) and named placeholders
(named style).
- This example shows how to use parameters with qmark style:
+ Here's an example of both styles:
.. literalinclude:: ../includes/sqlite3/execute_1.py
- This example shows how to use the named style:
-
- .. literalinclude:: ../includes/sqlite3/execute_2.py
-
:meth:`execute` will only execute a single SQL statement. If you try to execute
more than one statement with it, it will raise a Warning. Use
:meth:`executescript` if you want to execute multiple SQL statements with one
@@ -773,7 +769,7 @@ and constructs a :class:`Point` object from it.
::
def convert_point(s):
- x, y = map(float, s.split(";"))
+ x, y = map(float, s.split(b";"))
return Point(x, y)
Now you need to make the :mod:`sqlite3` module know that what you select from
diff --git a/Misc/ACKS b/Misc/ACKS
index a0f6f25..760ac53 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1041,6 +1041,7 @@ Kannan Vijayan
Kurt Vile
Norman Vine
Frank Visser
+Johannes Vogel
Sjoerd de Vries
Niki W. Waibel
Wojtek Walczak
diff --git a/Misc/NEWS b/Misc/NEWS
index faef50a..3aa7e52 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2254,6 +2254,9 @@ C-API
Documentation
-------------
+- Issue #13491: Fix many errors in sqlite3 documentation. Initial
+ patch by Johannes Vogel.
+
- Issue #13402: Document absoluteness of sys.executable.
- Issue #13883: PYTHONCASEOK also works on OS X.