Füge Unterstützung für verschiedene Versionen von libpqxx hinzu, um die Kompatibilität mit libpqxx 6.x und 7.x zu gewährleisten. Implementiere unterschiedliche Methoden zur Ausführung vorbereiteter Abfragen basierend auf der Anzahl der Parameter.

This commit is contained in:
Torsten Schulz (local)
2025-08-31 23:36:06 +02:00
committed by Torsten (PC)
parent 4bafc3a61c
commit 8d3e0423e7
2 changed files with 122 additions and 3 deletions

View File

@@ -78,9 +78,39 @@ Database::FieldList Database::execute(const std::string& stmtName,
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);
// Kompatibilität für libpqxx 6.x (Ubuntu 22) und 7.x (OpenSUSE Tumbleweed)
#if PQXX_VERSION_MAJOR >= 7
pqxx::params p;
for (const auto& v : params) p.append(v);
res = txn.exec_prepared(stmtName, p);
#else
// Für libpqxx 6.x - verwende exec_params mit variadic template
if (params.size() == 0) {
res = txn.exec_prepared(stmtName);
} else if (params.size() == 1) {
res = txn.exec_prepared(stmtName, params[0]);
} else if (params.size() == 2) {
res = txn.exec_prepared(stmtName, params[0], params[1]);
} else if (params.size() == 3) {
res = txn.exec_prepared(stmtName, params[0], params[1], params[2]);
} else if (params.size() == 4) {
res = txn.exec_prepared(stmtName, params[0], params[1], params[2], params[3]);
} else if (params.size() == 5) {
res = txn.exec_prepared(stmtName, params[0], params[1], params[2], params[3], params[4]);
} else {
// Für mehr als 5 Parameter, verwende exec_params
std::string sql = "EXECUTE " + stmtName;
if (!params.empty()) {
sql += "(";
for (size_t i = 0; i < params.size(); ++i) {
if (i > 0) sql += ", ";
sql += "$" + std::to_string(i + 1);
}
sql += ")";
}
res = txn.exec_params(sql, params);
}
#endif
}
FieldList out;