0

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.

2
  • so what is the problem? Commented Dec 23, 2015 at 14:49
  • Missing commit: con.commit()?.. Commented Dec 23, 2015 at 14:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

The documentation mentions this explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.