SQLite Forum

How to implement a table working like a ring buffer
Login
ID 	| GroupID 	| Ack
1	| 100		| 0
2	| 200		| 1
3	| 200		| 0
4	| 300		| 0
5	| 300		| 0
6	| 200		| 0
7	| 200		| 0

I want to implement a table working like a ring buffer. If it grows to the max row count, i want delete the "oldest row" and then insert a new row.
A) ID grows from 1 to n

But there are some conditions which defines the "oldest row".
1) A row is not the "oldest row", if it is the last row of all rows with same GroupID.
2) A row is not the "oldest row", if its Ack is 1.
3) A row is the "oldest row", if 1) and 2) fits and if its ID is the lowest of all possible "oldest row" candidates which results from grouping by GroupId.
4) If delete is necessary delete only the "oldest row" (one).

In the upper sample table the "oldest row" is ID = 3 and will be deleted if necessary.

To achive this, i want to use a trigger (before insert) to do this 'deleting' automatically. The condition, when a delete has do be done, works.

I've tried to solve this problem by myself. But now i'm stucked.

Is there anyone who can give me hint?

Thx a lot for any help!
heribert