|
|
 |
 |
 |
 |
Python Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
updates in sqlite3 do not work
Chris Fonnesbeck wrote: > I have a script set up to perform UPDATE commands on an sqlite database > using the sqlite3 module. Everything appears to run fine (there are no > error messages), except that none of the UPDATE commands appear to have > actually updated the table. If I run each command on its own in a sqlite > session, the UPDATE command works fine, so it is not a SQL syntax issue. > UPDATE simply seems not to work. Any idea what the problem might be?
You need to explicitly commit the transaction e.g.: import sqlite3.dbapi2 as sqlite con = sqlite.connect("temp.db") cur = con.cursor() cur.execute("create table test (id INTEGER, name CHAR)") cur.execute("insert into test values (1, 'bob')") con.commit() HTH Paul -- pkm ~ http://paulmcnett.com
Did you try a commit() ? SQLite3 works in autocommit mode by default, so it would help to see your code. On Mi, 30.05.2007, 00:30, Chris Fonnesbeck wrote:
> I have a script set up to perform UPDATE commands on an sqlite database > using the sqlite3 module. Everything appears to run fine (there are no > error > messages), except that none of the UPDATE commands appear to have actually > updated the table. If I run each command on its own in a sqlite session, > the > UPDATE command works fine, so it is not a SQL syntax issue. UPDATE simply > seems not to work. Any idea what the problem might be? > Thanks, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list
On 5/29/07, Stefan Sonnenberg-Carstens
<stefan.sonnenb @pythonmeister.com> wrote: > Did you try a commit() ? > SQLite3 works in autocommit mode by default, > so it would help to see your code. > On Mi, 30.05.2007, 00:30, Chris Fonnesbeck wrote: > > I have a script set up to perform UPDATE commands on an sqlite database > > using the sqlite3 module. Everything appears to run fine (there are no > > error > > messages), except that none of the UPDATE commands appear to have actually > > updated the table. If I run each command on its own in a sqlite session, > > the > > UPDATE command works fine, so it is not a SQL syntax issue. UPDATE simply > > seems not to work. Any idea what the problem might be? > > Thanks, > > Chris > > -- > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list
As the other people said, you need to issue db.commit() (or whatever you're database variable is). I just ran into this after converting a MyISAM table to InnoDB, and was annoyed as crap for a while, until I found out that you need to explicitly commit on InnoDB tables, then I felt stupid. I was using MySQLdb, not sqlite3, but I'm sure it's got right around the same functionality.
On May 30, 8:43 am, "Stefan Sonnenberg-Carstens" <stefan.sonnenb @pythonmeister.com> wrote: > Did you try a commit() ? > SQLite3 works in autocommit mode by default,
Errrrmmmm .... IF it worked in auto-commit mode, then the OP wouldn't need to use Connection.commit(-:) The underlying SLQite3 may work in auto-commit mode, but the Python interface should not. See PEP 249 : """Note that if the database supports an auto-commit feature, this must be initially off.""" Consequently the user of any/every DPAPIv2.0-compliant package should be calling commit. HTH, John
|
 |
 |
 |
 |
|