Mercurial > cpython-lru_cache-weakref
annotate Doc/includes/sqlite3/ctx_manager.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | bc16d1300ee1 |
| children |
| 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 |
|
73230
bc16d1300ee1
caught is the right pp of catch; thanks to Don Bennett from docs@
Sandro Tosi <sandro.tosi@gmail.com>
parents:
46181
diff
changeset
|
11 # exception is still raised and must be caught |
|
46181
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") |
