Python and sqlite3 simplest example not working

I'm trying to execute this simple python script but it seems to do nothing: I don't get any error, I try to execute the query directly on sqlite3 and it works....I don't have any idea why isn't working, can anyone help me?

import sqlite3 as lite
import sys

con = None

try:
    con = lite.connect('/home/pi/Moranberries/web/moranberries.db')

    cur = con.cursor()    
    cur.execute("INSERT INTO sensor_interior (temperatura,humedad) VALUES (111,222)")

except lite.Error, e:

    print "Error %s:" % e.args[0]
    sys.exit(1)

finally:

    if con:
        con.close()

To execute this script I named it prueba.py an call it from terminal as this:

python prueba.py

There is no error message.

Upvotes: 0

Views: 65

Answers (1)

Paolo Celati
Paolo Celati

Reputation: 312

You're not committing your changes to the DB. If you call con.commit() after cur.execute, it should write the changes.

Upvotes: 1

Related Questions