Mercurial > cpython-lru_cache-weakref
annotate Doc/includes/sqlite3/ctx_manager.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b7e966b7c880 |
| children |
| 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 |
|
73229
b7e966b7c880
caught is the right pp of catch; thanks to Don Bennett from docs@
Sandro Tosi <sandro.tosi@gmail.com>
parents:
46180
diff
changeset
|
11 # exception is still raised and must be caught |
|
46180
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" |
