Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12691
| References | <j3r859$rnt$1@foggy.unx.sas.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2011-09-02 22:38 -0600 |
| Subject | Re: sqlite3 with context manager |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.726.1315024734.27778.python-list@python.org> (permalink) |
On Fri, Sep 2, 2011 at 12:43 PM, Tim Arnold <Tim.Arnold@sas.com> wrote:
> Hi,
> 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,
> self.b['id']))
>
> my question is what happens if the update fails? Shouldn't it throw an
> exception?
That depends on why it fails. If you pass in an id that doesn't exist
in the database, it "successfully" updates 0 rows. I would guess
that's what happened here. You should check cursor.rowcount after
running the update query to make sure it actually did something.
Cheers,
Ian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sqlite3 with context manager Tim Arnold <Tim.Arnold@sas.com> - 2011-09-02 14:43 -0400
Re: sqlite3 with context manager Ian Kelly <ian.g.kelly@gmail.com> - 2011-09-02 22:38 -0600
Re: sqlite3 with context manager Carl Banks <pavlovevidence@gmail.com> - 2011-09-03 00:03 -0700
Re: sqlite3 with context manager Tim Arnold <Tim.Arnold@sas.com> - 2011-09-06 13:18 -0400
csiph-web