updates in sqlite3 do not work

Paul McNett p at ulmcnett.com
Tue May 29 18:42:49 EDT 2007


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



More information about the Python-list mailing list