]> git.donarmstrong.com Git - infobot.git/blobdiff - src/db_pgsql.pl
- basically fix up openDB to allow unix sockets. -lear.
[infobot.git] / src / db_pgsql.pl
index 7d025f9547401bdd891669fe6ea78d31362becbc..f7d91ae3016c69ae02e699ae58c636c33c6fb541 100644 (file)
@@ -7,22 +7,30 @@
 
 if (&IsParam("useStrict")) { use strict; }
 
+#####
+# openDB($dbname, $sqluser, $sqlpass, $nofail);
 sub openDB {
-    my $connectstr="dbi:Pg:dbname=$param{DBName};";
-    $connectstr.=";host=$param{SQLHost}" if(defined $param{'SQLHost'});
-    $dbh = DBI->connect($connectstr, $param{'SQLUser'}, $param{'SQLPass'});
+    my($dbname, $sqluser, $sqlpass, $nofail) = @_;
+    my $connectstr = "dbi:Pg:dbname=$dbname;";
+    my $hoststr           = "";
+    if (exists $param{'SQLHost'} and $param{'SQLHost'}) {
+       $hoststr     = " to $param{'SQLHost'}";
+       $connectstr .= ";host=$param{SQLHost}";
+    }
+    $dbh = DBI->connect($connectstr, $sqluser, $sqlpass);
 
-    if (!$dbh->err) {
-       &status("Opened pgSQL connection".
-               (exists $param{'SQLHost'} ? " to ".$param{'SQLHost'} : ""));
+    if ($dbh and !$dbh->err) {
+       &status("Opened pgSQL connection$hoststr");
     } else {
-       &ERROR("cannot connect to $param{'SQLHost'}.");
-       &ERROR("pgSQL: ".$dbh->errstr);
+       &ERROR("cannot connect$hoststr.");
+       &ERROR("pgSQL: ".$dbh->errstr) if ($dbh);
 
        &closePID();
        &closeSHM($shm);
        &closeLog();
 
+       return 0 if ($nofail);
+
        exit 1;
     }
 }