summaryrefslogtreecommitdiffstats
path: root/Doc/includes/sqlite3
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-03-01 19:28:00 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-03-01 19:48:30 (GMT)
commita15a8d2a0c51d8f6269c843407f70df957454859 (patch)
treed23ab6c907a76360271005dac0068e7c63b550b6 /Doc/includes/sqlite3
parentc56bca31e9b7ac87a459a65680ee7ad454fd4f22 (diff)
downloadcpython-a15a8d2a0c51d8f6269c843407f70df957454859.zip
cpython-a15a8d2a0c51d8f6269c843407f70df957454859.tar.gz
cpython-a15a8d2a0c51d8f6269c843407f70df957454859.tar.bz2
sqlite3: Port relevant documentation changes from 3.2
Initial patch by Johannes Vogel. Issue #13491.
Diffstat (limited to 'Doc/includes/sqlite3')
-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/rowclass.py8
-rw-r--r--Doc/includes/sqlite3/text_factory.py11
5 files changed, 18 insertions, 28 deletions
diff --git a/Doc/includes/sqlite3/execute_1.py b/Doc/includes/sqlite3/execute_1.py
index fb3784f..763167c 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 df6c894..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 05857c0..0b12688 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.lowercase:
yield (c,)
con = sqlite3.connect(":memory:")
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 1959498..577378f 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 = u"\xd6sterreich"
# by default, rows are returned as Unicode
@@ -17,7 +14,7 @@ assert row[0] == AUSTRIA
con.text_factory = str
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
-assert type(row[0]) == str
+assert type(row[0]) is str
# the bytestrings will be encoded in UTF-8, unless you stored garbage in the
# database ...
assert row[0] == AUSTRIA.encode("utf-8")
@@ -29,15 +26,15 @@ con.text_factory = lambda x: unicode(x, "utf-8", "ignore")
cur.execute("select ?", ("this is latin1 and would normally create errors" +
u"\xe4\xf6\xfc".encode("latin1"),))
row = cur.fetchone()
-assert type(row[0]) == unicode
+assert type(row[0]) is unicode
# sqlite3 offers a built-in optimized text_factory that will return bytestring
# objects, if the data is in ASCII only, and otherwise return unicode objects
con.text_factory = sqlite3.OptimizedUnicode
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
-assert type(row[0]) == unicode
+assert type(row[0]) is unicode
cur.execute("select ?", ("Germany",))
row = cur.fetchone()
-assert type(row[0]) == str
+assert type(row[0]) is str