31#ifndef MKCAL_SQLITEFORMAT_H
32#define MKCAL_SQLITEFORMAT_H
38#include <KCalendarCore/Incidence>
71 AllowEvents = (1 << 0),
72 AllowJournals = (1 << 1),
73 AllowTodos = (1 << 2),
76 Synchronized = (1 << 5),
79 RunTimeOnly = (1 << 8),
87 SqliteFormat(sqlite3 *database,
const QTimeZone &timeZone = {});
92 virtual ~SqliteFormat();
103 bool modifyCalendars(
const Notebook::Ptr ¬ebook, DBOperation dbop, sqlite3_stmt *stmt,
bool isDefault);
112 Notebook::Ptr selectCalendars(sqlite3_stmt *stmt,
bool *isDefault);
122 bool modifyComponents(
const KCalendarCore::Incidence::Ptr &incidence,
const QString ¬ebook,
125 bool purgeDeletedComponents(
const KCalendarCore::Incidence::Ptr &incidence);
134 KCalendarCore::Incidence::Ptr selectComponents(sqlite3_stmt *stmt1, QString ¬ebook);
143 bool selectMetadata(
int *
id);
144 bool incrementTransactionId(
int *
id);
196#define SL3_exec( db ) \
199 rv = sqlite3_exec( (db), query, NULL, 0, &errmsg ); \
201 if ( rv != SQLITE_CONSTRAINT ) { \
202 qCWarning(lcMkcal) << "sqlite3_exec error code:" << rv; \
205 if ( rv != SQLITE_CONSTRAINT ) { \
206 qCWarning(lcMkcal) << errmsg; \
208 sqlite3_free( errmsg ); \
211 if ( rv != SQLITE_CONSTRAINT ) { \
217#define SL3_prepare_v2( db, query, qsize, stmt, tail ) \
220 rv = sqlite3_prepare_v2( (db), (query), (qsize), (stmt), (tail) ); \
222 qCWarning(lcMkcal) << "sqlite3_prepare error code:" << rv; \
223 qCWarning(lcMkcal) << sqlite3_errmsg( (db) ); \
228#define SL3_bind_text( stmt, index, value, size, desc ) \
230 rv = sqlite3_bind_text( (stmt), (index), (value), (size), (desc) ); \
232 qCWarning(lcMkcal) << "sqlite3_bind_text error:" << rv << "on index and value:" << index << value; \
238#define SL3_bind_blob( stmt, index, value, size, desc ) \
240 rv = sqlite3_bind_blob( (stmt), (index), (value), (size), (desc) ); \
242 qCWarning(lcMkcal) << "sqlite3_bind_blob error:" << rv << "on index and value:" << index << value; \
248#define SL3_bind_int( stmt, index, value ) \
250 rv = sqlite3_bind_int( (stmt), (index), (value) ); \
252 qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
258#define SL3_bind_int64( stmt, index, value ) \
260 rv = sqlite3_bind_int64( (stmt), (index), (value) ); \
262 qCWarning(lcMkcal) << "sqlite3_bind_int64 error:" << rv << "on index and value:" << index << value; \
268#define SL3_bind_double( stmt, index, value ) \
270 rv = sqlite3_bind_double( (stmt), (index), (value) ); \
272 qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
278#define SL3_step( stmt ) \
280 rv = sqlite3_step( (stmt) ); \
281 if ( rv && rv != SQLITE_DONE && rv != SQLITE_ROW ) { \
282 if ( rv != SQLITE_CONSTRAINT ) { \
283 qCWarning(lcMkcal) << "sqlite3_step error:" << rv; \
289#define SL3_reset( stmt ) \
291 rv = sqlite3_reset( (stmt) ); \
292 if ( rv && rv != SQLITE_OK ) { \
293 qCWarning(lcMkcal) << "sqlite3_reset error:" << rv; \
298#define CREATE_METADATA \
299 "CREATE TABLE IF NOT EXISTS Metadata(transactionId INTEGER)"
300#define CREATE_TIMEZONES \
301 "CREATE TABLE IF NOT EXISTS Timezones(TzId INTEGER PRIMARY KEY, ICalData TEXT)"
302#define CREATE_CALENDARS \
303 "CREATE TABLE IF NOT EXISTS Calendars(CalendarId TEXT PRIMARY KEY, Name TEXT, Description TEXT, Color INTEGER, Flags INTEGER, syncDate INTEGER, pluginName TEXT, account TEXT, attachmentSize INTEGER, modifiedDate INTEGER, sharedWith TEXT, syncProfile TEXT, createdDate INTEGER, extra1 STRING, extra2 STRING)"
309#define CREATE_COMPONENTS \
310 "CREATE TABLE IF NOT EXISTS Components(ComponentId INTEGER PRIMARY KEY AUTOINCREMENT, Notebook TEXT, Type TEXT, Summary TEXT, Category TEXT, DateStart INTEGER, DateStartLocal INTEGER, StartTimeZone TEXT, HasDueDate INTEGER, DateEndDue INTEGER, DateEndDueLocal INTEGER, EndDueTimeZone TEXT, Duration INTEGER, Classification INTEGER, Location TEXT, Description TEXT, Status INTEGER, GeoLatitude REAL, GeoLongitude REAL, Priority INTEGER, Resources TEXT, DateCreated INTEGER, DateStamp INTEGER, DateLastModified INTEGER, Sequence INTEGER, Comments TEXT, Attachments TEXT, Contact TEXT, InvitationStatus INTEGER, RecurId INTEGER, RecurIdLocal INTEGER, RecurIdTimeZone TEXT, RelatedTo TEXT, URL TEXT, UID TEXT, Transparency INTEGER, LocalOnly INTEGER, Percent INTEGER, DateCompleted INTEGER, DateCompletedLocal INTEGER, CompletedTimeZone TEXT, DateDeleted INTEGER, extra1 STRING, extra2 STRING, extra3 INTEGER)"
315#define CREATE_RDATES \
316 "CREATE TABLE IF NOT EXISTS Rdates(ComponentId INTEGER, Type INTEGER, Date INTEGER, DateLocal INTEGER, TimeZone TEXT)"
317#define CREATE_CUSTOMPROPERTIES \
318 "CREATE TABLE IF NOT EXISTS Customproperties(ComponentId INTEGER, Name TEXT, Value TEXT, Parameters TEXT)"
319#define CREATE_RECURSIVE \
320 "CREATE TABLE IF NOT EXISTS Recursive(ComponentId INTEGER, RuleType INTEGER, Frequency INTEGER, Until INTEGER, UntilLocal INTEGER, untilTimeZone TEXT, Count INTEGER, Interval INTEGER, BySecond TEXT, ByMinute TEXT, ByHour TEXT, ByDay TEXT, ByDayPos Text, ByMonthDay TEXT, ByYearDay TEXT, ByWeekNum TEXT, ByMonth TEXT, BySetPos TEXT, WeekStart INTEGER)"
321#define CREATE_ALARM \
322 "CREATE TABLE IF NOT EXISTS Alarm(ComponentId INTEGER, Action INTEGER, Repeat INTEGER, Duration INTEGER, Offset INTEGER, Relation TEXT, DateTrigger INTEGER, DateTriggerLocal INTEGER, triggerTimeZone TEXT, Description TEXT, Attachment TEXT, Summary TEXT, Address TEXT, CustomProperties TEXT, isEnabled INTEGER)"
323#define CREATE_ATTENDEE \
324"CREATE TABLE IF NOT EXISTS Attendee(ComponentId INTEGER, Email TEXT, Name TEXT, IsOrganizer INTEGER, Role INTEGER, PartStat INTEGER, Rsvp INTEGER, DelegatedTo TEXT, DelegatedFrom TEXT)"
325#define CREATE_ATTACHMENTS \
326"CREATE TABLE IF NOT EXISTS Attachments(ComponentId INTEGER, Data BLOB, Uri TEXT, MimeType TEXT, ShowInLine INTEGER, Label TEXT, Local INTEGER)"
327#define CREATE_CALENDARPROPERTIES \
328 "CREATE TABLE IF NOT EXISTS Calendarproperties(CalendarId REFERENCES Calendars(CalendarId) ON DELETE CASCADE, Name TEXT NOT NULL, Value TEXT, UNIQUE (CalendarId, Name))"
330#define INDEX_CALENDAR \
331"CREATE INDEX IF NOT EXISTS IDX_CALENDAR on Calendars(CalendarId)"
332#define INDEX_COMPONENT \
333"CREATE INDEX IF NOT EXISTS IDX_COMPONENT on Components(ComponentId, Notebook, DateStart, DateEndDue, DateDeleted)"
334#define INDEX_COMPONENT_UID \
335"CREATE UNIQUE INDEX IF NOT EXISTS IDX_COMPONENT_UID on Components(UID, RecurId, DateDeleted)"
336#define INDEX_COMPONENT_NOTEBOOK \
337"CREATE INDEX IF NOT EXISTS IDX_COMPONENT_NOTEBOOK on Components(Notebook)"
338#define INDEX_RDATES \
339"CREATE INDEX IF NOT EXISTS IDX_RDATES on Rdates(ComponentId)"
340#define INDEX_CUSTOMPROPERTIES \
341"CREATE INDEX IF NOT EXISTS IDX_CUSTOMPROPERTIES on Customproperties(ComponentId)"
342#define INDEX_RECURSIVE \
343"CREATE INDEX IF NOT EXISTS IDX_RECURSIVE on Recursive(ComponentId)"
345"CREATE INDEX IF NOT EXISTS IDX_ALARM on Alarm(ComponentId)"
346#define INDEX_ATTENDEE \
347"CREATE UNIQUE INDEX IF NOT EXISTS IDX_ATTENDEE on Attendee(ComponentId, Email)"
348#define INDEX_ATTACHMENTS \
349"CREATE INDEX IF NOT EXISTS IDX_ATTACHMENTS on Attachments(ComponentId)"
350#define INDEX_CALENDARPROPERTIES \
351"CREATE INDEX IF NOT EXISTS IDX_CALENDARPROPERTIES on Calendarproperties(CalendarId)"
353#define INSERT_TIMEZONES \
354"insert into Timezones values (1, '')"
355#define INSERT_CALENDARS \
356"insert into Calendars values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', '')"
357#define INSERT_COMPONENTS \
358"insert into Components values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, '', 0)"
359#define INSERT_CUSTOMPROPERTIES \
360"insert into Customproperties values (?, ?, ?, ?)"
361#define INSERT_CALENDARPROPERTIES \
362"insert into Calendarproperties values (?, ?, ?)"
363#define INSERT_RDATES \
364"insert into Rdates values (?, ?, ?, ?, ?)"
365#define INSERT_RECURSIVE \
366"insert into Recursive values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
367#define INSERT_ALARM \
368"insert into Alarm values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
369#define INSERT_ATTENDEE \
370"insert into Attendee values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
371#define INSERT_ATTACHMENTS \
372"insert into Attachments values (?, ?, ?, ?, ?, ?, ?)"
374#define UPDATE_METADATA \
375"replace into Metadata (rowid, transactionId) values (1, ?)"
376#define UPDATE_TIMEZONES \
377"update Timezones set ICalData=? where TzId=1"
378#define UPDATE_CALENDARS \
379"update Calendars set Name=?, Description=?, Color=?, Flags=?, syncDate=?, pluginName=?, account=?, attachmentSize=?, modifiedDate=?, sharedWith=?, syncProfile=?, createdDate=? where CalendarId=?"
380#define UPDATE_COMPONENTS \
381"update Components set Notebook=?, Type=?, Summary=?, Category=?, DateStart=?, DateStartLocal=?, StartTimeZone=?, HasDueDate=?, DateEndDue=?, DateEndDueLocal=?, EndDueTimeZone=?, Duration=?, Classification=?, Location=?, Description=?, Status=?, GeoLatitude=?, GeoLongitude=?, Priority=?, Resources=?, DateCreated=?, DateStamp=?, DateLastModified=?, Sequence=?, Comments=?, Attachments=?, Contact=?, RecurId=?, RecurIdLocal=?, RecurIdTimeZone=?, RelatedTo=?, URL=?, UID=?, Transparency=?, LocalOnly=?, Percent=?, DateCompleted=?, DateCompletedLocal=?, CompletedTimeZone=?, extra1=? where ComponentId=?"
382#define UPDATE_COMPONENTS_AS_DELETED \
383"update Components set DateDeleted=? where ComponentId=?"
386#define DELETE_CALENDARS \
387"delete from Calendars where CalendarId=?"
388#define DELETE_COMPONENTS \
389"delete from Components where ComponentId=?"
390#define DELETE_RDATES \
391"delete from Rdates where ComponentId=?"
392#define DELETE_CUSTOMPROPERTIES \
393"delete from Customproperties where ComponentId=?"
394#define DELETE_CALENDARPROPERTIES \
395"delete from Calendarproperties where CalendarId=?"
396#define DELETE_RECURSIVE \
397"delete from Recursive where ComponentId=?"
398#define DELETE_ALARM \
399"delete from Alarm where ComponentId=?"
400#define DELETE_ATTENDEE \
401"delete from Attendee where ComponentId=?"
402#define DELETE_ATTACHMENTS \
403"delete from Attachments where ComponentId=?"
405#define SELECT_METADATA \
406"select * from Metadata where rowid=1"
407#define SELECT_TIMEZONES \
408"select * from Timezones where TzId=1"
409#define SELECT_CALENDARS_ALL \
410"select * from Calendars order by Name"
411#define SELECT_COMPONENTS_ALL \
412"select * from Components where DateDeleted=0"
413#define SELECT_COMPONENTS_BY_NOTEBOOK \
414"select * from Components where Notebook=? and DateDeleted=0"
415#define SELECT_COMPONENTS_ALL_DELETED \
416"select * from Components where DateDeleted<>0"
417#define SELECT_COMPONENTS_ALL_DELETED_BY_NOTEBOOK \
418"select * from Components where Notebook=? and DateDeleted<>0"
419#define SELECT_COMPONENTS_BY_GEO \
420"select * from Components where GeoLatitude!=255.0 and GeoLongitude!=255.0 and DateDeleted=0"
421#define SELECT_COMPONENTS_BY_GEO_AREA \
422"select * from Components where GeoLatitude>=? and GeoLongitude>=? and GeoLatitude<=? and GeoLongitude<=? and DateDeleted=0"
423#define SELECT_COMPONENTS_BY_JOURNAL \
424"select * from Components where Type='Journal' and DateDeleted=0"
425#define SELECT_COMPONENTS_BY_JOURNAL_DATE \
426"select * from Components where Type='Journal' and DateDeleted=0 and datestart<=? order by DateStart desc, DateCreated desc"
427#define SELECT_COMPONENTS_BY_PLAIN \
428"select * from Components where DateStart=0 and DateEndDue=0 and DateDeleted=0"
429#define SELECT_COMPONENTS_BY_RECURSIVE \
430"select * from Components where ((ComponentId in (select DISTINCT ComponentId from Recursive)) or (ComponentId in (select DISTINCT ComponentId from Rdates)) or (RecurId!=0)) and DateDeleted=0"
431#define SELECT_COMPONENTS_BY_ATTENDEE \
432"select * from Components where ComponentId in (select DISTINCT ComponentId from Attendee) and DateDeleted=0"
433#define SELECT_COMPONENTS_BY_DATE_BOTH \
434"select * from Components where DateStart<? and (DateEndDue>=? or (DateEndDue=0 and DateStart>=?)) and DateDeleted=0"
435#define SELECT_COMPONENTS_BY_DATE_START \
436"select * from Components where (DateEndDue>=? or (DateEndDue=0 and DateStart>=?)) and DateDeleted=0"
437#define SELECT_COMPONENTS_BY_DATE_END \
438"select * from Components where DateStart<? and DateDeleted=0"
439#define SELECT_COMPONENTS_BY_UID_AND_RECURID \
440"select * from Components where UID=? and RecurId=? and DateDeleted=0"
441#define SELECT_COMPONENTS_BY_UID \
442"select * from Components where UID=? and DateDeleted=0"
443#define SELECT_COMPONENTS_BY_NOTEBOOKUID \
444"select * from Components where Notebook=? and DateDeleted=0"
445#define SELECT_ROWID_FROM_COMPONENTS_BY_UID_AND_RECURID \
446"select ComponentId from Components where UID=? and RecurId=? and DateDeleted=0"
447#define SELECT_COMPONENTS_BY_UNCOMPLETED_TODOS \
448"select * from Components where Type='Todo' and DateCompleted=0 and DateDeleted=0"
449#define SELECT_COMPONENTS_BY_COMPLETED_TODOS_AND_DATE \
450"select * from Components where Type='Todo' and DateCompleted<>0 and DateEndDue<>0 and DateEndDue<=? and DateDeleted=0 order by DateEndDue desc, DateCreated desc"
451#define SELECT_COMPONENTS_BY_COMPLETED_TODOS_AND_CREATED \
452"select * from Components where Type='Todo' and DateCompleted<>0 and DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
453#define SELECT_COMPONENTS_BY_DATE_SMART \
454"select * from Components where DateEndDue<>0 and DateEndDue<=? and DateDeleted=0 order by DateEndDue desc, DateCreated desc"
456#define FUTURE_DATE_SMART_FIELD \
457" (case type when 'Todo' then DateEndDue else DateStart end) "
458#define SELECT_COMPONENTS_BY_FUTURE_DATE_SMART \
459 "select * from Components where " \
460 FUTURE_DATE_SMART_FIELD ">=? and DateDeleted=0 order by " \
461 FUTURE_DATE_SMART_FIELD " asc, DateCreated asc"
463#define SELECT_COMPONENTS_BY_CREATED_SMART \
464"select * from Components where DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
465#define SELECT_COMPONENTS_BY_GEO_AND_DATE \
466"select * from Components where GeoLatitude!=255.0 and GeoLongitude!=255.0 and DateEndDue<>0 and DateEndDue<=? and DateDeleted=0 order by DateEndDue desc, DateCreated desc"
467#define SELECT_COMPONENTS_BY_GEO_AND_CREATED \
468"select * from Components where GeoLatitude!=255.0 and GeoLongitude!=255.0 and DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
469#define SELECT_COMPONENTS_BY_ATTENDEE_EMAIL_AND_CREATED \
470"select * from Components where ComponentId in (select distinct ComponentId from Attendee where email=?) and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
471#define SELECT_COMPONENTS_BY_ATTENDEE_AND_CREATED \
472"select * from Components where ComponentId in (select distinct ComponentId from Attendee) and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
473#define SELECT_RDATES_BY_ID \
474"select * from Rdates where ComponentId=?"
475#define SELECT_CUSTOMPROPERTIES_BY_ID \
476"select * from Customproperties where ComponentId=?"
477#define SELECT_RECURSIVE_BY_ID \
478"select * from Recursive where ComponentId=?"
479#define SELECT_ALARM_BY_ID \
480"select * from Alarm where ComponentId=?"
481#define SELECT_ATTENDEE_BY_ID \
482"select * from Attendee where ComponentId=?"
483#define SELECT_ATTACHMENTS_BY_ID \
484"select * from Attachments where ComponentId=?"
485#define SELECT_CALENDARPROPERTIES_BY_ID \
486"select * from Calendarproperties where CalendarId=?"
487#define SELECT_COMPONENTS_BY_DUPLICATE \
488"select * from Components where DateStart=? and Summary=? and DateDeleted=0"
489#define SELECT_COMPONENTS_BY_DUPLICATE_AND_NOTEBOOK \
490"select * from Components where DateStart=? and Summary=? and Notebook=? and DateDeleted=0"
491#define SELECT_COMPONENTS_BY_CREATED \
492"select * from Components where DateCreated>=? and DateDeleted=0"
493#define SELECT_COMPONENTS_BY_CREATED_AND_NOTEBOOK \
494"select * from Components where DateCreated>=? and Notebook=? and DateDeleted=0"
495#define SELECT_COMPONENTS_BY_LAST_MODIFIED \
496"select * from Components where DateLastModified>=? and DateCreated<? and DateDeleted=0"
497#define SELECT_COMPONENTS_BY_LAST_MODIFIED_AND_NOTEBOOK \
498"select * from Components where DateLastModified>=? and DateCreated<? and Notebook=? and DateDeleted=0"
499#define SELECT_COMPONENTS_BY_DELETED \
500"select * from Components where DateDeleted>=? and DateCreated<?"
501#define SELECT_COMPONENTS_BY_DELETED_AND_NOTEBOOK \
502"select * from Components where DateDeleted>=? and DateCreated<? and Notebook=?"
503#define SELECT_COMPONENTS_BY_UID_RECID_AND_DELETED \
504"select ComponentId, DateDeleted from Components where UID=? and RecurId=? and DateDeleted<>0"
505#define SELECT_ATTENDEE_AND_COUNT \
506"select Email, Name, count(Email) from Attendee where Email<>0 group by Email"
507#define SELECT_EVENT_COUNT \
508"select count(*) from Components where Type='Event' and DateDeleted=0"
509#define SELECT_TODO_COUNT \
510"select count(*) from Components where Type='Todo' and DateDeleted=0"
511#define SELECT_JOURNAL_COUNT \
512"select count(*) from Components where Type='Journal' and DateDeleted=0"
514#define UNSET_FLAG_FROM_CALENDAR \
515"update Calendars set Flags=(Flags & (~?))"
517#define BEGIN_TRANSACTION \
519#define COMMIT_TRANSACTION \
This file is part of the API for handling calendar data and defines the ExtendedStorage interface.
#define MKCAL_EXPORT
Definition mkcal_export.h:27
#define MKCAL_HIDE
Definition mkcal_export.h:31
Definition extendedstorage.h:49
This file is part of the API for handling calendar data and defines the Notebook class.