0

I am working on a project in which I am using python to store sensor data in a SQLite Database.

If the table does not exists it will be created like this:

query_db('create table if not exists %s (id INTEGER PRIMARY KEY AUTOINCREMENT, value double, datetimestamp DATETIME, user CHAR(2));' % (sensor_name+'_VALUES'))

Next I want to insert the values from a HTTP Post Request:

  sensor_value = request.json['value']
        dtstamp = request.json['timestamp']
        user_name = request.json['user']
        result = query_db('INSERT INTO %s  ("value", "datetimestamp", "user") VALUES ( "%s" ,"%s" , "%s");' % (sensor_name + '_VALUES', sensor_value, dtstamp, user_name))

But I don't get an error and it also seems like the insert is not executed. The request looks like this:

{
    "value" : 22,
    "timestamp" : "2017-02-17 22:22:22",
    "user" : "TE"
} 

Anyone know why?

Curunir
  • 1,020
  • 1
  • 11
  • 25

1 Answers1

1

You need to commit the transaction to persist the changes in the database:

db.commit()

Here is some additional information about why and when do you need to commit:

alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148