Reputation: 4562
I am working with android and SQLITE Database. There I have to Limit the maximum number of records as 10 in one table. That table has a column(dateReg)
to insert the date and time when the record is inserted. I am inserting records in to that column in the following format.(dd/MM/yy HH:mm:ss)
I am trying to find the oldest record by the date and to update that record if the row count is 10.
Like to know whether there is a way to select the oldest day by a SQL query, to update that record if the total number of records are 10 in that table.
Thank you very much and Any guidance is highly appreciated. Thanks...!
Upvotes: 0
Views: 448
Reputation: 821
You should store dates in SQLite using columns with INTEGER datatype. To store them, use the Date
or Calendar
classes in Java to convert your date to Unix Format, and then simply order by this column. It's easier.
Upvotes: 4
Reputation: 39405
There is a simplest way if you cannot change your database schema :
there is an id (_id, usually) which is autoincrement. the min(_id) is the oldest row, you can delete it and insert a new row.
Upvotes: 2