sqlitestorage.h
Go to the documentation of this file.
1 /*
2  This file is part of the mkcal library.
3 
4  Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5  Copyright (c) 2014-2019 Jolla Ltd.
6  Copyright (c) 2019 Open Mobile Platform LLC.
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23 */
34 #ifndef MKCAL_SQLITESTORAGE_H
35 #define MKCAL_SQLITESTORAGE_H
36 
37 #include "mkcal_export.h"
38 #include "extendedstorage.h"
39 
40 #include <sqlite3.h>
41 
42 namespace mKCal {
43 
44 const int VersionMajor = 11; // Major version, if different than stored in database, open fails
45 const int VersionMinor = 0; // Minor version, if different than stored in database, open warning
46 
54 {
55  Q_OBJECT
56 
57 public:
58 
62  typedef QSharedPointer<SqliteStorage> Ptr;
63 
73  explicit SqliteStorage(const ExtendedCalendar::Ptr &cal,
74  const QString &databaseName,
75  bool validateNotebooks = true);
76 
80  virtual ~SqliteStorage();
81 
85  QString databaseName() const;
86 
91  bool open();
92 
97  bool load();
98 
103  bool load(const QString &uid, const QDateTime &recurrenceId = QDateTime());
104 
109  bool load(const QDate &date);
110 
115  bool load(const QDate &start, const QDate &end);
116 
121  bool loadSeries(const QString &uid);
122 
127  bool loadIncidenceInstance(const QString &instanceIdentifier);
128 
133  bool loadNotebookIncidences(const QString &notebookUid);
134 
139  bool loadJournals();
140 
145  bool loadPlainIncidences();
146 
151  bool loadRecurringIncidences();
152 
157  bool loadGeoIncidences();
158 
163  bool loadGeoIncidences(float geoLatitude, float geoLongitude,
164  float diffLatitude, float diffLongitude);
165 
170  bool loadAttendeeIncidences();
171 
176  int loadUncompletedTodos();
177 
182  int loadCompletedTodos(bool hasDate, int limit, QDateTime *last);
183 
188  int loadIncidences(bool hasDate, int limit, QDateTime *last);
189 
194  int loadFutureIncidences(int limit, QDateTime *last);
195 
200  int loadGeoIncidences(bool hasDate, int limit, QDateTime *last);
201 
206  int loadUnreadInvitationIncidences();
207 
212  int loadOldInvitationIncidences(int limit, QDateTime *last);
213 
218  KCalendarCore::Person::List loadContacts();
219 
224  int loadContactIncidences(const KCalendarCore::Person &person, int limit, QDateTime *last);
225 
230  int loadJournals(int limit, QDateTime *last);
231 
236  bool notifyOpened(const KCalendarCore::Incidence::Ptr &incidence);
237 
242  bool purgeDeletedIncidences(const KCalendarCore::Incidence::List &list);
243 
248  bool save();
249 
254  bool save(ExtendedStorage::DeleteAction deleteAction);
255 
260  bool cancel();
261 
266  bool close();
267 
272  void calendarModified(bool modified, KCalendarCore::Calendar *calendar);
273 
278  void calendarIncidenceCreated(const KCalendarCore::Incidence::Ptr &incidence);
279 
284  void calendarIncidenceAdded(const KCalendarCore::Incidence::Ptr &incidence);
285 
290  void calendarIncidenceChanged(const KCalendarCore::Incidence::Ptr &incidence);
291 
296  void calendarIncidenceDeleted(const KCalendarCore::Incidence::Ptr &incidence, const KCalendarCore::Calendar *calendar);
297 
302  void calendarIncidenceAdditionCanceled(const KCalendarCore::Incidence::Ptr &incidence);
303 
308  bool insertedIncidences(KCalendarCore::Incidence::List *list, const QDateTime &after,
309  const QString &notebookUid = QString());
310 
315  bool modifiedIncidences(KCalendarCore::Incidence::List *list, const QDateTime &after,
316  const QString &notebookUid = QString());
317 
322  bool deletedIncidences(KCalendarCore::Incidence::List *list,
323  const QDateTime &after = QDateTime(),
324  const QString &notebookUid = QString());
325 
330  bool allIncidences(KCalendarCore::Incidence::List *list, const QString &notebookUid = QString());
331 
336  bool duplicateIncidences(KCalendarCore::Incidence::List *list,
337  const KCalendarCore::Incidence::Ptr &incidence,
338  const QString &notebookUid = QString());
339 
344  QDateTime incidenceDeletedDate(const KCalendarCore::Incidence::Ptr &incidence);
345 
350  int eventCount();
351 
356  int todoCount();
357 
362  int journalCount();
363 
368  virtual void virtual_hook(int id, void *data);
369 
370 
371  // Helper Functions //
372 
379  sqlite3_int64 toOriginTime(const QDateTime &dt);
380 
387  sqlite3_int64 toLocalOriginTime(const QDateTime &dt);
388 
394  QDateTime fromLocalOriginTime(sqlite3_int64 seconds);
395 
401  QDateTime fromOriginTime(sqlite3_int64 seconds);
402 
409  QDateTime fromOriginTime(sqlite3_int64 seconds, const QByteArray &zonename);
410 
411 private:
417  bool initializeDatabase();
418 
419 protected:
420  bool loadNotebooks();
421  bool reloadNotebooks();
422  bool modifyNotebook(const Notebook::Ptr &nb, DBOperation dbop, bool signal = true);
423 
424 private:
425  //@cond PRIVATE
426  Q_DISABLE_COPY(SqliteStorage)
427  class MKCAL_HIDE Private;
428  Private *const d;
429  //@endcond
430 
431 public Q_SLOTS:
432  void fileChanged(const QString &path);
433 
434  void queryFinished();
435 };
436 
437 #define sqlite3_exec( db ) \
438 { \
439  /* kDebug() << "SQL query:" << query; */ \
440  rv = sqlite3_exec( (db), query, NULL, 0, &errmsg ); \
441  if ( rv ) { \
442  if ( rv != SQLITE_CONSTRAINT ) { \
443  qCWarning(lcMkcal) << "sqlite3_exec error code:" << rv; \
444  } \
445  if ( errmsg ) { \
446  if ( rv != SQLITE_CONSTRAINT ) { \
447  qCWarning(lcMkcal) << errmsg; \
448  } \
449  sqlite3_free( errmsg ); \
450  errmsg = NULL; \
451  } \
452  if ( rv != SQLITE_CONSTRAINT ) { \
453  goto error; \
454  } \
455  } \
456 }
457 
458 #define sqlite3_prepare_v2( db, query, qsize, stmt, tail ) \
459 { \
460  /* kDebug() << "SQL query:" << query; */ \
461  rv = sqlite3_prepare_v2( (db), (query), (qsize), (stmt), (tail) ); \
462  if ( rv ) { \
463  qCWarning(lcMkcal) << "sqlite3_prepare error code:" << rv; \
464  qCWarning(lcMkcal) << sqlite3_errmsg( (db) ); \
465  goto error; \
466  } \
467 }
468 
469 #define sqlite3_bind_text( stmt, index, value, size, desc ) \
470 { \
471  rv = sqlite3_bind_text( (stmt), (index), (value), (size), (desc) ); \
472  if ( rv ) { \
473  qCWarning(lcMkcal) << "sqlite3_bind_text error:" << rv << "on index and value:" << index << value; \
474  goto error; \
475  } \
476  index++; \
477 }
478 
479 #define sqlite3_bind_blob( stmt, index, value, size, desc ) \
480 { \
481  rv = sqlite3_bind_blob( (stmt), (index), (value), (size), (desc) ); \
482  if ( rv ) { \
483  qCWarning(lcMkcal) << "sqlite3_bind_blob error:" << rv << "on index and value:" << index << value; \
484  goto error; \
485  } \
486  index++; \
487 }
488 
489 #define sqlite3_bind_int( stmt, index, value ) \
490 { \
491  rv = sqlite3_bind_int( (stmt), (index), (value) ); \
492  if ( rv ) { \
493  qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
494  goto error; \
495  } \
496  index++; \
497 }
498 
499 #define sqlite3_bind_int64( stmt, index, value ) \
500 { \
501  rv = sqlite3_bind_int64( (stmt), (index), (value) ); \
502  if ( rv ) { \
503  qCWarning(lcMkcal) << "sqlite3_bind_int64 error:" << rv << "on index and value:" << index << value; \
504  goto error; \
505  } \
506  index++; \
507 }
508 
509 #define sqlite3_bind_double( stmt, index, value ) \
510 { \
511  rv = sqlite3_bind_double( (stmt), (index), (value) ); \
512  if ( rv ) { \
513  qCWarning(lcMkcal) << "sqlite3_bind_int error:" << rv << "on index and value:" << index << value; \
514  goto error; \
515  } \
516  index++; \
517 }
518 
519 #define sqlite3_step( stmt ) \
520 { \
521  rv = sqlite3_step( (stmt) ); \
522  if ( rv && rv != SQLITE_DONE && rv != SQLITE_ROW ) { \
523  if ( rv != SQLITE_CONSTRAINT ) { \
524  qCWarning(lcMkcal) << "sqlite3_step error:" << rv; \
525  } \
526  goto error; \
527  } \
528 }
529 
530 #define CREATE_VERSION \
531  "CREATE TABLE IF NOT EXISTS Version(Major INTEGER, Minor INTEGER)"
532 #define CREATE_TIMEZONES \
533  "CREATE TABLE IF NOT EXISTS Timezones(TzId INTEGER PRIMARY KEY, ICalData TEXT)"
534 #define CREATE_CALENDARS \
535  "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)"
536 
537 //Extra fields added for future use in case they are needed. They will be documented here
538 //So we can add something without breaking the schema and not adding tables
539 //extra1: used to store the color of a single component.
540 
541 #define CREATE_COMPONENTS \
542  "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)"
543 
544 //Extra fields added for future use in case they are needed. They will be documented here
545 //So we can add something without breaking the schema and not adding tables
546 
547 #define CREATE_RDATES \
548  "CREATE TABLE IF NOT EXISTS Rdates(ComponentId INTEGER, Type INTEGER, Date INTEGER, DateLocal INTEGER, TimeZone TEXT)"
549 #define CREATE_CUSTOMPROPERTIES \
550  "CREATE TABLE IF NOT EXISTS Customproperties(ComponentId INTEGER, Name TEXT, Value TEXT, Parameters TEXT)"
551 #define CREATE_RECURSIVE \
552  "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)"
553 #define CREATE_ALARM \
554  "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)"
555 #define CREATE_ATTENDEE \
556 "CREATE TABLE IF NOT EXISTS Attendee(ComponentId INTEGER, Email TEXT, Name TEXT, IsOrganizer INTEGER, Role INTEGER, PartStat INTEGER, Rsvp INTEGER, DelegatedTo TEXT, DelegatedFrom TEXT)"
557 #define CREATE_ATTACHMENTS \
558 "CREATE TABLE IF NOT EXISTS Attachments(ComponentId INTEGER, Data BLOB, Uri TEXT, MimeType TEXT, ShowInLine INTEGER, Label TEXT, Local INTEGER)"
559 #define CREATE_CALENDARPROPERTIES \
560  "CREATE TABLE IF NOT EXISTS Calendarproperties(CalendarId REFERENCES Calendars(CalendarId) ON DELETE CASCADE, Name TEXT NOT NULL, Value TEXT, UNIQUE (CalendarId, Name))"
561 
562 #define INDEX_CALENDAR \
563 "CREATE INDEX IF NOT EXISTS IDX_CALENDAR on Calendars(CalendarId)"
564 #define INDEX_INVITATION \
565 "CREATE INDEX IF NOT EXISTS IDX_INVITATION on Invitations(InvitationId)"
566 #define INDEX_COMPONENT \
567 "CREATE INDEX IF NOT EXISTS IDX_COMPONENT on Components(ComponentId, Notebook, DateStart, DateEndDue, DateDeleted)"
568 #define INDEX_COMPONENT_UID \
569 "CREATE UNIQUE INDEX IF NOT EXISTS IDX_COMPONENT_UID on Components(UID, RecurId, DateDeleted)"
570 #define INDEX_COMPONENT_NOTEBOOK \
571 "CREATE INDEX IF NOT EXISTS IDX_COMPONENT_NOTEBOOK on Components(Notebook)"
572 #define INDEX_RDATES \
573 "CREATE INDEX IF NOT EXISTS IDX_RDATES on Rdates(ComponentId)"
574 #define INDEX_CUSTOMPROPERTIES \
575 "CREATE INDEX IF NOT EXISTS IDX_CUSTOMPROPERTIES on Customproperties(ComponentId)"
576 #define INDEX_RECURSIVE \
577 "CREATE INDEX IF NOT EXISTS IDX_RECURSIVE on Recursive(ComponentId)"
578 #define INDEX_ALARM \
579 "CREATE INDEX IF NOT EXISTS IDX_ALARM on Alarm(ComponentId)"
580 #define INDEX_ATTENDEE \
581 "CREATE UNIQUE INDEX IF NOT EXISTS IDX_ATTENDEE on Attendee(ComponentId, Email)"
582 #define INDEX_ATTACHMENTS \
583 "CREATE INDEX IF NOT EXISTS IDX_ATTACHMENTS on Attachments(ComponentId)"
584 #define INDEX_CALENDARPROPERTIES \
585 "CREATE INDEX IF NOT EXISTS IDX_CALENDARPROPERTIES on Calendarproperties(CalendarId)"
586 
587 #define INSERT_VERSION \
588 "insert into Version values (?, ?)"
589 #define INSERT_TIMEZONES \
590 "insert into Timezones values (1, '')"
591 #define INSERT_CALENDARS \
592 "insert into Calendars values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', '')"
593 #define INSERT_INVITATIONS \
594 "insert into Invitations values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
595 #define INSERT_COMPONENTS \
596 "insert into Components values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, '', 0)"
597 #define INSERT_CUSTOMPROPERTIES \
598 "insert into Customproperties values (?, ?, ?, ?)"
599 #define INSERT_CALENDARPROPERTIES \
600 "insert into Calendarproperties values (?, ?, ?)"
601 #define INSERT_RDATES \
602 "insert into Rdates values (?, ?, ?, ?, ?)"
603 #define INSERT_RECURSIVE \
604 "insert into Recursive values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
605 #define INSERT_ALARM \
606 "insert into Alarm values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
607 #define INSERT_ATTENDEE \
608 "insert into Attendee values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
609 #define INSERT_ATTACHMENTS \
610 "insert into Attachments values (?, ?, ?, ?, ?, ?, ?)"
611 
612 #define UPDATE_TIMEZONES \
613 "update Timezones set ICalData=? where TzId=1"
614 #define UPDATE_CALENDARS \
615 "update Calendars set Name=?, Description=?, Color=?, Flags=?, syncDate=?, pluginName=?, account=?, attachmentSize=?, modifiedDate=?, sharedWith=?, syncProfile=?, createdDate=? where CalendarId=?"
616 #define UPDATE_COMPONENTS \
617 "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=?, InvitationStatus=?, RecurId=?, RecurIdLocal=?, RecurIdTimeZone=?, RelatedTo=?, URL=?, UID=?, Transparency=?, LocalOnly=?, Percent=?, DateCompleted=?, DateCompletedLocal=?, CompletedTimeZone=?, extra1=? where ComponentId=?"
618 #define UPDATE_COMPONENTS_AS_DELETED \
619 "update Components set DateDeleted=? where ComponentId=?"
620 //"update Components set DateDeleted=strftime('%s','now') where ComponentId=?"
621 
622 #define DELETE_TIMEZONES \
623 "delete from Timezones where TzId=1"
624 #define DELETE_CALENDARS \
625 "delete from Calendars where CalendarId=?"
626 #define DELETE_INVITATIONS \
627 "delete from Invitations where InvitationId=?"
628 #define DELETE_COMPONENTS \
629 "delete from Components where ComponentId=?"
630 #define DELETE_RDATES \
631 "delete from Rdates where ComponentId=?"
632 #define DELETE_CUSTOMPROPERTIES \
633 "delete from Customproperties where ComponentId=?"
634 #define DELETE_CALENDARPROPERTIES \
635 "delete from Calendarproperties where CalendarId=?"
636 #define DELETE_RECURSIVE \
637 "delete from Recursive where ComponentId=?"
638 #define DELETE_ALARM \
639 "delete from Alarm where ComponentId=?"
640 #define DELETE_ATTENDEE \
641 "delete from Attendee where ComponentId=?"
642 #define DELETE_ATTACHMENTS \
643 "delete from Attachments where ComponentId=?"
644 
645 #define SELECT_VERSION \
646 "select * from Version"
647 #define SELECT_TIMEZONES \
648 "select * from Timezones where TzId=1"
649 #define SELECT_CALENDARS_ALL \
650 "select * from Calendars order by Name"
651 #define SELECT_INVITATIONS_ALL \
652 "select * from Invitations"
653 #define SELECT_COMPONENTS_ALL \
654 "select * from Components where DateDeleted=0"
655 #define SELECT_COMPONENTS_BY_NOTEBOOK \
656 "select * from Components where Notebook=? and DateDeleted=0"
657 #define SELECT_COMPONENTS_ALL_DELETED \
658 "select * from Components where DateDeleted<>0"
659 #define SELECT_COMPONENTS_ALL_DELETED_BY_NOTEBOOK \
660 "select * from Components where Notebook=? and DateDeleted<>0"
661 #define SELECT_COMPONENTS_BY_GEO \
662 "select * from Components where GeoLatitude!=255.0 and GeoLongitude!=255.0 and DateDeleted=0"
663 #define SELECT_COMPONENTS_BY_GEO_AREA \
664 "select * from Components where GeoLatitude>=? and GeoLongitude>=? and GeoLatitude<=? and GeoLongitude<=? and DateDeleted=0"
665 #define SELECT_COMPONENTS_BY_JOURNAL \
666 "select * from Components where Type='Journal' and DateDeleted=0"
667 #define SELECT_COMPONENTS_BY_JOURNAL_DATE \
668 "select * from Components where Type='Journal' and DateDeleted=0 and datestart<=? order by DateStart desc, DateCreated desc"
669 #define SELECT_COMPONENTS_BY_PLAIN \
670 "select * from Components where DateStart=0 and DateEndDue=0 and DateDeleted=0"
671 #define SELECT_COMPONENTS_BY_RECURSIVE \
672 "select * from components where ((ComponentId in (select DISTINCT ComponentId from recursive)) or (RecurId!=0)) and DateDeleted=0"
673 #define SELECT_COMPONENTS_BY_ATTENDEE \
674 "select * from components where ComponentId in (select DISTINCT ComponentId from attendee) and DateDeleted=0"
675 #define SELECT_COMPONENTS_BY_DATE_BOTH \
676 "select * from Components where DateStart<=? and (DateEndDue>=? or DateEndDue=0) and DateDeleted=0"
677 #define SELECT_COMPONENTS_BY_DATE_START \
678 "select * from Components where DateEndDue>=? and DateDeleted=0"
679 #define SELECT_COMPONENTS_BY_DATE_END \
680 "select * from Components where DateStart<=? and DateDeleted=0"
681 #define SELECT_COMPONENTS_BY_UID_AND_RECURID \
682 "select * from Components where UID=? and RecurId=? and DateDeleted=0"
683 #define SELECT_COMPONENTS_BY_UID \
684 "select * from Components where UID=? and DateDeleted=0"
685 #define SELECT_COMPONENTS_BY_NOTEBOOKUID \
686 "select * from Components where Notebook=? and DateDeleted=0"
687 #define SELECT_ROWID_FROM_COMPONENTS_BY_UID_AND_RECURID \
688 "select ComponentId from Components where UID=? and RecurId=? and DateDeleted=0"
689 #define SELECT_COMPONENTS_BY_UNCOMPLETED_TODOS \
690 "select * from Components where Type='Todo' and DateCompleted=0 and DateDeleted=0"
691 #define SELECT_COMPONENTS_BY_COMPLETED_TODOS_AND_DATE \
692 "select * from Components where Type='Todo' and DateCompleted<>0 and DateEndDue<>0 and DateEndDue<=? and DateDeleted=0 order by DateEndDue desc, DateCreated desc"
693 #define SELECT_COMPONENTS_BY_COMPLETED_TODOS_AND_CREATED \
694 "select * from Components where Type='Todo' and DateCompleted<>0 and DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
695 #define SELECT_COMPONENTS_BY_DATE_SMART \
696 "select * from Components where DateEndDue<>0 and DateEndDue<=? and DateDeleted=0 order by DateEndDue desc, DateCreated desc"
697 
698 #define FUTURE_DATE_SMART_FIELD \
699 " (case type when 'Todo' then DateEndDue else DateStart end) "
700 #define SELECT_COMPONENTS_BY_FUTURE_DATE_SMART \
701  "select * from Components where " \
702  FUTURE_DATE_SMART_FIELD ">=? and DateDeleted=0 order by " \
703  FUTURE_DATE_SMART_FIELD " asc, DateCreated asc"
704 
705 #define SELECT_COMPONENTS_BY_CREATED_SMART \
706 "select * from Components where DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
707 #define SELECT_COMPONENTS_BY_GEO_AND_DATE \
708 "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"
709 #define SELECT_COMPONENTS_BY_GEO_AND_CREATED \
710 "select * from Components where GeoLatitude!=255.0 and GeoLongitude!=255.0 and DateEndDue=0 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
711 #define SELECT_COMPONENTS_BY_INVITATION_UNREAD \
712 "select * from Components where InvitationStatus=1 and DateDeleted=0"
713 #define SELECT_COMPONENTS_BY_INVITATION_AND_CREATED \
714 "select * from Components where InvitationStatus>1 and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
715 #define SELECT_COMPONENTS_BY_ATTENDEE_EMAIL_AND_CREATED \
716 "select * from Components where ComponentId in (select distinct ComponentId from Attendee where email=?) and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
717 #define SELECT_COMPONENTS_BY_ATTENDEE_AND_CREATED \
718 "select * from Components where ComponentId in (select distinct ComponentId from Attendee) and DateCreated<=? and DateDeleted=0 order by DateCreated desc"
719 #define SELECT_RDATES_BY_ID \
720 "select * from Rdates where ComponentId=?"
721 #define SELECT_CUSTOMPROPERTIES_BY_ID \
722 "select * from Customproperties where ComponentId=?"
723 #define SELECT_RECURSIVE_BY_ID \
724 "select * from Recursive where ComponentId=?"
725 #define SELECT_ALARM_BY_ID \
726 "select * from Alarm where ComponentId=?"
727 #define SELECT_ATTENDEE_BY_ID \
728 "select * from Attendee where ComponentId=?"
729 #define SELECT_ATTACHMENTS_BY_ID \
730 "select * from Attachments where ComponentId=?"
731 #define SELECT_CALENDARPROPERTIES_BY_ID \
732 "select * from Calendarproperties where CalendarId=?"
733 #define SELECT_COMPONENTS_BY_DUPLICATE \
734 "select * from Components where DateStart=? and Summary=? and DateDeleted=0"
735 #define SELECT_COMPONENTS_BY_DUPLICATE_AND_NOTEBOOK \
736 "select * from Components where DateStart=? and Summary=? and Notebook=? and DateDeleted=0"
737 #define SELECT_COMPONENTS_BY_CREATED \
738 "select * from Components where DateCreated>=? and DateDeleted=0"
739 #define SELECT_COMPONENTS_BY_CREATED_AND_NOTEBOOK \
740 "select * from Components where DateCreated>=? and Notebook=? and DateDeleted=0"
741 #define SELECT_COMPONENTS_BY_LAST_MODIFIED \
742 "select * from Components where DateLastModified>=? and DateCreated<? and DateDeleted=0"
743 #define SELECT_COMPONENTS_BY_LAST_MODIFIED_AND_NOTEBOOK \
744 "select * from Components where DateLastModified>=? and DateCreated<? and Notebook=? and DateDeleted=0"
745 #define SELECT_COMPONENTS_BY_DELETED \
746 "select * from Components where DateDeleted>=? and DateCreated<?"
747 #define SELECT_COMPONENTS_BY_DELETED_AND_NOTEBOOK \
748 "select * from Components where DateDeleted>=? and DateCreated<? and Notebook=?"
749 #define SELECT_COMPONENTS_BY_UID_RECID_AND_DELETED \
750 "select ComponentId, DateDeleted from Components where UID=? and RecurId=? and DateDeleted<>0"
751 #define SELECT_ATTENDEE_AND_COUNT \
752 "select Email, Name, count(Email) from Attendee where Email<>0 group by Email"
753 #define SELECT_EVENT_COUNT \
754 "select count(*) from Components where Type='Event' and DateDeleted=0"
755 #define SELECT_TODO_COUNT \
756 "select count(*) from Components where Type='Todo' and DateDeleted=0"
757 #define SELECT_JOURNAL_COUNT \
758 "select count(*) from Components where Type='Journal' and DateDeleted=0"
759 
760 #define BEGIN_TRANSACTION \
761 "BEGIN IMMEDIATE;"
762 #define COMMIT_TRANSACTION \
763 "END;"
764 
765 }
766 
767 #endif
This class provides a calendar storage interface.
Definition: extendedstorage.h:76
DeleteAction
Action to be performed on save for deleted incidences.
Definition: extendedstorage.h:84
QSharedPointer< Notebook > Ptr
A shared pointer to a Notebook object.
Definition: notebook.h:51
This class provides a calendar storage as an sqlite database.
Definition: sqlitestorage.h:54
void calendarIncidenceCreated(const KCalendarCore::Incidence::Ptr &incidence)
QSharedPointer< SqliteStorage > Ptr
A shared pointer to a SqliteStorage.
Definition: sqlitestorage.h:62
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:47
DBOperation
Database operation type.
Definition: extendedstorage.h:52
const int VersionMajor
Definition: sqlitestorage.h:44
const int VersionMinor
Definition: sqlitestorage.h:45

Generated on Wed Jun 9 2021 14:20:48 for libextendedkcal by doxygen 1.9.1