X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;ds=inline;f=source%2Flibraries%2FCalendarDataStorage%2FCalendarDataStorage.cpp;h=d6d335effb23714aad62d8c1643850fa906dea06;hb=3b8fa1539bff637461965a88b217e92b3bac4cde;hp=a47a3548dbfe1b5d64572f576c159c2c560c7776;hpb=baa27c175ee6111fd4b88a3c53614a9b6be3541e;p=xestiacalendar%2F.git
diff --git a/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp b/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp
index a47a354..d6d335e 100644
--- a/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp
+++ b/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp
@@ -1,9 +1,25 @@
+// CalendarDataStorage.cpp - CalendarDataStorage class
+//
+// (c) 2016-2017 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Calendar is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Calendar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see
+
#include "CalendarDataStorage.h"
#define CDS_RANDOMPOW 24
-#include
-
using namespace std;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
@@ -37,7 +53,8 @@ void CalendarDataStorage::SetupTables(){
// Setup the accounts table.
const char *accountsTableString;
- accountsTableString = "CREATE TABLE accounts(id INTEGER PRIMARY KEY "
+ accountsTableString = "CREATE TABLE accounts(id INTEGER PRIMARY KEY AUTOINCREMENT"
+ ", preferencesid INTEGER"
", name TEXT"
");";
@@ -51,11 +68,12 @@ void CalendarDataStorage::SetupTables(){
// Setup the calendars table.
const char *calendarTableString;
- calendarTableString = "CREATE TABLE calendars(id INTEGER PRIMARY KEY "
+ calendarTableString = "CREATE TABLE calendars(id INTEGER PRIMARY KEY AUTOINCREMENT"
", accountid INTEGER"
", name TEXT"
", calendarid TEXT"
", colour TEXT"
+ ", description TEXT"
");";
resultCode = sqlite3_exec(db, calendarTableString, callback, nullptr, &setupTablesErrMsg);
@@ -68,7 +86,7 @@ void CalendarDataStorage::SetupTables(){
// Setup the calendar entries table.
const char *calendarentriesTableString;
- calendarentriesTableString = "CREATE TABLE calendarentries(id INTEGER PRIMARY KEY "
+ calendarentriesTableString = "CREATE TABLE calendarentries(id INTEGER PRIMARY KEY AUTOINCREMENT"
", calendarid INTEGER"
", entryname TEXT"
", entrydescription TEXT"
@@ -89,6 +107,7 @@ void CalendarDataStorage::SetupTables(){
", entrydurationhour INTEGER"
", entrydurationminute INTEGER"
", entrydurationsecond INTEGER"
+ ", filename TEXT"
");";
resultCode = sqlite3_exec(db, calendarentriesTableString, callback, nullptr, &setupTablesErrMsg);
@@ -131,15 +150,42 @@ bool CalendarDataStorage::DidInitOK()
}
-CDSAccountResult CalendarDataStorage::AddAccount(string accountName)
+CDSAccountResult CalendarDataStorage::AddAccount(string accountName, int accountPreferencesID)
{
CDSAccountResult addResult = CDSACCOUNT_UNITTESTFAIL;
int resultCode;
sqlite3_stmt *statementHandle;
+ sqlite3_stmt *findHandle;
+
+ if (accountName == ""){
+ return CDSACCOUNT_NONAME;
+ }
+
+ // Check if the account name already exsits.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT name FROM accounts WHERE name=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(findHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
- resultCode = sqlite3_prepare_v2(db, "INSERT INTO accounts (name) VALUES(?1);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSACCOUNT_FAILED;
+ } else if (resultCode == SQLITE_ROW){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "INSERT INTO accounts (name, preferencesid) VALUES(?1, ?2);", -1, &statementHandle, nullptr);
if (resultCode != 0){
return CDSACCOUNT_FAILED;
@@ -147,6 +193,12 @@ CDSAccountResult CalendarDataStorage::AddAccount(string accountName)
resultCode = sqlite3_bind_text(statementHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 2, accountPreferencesID);
+
if (resultCode != 0){
return CDSACCOUNT_FAILED;
}
@@ -178,7 +230,7 @@ CDSAccountList CalendarDataStorage::GetAccountList()
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "SELECT id, name from accounts;", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "SELECT id, name, preferencesid from accounts;", -1, &statementHandle, nullptr);
if (resultCode != 0){
accountList.getAccountListResult = CDSACCOUNT_FAILED;
@@ -207,6 +259,7 @@ CDSAccountList CalendarDataStorage::GetAccountList()
CDSGetAccountInfo accountInfo;
accountInfo.accountID = sqlite3_column_int(statementHandle, 0);
+ accountInfo.accountPreferencesID = sqlite3_column_int(statementHandle, 2);
stringstream calendarStream;
@@ -236,7 +289,7 @@ CDSGetAccountInfo CalendarDataStorage::GetAccount(string accountName)
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "SELECT name, id FROM accounts WHERE name=(?1);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "SELECT name, id, preferencesid FROM accounts WHERE name=(?1);", -1, &statementHandle, nullptr);
if (resultCode != 0){
accountInfo.accountInfoResult = CDSACCOUNT_FAILED;
@@ -267,6 +320,7 @@ CDSGetAccountInfo CalendarDataStorage::GetAccount(string accountName)
accountInfo.accountName = accountNameStream.str();
accountInfo.accountID = sqlite3_column_int(statementHandle, 1);
+ accountInfo.accountPreferencesID = sqlite3_column_int(statementHandle, 2);
accountInfo.accountInfoResult = CDSACCOUNT_OK;
return accountInfo;
@@ -289,8 +343,13 @@ CDSAccountResult CalendarDataStorage::UpdateAccount(int accountID, string accoun
int resultCode;
sqlite3_stmt *findHandle;
+ sqlite3_stmt *existingHandle;
sqlite3_stmt *statementHandle;
+ if (accountName == ""){
+ return CDSACCOUNT_NONAME;
+ }
+
// Check if account exists first.
resultCode = sqlite3_prepare_v2(db, "SELECT id from accounts WHERE id=(?1);", -1, &findHandle, nullptr);
@@ -315,6 +374,30 @@ CDSAccountResult CalendarDataStorage::UpdateAccount(int accountID, string accoun
return CDSACCOUNT_FAILED;
}
+ // Check if account with the name given already exists before renaming.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT name from accounts WHERE name=(?1);", -1, &existingHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(existingHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_step(existingHandle);
+
+ if (resultCode == SQLITE_ROW){
+ return CDSACCOUNT_FAILED;
+ } else if (resultCode == SQLITE_DONE) {
+
+ } else {
+ return CDSACCOUNT_FAILED;
+ }
+
// Update the account.
resultCode = sqlite3_prepare_v2(db, "UPDATE accounts SET name=(?1) WHERE id=(?2);", -1, &statementHandle, nullptr);
@@ -382,7 +465,7 @@ CDSAccountResult CalendarDataStorage::DeleteAccount(int accountID)
} else if (resultCode == SQLITE_DONE) {
return CDSACCOUNT_NOACCOUNT;
} else {
- return CDSACCOUNT_FAILED;
+
}
// Delete the account.
@@ -450,15 +533,36 @@ CDSAccountResult CalendarDataStorage::DeleteAccount(int accountID)
}
-CDSCalendarResult CalendarDataStorage::AddCalendar(int accountID, string calendarName, string calendarID, Colour calendarColour)
+CDSCalendarResult CalendarDataStorage::AddCalendar(int accountID, string calendarName, string calendarID, Colour calendarColour, string calendarDescription)
{
CDSCalendarResult addResult = CDSCALENDAR_UNITTESTFAIL;
int resultCode;
-
+
+ sqlite3_stmt *findHandle;
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "INSERT INTO calendars (name, calendarid, accountid, colour) VALUES(?1, ?2, ?3, ?4);", -1, &statementHandle, nullptr);
+ // Check if the account exists first.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT id FROM accounts WHERE id=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_bind_int(findHandle, 1, accountID);
+
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode != SQLITE_ROW){
+ return CDSCALENDAR_NOACCOUNT;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "INSERT INTO calendars (name, calendarid, accountid, colour, description) VALUES(?1, ?2, ?3, ?4, ?5);", -1, &statementHandle, nullptr);
if (resultCode != 0){
return CDSCALENDAR_FAILED;
@@ -484,6 +588,12 @@ CDSCalendarResult CalendarDataStorage::AddCalendar(int accountID, string calenda
resultCode = sqlite3_bind_text(statementHandle, 4, ((string)calendarColour).c_str(), -1, SQLITE_STATIC);
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(statementHandle, 5, calendarDescription.c_str(), -1, SQLITE_STATIC);
+
if (resultCode != 0){
return CDSCALENDAR_FAILED;
}
@@ -535,7 +645,7 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(std::string accountName, std
// Check if the calendar exists.
- resultCode = sqlite3_prepare_v2(db, "SELECT id, accountid, name, calendarid, colour FROM calendars WHERE accountid=(?1) AND calendarid=(?2);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "SELECT id, accountid, name, calendarid, colour, description FROM calendars WHERE accountid=(?1) AND calendarid=(?2);", -1, &statementHandle, nullptr);
if (resultCode != 0){
calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
@@ -580,6 +690,10 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(std::string accountName, std
calendarStream << sqlite3_column_text(statementHandle, 4);
calendarResult.calendarColour = calendarStream.str();
+ calendarStream.str("");
+ calendarStream << sqlite3_column_text(statementHandle, 5);
+ calendarResult.calendarDescription = calendarStream.str();
+
calendarResult.calendarID = sqlite3_column_int(statementHandle, 0);
calendarResult.accountID = sqlite3_column_int(statementHandle, 1);
calendarResult.calendarInfoResult = CDSCALENDAR_OK;
@@ -601,11 +715,12 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(int calendarID)
CDSGetCalendarInfo calendarResult;
sqlite3_stmt *statementHandle;
+ sqlite3_stmt *accountHandle;
int resultCode;
// Check if the calendar exists.
- resultCode = sqlite3_prepare_v2(db, "SELECT id, accountid, name, calendarid, colour FROM calendars WHERE id=(?1);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "SELECT id, accountid, name, calendarid, colour, description FROM calendars WHERE id=(?1);", -1, &statementHandle, nullptr);
if (resultCode != 0){
calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
@@ -642,9 +757,45 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(int calendarID)
calendarStream.str("");
calendarStream << sqlite3_column_text(statementHandle, 4);
calendarResult.calendarColour = calendarStream.str();
+
+ calendarStream.str("");
+ calendarStream << sqlite3_column_text(statementHandle, 5);
+ calendarResult.calendarDescription = calendarStream.str();
calendarResult.calendarID = sqlite3_column_int(statementHandle, 0);
calendarResult.accountID = sqlite3_column_int(statementHandle, 1);
+
+ // Get the account name.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT name FROM accounts WHERE id=(?1);", -1, &accountHandle, nullptr);
+
+ if (resultCode != 0){
+ calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
+ return calendarResult;
+ }
+
+ resultCode = sqlite3_bind_int(accountHandle, 1, calendarResult.accountID);
+
+ if (resultCode != 0){
+ calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
+ return calendarResult;
+ }
+
+ resultCode = sqlite3_step(accountHandle);
+
+ if (resultCode == SQLITE_ROW){
+
+ stringstream accountStream;
+ accountStream << sqlite3_column_text(accountHandle, 0);
+ calendarResult.accountName = accountStream.str();
+ calendarResult.accountInfoResult = CDSACCOUNT_OK;
+
+ } else {
+
+ calendarResult.accountInfoResult = CDSACCOUNT_FAILED;
+
+ }
+
calendarResult.calendarInfoResult = CDSCALENDAR_OK;
return calendarResult;
@@ -660,7 +811,7 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(int calendarID)
}
-CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName)
+CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName, Colour calendarColour, std::string calendarDescription)
{
CDSCalendarResult updateResult = CDSCALENDAR_UNITTESTFAIL;
@@ -695,7 +846,7 @@ CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string cal
// Update the account.
- resultCode = sqlite3_prepare_v2(db, "UPDATE calendars SET name=(?1) WHERE id=(?2);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "UPDATE calendars SET name=(?1), colour=(?2), description=(?3) WHERE id=(?4);", -1, &statementHandle, nullptr);
if (resultCode != 0){
return CDSCALENDAR_FAILED;
@@ -703,11 +854,23 @@ CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string cal
resultCode = sqlite3_bind_text(statementHandle, 1, calendarName.c_str(), -1, SQLITE_STATIC);
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(statementHandle, 2, string(calendarColour).c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(statementHandle, 3, calendarDescription.c_str(), -1, SQLITE_STATIC);
+
if (resultCode != 0){
return CDSCALENDAR_FAILED;
}
- resultCode = sqlite3_bind_int(statementHandle, 2, calendarID);
+ resultCode = sqlite3_bind_int(statementHandle, 4, calendarID);
if (resultCode != 0){
return CDSCALENDAR_FAILED;
@@ -888,14 +1051,14 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
// Start Date.
- if (eventData.DateTimeStartData.size() < 16){
+ if (eventData.dateTimeStartData.size() < 16){
addResult.addEventResult = CDSENTRY_INVALIDFILE;
return addResult;
}
- eventString = eventData.DateTimeStartData.substr(0,4);
+ eventString = eventData.dateTimeStartData.substr(0,4);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -908,7 +1071,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeStartData.substr(4,2);
+ eventString = eventData.dateTimeStartData.substr(4,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -921,7 +1084,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeStartData.substr(6,2);
+ eventString = eventData.dateTimeStartData.substr(6,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -934,7 +1097,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeStartData.substr(9,2);
+ eventString = eventData.dateTimeStartData.substr(9,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -947,7 +1110,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeStartData.substr(11,2);
+ eventString = eventData.dateTimeStartData.substr(11,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -960,7 +1123,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeStartData.substr(13,2);
+ eventString = eventData.dateTimeStartData.substr(13,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -985,16 +1148,16 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
int eventEndSecond = 0;
int eventEndDuration = 0;
- if (eventData.DateTimeEndData != ""){
+ if (eventData.dateTimeEndData != ""){
- if (eventData.DateTimeEndData.size() < 16){
+ if (eventData.dateTimeEndData.size() < 16){
addResult.addEventResult = CDSENTRY_INVALIDFILE;
return addResult;
}
- eventString = eventData.DateTimeEndData.substr(0,4);
+ eventString = eventData.dateTimeEndData.substr(0,4);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1007,7 +1170,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeEndData.substr(4,2);
+ eventString = eventData.dateTimeEndData.substr(4,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1020,7 +1183,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeEndData.substr(6,2);
+ eventString = eventData.dateTimeEndData.substr(6,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1033,7 +1196,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeEndData.substr(9,2);
+ eventString = eventData.dateTimeEndData.substr(9,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1046,7 +1209,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeEndData.substr(11,2);
+ eventString = eventData.dateTimeEndData.substr(11,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1059,7 +1222,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DateTimeEndData.substr(13,2);
+ eventString = eventData.dateTimeEndData.substr(13,2);
if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
@@ -1074,7 +1237,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
- eventString = eventData.DurationData;
+ eventString = eventData.durationData;
// Process the duration data.
@@ -1086,22 +1249,22 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
// Get the duration (if DTEND hasn't been specified).
- if (eventData.DurationData.size() > 0){
+ if (eventData.durationData.size() > 0){
bool FoundP = false;
bool FoundW = false;
bool DateTimeMode = false;
- std::string::iterator eventDataChar = eventData.DurationData.begin();
+ std::string::iterator eventDataChar = eventData.durationData.begin();
std::string currentValue = "";
if (*eventDataChar != 'P'){
- eventDataChar = eventData.DurationData.end();
+ eventDataChar = eventData.durationData.end();
}
- for(eventDataChar; eventDataChar != eventData.DurationData.end(); eventDataChar++){
+ for(eventDataChar; eventDataChar != eventData.durationData.end(); eventDataChar++){
// Check if value is a digit.
@@ -1154,9 +1317,10 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
std::string sqlParameter = "INSERT INTO calendarentries (calendarid, entryname, entrydescription,"
" entrystartyear, entrystartmonth, entrystartday, entrystarthour, entrystartminute, entrystartsecond,"
" entryendyear, entryendmonth, entryendday, entryendhour, entryendminute, entryendsecond, "
- " entrydurationweek, entrydurationday, entrydurationhour, entrydurationminute, entrydurationsecond)"
+ " entrydurationweek, entrydurationday, entrydurationhour, entrydurationminute, entrydurationsecond, "
+ " filename)"
" VALUES ((?1), (?2), (?3), (?4), (?5), (?6), (?7), (?8), (?9), (?10), "
- " (?11), (?12), (?13), (?14), (?15), (?16), (?17), (?18), (?19), (?20))";
+ " (?11), (?12), (?13), (?14), (?15), (?16), (?17), (?18), (?19), (?20), (?21))";
resultCode = sqlite3_prepare_v2(db, sqlParameter.c_str(), -1, &statementHandle, nullptr);
@@ -1169,7 +1333,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
// Process Entry Name.
- resultCode = sqlite3_bind_text(statementHandle, 2, eventData.SummaryData.c_str(), -1, SQLITE_STATIC);
+ resultCode = sqlite3_bind_text(statementHandle, 2, eventData.summaryData.c_str(), -1, SQLITE_STATIC);
if (resultCode != 0){
addResult.addEventResult = CDSENTRY_FAILED;
@@ -1181,7 +1345,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
string eventDescription;
try {
- eventDescription = eventData.DescriptionList.at(0);
+ eventDescription = eventData.descriptionList.at(0);
}
catch (out_of_range &err){
@@ -1318,6 +1482,13 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
return addResult;
}
+ resultCode = sqlite3_bind_text(statementHandle, 21, filename.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ addResult.addEventResult = CDSENTRY_FAILED;
+ return addResult;
+ }
+
resultCode = sqlite3_step(statementHandle);
if (resultCode != SQLITE_DONE){
@@ -1336,30 +1507,54 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
}
-CDSGetCalendarEntryInfo CalendarDataStorage::GetEvent(int calendarEntryID)
+CDSEditEntryResult CalendarDataStorage::UpdateEvent(int eventID, std::string filename)
{
- CDSGetCalendarEntryInfo entryResult;
+ CDSEditEntryResult editResult;
+ editResult.editEventResult = CDSENTRY_UNITTESTFAIL;
- // Check if the calendar entry exists.
+ // Load the event file.
+
+ CalendarEventObject eventData;
+ CalendarObjectLoadResult eventLoadResult = eventData.LoadFile(filename);
+
+ // Check the result of the event file load.
+
+ switch (eventLoadResult){
+
+ case CALENDAROBJECTLOAD_OK:
+ break;
+ case CALENDAROBJECTLOAD_MISSING:
+ editResult.editEventResult = CDSENTRY_MISSINGFILE;
+ return editResult;
+ case CALENDAROBJECTLOAD_INVALIDFORMAT:
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+ case CALENDAROBJECTLOAD_CANNOTOPEN:
+ editResult.editEventResult = CDSENTRY_CANNOTOPENFILE;
+ return editResult;
+
+ }
+
+ // Check if event exists first.
int resultCode;
sqlite3_stmt *findHandle;
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "SELECT id FROM calendarentries WHERE id=(?1);", -1, &findHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "SELECT id from calendarentries WHERE id=(?1);", -1, &findHandle, nullptr);
if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
}
- resultCode = sqlite3_bind_int(findHandle, 1, calendarEntryID);
+ resultCode = sqlite3_bind_int(findHandle, 1, eventID);
if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
}
resultCode = sqlite3_step(findHandle);
@@ -1367,96 +1562,601 @@ CDSGetCalendarEntryInfo CalendarDataStorage::GetEvent(int calendarEntryID)
if (resultCode == SQLITE_ROW){
} else if (resultCode == SQLITE_DONE) {
- entryResult.getEventResult = CDSENTRY_NOENTRY;
- return entryResult;
+ editResult.editEventResult = CDSENTRY_NOENTRY;
+ return editResult;
} else {
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
}
- // Get the calendar entry data.
+ // Get the required values from the event object.
- std::string sqlParameter = "SELECT entryname, entrydescription,"
- " entrystartyear, entrystartmonth, entrystartday, entrystarthour, entrystartminute, entrystartsecond,"
- " entryendyear, entryendmonth, entryendday, entryendhour, entryendminute, entryendsecond, "
- " entrydurationweek, entrydurationday, entrydurationhour, entrydurationminute, entrydurationsecond, "
- " calendarid, id"
- " FROM calendarentries WHERE id=(?1)";
+ int eventStartYear = 0;
+ int eventStartMonth = 0;
+ int eventStartDay = 0;
+ int eventStartHour = 0;
+ int eventStartMinute = 0;
+ int eventStartSecond = 0;
+ int eventStartDuration = 0;
+ std::string eventString = "";
- resultCode = sqlite3_prepare_v2(db, sqlParameter.c_str(), -1, &statementHandle, nullptr);
-
- if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ // Start Date.
+
+ if (eventData.dateTimeStartData.size() < 16){
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- resultCode = sqlite3_bind_int(statementHandle, 1, calendarEntryID);
+ eventString = eventData.dateTimeStartData.substr(0,4);
- if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartYear = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
+
+ eventString = eventData.dateTimeStartData.substr(4,2);
- resultCode = sqlite3_step(statementHandle);
-
- if (resultCode == SQLITE_ROW){
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
- // Get the calendar entry name,
+ eventStartMonth = atoi(eventString.c_str());
- stringstream entryStream;
+ } else {
- entryStream << sqlite3_column_text(statementHandle, 0);
- entryResult.entryName = entryStream.str();
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
- entryStream.str("");
+ }
+
+ eventString = eventData.dateTimeStartData.substr(6,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
- // Get the calendar entry description.
+ eventStartDay = atoi(eventString.c_str());
- entryStream << sqlite3_column_text(statementHandle, 1);
- entryResult.entryDescription = entryStream.str();
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
- entryStream.str("");
+ eventString = eventData.dateTimeStartData.substr(9,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
- entryResult.entryStartYear = sqlite3_column_int(statementHandle, 2);
- entryResult.entryStartMonth = sqlite3_column_int(statementHandle, 3);
- entryResult.entryStartDay = sqlite3_column_int(statementHandle, 4);
- entryResult.entryStartHour = sqlite3_column_int(statementHandle, 5);
- entryResult.entryStartMinute = sqlite3_column_int(statementHandle, 6);
- entryResult.entryStartSecond = sqlite3_column_int(statementHandle, 7);
- entryResult.entryEndYear = sqlite3_column_int(statementHandle, 8);
- entryResult.entryEndMonth = sqlite3_column_int(statementHandle, 9);
- entryResult.entryEndDay = sqlite3_column_int(statementHandle, 10);
- entryResult.entryEndHour = sqlite3_column_int(statementHandle, 11);
- entryResult.entryEndMinute = sqlite3_column_int(statementHandle, 12);
- entryResult.entryEndSecond = sqlite3_column_int(statementHandle, 13);
- entryResult.entryDurationWeeks = sqlite3_column_int(statementHandle, 14);
- entryResult.entryDurationDays = sqlite3_column_int(statementHandle, 15);
- entryResult.entryDurationHours = sqlite3_column_int(statementHandle, 16);
- entryResult.entryDurationMinutes = sqlite3_column_int(statementHandle, 17);
- entryResult.entryDurationSeconds = sqlite3_column_int(statementHandle, 18);
- entryResult.calendarID = sqlite3_column_int(statementHandle, 19);
- entryResult.calendarEntryID = sqlite3_column_int(statementHandle, 20);
+ eventStartHour = atoi(eventString.c_str());
- } else if (resultCode == SQLITE_DONE) {
- entryResult.getEventResult = CDSENTRY_NOCALENDAR;
- return entryResult;
} else {
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- entryResult.getEventResult = CDSENTRY_OK;
-
- return entryResult;
-
-}
-
-CDSEntryResult CalendarDataStorage::DeleteEvent(int calendarEntryID)
-{
+ eventString = eventData.dateTimeStartData.substr(11,2);
- CDSEntryResult deleteResult = CDSENTRY_UNITTESTFAIL;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartMinute = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
- // Check if the calendar entry exists.
+ eventString = eventData.dateTimeStartData.substr(13,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartSecond = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ //eventYear = eventStartDate.substr(0, 4);
+
+ // End Date.
+
+ int eventEndYear = 0;
+ int eventEndMonth = 0;
+ int eventEndDay = 0;
+ int eventEndHour = 0;
+ int eventEndMinute = 0;
+ int eventEndSecond = 0;
+ int eventEndDuration = 0;
+
+ if (eventData.dateTimeEndData != ""){
+
+ if (eventData.dateTimeEndData.size() < 16){
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(0,4);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndYear = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(4,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndMonth = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(6,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndDay = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(9,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndHour = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(11,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndMinute = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ eventString = eventData.dateTimeEndData.substr(13,2);
+
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventEndSecond = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
+ }
+
+ }
+
+ eventString = eventData.durationData;
+
+ // Process the duration data.
+
+ int eventDurationWeeks = 0;
+ int eventDurationDays = 0;
+ int eventDurationHours = 0;
+ int eventDurationMinutes = 0;
+ int eventDurationSeconds = 0;
+
+ // Get the duration (if DTEND hasn't been specified).
+
+ if (eventData.durationData.size() > 0){
+
+ bool FoundP = false;
+ bool FoundW = false;
+ bool DateTimeMode = false;
+
+ std::string::iterator eventDataChar = eventData.durationData.begin();
+ std::string currentValue = "";
+
+ if (*eventDataChar != 'P'){
+
+ eventDataChar = eventData.durationData.end();
+
+ }
+
+ for(eventDataChar; eventDataChar != eventData.durationData.end(); eventDataChar++){
+
+ // Check if value is a digit.
+
+ if (isdigit(*eventDataChar)){
+
+ currentValue += *eventDataChar;
+
+ } else {
+
+ // Check that the value matches one of the letters.
+
+ if (*eventDataChar == 'W' && DateTimeMode == false){
+
+ eventDurationWeeks = atoi(currentValue.c_str());
+
+ } else if (*eventDataChar == 'D' && DateTimeMode == false){
+
+ eventDurationDays = atoi(currentValue.c_str());
+
+ } else if (*eventDataChar == 'T' && DateTimeMode == false){
+
+ DateTimeMode = true;
+
+ } else if (*eventDataChar == 'H'){
+
+ eventDurationHours = atoi(currentValue.c_str());
+
+ } else if (*eventDataChar == 'M'){
+
+ eventDurationMinutes = atoi(currentValue.c_str());
+
+ } else if (*eventDataChar == 'S'){
+
+ eventDurationSeconds = atoi(currentValue.c_str());
+
+ }
+
+ // Reset the current value.
+
+ currentValue = "";
+
+ }
+
+ }
+
+ }
+
+ // Add the calendar entry.
+
+ std::string sqlParameter = "UPDATE calendarentries SET entryname=(?2), entrydescription=(?3),"
+ " entrystartyear=(?4), entrystartmonth=(?5), entrystartday=(?6), entrystarthour=(?7), entrystartminute=(?8), entrystartsecond=(?9),"
+ " entryendyear=(?10), entryendmonth=(?11), entryendday=(?12), entryendhour=(?13), entryendminute=(?14), entryendsecond=(?15), "
+ " entrydurationweek=(?16), entrydurationday=(?17), entrydurationhour=(?18), entrydurationminute=(?19), entrydurationsecond=(?20) "
+ " WHERE id=(?1)";
+
+ resultCode = sqlite3_prepare_v2(db, sqlParameter.c_str(), -1, &statementHandle, nullptr);
+
+ resultCode = sqlite3_bind_int(statementHandle, 1, eventID);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ // Process Entry Name.
+
+ resultCode = sqlite3_bind_text(statementHandle, 2, eventData.summaryData.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ // Process Entry Description.
+
+ string eventDescription;
+
+ try {
+ eventDescription = eventData.descriptionList.at(0);
+ }
+
+ catch (out_of_range &err){
+ eventDescription = "";
+ }
+
+ resultCode = sqlite3_bind_text(statementHandle, 3, eventDescription.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ // Process Entry Start Date information.
+
+ resultCode = sqlite3_bind_int(statementHandle, 4, eventStartYear);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 5, eventStartMonth);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 6, eventStartDay);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 7, eventStartHour);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 8, eventStartMinute);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 9, eventStartSecond);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ // Process Entry Start End information.
+
+ resultCode = sqlite3_bind_int(statementHandle, 10, eventEndYear);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 11, eventEndMonth);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 12, eventEndDay);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 13, eventEndHour);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 14, eventEndMinute);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 15, eventEndSecond);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 16, eventDurationWeeks);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 17, eventDurationDays);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 18, eventDurationHours);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 19, eventDurationMinutes);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 20, eventDurationSeconds);
+
+ if (resultCode != 0){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ editResult.editEventResult = CDSENTRY_FAILED;
+ return editResult;
+ }
+
+ editResult.calendarEntryID = sqlite3_last_insert_rowid(db);
+ editResult.editEventResult = CDSENTRY_OK;
+
+ // Update the checksum.
+
+ UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+
+ return editResult;
+
+}
+
+CDSGetCalendarEntryInfo CalendarDataStorage::GetEvent(int calendarEntryID)
+{
+
+ CDSGetCalendarEntryInfo entryResult;
+
+ // Check if the calendar entry exists.
+
+ int resultCode;
+
+ sqlite3_stmt *findHandle;
+ sqlite3_stmt *statementHandle;
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT id FROM calendarentries WHERE id=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ resultCode = sqlite3_bind_int(findHandle, 1, calendarEntryID);
+
+ if (resultCode != 0){
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode == SQLITE_ROW){
+
+ } else if (resultCode == SQLITE_DONE) {
+ entryResult.getEventResult = CDSENTRY_NOENTRY;
+ return entryResult;
+ } else {
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ // Get the calendar entry data.
+
+ std::string sqlParameter = "SELECT entryname, entrydescription,"
+ " entrystartyear, entrystartmonth, entrystartday, entrystarthour, entrystartminute, entrystartsecond,"
+ " entryendyear, entryendmonth, entryendday, entryendhour, entryendminute, entryendsecond, "
+ " entrydurationweek, entrydurationday, entrydurationhour, entrydurationminute, entrydurationsecond, "
+ " calendarid, id, filename"
+ " FROM calendarentries WHERE id=(?1)";
+
+ resultCode = sqlite3_prepare_v2(db, sqlParameter.c_str(), -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 1, calendarEntryID);
+
+ if (resultCode != 0){
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode == SQLITE_ROW){
+
+ // Get the calendar entry name,
+
+ stringstream entryStream;
+
+ entryStream << sqlite3_column_text(statementHandle, 0);
+ entryResult.entryName = entryStream.str();
+
+ entryStream.str("");
+
+ // Get the calendar entry description.
+
+ entryStream << sqlite3_column_text(statementHandle, 1);
+ entryResult.entryDescription = entryStream.str();
+
+ entryStream.str("");
+
+ // Get the calendar entry filename.
+
+ entryStream << sqlite3_column_text(statementHandle, 21);
+ entryResult.entryFilename = entryStream.str();
+
+ entryStream.str("");
+
+ entryResult.entryStartYear = sqlite3_column_int(statementHandle, 2);
+ entryResult.entryStartMonth = sqlite3_column_int(statementHandle, 3);
+ entryResult.entryStartDay = sqlite3_column_int(statementHandle, 4);
+ entryResult.entryStartHour = sqlite3_column_int(statementHandle, 5);
+ entryResult.entryStartMinute = sqlite3_column_int(statementHandle, 6);
+ entryResult.entryStartSecond = sqlite3_column_int(statementHandle, 7);
+ entryResult.entryEndYear = sqlite3_column_int(statementHandle, 8);
+ entryResult.entryEndMonth = sqlite3_column_int(statementHandle, 9);
+ entryResult.entryEndDay = sqlite3_column_int(statementHandle, 10);
+ entryResult.entryEndHour = sqlite3_column_int(statementHandle, 11);
+ entryResult.entryEndMinute = sqlite3_column_int(statementHandle, 12);
+ entryResult.entryEndSecond = sqlite3_column_int(statementHandle, 13);
+ entryResult.entryDurationWeeks = sqlite3_column_int(statementHandle, 14);
+ entryResult.entryDurationDays = sqlite3_column_int(statementHandle, 15);
+ entryResult.entryDurationHours = sqlite3_column_int(statementHandle, 16);
+ entryResult.entryDurationMinutes = sqlite3_column_int(statementHandle, 17);
+ entryResult.entryDurationSeconds = sqlite3_column_int(statementHandle, 18);
+ entryResult.calendarID = sqlite3_column_int(statementHandle, 19);
+ entryResult.calendarEntryID = sqlite3_column_int(statementHandle, 20);
+
+ } else if (resultCode == SQLITE_DONE) {
+ entryResult.getEventResult = CDSENTRY_NOCALENDAR;
+ return entryResult;
+ } else {
+ entryResult.getEventResult = CDSENTRY_FAILED;
+ return entryResult;
+ }
+
+ entryResult.getEventResult = CDSENTRY_OK;
+
+ return entryResult;
+
+}
+
+CDSEntryResult CalendarDataStorage::DeleteEvent(int calendarEntryID)
+{
+
+ CDSEntryResult deleteResult = CDSENTRY_UNITTESTFAIL;
+
+ // Check if the calendar entry exists.
int resultCode;
@@ -1909,4 +2609,91 @@ CDSChecksumResult CalendarDataStorage::UpdateChecksum(std::string checksumName,
return CDSCHECKSUM_OK;
+}
+
+CDSCleanupResult CalendarDataStorage::Clear(){
+
+ // Remove all data from the tables and reset the sequence numbers.
+
+ int resultCode;
+ sqlite3_stmt *statementHandle;
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM calendarentries", - 1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='calendarentries';", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM calendars", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='calendars';", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM accounts", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='accounts'", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCLEANUP_FAILED;
+ }
+
+ // Update the checksum.
+
+ UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+
+ return CDSCLEANUP_OK;
+
}
\ No newline at end of file