E
E
Eldar Musin2016-09-01 08:01:12
SQL
Eldar Musin, 2016-09-01 08:01:12

How to get the id of the last record in SQLite from another session?

I am implementing for myself a project of a home energy meter with the subsequent display of consumption for m-years. (maybe for n-years, let's see how many resources will last).
Electronics based on Arduino reads the readings of 20 sensors and, when ready, transmits the data to the server.
The server in the form of a small GL-AR150 router, running OpenWRT, has lighttpd, php5 and SQLite3 on board. Arduino runs the data update script.
The algorithm is quite simple:

  • Checking the date-time at which the data was received
  • If there is already a date stamp for the minute mm in the database, then we add to the current values ​​​​and make an increment of the division coefficient. If there is no date stamp, then we make a new record with the minute mm + 1
  • We update the data in the data stamp for a minute mm, by averaging using the coefficient

Perhaps for a server that will work almost without load, you can not puff on the code, but "cook" something. But the soul asks for an elegant solution.
Actually the question is, in the previous session, the database received its new record in the form of a new line or an update of the old one. How to determine the ID of the last record in a new session if it has the value AUTOINCREMENT.
last_insert_rowid() - returns 0 in a new database connection, or I misunderstood it max
(id) - works, but primly
select asc limit 1 - worse than max(id)
ideas.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question