Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Win32: implement further UTF8 support
[xestiacalendar/.git] / source / libraries / CalendarDataStorage / CalendarDataStorage.cpp
index f516df8..5b24853 100644 (file)
@@ -1,6 +1,24 @@
+// 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 <http://www.gnu.org/licenses/>
+
 #include "CalendarDataStorage.h"
 
-#include <iostream>
+#define CDS_RANDOMPOW 24
 
 using namespace std;
 
@@ -35,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"
                ");";
        
@@ -49,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);
@@ -66,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"
@@ -87,6 +107,7 @@ void CalendarDataStorage::SetupTables(){
                ", entrydurationhour INTEGER"
                ", entrydurationminute INTEGER"
                ", entrydurationsecond INTEGER"
+               ", filename TEXT"
                ");";
        
        resultCode = sqlite3_exec(db, calendarentriesTableString, callback, nullptr, &setupTablesErrMsg);
@@ -99,8 +120,8 @@ void CalendarDataStorage::SetupTables(){
        // Setup the checksums table.
        
        const char *checksumsTableString;
-       checksumsTableString = "CREATE TABLE checksums(hashname TEXT PRIMARY KEY "
-               ", hashvalue TEXT);";
+       checksumsTableString = "CREATE TABLE checksums(checksumname TEXT PRIMARY KEY "
+               ", checksumvalue TEXT);";
        
        resultCode = sqlite3_exec(db, checksumsTableString, callback, nullptr, &setupTablesErrMsg);
        
@@ -109,6 +130,15 @@ void CalendarDataStorage::SetupTables(){
                return;
        }
        
+       // Setup internal checksums.
+       
+       CDSChecksumResult addChecksum = AddChecksum("internal_updatedata", "");
+       
+       if (addChecksum != CDSCHECKSUM_OK){
+               DataStorageInitOK = false;
+               return;
+       }
+       
        DataStorageInitOK = true;
        
 }
@@ -120,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_prepare_v2(db, "INSERT INTO accounts (name) VALUES(?1);", -1, &statementHandle, nullptr);
+       resultCode = sqlite3_bind_text(findHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSACCOUNT_FAILED;
+       }
+       
+       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;
@@ -136,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;
        }
@@ -146,6 +209,10 @@ CDSAccountResult CalendarDataStorage::AddAccount(string accountName)
                return CDSACCOUNT_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        addResult = CDSACCOUNT_OK;
        
        return addResult;
@@ -163,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;
@@ -192,6 +259,7 @@ CDSAccountList CalendarDataStorage::GetAccountList()
                CDSGetAccountInfo accountInfo;
                
                accountInfo.accountID = sqlite3_column_int(statementHandle, 0);
+               accountInfo.accountPreferencesID = sqlite3_column_int(statementHandle, 2);
                
                stringstream calendarStream;
                
@@ -221,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;
@@ -252,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;
@@ -274,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);
@@ -300,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);
@@ -326,6 +424,10 @@ CDSAccountResult CalendarDataStorage::UpdateAccount(int accountID, string accoun
                return CDSACCOUNT_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        updateResult = CDSACCOUNT_OK;
        
        return updateResult;
@@ -363,7 +465,7 @@ CDSAccountResult CalendarDataStorage::DeleteAccount(int accountID)
        } else if (resultCode == SQLITE_DONE) {
                return CDSACCOUNT_NOACCOUNT;
        } else {
-               return CDSACCOUNT_FAILED;
+
        }
        
        // Delete the account.
@@ -420,6 +522,10 @@ CDSAccountResult CalendarDataStorage::DeleteAccount(int accountID)
                
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        deleteResult = CDSACCOUNT_OK;
        
        return deleteResult;
@@ -427,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;
@@ -459,7 +586,14 @@ CDSCalendarResult CalendarDataStorage::AddCalendar(int accountID, string calenda
                return CDSCALENDAR_FAILED;
        }
        
