1
0
Fork 0

Basic demonstrator

Works fine but can be slow, especially because of heavy IO.
This commit is contained in:
trotFunky 2021-10-03 19:42:28 +01:00
commit afe832654d
8 changed files with 414 additions and 0 deletions

56
main.cpp Normal file
View file

@ -0,0 +1,56 @@
#include <iostream>
#include <sqlite3.h>
#include <ctime>
#include "db_info.h"
#include "LicenceOperations.h"
int main()
{
char* errorMessage = nullptr;
int errorCode;
sqlite3* db = nullptr;
if (sqlite3_open(dbName.c_str(), &db)) {
std::cerr << "Error opening database : " << std::endl << sqlite3_errmsg(db) << std::endl;
sqlite3_close(db);
return -1;
}
std::time_t startTime = std::time(nullptr);
errorCode = sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, &errorMessage);
if (errorCode) {
dbError("Error while beginning transaction", errorMessage);
sqlite3_close(db);
return -1;
}
errorCode = sqlite3_exec(db, ("SELECT "
+ keyColumn + ", "
+ pointsColumn + ", "
+ countdownColumn + ", "
+ onePointCountdownColumn + ", "
+ tenYearsCountdownColumn
+ " FROM " + pointsTable
+ " WHERE " + pointsColumn + " > 0 AND " + pointsColumn + " < 12;").c_str(),
countdown, db, &errorMessage);
if (errorCode) {
dbError("Error while running coutdowns", errorMessage);
sqlite3_close(db);
return -1;
}
errorCode = sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, &errorMessage);
if (errorCode) {
dbError("Error while closing transaction", errorMessage);
sqlite3_close(db);
return -1;
}
std::cout << "Successfully updated database in " << std::time(nullptr) - startTime << "s" << std::endl;
sqlite3_close(db);
return 0;
}