Add proper error logging to solar-logger
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <solar/logger/database.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <util/date.hpp>
|
||||
@@ -42,12 +43,22 @@ bool Database::Insert(ZeverRow & row)
|
||||
std::stringstream transaction;
|
||||
transaction << "BEGIN TRANSACTION;" << ToSqlInsertStatement(row) << ToSqlUpsertStatement(row) << "COMMIT;";
|
||||
|
||||
return sqlite3_exec(connectionPtr, transaction.str().c_str(), nullptr, nullptr, nullptr);
|
||||
if(sqlite3_exec(connectionPtr, transaction.str().c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
||||
{
|
||||
spdlog::error("Failed to insert Zeverlution record into SQLite database: {}", sqlite3_errmsg(connectionPtr));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Database::Insert(EnvoyRow & row)
|
||||
{
|
||||
return sqlite3_exec(connectionPtr, ToSqlInsertStatement(row).c_str(), nullptr, nullptr, nullptr);
|
||||
if(sqlite3_exec(connectionPtr, ToSqlInsertStatement(row).c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
||||
{
|
||||
spdlog::error("Failed to insert Envoy record into SQLite database: {}", sqlite3_errmsg(connectionPtr));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Database::Database(std::string const & databasePath) : connectionPtr(nullptr)
|
||||
|
||||
@@ -127,10 +127,8 @@ int main(int argc, char ** argv)
|
||||
.kilowattPerHour = zeverData->kilowattPerHour,
|
||||
};
|
||||
|
||||
auto const insertionResult = db.Insert(row);
|
||||
if(insertionResult)
|
||||
if(!db.Insert(row))
|
||||
{
|
||||
spdlog::error("Error {} during insertion of new value into database", insertionResult);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -156,10 +154,8 @@ int main(int argc, char ** argv)
|
||||
.inverterTime = parsed->readingTime,
|
||||
};
|
||||
|
||||
auto const insertionResult = db.Insert(row);
|
||||
if(insertionResult)
|
||||
if(!db.Insert(row))
|
||||
{
|
||||
spdlog::error("Error {} during insertion of new value into database", insertionResult);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user