|
Re: Emulating a sequence: msg#00028python.db.pysqlite.user
David Pratt wrote: > [...] > I figure excutescript should execute both statements in a single > transaction so it will be as safe way to go. The value will always be > correct without worrying that another connection picked off the next > value before another committed it. [...] As I said in the other message, transactions "just work" - with and without executescript(). - pysqlite (as mandated by the DB-API 2.0) transparently opens transactions for you once you use a DML command (INSERT, UPDATE, DELETE, REPLACE). It also transparently COMMITs if you use a DDL command (CREATE, DROP, ...). - Then, just use as many DML commands as you want - If you're in a consistent state, use .commit() on the connection object. - If you want to roll back your changes, use .rollback() on the connection object. A sequence like this is quite common for using the DB-API: class DataAccessLayer: ... def some_action(self): try: cur = self.con.cursor() cur.execute(...) cur.execute(...) cur.execute(...) self.con.commit() except: self.con.rollback() -- Gerhard |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Installation problem around sqlite3.h: 00028, Geoff Gardiner |
|---|---|
| Next by Date: | Re: Emulating a sequence: 00028, ggivler-zdgUFu1MqnQ |
| Previous by Thread: | Re: Emulating a sequencei: 00028, David Pratt |
| Next by Thread: | Re: Emulating a sequence: 00028, David Pratt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |