--- a/db_bridge/postgresql_db.cpp
+++ b/db_bridge/postgresql_db.cpp
@@ -8,16 +8,18 @@
PostgreSQL_DB::PostgreSQL_DB (std::string srv, std::string usr, std::string pwd, std::string db)
{
- server = (srv != "") ? "host=" + srv : "";
- user = (usr != "") ? "user=" + usr : "user=" + std::string (getenv ("USER"));
- password = (pwd != "") ? "password=" + pwd : "";
- database = "dbname=" + db;
+ server = srv;
+ user = (usr != "") ? usr : getenv ("USER");
+ password = pwd;
+ database = db;
+
+ conninfo = "user=" + user + "dbname=" + database;
if (server != "" && pwd == "") {
- std::cerr << "HBA funktioniert nur mit Passwoertern..." << std::endl;
+ std::cout << "Passwort von " << user << "@" << server << ": ";
+ std::getline (std::cin, password);
+ conninfo += " host=" + server + "password=" + password;
}
-
- conninfo = server + " " + user + " " + password + " " + database;
}
PostgreSQL_DB::~PostgreSQL_DB ()
@@ -30,12 +32,14 @@
bool PostgreSQL_DB::connect ()
{
+ std::cerr << "Verbindungsparameter:" << " host=" << ((server != "") ? server : "LOCAL")
+ << " user=" << user << " password=" << password << " database=" << database << std::endl;
+
if ((conn = PQconnectdb (conninfo.c_str ())) == NULL) {
std::cerr << server << ": " << "ERROR " << std::endl;
return false;
}
- std::cerr << "Verbindungsparameter: " << conninfo << std::endl;
return true;
}