db_bridge/postgresql_db.cpp
changeset 17 b3731a25b9ec
parent 15 5a0ca1f9a2f1
child 18 f3657061ec00
--- 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;
 }