-       resultCode = sqlite3_bind_text(statementHandle, 4, ((string)calendarColour).c_str(), -1, SQLITE_STATIC);
+       string calendarColourString = (string)calendarColour;
+       resultCode = sqlite3_bind_text(statementHandle, 4, calendarColourString.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;
@@ -471,6 +605,10 @@ CDSCalendarResult CalendarDataStorage::AddCalendar(int accountID, string calenda
                return CDSCALENDAR_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        addResult = CDSCALENDAR_OK;
        
        return addResult;
@@ -508,7 +646,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;
@@ -553,8 +691,112 @@ 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;
+               return calendarResult;
+               
+       } else {
+               
+               calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
+               return calendarResult;
+               
+       }
+       
+       return calendarResult;
+       
+}
+
+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, description FROM calendars WHERE id=(?1);", -1, &statementHandle, nullptr);
+       
+       if (resultCode != 0){
+               calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
+               return calendarResult;
+       }
+
+       resultCode = sqlite3_bind_int(statementHandle, 1, calendarID);
+       
+       if (resultCode != 0){
+               calendarResult.calendarInfoResult = CDSCALENDAR_FAILED;
+               return calendarResult;
+       }
+       
+       resultCode = sqlite3_step(statementHandle);
+       
+       if (resultCode == SQLITE_DONE){
+               
+               calendarResult.calendarInfoResult = CDSCALENDAR_NOCALENDAR;
+               return calendarResult;
+               
+       } else if (resultCode == SQLITE_ROW){
+               
+               // Get the calendar data.
+               
+               stringstream calendarStream;
+               
+               calendarStream << sqlite3_column_text(statementHandle, 2);
+               calendarResult.calendarName = calendarStream.str();
+               
+               calendarStream.str("");
+               calendarStream << sqlite3_column_text(statementHandle, 3);
+               calendarResult.calendarTextID = calendarStream.str();
+
+               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;
                
@@ -569,7 +811,8 @@ CDSGetCalendarInfo CalendarDataStorage::GetCalendar(std::string accountName, std
        
 }
 
-CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName)
+
+CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName, Colour calendarColour, std::string calendarDescription)
 {
        
        CDSCalendarResult updateResult = CDSCALENDAR_UNITTESTFAIL;
@@ -604,7 +847,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;
@@ -612,11 +855,24 @@ 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;
+       }
+
+       string calendarColourString = calendarColour;
+       resultCode = sqlite3_bind_text(statementHandle, 2, calendarColourString.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;
@@ -628,6 +884,10 @@ CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string cal
                return CDSCALENDAR_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        updateResult = CDSCALENDAR_OK;
        
        return updateResult;
@@ -710,6 +970,10 @@ CDSCalendarResult CalendarDataStorage::DeleteCalendar(int calendarID)
                return CDSCALENDAR_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        return deleteResult;
        
 }
@@ -722,9 +986,9 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
        
        // Load the event file.
        
-       CalendarEventObject eventData;
+       CalendarEventObject eventData;  
        CalendarObjectLoadResult eventLoadResult = eventData.LoadFile(filename);
-       
+
        // Check the result of the event file load.
        
        switch (eventLoadResult){
@@ -789,14 +1053,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)){
                
@@ -809,7 +1073,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)){
                
@@ -822,7 +1086,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)){
                
@@ -835,7 +1099,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)){
                
@@ -848,7 +1112,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)){
                
@@ -861,7 +1125,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)){
                
@@ -886,16 +1150,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)){
                
@@ -908,7 +1172,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)){
                
@@ -921,7 +1185,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)){
                
@@ -934,7 +1198,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)){
                
@@ -947,7 +1211,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)){
                
@@ -960,7 +1224,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)){
                
@@ -975,7 +1239,7 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
                
        }
 
-       eventString = eventData.DurationData;
+       eventString = eventData.durationData;
        
        // Process the duration data.
        
@@ -987,22 +1251,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.
                        
@@ -1055,9 +1319,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);
 
@@ -1070,7 +1335,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;
@@ -1082,7 +1347,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){
@@ -1219,6 +1484,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){
@@ -1229,34 +1501,62 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file
        addResult.calendarEntryID = sqlite3_last_insert_rowid(db);
        addResult.addEventResult = CDSENTRY_OK;
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        return addResult;
        
 }
 
-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);
@@ -1264,31 +1564,530 @@ 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 "
-       " 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){
+       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);
+       
+       if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+               
+               eventStartMonth = atoi(eventString.c_str());
+               
+       } else {
+               
+               editResult.editEventResult = CDSENTRY_INVALIDFILE;
+               return editResult;
+               
+       }
+       
+       eventString = eventData.dateTimeStartData.substr(6,2);
+       
+       if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+               
+               eventStartDay = atoi(eventString.c_str());
+               
+       } else {
+               
+               editResult.editEventResult = CDSENTRY_INVALIDFILE;
+               return editResult;
+               
+       }
+
+       eventString = eventData.dateTimeStartData.substr(9,2);
+       
+       if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+               
+               eventStartHour = atoi(eventString.c_str());
+               
+       } else {
+               
+               editResult.editEventResult = CDSENTRY_INVALIDFILE;
+               return editResult;
+               
+       }
+       
+       eventString = eventData.dateTimeStartData.substr(11,2);
+       
+       if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+               
+               eventStartMinute = atoi(eventString.c_str());
+               
+       } else {
+               
+               editResult.editEventResult = CDSENTRY_INVALIDFILE;
+               return editResult;
+               
+       }
+       
+       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;
        }
@@ -1313,6 +2112,13 @@ CDSGetCalendarEntryInfo CalendarDataStorage::GetEvent(int calendarEntryID)
 
                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);
@@ -1330,6 +2136,8 @@ CDSGetCalendarEntryInfo CalendarDataStorage::GetEvent(int calendarEntryID)
                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;
@@ -1401,6 +2209,10 @@ CDSEntryResult CalendarDataStorage::DeleteEvent(int calendarEntryID)
                return CDSENTRY_FAILED;
        }
        
+       // Update the checksum.
+       
+       UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+       
        return deleteResult;    
        
 }
@@ -1483,6 +2295,71 @@ CDSEntryList CalendarDataStorage::GetEventList(int calendarID){
        
 }
 
