|
Re: Emulating a sequence: msg#00030python.db.pysqlite.user
Hi Gerhard. I am back on track. Many thanks for your advice. Regards, David Gerhard Häring wrote: > 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 > _______________________________________________ > pysqlite mailing list > pysqlite-IAPFreCvJWPBWskQ1e/+sw@xxxxxxxxxxxxxxxx > http://lists.initd.org/mailman/listinfo/pysqlite > |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Emulating a sequence: 00030, ggivler-zdgUFu1MqnQ |
|---|---|
| Next by Date: | Re: Emulating a sequence: 00030, David Pratt |
| Previous by Thread: | Re: Emulating a sequencei: 00030, Gerhard Häring |
| Next by Thread: | Re: Emulating a sequence: 00030, ggivler-zdgUFu1MqnQ |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |