annotate Doc/includes/sqlite3/ctx_manager.py @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents 0ea5c055ab54
children b7e966b7c880
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46180
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
1 import sqlite3
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
2
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
3 con = sqlite3.connect(":memory:")
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
4 con.execute("create table person (id integer primary key, firstname varchar unique)")
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
5
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
6 # Successful, con.commit() is called automatically afterwards
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
7 with con:
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
8 con.execute("insert into person(firstname) values (?)", ("Joe",))
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
9
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
10 # con.rollback() is called after the with block finishes with an exception, the
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
11 # exception is still raised and must be catched
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
12 try:
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
13 with con:
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
14 con.execute("insert into person(firstname) values (?)", ("Joe",))
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
15 except sqlite3.IntegrityError:
0ea5c055ab54 Brought documentation for sqlite3 module up-to-date. Fixed Issue1625205 which
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
16 print "couldn't add Joe twice"