I assume that you want to determine if one recently inserted (or updated) event overlaps ( doesn’t it , does any of the events already exist in the database)?
If so, you can procedurally (in your client language) generate all the start and end intervals [s, e] based on the newly inserted "repeat Type" event, and then run the following query for each of these intervals to detect overlap (I use Oracle syntax is here, I assume SQLite is similar):
-- A time interval must be either completely "to the left" or completely -- "to the right" of the other time interval for them not to overlap. SELECT * FROM EVENT WHERE NOT( (:s < DTSTART AND :s < DTEND AND :e < DTSTART AND :e < DTEND) OR (:s > DTSTART AND :s > DTEND AND :e > DTSTART AND :e > DTEND) )
Do not expect stellar performance (especially if your event has a large number of repetitions or DTSTART / DTEND is not indexed, or SQLite cannot correctly use this index).
For performance, you will probably be better off caching all events in memory and doing all the processing on the client side, which will allow you to more easily use the heuristic to “short circuit” some processing. For instance:
- If two events have the same “repeat type”, you can simply compare their start intervals without worrying about repetitions - if they do not match, they will never match.
- If one event "last occurrence" is in front of another, even "dtstart", they will never be able to match regardless of "repeat Type".
- Etc ...
If you really want all your processing to be on the database side and which you want (query), you are probably looking at some kind of geospatial / multidimensional indexing, and you will need to actually keep the repetitions of events in the database so that they could be indexed, which would probably ruin the performance of your insert. I am not familiar with SQLite and does it support this type of indexing ...
source share