sqlite3 with context manager
Tim.Arnold at sas.com
Tue Sep 6 19:18:07 CEST 2011
On 9/3/2011 3:03 AM, Carl Banks wrote:
> On Friday, September 2, 2011 11:43:53 AM UTC-7, Tim Arnold wrote:
>> I'm using the 'with' context manager for a sqlite3 connection:
>> with sqlite3.connect(my.database,timeout=10) as conn:
>> conn.execute('update config_build set datetime=?,result=?
>> where id=?',
>> (datetime.datetime.now(), success,
>> my question is what happens if the update fails? Shouldn't it throw an
> If you look at the sqlite3 syntax documentation, you'll see it has a SQL extension that allows you to specify error semantics. It looks something like this:
> UPDATE OR IGNORE
> UPDATE OR FAIL
> UPDATE OR ROLLBACK
> I'm not sure exactly how this interacts with pysqlite3, but using one of these might help it throw exceptions when you want it to.
> Carl Banks
I see now. You can use 'update or fail' if you have the extensions built
example of use, line 76:
For my case, however, I'll follow Ian's advice and check on the rowcount
after the update.
thanks for the explanation and advice,
More information about the Python-list