-import sqlite3
-
-persons = [
- ("Hugo", "Boss"),
- ("Calvin", "Klein")
- ]
-
-con = sqlite3.connect(":memory:")
-
-# Create the table
-con.execute("create table person(firstname, lastname)")
-
-# Fill the table
-con.executemany("insert into person(firstname, lastname) values (?, ?)", persons)
-
-# Print the table contents
-for row in con.execute("select firstname, lastname from person"):
- print row
-
-# Using a dummy WHERE clause to not let SQLite take the shortcut table deletes.
-print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows"
-
+import sqlite3\r
+\r
+persons = [\r
+ ("Hugo", "Boss"),\r
+ ("Calvin", "Klein")\r
+ ]\r
+\r
+con = sqlite3.connect(":memory:")\r
+\r
+# Create the table\r
+con.execute("create table person(firstname, lastname)")\r
+\r
+# Fill the table\r
+con.executemany("insert into person(firstname, lastname) values (?, ?)", persons)\r
+\r
+# Print the table contents\r
+for row in con.execute("select firstname, lastname from person"):\r
+ print row\r
+\r
+# Using a dummy WHERE clause to not let SQLite take the shortcut table deletes.\r
+print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows"\r
-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
-cur.execute("select ?", (AUSTRIA,))
-row = cur.fetchone()
-assert row[0] == AUSTRIA
-
-# but we can make pysqlite always return bytestrings ...
-con.text_factory = str
-cur.execute("select ?", (AUSTRIA,))
-row = cur.fetchone()
-assert type(row[0]) == str
-# 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: 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
-
-# pysqlite offers a builtin 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
-
-cur.execute("select ?", ("Germany",))
-row = cur.fetchone()
-assert type(row[0]) == str
-
+import sqlite3\r
+\r
+con = sqlite3.connect(":memory:")\r
+cur = con.cursor()\r
+\r
+# Create the table\r
+con.execute("create table person(lastname, firstname)")\r
+\r
+AUSTRIA = u"\xd6sterreich"\r
+\r
+# by default, rows are returned as Unicode\r
+cur.execute("select ?", (AUSTRIA,))\r
+row = cur.fetchone()\r
+assert row[0] == AUSTRIA\r
+\r
+# but we can make pysqlite always return bytestrings ...\r
+con.text_factory = str\r
+cur.execute("select ?", (AUSTRIA,))\r
+row = cur.fetchone()\r
+assert type(row[0]) == str\r
+# the bytestrings will be encoded in UTF-8, unless you stored garbage in the\r
+# database ...\r
+assert row[0] == AUSTRIA.encode("utf-8")\r
+\r
+# we can also implement a custom text_factory ...\r
+# here we implement one that will ignore Unicode characters that cannot be\r
+# decoded from UTF-8\r
+con.text_factory = lambda x: unicode(x, "utf-8", "ignore")\r
+cur.execute("select ?", ("this is latin1 and would normally create errors" + u"\xe4\xf6\xfc".encode("latin1"),))\r
+row = cur.fetchone()\r
+assert type(row[0]) == unicode\r
+\r
+# pysqlite offers a builtin optimized text_factory that will return bytestring\r
+# objects, if the data is in ASCII only, and otherwise return unicode objects\r
+con.text_factory = sqlite3.OptimizedUnicode\r
+cur.execute("select ?", (AUSTRIA,))\r
+row = cur.fetchone()\r
+assert type(row[0]) == unicode\r
+\r
+cur.execute("select ?", ("Germany",))\r
+row = cur.fetchone()\r
+assert type(row[0]) == str\r