annotate Doc/includes/sqlite3/ctx_manager.py @ 57114:d3a81051663b

importlib.test.source.util referenced variables in the 'finally' part of a try/finally which may not have been set.
author Brett Cannon <bcannon@gmail.com>
date Thu, 05 Nov 2009 01:17:22 +0000
parents 09053a7c1cdf
children bc16d1300ee1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46181
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
1 import sqlite3
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
2
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
3 con = sqlite3.connect(":memory:")
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
4 con.execute("create table person (id integer primary key, firstname varchar unique)")
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
5
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
6 # Successful, con.commit() is called automatically afterwards
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
7 with con:
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
8 con.execute("insert into person(firstname) values (?)", ("Joe",))
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
9
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
10 # con.rollback() is called after the with block finishes with an exception, the
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
11 # exception is still raised and must be catched
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
12 try:
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
13 with con:
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
14 con.execute("insert into person(firstname) values (?)", ("Joe",))
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
15 except sqlite3.IntegrityError:
09053a7c1cdf Same documentation for sqlite3 module as in 2.6.
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
16 print("couldn't add Joe twice")