+CDSEntryList CalendarDataStorage::GetEventListByDate(int calendarYear, int calendarMonth, int calendarDay){
+       
+       CDSEntryList entryList;
+       entryList.getEventListResult = CDSENTRY_UNITTESTFAIL;
+       
+       // Check if calendar exists first.
+       
+       int resultCode;
+
+       sqlite3_stmt *calendarHandle;
+       
+       // Get the list of entry IDs.
+
+       resultCode = sqlite3_prepare_v2(db, "SELECT id FROM calendarentries WHERE entrystartyear=(?1) AND entrystartmonth=(?2) AND entrystartday=(?3);", -1, &calendarHandle, nullptr);
+       
+       if (resultCode != 0){
+               entryList.getEventListResult = CDSENTRY_FAILED;
+               return entryList;
+       }
+       
+       resultCode = sqlite3_bind_int(calendarHandle, 1, calendarYear);
+       
+       if (resultCode != 0){
+               entryList.getEventListResult = CDSENTRY_FAILED;
+               return entryList;
+       }
+
+       resultCode = sqlite3_bind_int(calendarHandle, 2, calendarMonth);
+       
+       if (resultCode != 0){
+               entryList.getEventListResult = CDSENTRY_FAILED;
+               return entryList;
+       }
+       
+       resultCode = sqlite3_bind_int(calendarHandle, 3, calendarDay);
+       
+       if (resultCode != 0){
+               entryList.getEventListResult = CDSENTRY_FAILED;
+               return entryList;
+       }
+       
+       resultCode = sqlite3_step(calendarHandle);
+       
+       if (resultCode == SQLITE_DONE || resultCode == SQLITE_ROW){
+       } else {
+               entryList.getEventListResult = CDSENTRY_FAILED;
+               return entryList;
+       }
+       
+       while (resultCode == SQLITE_ROW){
+               
+               int calendarID = sqlite3_column_int(calendarHandle, 0);
+               
+               entryList.entryList.push_back(calendarID);
+               
+               resultCode = sqlite3_step(calendarHandle);
+               
+       }       
+       
+       entryList.getEventListResult = CDSENTRY_OK;
+       
+       return entryList;
+       
+}
+
 CDSCalendarList CalendarDataStorage::GetCalendarList(int accountID){
        
        CDSCalendarList calendarList;
@@ -1566,4 +2443,259 @@ CDSCalendarList CalendarDataStorage::GetCalendarList(int accountID){
        
        return calendarList;
        
+}
+
+CDSChecksumResult CalendarDataStorage::AddChecksum(string checksumName, string checksumValue){
+       
+       int resultCode;
+       
+       // Check if the checksum already exists.
+       
+       sqlite3_stmt *findHandle;
+       sqlite3_stmt *checksumHandle;
+       
+       resultCode = sqlite3_prepare_v2(db, "SELECT checksumvalue from checksums WHERE checksumname=(?1);", -1, &findHandle, nullptr);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(findHandle, 1, checksumName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_step(findHandle);
+       
+       if (resultCode == SQLITE_ROW){
+               return CDSCHECKSUM_CHECKSUMALREADYEXISTS;
+       } else if (resultCode == SQLITE_DONE) {
+               
+       } else {
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       // Add the checksum to the checksum table.
+       
+       resultCode = sqlite3_prepare_v2(db, "INSERT INTO checksums (checksumname, checksumvalue) VALUES(?1, ?2);", -1, &checksumHandle, nullptr);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(checksumHandle, 1, checksumName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(checksumHandle, 2, checksumValue.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_step(checksumHandle);
+       
+       if (resultCode != SQLITE_DONE){
+               return CDSCHECKSUM_FAILED;
+       }       
+       
+       return CDSCHECKSUM_OK;
+       
+}
+
+CDSGetChecksumResult CalendarDataStorage::GetChecksum(string checksumName){
+       
+       CDSGetChecksumResult getChecksumResult;
+       
+       int resultCode;
+       
+       // Check if the checksum already exists.
+       
+       sqlite3_stmt *getHandle;
+       
+       resultCode = sqlite3_prepare_v2(db, "SELECT checksumvalue from checksums WHERE checksumname=(?1);", -1, &getHandle, nullptr);
+       
+       if (resultCode != 0){
+               getChecksumResult.getChecksumResult = CDSCHECKSUM_FAILED;
+               return getChecksumResult;
+       }
+       
+       resultCode = sqlite3_bind_text(getHandle, 1, checksumName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               getChecksumResult.getChecksumResult = CDSCHECKSUM_FAILED;
+               return getChecksumResult;
+       }
+       
+       resultCode = sqlite3_step(getHandle);
+       
+       if (resultCode == SQLITE_ROW){
+       } else if (resultCode == SQLITE_DONE) {
+               getChecksumResult.getChecksumResult = CDSCHECKSUM_NOHASH;
+               return getChecksumResult;
+       } else {
+               getChecksumResult.getChecksumResult = CDSCHECKSUM_FAILED;
+               return getChecksumResult;
+       }
+       
+       stringstream checksumStream;
+               
+       checksumStream << sqlite3_column_text(getHandle, 0);
+               
+       getChecksumResult.checksumValue = checksumStream.str();
+       
+       getChecksumResult.getChecksumResult = CDSCHECKSUM_OK;
+       
+       return getChecksumResult;
+       
+}
+
+CDSChecksumResult CalendarDataStorage::UpdateChecksum(std::string checksumName, std::string checksumValue){
+       
+       int resultCode;
+       
+       // Check if the checksum already exists.
+       
+       sqlite3_stmt *getHandle;
+       sqlite3_stmt *statementHandle;
+       
+       resultCode = sqlite3_prepare_v2(db, "SELECT checksumvalue from checksums WHERE checksumname=(?1);", -1, &getHandle, nullptr);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(getHandle, 1, checksumName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_step(getHandle);
+       
+       if (resultCode == SQLITE_ROW){
+       } else if (resultCode == SQLITE_DONE) {
+               return CDSCHECKSUM_NOHASH;
+       } else {
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       // Update the checksum.
+       
+       resultCode = sqlite3_prepare_v2(db, "UPDATE checksums SET checksumvalue=(?1) WHERE checksumname=(?2);", -1, &statementHandle, nullptr);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(statementHandle, 1, checksumValue.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_bind_text(statementHandle, 2, checksumName.c_str(), -1, SQLITE_STATIC);
+       
+       if (resultCode != 0){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       resultCode = sqlite3_step(statementHandle);
+       
+       if (resultCode != SQLITE_DONE){
+               return CDSCHECKSUM_FAILED;
+       }
+       
+       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
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy