Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python sqlite3 update not updating

Tags:

python

sqlite

Question: Why is this sqlite3 statement not updating the record?


Info:

cur.execute('UPDATE workunits SET Completed=1 AND Returns=(?) WHERE PID=(?) AND Args=(?)',(pickle.dumps(Ret),PID,Args))

I'm using python and sqlite3. this statement does not throw an error, it just seems like it is out right ignored. for testing reasons I included below it:

cur.execute('SELECT * FROM workunits WHERE PID=(?) AND Args=(?)',(PID,Args))

Which returns a record just fine. but the record doesn't up date with the new value of the pickled ret. it remains u''. I can't figure out why. my where statement seems to work. my syntax seems to be correct because there is no error being thrown. I'm clueless as to why exactly it doesn't work.

like image 245
Narcolapser Avatar asked Jan 30 '11 02:01

Narcolapser


2 Answers

If the problem persists after you fixed your syntax. Please make sure you're using:

conn.commit()

After cur.execute, UPDATES and INSERTS require COMMIT.

like image 176
Ariel Monaco Avatar answered Oct 22 '22 04:10

Ariel Monaco


don't use 'AND', use a ','.

cur.execute('UPDATE workunits SET Completed=1, Returns=? WHERE PID=? AND Args=?',
    (pickle.dumps(Ret), PID, Args)
)
like image 41
Harmen Avatar answered Oct 22 '22 05:10

Harmen