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?

1
  • Solved it - but why do you have to commit on Inserts? DDL Statements just work -.- Commented Dec 13, 2017 at 13:16

1 Answer 1

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:

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

Comments

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.