tsudoko / anki-sync-server

Self-hosted Anki sync server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQLite code does not use context manager

expectocode opened this issue · comments

commented

Instead of

conn = self._conn()
cursor = conn.cursor()
cursor.execute(<some sql>)
conn.commit()

we can do:

conn = self._conn()
with conn:
    conn.execute(<some sql>)

which also handles rollbacks. Would you accept a PR to this effect?

If memory serves, sqlite3 has some quirks compared with other common DB2 libs, and doesn't provide context managers for some things (cursors?). The code is supposed to be generic enough now to support other RDBMSes, so reintroducing sqlite3-specific code would break that, and my heart :-).
That said, I think I did try and use with where possible/sensible when I refactored the code a few months ago, so that may just be an oversight on my part.