SQLite3 select previous row to do some math

by: MertensToon, 8 years ago


Hi,

I'm trying to find out how I can select data from the previous row.
I'm storing GPS data into my database. When I'm reading the data into the database I want to select the previous row and then use this data to calculate the distance between previous point and real point.
for the calculation I will use the Haversin Algoritme.

So this is what I tryed to select the previous row.


                                print (gpsTime)
                                print (gpsLat)
                                print (gpsLon)
                                print (drivingTime)
                               drivenTime = int(drivingTime)-1
                                print (drivenTime)

                                if drivingTime > 0:
                                        previousLon = c.execute('SELECT longitude FROM readings where id=?')
                                        result = cursor.execute(previousLon, (drivenTime,))
                                        print (result)

So the result of this is the following: I get the first 2 datapoints but after  the following error.

2016-08-20T06:53:56.000Z
50.991696667
4.282545
0
-1
2016-08-20T06:53:57.000Z
50.991696667
4.282545
1
0
Traceback (most recent call last):
  File "GPSCoordinatesToMeters.py", line 60, in <module>
    previousLon = c.execute('SELECT longitude FROM readings where id=?')
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.


Any Idea what the problem is here?

Kind regards Toon



You must be logged in to post. Please login or register an account.



The problem is that you have to give something in id. Thats error saying
[c.execute('SELECT longitude FROM readings where id=?',(id))]

-alexdotis 8 years ago
Last edited 8 years ago

You must be logged in to post. Please login or register an account.