Android Question Write to SQL Lite database but limit and replace rows

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

Just wondering if anyone knows a way to only write a xx amount of items to a table in a SQL Lite database before overwriting the old rows.

For Example:
I want to write, lets say 5 rows to a table and when the 5 rows are entered in I want to start replacing the old ones.

So, lets say I add if I add
row 1 = Bob
row 2 = John
row 3 = Bill
row 4 = Harry
row 5 = Tom

Now when I add a item I want to delete Bob and add my new item to the end. So it will become:
row 1 = John
row 2 = Bill
row 3 = Harry
row 4 = Tom
row 5 = Tony

I am trying to store each in the SQL Lite database so that if you close the app and re-open it again the data is still there.

I can't seem to work out how to do this.. Anyone able to help ?
 

LucaMs

Expert
Licensed User
Longtime User
You should not give much importance to RowId.

To read the data in a certain order, you can use an index.
In this case, for example, you could add the date of registration and re-read the data in ascending order of date.

Otherwise, you could delete the first record and add a new record.
B4X:
Query = "DELETE FROM YourTable WHERE rowid = (SELECT MIN(rowid) FROM YourTable)"

... INSERT...
 
Upvote 0
Top