27#ifndef MKCAL_SQLITEFORMAT_H
28#define MKCAL_SQLITEFORMAT_H
34#include <KCalendarCore/Incidence>
97 bool modifyCalendars(
const Notebook ¬ebook,
DBOperation dbop, sqlite3_stmt *stmt,
bool isDefault);
106 Notebook::Ptr selectCalendars(sqlite3_stmt *stmt,
bool *isDefault);
116 bool modifyComponents(
const KCalendarCore::Incidence &incidence,
const QString ¬ebook,
119 bool purgeDeletedComponents(
const KCalendarCore::Incidence &incidence,
120 const QString ¬ebook = QString());
129 KCalendarCore::Incidence::Ptr selectComponents(sqlite3_stmt *stmt1, QString ¬ebook);
131 bool selectMetadata(
int *
id);
132 bool incrementTransactionId(
int *
id);
172 static QDateTime
fromOriginTime(sqlite3_int64 seconds,
const QByteArray &zonename);
184#define SL3_try_exec( db ) \
187 rv = sqlite3_exec( (db), query, NULL, 0, &errmsg ); \
189 qCWarning(lcMkcal) << "sqlite3_exec error code:" << rv; \
191 qCWarning(lcMkcal) << errmsg; \
192 sqlite3_free( errmsg ); \
198#define SL3_exec( db ) \
200 SL3_try_exec( (db) ); \
201 if ( rv && rv != SQLITE_CONSTRAINT ) { \
206#define SL3_prepare_v2( db, query, qsize, stmt, tail ) \
209 rv = sqlite3_prepare_v2( (db), (query), (qsize), (stmt), (tail) ); \
211 qCWarning(lcMkcal) << "sqlite3_prepare error code:" << rv; \
212 qCWarning(lcMkcal) << sqlite3_errmsg( (db) ); \
217#define SL3_bind_text( stmt, index, value, size, desc ) \
219 rv = sqlite3_bind_text( (stmt), (index), (value), (size), (desc) ); \
221 qCWarning(lcMkcal) << "sqlite3_bind_text error:" << rv << "on index and value:" << index << value; \
227#define SL3_bind_blob( stmt, index, value, size, desc ) \
229 rv = sqlite3_bind_blob( (stmt), (index), (value), (size), (desc) ); \
231 qCWarning(lcMkcal) << "sqlite3_bind_blob error:" << rv << "on index and value:" << index << value; \
237#define SL3_bind_int( stmt, index, value ) \
239 rv = sqlite3_bind_int( (stmt), (index), (value) ); \
241 qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
247#define SL3_bind_int64( stmt, index, value ) \
249 rv = sqlite3_bind_int64( (stmt), (index), (value) ); \
251 qCWarning(lcMkcal) << "sqlite3_bind_int64 error:" << rv << "on index and value:" << index << value; \
257#define SL3_bind_double( stmt, index, value ) \
259 rv = sqlite3_bind_double( (stmt), (index), (value) ); \
261 qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
267#define SL3_step( stmt ) \
269 rv = sqlite3_step( (stmt) ); \
270 if ( rv && rv != SQLITE_DONE && rv != SQLITE_ROW ) { \
271 if ( rv != SQLITE_CONSTRAINT ) { \
272 qCWarning(lcMkcal) << "sqlite3_step error:" << rv; \
278#define SL3_reset( stmt ) \
280 rv = sqlite3_reset( (stmt) ); \
281 if ( rv && rv != SQLITE_OK ) { \
282 qCWarning(lcMkcal) << "sqlite3_reset error:" << rv; \
287#define CREATE_METADATA \
288 "CREATE TABLE IF NOT EXISTS Metadata(transactionId INTEGER)"
289#define CREATE_CALENDARS \
290 "CREATE TABLE IF NOT EXISTS Calendars(CalendarId TEXT PRIMARY KEY, Name TEXT, Description TEXT, Color INTEGER, " \
291 "Flags INTEGER, syncDate INTEGER, pluginName TEXT, account TEXT, attachmentSize INTEGER, modifiedDate INTEGER, " \
292 "sharedWith TEXT, syncProfile TEXT, createdDate INTEGER, extra1 STRING, extra2 STRING)"
298#define CREATE_COMPONENTS \
299 "CREATE TABLE IF NOT EXISTS Components(ComponentId INTEGER PRIMARY KEY AUTOINCREMENT, Notebook TEXT, Type TEXT, " \
300 "Summary TEXT, Category TEXT, DateStart INTEGER, DateStartLocal INTEGER, StartTimeZone TEXT, HasDueDate INTEGER, " \
301 "DateEndDue INTEGER, DateEndDueLocal INTEGER, EndDueTimeZone TEXT, Duration INTEGER, Classification INTEGER, " \
302 "Location TEXT, Description TEXT, Status INTEGER, GeoLatitude REAL, GeoLongitude REAL, Priority INTEGER, " \
303 "Resources TEXT, DateCreated INTEGER, DateStamp INTEGER, DateLastModified INTEGER, Sequence INTEGER, Comments TEXT, " \
304 "Attachments TEXT, Contact TEXT, InvitationStatus INTEGER, RecurId INTEGER, RecurIdLocal INTEGER, " \
305 "RecurIdTimeZone TEXT, RelatedTo TEXT, URL TEXT, UID TEXT, Transparency INTEGER, LocalOnly INTEGER, Percent INTEGER, " \
306 "DateCompleted INTEGER, DateCompletedLocal INTEGER, CompletedTimeZone TEXT, DateDeleted INTEGER, " \
307 "extra1 STRING, extra2 STRING, extra3 INTEGER, thisAndFuture INTEGER)"
312#define CREATE_RDATES \
313 "CREATE TABLE IF NOT EXISTS Rdates(ComponentId INTEGER, Type INTEGER, Date INTEGER, DateLocal INTEGER, TimeZone TEXT)"
314#define CREATE_CUSTOMPROPERTIES \
315 "CREATE TABLE IF NOT EXISTS Customproperties(ComponentId INTEGER, Name TEXT, Value TEXT, Parameters TEXT)"
316#define CREATE_RECURSIVE \
317 "CREATE TABLE IF NOT EXISTS Recursive(ComponentId INTEGER, RuleType INTEGER, Frequency INTEGER, Until INTEGER, " \
318 "UntilLocal INTEGER, untilTimeZone TEXT, Count INTEGER, Interval INTEGER, BySecond TEXT, ByMinute TEXT, " \
319 "ByHour TEXT, ByDay TEXT, ByDayPos Text, ByMonthDay TEXT, ByYearDay TEXT, ByWeekNum TEXT, ByMonth TEXT, " \
320 "BySetPos TEXT, WeekStart INTEGER)"
321#define CREATE_ALARM \
322 "CREATE TABLE IF NOT EXISTS Alarm(ComponentId INTEGER, Action INTEGER, Repeat INTEGER, Duration INTEGER, " \
323 "Offset INTEGER, Relation TEXT, DateTrigger INTEGER, DateTriggerLocal INTEGER, triggerTimeZone TEXT, " \
324 "Description TEXT, Attachment TEXT, Summary TEXT, Address TEXT, CustomProperties TEXT, isEnabled INTEGER)"
325#define CREATE_ATTENDEE \
326"CREATE TABLE IF NOT EXISTS Attendee(ComponentId INTEGER, Email TEXT, Name TEXT, IsOrganizer INTEGER, Role INTEGER, " \
327 "PartStat INTEGER, Rsvp INTEGER, DelegatedTo TEXT, DelegatedFrom TEXT)"
328#define CREATE_ATTACHMENTS \
329"CREATE TABLE IF NOT EXISTS Attachments(ComponentId INTEGER, Data BLOB, Uri TEXT, MimeType TEXT, " \
330 "ShowInLine INTEGER, Label TEXT, Local INTEGER)"
331#define CREATE_CALENDARPROPERTIES \
332 "CREATE TABLE IF NOT EXISTS Calendarproperties(CalendarId REFERENCES Calendars(CalendarId) " \
333 "ON DELETE CASCADE, Name TEXT NOT NULL, Value TEXT, UNIQUE (CalendarId, Name))"
335#define INDEX_CALENDAR \
336"CREATE INDEX IF NOT EXISTS IDX_CALENDAR on Calendars(CalendarId)"
337#define INDEX_COMPONENT \
338"CREATE INDEX IF NOT EXISTS IDX_COMPONENT on Components(ComponentId, Notebook, DateStart, DateEndDue, DateDeleted)"
339#define INDEX_COMPONENT_UID \
340"CREATE UNIQUE INDEX IF NOT EXISTS IDX_COMPONENT_UID on Components(UID, RecurId, DateDeleted)"
341#define INDEX_COMPONENT_NOTEBOOK \
342"CREATE INDEX IF NOT EXISTS IDX_COMPONENT_NOTEBOOK on Components(Notebook)"
343#define INDEX_RDATES \
344"CREATE INDEX IF NOT EXISTS IDX_RDATES on Rdates(ComponentId)"
345#define INDEX_CUSTOMPROPERTIES \
346"CREATE INDEX IF NOT EXISTS IDX_CUSTOMPROPERTIES on Customproperties(ComponentId)"
347#define INDEX_RECURSIVE \
348"CREATE INDEX IF NOT EXISTS IDX_RECURSIVE on Recursive(ComponentId)"
350"CREATE INDEX IF NOT EXISTS IDX_ALARM on Alarm(ComponentId)"
351#define INDEX_ATTENDEE \
352"CREATE INDEX IF NOT EXISTS IDX_ATTENDEE on Attendee(ComponentId)"
353#define INDEX_ATTACHMENTS \
354"CREATE INDEX IF NOT EXISTS IDX_ATTACHMENTS on Attachments(ComponentId)"
355#define INDEX_CALENDARPROPERTIES \
356"CREATE INDEX IF NOT EXISTS IDX_CALENDARPROPERTIES on Calendarproperties(CalendarId)"
358#define INSERT_CALENDARS \
359"insert into Calendars values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', '')"
360#define INSERT_COMPONENTS \
361"insert into Components values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " \
362 "?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, '', 0, ?)"
363#define INSERT_CUSTOMPROPERTIES \
364"insert into Customproperties values (?, ?, ?, ?)"
365#define INSERT_CALENDARPROPERTIES \
366"insert into Calendarproperties values (?, ?, ?)"
367#define INSERT_RDATES \
368"insert into Rdates values (?, ?, ?, ?, ?)"
369#define INSERT_RECURSIVE \
370"insert into Recursive values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
371#define INSERT_ALARM \
372"insert into Alarm values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
373#define INSERT_ATTENDEE \
374"insert into Attendee values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
375#define INSERT_ATTACHMENTS \
376"insert into Attachments values (?, ?, ?, ?, ?, ?, ?)"
378#define UPDATE_METADATA \
379"replace into Metadata (rowid, transactionId) values (1, ?)"
380#define UPDATE_CALENDARS \
381"update Calendars set Name=?, Description=?, Color=?, Flags=?, syncDate=?, pluginName=?, account=?, attachmentSize=?, " \
382 "modifiedDate=?, sharedWith=?, syncProfile=?, createdDate=? where CalendarId=?"
383#define UPDATE_COMPONENTS \
384 "update Components set Notebook=?, Type=?, Summary=?, Category=?, DateStart=?, DateStartLocal=?, StartTimeZone=?, " \
385 "HasDueDate=?, DateEndDue=?, DateEndDueLocal=?, EndDueTimeZone=?, Duration=?, Classification=?, Location=?, " \
386 "Description=?, Status=?, GeoLatitude=?, GeoLongitude=?, Priority=?, Resources=?, DateCreated=?, DateStamp=?, " \
387 "DateLastModified=?, Sequence=?, Comments=?, Attachments=?, Contact=?, RecurId=?, RecurIdLocal=?, RecurIdTimeZone=?, " \
388 "RelatedTo=?, URL=?, UID=?, Transparency=?, LocalOnly=?, Percent=?, DateCompleted=?, DateCompletedLocal=?, " \
389 "CompletedTimeZone=?, extra1=?, thisAndFuture=? where ComponentId=?"
390#define UPDATE_COMPONENTS_AS_DELETED \
391"update Components set DateDeleted=? where ComponentId=?"
394#define DELETE_CALENDARS \
395"delete from Calendars where CalendarId=?"
396#define DELETE_COMPONENTS \
397"delete from Components where ComponentId=?"
398#define DELETE_RDATES \
399"delete from Rdates where ComponentId=?"
400#define DELETE_CUSTOMPROPERTIES \
401"delete from Customproperties where ComponentId=?"
402#define DELETE_CALENDARPROPERTIES \
403"delete from Calendarproperties where CalendarId=?"
404#define DELETE_RECURSIVE \
405"delete from Recursive where ComponentId=?"
406#define DELETE_ALARM \
407"delete from Alarm where ComponentId=?"
408#define DELETE_ATTENDEE \
409"delete from Attendee where ComponentId=?"
410#define DELETE_ATTACHMENTS \
411"delete from Attachments where ComponentId=?"
413#define SELECT_METADATA \
414"select * from Metadata where rowid=1"
415#define SELECT_CALENDARS_ALL \
416"select * from Calendars order by Name"
417#define SELECT_COMPONENTS_ALL \
418"select * from Components where DateDeleted=0"
419#define SELECT_COMPONENTS_ALL_DELETED \
420"select * from Components where DateDeleted<>0"
421#define SELECT_COMPONENTS_ALL_DELETED_BY_NOTEBOOK \
422"select * from Components where Notebook=? and DateDeleted<>0"
423#define SELECT_COMPONENTS_BY_RECURSIVE \
424"select * from Components where ((ComponentId in (select DISTINCT ComponentId from Recursive)) "\
425 "or (ComponentId in (select DISTINCT ComponentId from Rdates)) or (RecurId!=0)) and DateDeleted=0"
426#define SELECT_COMPONENTS_BY_DATE_BOTH \
427"select * from Components where DateStart<? and (DateEndDue>=? or (DateEndDue=0 and DateStart>=?)) and DateDeleted=0"
428#define SELECT_COMPONENTS_BY_DATE_START \
429"select * from Components where (DateEndDue>=? or (DateEndDue=0 and DateStart>=?)) and DateDeleted=0"
430#define SELECT_COMPONENTS_BY_DATE_END \
431"select * from Components where DateStart<? and DateDeleted=0"
432#define SELECT_COMPONENTS_BY_UID \
433"select * from Components where UID=? and DateDeleted=0"
434#define SELECT_COMPONENTS_BY_NOTEBOOKUID \
435"select * from Components where Notebook=? and DateDeleted=0"
436#define SELECT_ROWID_FROM_COMPONENTS_BY_NOTEBOOK_UID_AND_RECURID \
437"select ComponentId from Components where Notebook=? and UID=? and RecurId=? and DateDeleted=0"
439#define SELECT_RDATES_BY_ID \
440"select * from Rdates where ComponentId=?"
441#define SELECT_CUSTOMPROPERTIES_BY_ID \
442"select * from Customproperties where ComponentId=?"
443#define SELECT_RECURSIVE_BY_ID \
444"select * from Recursive where ComponentId=?"
445#define SELECT_ALARM_BY_ID \
446"select * from Alarm where ComponentId=?"
447#define SELECT_ATTENDEE_BY_ID \
448"select * from Attendee where ComponentId=?"
449#define SELECT_ATTACHMENTS_BY_ID \
450"select * from Attachments where ComponentId=?"
451#define SELECT_CALENDARPROPERTIES_BY_ID \
452"select * from Calendarproperties where CalendarId=?"
453#define SELECT_COMPONENTS_BY_CREATED \
454"select * from Components where DateCreated>=? and DateDeleted=0"
455#define SELECT_COMPONENTS_BY_CREATED_AND_NOTEBOOK \
456"select * from Components where DateCreated>=? and Notebook=? and DateDeleted=0"
457#define SELECT_COMPONENTS_BY_LAST_MODIFIED \
458"select * from Components where DateLastModified>=? and DateCreated<? and DateDeleted=0"
459#define SELECT_COMPONENTS_BY_LAST_MODIFIED_AND_NOTEBOOK \
460"select * from Components where DateLastModified>=? and DateCreated<? and Notebook=? and DateDeleted=0"
461#define SELECT_COMPONENTS_BY_DELETED \
462"select * from Components where DateDeleted>=? and DateCreated<?"
463#define SELECT_COMPONENTS_BY_DELETED_AND_NOTEBOOK \
464"select * from Components where DateDeleted>=? and DateCreated<? and Notebook=?"
465#define SELECT_COMPONENTS_BY_UID_RECID_AND_DELETED \
466"select ComponentId, DateDeleted from Components where UID=? and RecurId=? and DateDeleted<>0"
467#define SELECT_COMPONENTS_BY_NOTEBOOK_UID_RECID_AND_DELETED \
468"select ComponentId from Components where Notebook=? and UID=? and RecurId=? and DateDeleted<>0"
470#define SEARCH_COMPONENTS \
471"select *, (ComponentId in (select DISTINCT ComponentId from Recursive)" \
472" or ComponentId in (select DISTINCT ComponentId from Rdates)) as doRecur" \
473" from Components where DateDeleted=0 and (summary like ? escape '\\'" \
474" or description like ? escape '\\'" \
475" or location like ? escape '\\') order by doRecur desc, datestart desc"
477#define UNSET_FLAG_FROM_CALENDAR \
478"update Calendars set Flags=(Flags & (~?))"
480#define BEGIN_TRANSACTION \
482#define COMMIT_TRANSACTION \
Placeholder for Notebook parameters.
Definition notebook.h:46
QSharedPointer< Notebook > Ptr
A shared pointer to a Notebook object.
Definition notebook.h:51
This file is part of the API for handling calendar data and defines the ExtendedStorage interface.
#define MKCAL_EXPORT
Definition mkcal_export.h:29
Definition extendedstorage.h:49
DBOperation
Definition sqliteformat.h:40
@ DBUpdate
Definition sqliteformat.h:42
@ DBMarkDeleted
Definition sqliteformat.h:43
@ DBInsert
Definition sqliteformat.h:41
@ DBDelete
Definition sqliteformat.h:44
This file is part of the API for handling calendar data and defines the Notebook class.