56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#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;
|
|
}
|