Füge UndergroundWorker hinzu und implementiere Logik für unterirdische Aufgaben. Aktualisiere CMakeLists.txt, um neue Quell- und Header-Dateien einzuschließen. Verbessere die Fehlerbehandlung in der Datenbank und sende Benachrichtigungen nach bestimmten Ereignissen. Integriere Hilfsfunktionen zur sicheren Verarbeitung von Daten.

This commit is contained in:
Torsten Schulz (local)
2025-08-31 23:11:09 +02:00
committed by Torsten (PC)
parent 1451225978
commit 23c07a3570
18 changed files with 1255 additions and 88 deletions

View File

@@ -46,6 +46,14 @@ Database::query(const std::string &sql)
void Database::prepare(const std::string &stmtName, const std::string &sql)
{
try {
// Versuche zuerst, das alte Statement zu entfernen, falls es existiert
try {
remove(stmtName);
} catch (...) {
// Ignoriere Fehler beim Entfernen - das Statement existiert möglicherweise nicht
}
// Erstelle das neue Statement
pqxx::work txn(*connection_);
txn.conn().prepare(stmtName, sql);
txn.commit();
@@ -55,31 +63,38 @@ void Database::prepare(const std::string &stmtName, const std::string &sql)
}
}
Database::FieldList Database::execute(const std::string &stmtName, const std::vector<std::string> &params) {
std::vector<std::unordered_map<std::string, std::string>> rows;
Database::FieldList Database::execute(const std::string& stmtName,
const std::vector<std::string>& params)
{
try {
pqxx::work txn(*connection_);
pqxx::prepare::invocation inv = txn.prepared(stmtName);
for (auto &p : params) {
inv(p);
}
pqxx::result r = inv.exec();
txn.commit();
for (const auto &row : r) {
std::unordered_map<std::string, std::string> mapRow;
for (pqxx::row::size_type i = 0; i < row.size(); ++i) {
std::string colName = r.column_name(i);
mapRow[colName] = row[i].c_str() ? row[i].c_str() : "";
}
rows.push_back(std::move(mapRow));
}
}
catch (const std::exception &ex) {
std::cerr << "[Database] execute-Fehler: " << ex.what()
<< "\nStatement: " << stmtName << std::endl;
}
return rows;
pqxx::result res;
if (params.empty()) {
res = txn.exec_prepared(stmtName);
} else {
pqxx::params p;
for (const auto& v : params) p.append(v);
res = txn.exec_prepared(stmtName, p);
}
FieldList out;
out.reserve(res.size());
for (const auto& row : res) {
std::unordered_map<std::string, std::string> m;
for (const auto& f : row) {
m.emplace(f.name(), f.is_null() ? std::string{} : std::string(f.c_str()));
}
out.emplace_back(std::move(m));
}
txn.commit();
return out;
} catch (const std::exception& e) {
std::cerr << "[Database] execute-Fehler: " << e.what()
<< "\n\nStatement: " << stmtName << std::endl;
return {};
}
}
void Database::remove(const std::string &stmtName) {