stabilized app
This commit is contained in:
committed by
Torsten (PC)
parent
51fd9fcd13
commit
1451225978
@@ -1,4 +1,9 @@
|
||||
#include "database.h"
|
||||
#include <pqxx/pqxx>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
Database::Database(const std::string &conninfo)
|
||||
{
|
||||
@@ -9,7 +14,9 @@ Database::Database(const std::string &conninfo)
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "[Database] Fehler beim Verbinden: " << e.what() << std::endl;
|
||||
throw;
|
||||
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,32 +55,16 @@ void Database::prepare(const std::string &stmtName, const std::string &sql)
|
||||
}
|
||||
}
|
||||
|
||||
#include <pqxx/pqxx>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
std::vector<std::unordered_map<std::string, std::string>>
|
||||
Database::execute(const std::string &stmtName, const std::vector<std::string> ¶ms)
|
||||
{
|
||||
Database::FieldList Database::execute(const std::string &stmtName, const std::vector<std::string> ¶ms) {
|
||||
std::vector<std::unordered_map<std::string, std::string>> rows;
|
||||
|
||||
try {
|
||||
pqxx::work txn(*connection_);
|
||||
pqxx::prepare::invocation inv = txn.prepared(stmtName);
|
||||
|
||||
// Parameter einzeln hinzufügen
|
||||
for (auto &p : params) {
|
||||
inv(p);
|
||||
}
|
||||
|
||||
// Ausführung
|
||||
pqxx::result r = inv.exec();
|
||||
txn.commit();
|
||||
|
||||
// Ergebnis verarbeiten
|
||||
for (const auto &row : r) {
|
||||
std::unordered_map<std::string, std::string> mapRow;
|
||||
for (pqxx::row::size_type i = 0; i < row.size(); ++i) {
|
||||
@@ -91,6 +82,12 @@ Database::execute(const std::string &stmtName, const std::vector<std::string> &p
|
||||
return rows;
|
||||
}
|
||||
|
||||
void Database::remove(const std::string &stmtName) {
|
||||
pqxx::work txn(*connection_);
|
||||
txn.conn().unprepare(stmtName);
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
bool Database::isValid() const {
|
||||
try {
|
||||
if (!connection_ || !connection_->is_open()) {
|
||||
|
||||
Reference in New Issue
Block a user