// 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"
");";
// 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);
// 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"
", entrydurationhour INTEGER"
", entrydurationminute INTEGER"
", entrydurationsecond INTEGER"
+ ", filename TEXT"
");";
resultCode = sqlite3_exec(db, calendarentriesTableString, callback, nullptr, &setupTablesErrMsg);
}
-CDSAccountResult CalendarDataStorage::AddAccount(string accountName)
+CDSAccountResult CalendarDataStorage::AddAccount(string accountName, int accountPreferencesID)
{
CDSAccountResult addResult = CDSACCOUNT_UNITTESTFAIL;
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "INSERT INTO accounts (name) VALUES(?1);", -1, &statementHandle, nullptr);
+ resultCode = sqlite3_prepare_v2(db, "INSERT INTO accounts (name, preferencesid) VALUES(?1, ?2);", -1, &statementHandle, nullptr);
if (resultCode != 0){
return CDSACCOUNT_FAILED;
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;
}
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;
CDSGetAccountInfo accountInfo;
accountInfo.accountID = sqlite3_column_int(statementHandle, 0);
+ accountInfo.accountPreferencesID = sqlite3_column_int(statementHandle, 2);
stringstream calendarStream;
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;
accountInfo.accountName = accountNameStream.str();
accountInfo.accountID = sqlite3_column_int(statementHandle, 1);
+ accountInfo.accountPreferencesID = sqlite3_column_int(statementHandle, 2);
accountInfo.accountInfoResult = CDSACCOUNT_OK;
return accountInfo;
}
-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;
sqlite3_stmt *statementHandle;
- resultCode = sqlite3_prepare_v2(db, "INSERT INTO calendars (name, calendarid, accountid, colour) VALUES(?1, ?2, ?3, ?4);", -1, &statementHandle, nullptr);
+ 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;
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;
}
// 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;
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;
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;
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;
}
-CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName)
+CDSCalendarResult CalendarDataStorage::UpdateCalendar(int calendarID, string calendarName, Colour calendarColour, std::string calendarDescription)
{
CDSCalendarResult updateResult = CDSCALENDAR_UNITTESTFAIL;
// 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;
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;
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);
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){
}
-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);
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.
-
- 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)";
+ // Get the required values from the event object.
- resultCode = sqlite3_prepare_v2(db, sqlParameter.c_str(), -1, &statementHandle, nullptr);
-
- if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
- }
+ 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_bind_int(statementHandle, 1, calendarEntryID);
+ // Start Date.
- if (resultCode != 0){
- entryResult.getEventResult = CDSENTRY_FAILED;
- return entryResult;
+ if (eventData.DateTimeStartData.size() < 16){
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- resultCode = sqlite3_step(statementHandle);
+ eventString = eventData.DateTimeStartData.substr(0,4);
- if (resultCode == SQLITE_ROW){
-
- // Get the calendar entry name,
-
- stringstream entryStream;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
- entryStream << sqlite3_column_text(statementHandle, 0);
- entryResult.entryName = entryStream.str();
+ eventStartYear = atoi(eventString.c_str());
- entryStream.str("");
+ } else {
- // Get the calendar entry description.
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
- entryStream << sqlite3_column_text(statementHandle, 1);
- entryResult.entryDescription = entryStream.str();
+ }
- entryStream.str("");
+ eventString = eventData.DateTimeStartData.substr(4,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);
+ eventStartMonth = atoi(eventString.c_str());
- } 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;
-
- sqlite3_stmt *findHandle;
- sqlite3_stmt *statementHandle;
-
- resultCode = sqlite3_prepare_v2(db, "SELECT id FROM calendarentries WHERE id=(?1);", -1, &findHandle, nullptr);
-
- if (resultCode != 0){
- return CDSENTRY_FAILED;
- }
-
- resultCode = sqlite3_bind_int(findHandle, 1, calendarEntryID);
-
- if (resultCode != 0){
- return CDSENTRY_FAILED;
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- resultCode = sqlite3_step(findHandle);
+ eventString = eventData.DateTimeStartData.substr(6,2);
- if (resultCode == SQLITE_ROW){
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartDay = atoi(eventString.c_str());
- } else if (resultCode == SQLITE_DONE) {
- return CDSENTRY_NOENTRY;
} else {
- return CDSENTRY_FAILED;
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- // Delete the account.
-
- resultCode = sqlite3_prepare_v2(db, "DELETE FROM calendarentries WHERE id=(?1);", -1, &statementHandle, nullptr);
+ eventString = eventData.DateTimeStartData.substr(9,2);
- if (resultCode != 0){
- return CDSENTRY_FAILED;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartHour = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- resultCode = sqlite3_bind_int(statementHandle, 1, calendarEntryID);
+ eventString = eventData.DateTimeStartData.substr(11,2);
- if (resultCode != 0){
- return CDSENTRY_FAILED;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartMinute = atoi(eventString.c_str());
+
+ } else {
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- resultCode = sqlite3_step(statementHandle);
+ eventString = eventData.DateTimeStartData.substr(13,2);
- if (resultCode == SQLITE_DONE){
- deleteResult = CDSENTRY_OK;
+ if (all_of(eventString.begin(), eventString.end(), ::isdigit)){
+
+ eventStartSecond = atoi(eventString.c_str());
+
} else {
- return CDSENTRY_FAILED;
+
+ editResult.editEventResult = CDSENTRY_INVALIDFILE;
+ return editResult;
+
}
- // Update the checksum.
-
- UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+ //eventYear = eventStartDate.substr(0, 4);
- return deleteResult;
+ // End Date.
-}
-
-CDSEntryList CalendarDataStorage::GetEventList(int calendarID){
+ int eventEndYear = 0;
+ int eventEndMonth = 0;
+ int eventEndDay = 0;
+ int eventEndHour = 0;
+ int eventEndMinute = 0;
+ int eventEndSecond = 0;
+ int eventEndDuration = 0;
- CDSEntryList entryList;
- entryList.getEventListResult = CDSENTRY_UNITTESTFAIL;
+ 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;
+
+ sqlite3_stmt *findHandle;
+ sqlite3_stmt *statementHandle;
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT id FROM calendarentries WHERE id=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSENTRY_FAILED;
+ }
+
+ resultCode = sqlite3_bind_int(findHandle, 1, calendarEntryID);
+
+ if (resultCode != 0){
+ return CDSENTRY_FAILED;
+ }
+
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode == SQLITE_ROW){
+
+ } else if (resultCode == SQLITE_DONE) {
+ return CDSENTRY_NOENTRY;
+ } else {
+ return CDSENTRY_FAILED;
+ }
+
+ // Delete the account.
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM calendarentries WHERE id=(?1);", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSENTRY_FAILED;
+ }
+
+ resultCode = sqlite3_bind_int(statementHandle, 1, calendarEntryID);
+
+ if (resultCode != 0){
+ return CDSENTRY_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode == SQLITE_DONE){
+ deleteResult = CDSENTRY_OK;
+ } else {
+ return CDSENTRY_FAILED;
+ }
+
+ // Update the checksum.
+
+ UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+
+ return deleteResult;
+
+}
+
+CDSEntryList CalendarDataStorage::GetEventList(int calendarID){
+
+ CDSEntryList entryList;
+ entryList.getEventListResult = CDSENTRY_UNITTESTFAIL;
// Check if calendar exists first.
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){
+ cout << "Fail 1" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 2" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='calendarentries';", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ cout << "Fail 3" << endl;
+ cout << sqlite3_errmsg(db) << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 4" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM calendars", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ cout << "Fail 5" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 6" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='calendars';", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ cout << "Fail 7" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 8" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM accounts", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ cout << "Fail 9" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 10" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_prepare_v2(db, "DELETE FROM sqlite_sequence WHERE name='accounts'", -1, &statementHandle, nullptr);
+
+ if (resultCode != 0){
+ cout << "Fail 11" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ resultCode = sqlite3_step(statementHandle);
+
+ if (resultCode != SQLITE_DONE){
+ cout << "Fail 12" << endl;
+ return CDSCLEANUP_FAILED;
+ }
+
+ // Update the checksum.
+
+ UpdateChecksum("internal_updatedata", to_string(GenerateRandomNumber(CDS_RANDOMPOW)));
+
+ return CDSCLEANUP_OK;
+
}
\ No newline at end of file