Mercurial > cpython-lru_cache-weakref
annotate Doc/includes/sqlite3/ctx_manager.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 0ea5c055ab54 |
| children | b7e966b7c880 |
| 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" |
