# HG changeset patch
# User Jasper Lievisse Adriaanse <jasper@humppa.nl>
# Date 1502297009 -7200
#      Wed Aug 09 18:43:29 2017 +0200
# Branch postgres_uri
# Node ID 7a6222070e5427a5a5ad6d052b49538da10b3a13
# Parent  cdc12000160c77940617eb9a6ea26c2891fbb618
Allow to connect to postgres without specifying username and/or port

diff -r cdc12000160c -r 7a6222070e54 Core/PostgreSQLConnection.cpp
--- a/Core/PostgreSQLConnection.cpp	Fri Jan 06 11:03:20 2017 +0100
+++ b/Core/PostgreSQLConnection.cpp	Wed Aug 09 18:43:29 2017 +0200
@@ -80,8 +80,18 @@
   {
     if (uri_.empty())
     {
-      return ("postgresql://" + username_ + ":" + password_ + "@" + 
-              host_ + ":" + boost::lexical_cast<std::string>(port_) + "/" + database_);
+      std::string actualUri = "postgresql://" + username_;
+      if (!password_.empty())
+      {
+        actualUri += ":" + password_;
+      }
+      actualUri += "@" + host_;
+      if (port_ > 0)
+      {
+        actualUri += ":" + boost::lexical_cast<std::string>(port_);
+      }
+      actualUri += "/" + database_;
+      return actualUri;
     }
     else
     {
