ยปCore Development>Code coverage>Doc/includes/sqlite3/ctx_manager.py

Python code coverage for Doc/includes/sqlite3/ctx_manager.py

#countcontent
1n/aimport sqlite3
2n/a
3n/acon = sqlite3.connect(":memory:")
4n/acon.execute("create table person (id integer primary key, firstname varchar unique)")
5n/a
6n/a# Successful, con.commit() is called automatically afterwards
7n/awith con:
8n/a con.execute("insert into person(firstname) values (?)", ("Joe",))
9n/a
10n/a# con.rollback() is called after the with block finishes with an exception, the
11n/a# exception is still raised and must be caught
12n/atry:
13n/a with con:
14n/a con.execute("insert into person(firstname) values (?)", ("Joe",))
15n/aexcept sqlite3.IntegrityError:
16n/a print("couldn't add Joe twice")