My python code produces a condition (such as Up, Down, Left, Right), the start time when that condition occurs, and at some point in the future an end time for that condition ending.
Presently, the code produces the following output in the database.
Current State
condition | start_time | end_time
Up | NULL | NULL
NULL | 44:03.1 | NULL
NULL | NULL | 44:05.2
Down | NULL | NULL
NULL | 44:05.2 | NULL
NULL | NULL | 44:20.4
Right | NULL | NULL
NULL | 44:20.4 | NULL
NULL | NULL |44:21.6
This is my current code for logging the first value, the condition direction:
c.execute('INSERT INTO conditionsAndTimesToPlot (condition_direction) VALUES (?)', (condition,))
conn.commit()
After some other stuff has to happen, the start_time is then recorded with:
c.execute('INSERT INTO conditionsAndTimesToPlot (start_time) VALUES (?)', (start_time_full,))
conn.commit()
Then after some arbitrary time that condition ends and the end time is recorded with:
c.execute('INSERT INTO conditionsAndTimesToPlot (end_time) VALUES (?)', (end_time_full,))
conn.commit()
What I Want To Achieve
condition | start_time | end_time
Up | 44:03.1 | 44:05.2
Down | 44:05.2 | 44:20.4
Right | 44:20.4 | 44:21.6
What I Tried
I tried using UPDATE for the time arguments. I thought that INSERT for the condition direction would insert a new line and UPDATE for the start and end times would then naturally backfill the 2nd and 3rd columns but now I get this error in the terminal:
sqlite3.OperationalError: near "INTO": syntax error
Questions
- Is there something obvious that I am missing here to make this happen?
- Should I create 3 tables (one for each value [condition, start_time, end_time] and then write code that combines the three tables by row into a single table for every cycle through my loop?
Thanks for your help on my first ever stackoverflow question,
David
INTOkeyword inUpdate. Please see the document forUpdatefirst.