Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SQLite context manager for queries #257

Open
anoadragon453 opened this issue Jan 28, 2020 · 0 comments
Open

Use SQLite context manager for queries #257

anoadragon453 opened this issue Jan 28, 2020 · 0 comments

Comments

@anoadragon453
Copy link
Member

https://docs.python.org/2/library/sqlite3.html#using-the-connection-as-a-context-manager

This allows us to wrap queries in a block:

try:
    with con:
        con.execute("insert into person(firstname) values (?)", ("Joe",))
except sqlite3.IntegrityError:
    print "couldn't add Joe twice"

that will automatically commit upon success (though note that there are some places where we explicitly do not commit the DB) and roll back upon error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant