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:
committed by
Torsten (PC)
parent
4bafc3a61c
commit
8d3e0423e7
@@ -78,9 +78,39 @@ Database::FieldList Database::execute(const std::string& stmtName,
|
|||||||
if (params.empty()) {
|
if (params.empty()) {
|
||||||
res = txn.exec_prepared(stmtName);
|
res = txn.exec_prepared(stmtName);
|
||||||
} else {
|
} else {
|
||||||
pqxx::params p;
|
// Kompatibilität für libpqxx 6.x (Ubuntu 22) und 7.x (OpenSUSE Tumbleweed)
|
||||||
for (const auto& v : params) p.append(v);
|
#if PQXX_VERSION_MAJOR >= 7
|
||||||
res = txn.exec_prepared(stmtName, p);
|
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;
|
FieldList out;
|
||||||
|
|||||||
89
upgrade-libpqxx-ubuntu22.sh
Executable file
89
upgrade-libpqxx-ubuntu22.sh
Executable file
@@ -0,0 +1,89 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Upgrade libpqxx to version 7.x on Ubuntu 22
|
||||||
|
# Führen Sie dieses Script auf dem Ubuntu 22 Server aus
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Farben
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||||
|
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||||
|
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
||||||
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||||
|
|
||||||
|
log_info "Upgrade libpqxx auf Ubuntu 22 für bessere C++23 Kompatibilität..."
|
||||||
|
|
||||||
|
# Prüfe aktuelle Version
|
||||||
|
log_info "Aktuelle libpqxx Version:"
|
||||||
|
dpkg -l | grep libpqxx || log_info "libpqxx nicht installiert"
|
||||||
|
|
||||||
|
# Installiere Build-Dependencies
|
||||||
|
log_info "Installiere Build-Dependencies..."
|
||||||
|
apt update
|
||||||
|
apt install -y \
|
||||||
|
build-essential \
|
||||||
|
cmake \
|
||||||
|
pkg-config \
|
||||||
|
git \
|
||||||
|
libpq-dev \
|
||||||
|
postgresql-server-dev-14
|
||||||
|
|
||||||
|
# Lade libpqxx 7.x herunter und kompiliere
|
||||||
|
log_info "Lade libpqxx 7.x herunter..."
|
||||||
|
cd /tmp
|
||||||
|
if [ -d "libpqxx" ]; then
|
||||||
|
rm -rf libpqxx
|
||||||
|
fi
|
||||||
|
|
||||||
|
git clone https://github.com/jtv/libpqxx.git
|
||||||
|
cd libpqxx
|
||||||
|
|
||||||
|
# Checkout Version 7.9.2 (stabile Version)
|
||||||
|
git checkout 7.9.2
|
||||||
|
|
||||||
|
# Kompiliere und installiere
|
||||||
|
log_info "Kompiliere libpqxx 7.x..."
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
|
||||||
|
make -j$(nproc)
|
||||||
|
make install
|
||||||
|
|
||||||
|
# Update library cache
|
||||||
|
ldconfig
|
||||||
|
|
||||||
|
log_success "libpqxx 7.x erfolgreich installiert!"
|
||||||
|
|
||||||
|
# Prüfe neue Version
|
||||||
|
log_info "Neue libpqxx Version:"
|
||||||
|
pkg-config --modversion libpqxx
|
||||||
|
|
||||||
|
log_info "Teste Kompilierung..."
|
||||||
|
cat > /tmp/test_pqxx.cpp << 'EOF'
|
||||||
|
#include <pqxx/pqxx>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << "libpqxx Version: " << PQXX_VERSION << std::endl;
|
||||||
|
std::cout << "Major Version: " << PQXX_VERSION_MAJOR << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if g++ -o /tmp/test_pqxx /tmp/test_pqxx.cpp -lpqxx -lpq; then
|
||||||
|
log_success "Kompilierung erfolgreich!"
|
||||||
|
/tmp/test_pqxx
|
||||||
|
rm -f /tmp/test_pqxx /tmp/test_pqxx.cpp
|
||||||
|
else
|
||||||
|
log_error "Kompilierung fehlgeschlagen!"
|
||||||
|
rm -f /tmp/test_pqxx /tmp/test_pqxx.cpp
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_success "libpqxx Upgrade abgeschlossen!"
|
||||||
|
log_info "Sie können jetzt das Projekt mit der neuesten libpqxx Version kompilieren."
|
||||||
Reference in New Issue
Block a user