diff -r c7d1768d4fac Doc/includes/sqlite3/converter_point.py --- a/Doc/includes/sqlite3/converter_point.py Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/includes/sqlite3/converter_point.py Sun Nov 27 11:19:46 2011 +0100 @@ -8,10 +8,10 @@ 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 -r c7d1768d4fac Doc/includes/sqlite3/execute_1.py --- a/Doc/includes/sqlite3/execute_1.py Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/includes/sqlite3/execute_1.py Sun Nov 27 11:19:46 2011 +0100 @@ -4,6 +4,15 @@ cur = con.cursor() +# Create table +cur.execute('''create table people +(name_last, age)''') + +# Insert a row of data +cur.execute("""insert into people + values ('Kohl', 85)""") + + who = "Yeltsin" age = 72 diff -r c7d1768d4fac Doc/includes/sqlite3/executemany_2.py --- a/Doc/includes/sqlite3/executemany_2.py Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/includes/sqlite3/executemany_2.py Sun Nov 27 11:19:46 2011 +0100 @@ -1,8 +1,8 @@ import sqlite3 +import string def char_generator(): - import string - for c in string.letters[:26]: + for c in string.ascii_letters_lowercase: yield (c,) con = sqlite3.connect(":memory:") diff -r c7d1768d4fac Doc/includes/sqlite3/md5func.py --- a/Doc/includes/sqlite3/md5func.py Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/includes/sqlite3/md5func.py Sun Nov 27 11:19:46 2011 +0100 @@ -7,5 +7,5 @@ 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 -r c7d1768d4fac Doc/includes/sqlite3/text_factory.py --- a/Doc/includes/sqlite3/text_factory.py Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/includes/sqlite3/text_factory.py Sun Nov 27 11:19:46 2011 +0100 @@ -3,9 +3,6 @@ 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,23 +11,14 @@ 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]) == 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"),)) -row = cur.fetchone() -assert type(row[0]) == str - # 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 diff -r c7d1768d4fac Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst Tue Nov 15 16:13:16 2011 +0100 +++ b/Doc/library/sqlite3.rst Sun Nov 27 11:19:46 2011 +0100 @@ -293,7 +293,6 @@ .. literalinclude:: ../includes/sqlite3/md5func.py - .. method:: Connection.create_aggregate(name, num_params, aggregate_class) Creates a user-defined aggregate function. @@ -500,6 +499,7 @@ more than one statement with it, it will raise a Warning. Use :meth:`executescript` if you want to execute multiple SQL statements with one call. + :meth:`[parameters]` needs to be a bytes type otherwise a TypeError will be raised. .. method:: Cursor.executemany(sql, seq_of_parameters) @@ -777,7 +777,7 @@ :: def convert_point(s): - x, y = map(float, s.split(";")) + x, y = list(map(float, s.split(b";"))) return Point(x, y) Now you need to make the :mod:`sqlite3` module know that what you select from