]> git.donarmstrong.com Git - infobot.git/blobdiff - src/db_pgsql.pl
allow use as a module
[infobot.git] / src / db_pgsql.pl
index e32d0b7399419866bc71bc9ed78e4124a6047c49..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;
     }
 }
@@ -282,7 +290,7 @@ sub dbReplace {
        }
        $uquery .= "$keys[-1] = $vals[-1], ";
     }
-    $uquery = ~s/, $/ $where;/;
+    $uquery =s/, $/ $where;/;
     $iquery .= "(". join(',',@keys) .") VALUES (". join(',',@vals) .");";
 
     &DEBUG($squery) if (0);
@@ -451,34 +459,6 @@ sub searchTable {
     return @results;
 }
 
-####################################################################
-##### Factoid related stuff...
-#####
-
-#####
-# Usage: &getFactInfo($faqtoid, $type);
-#  Note: getFactInfo does dbQuote
-sub getFactInfo {
-    return &dbGet("factoids", $_[1], "factoid_key=".&dbQuote($_[0]) );
-}
-
-#####
-# Usage: &getFactoid($faqtoid);
-sub getFactoid {
-    return &getFactInfo($_[0], "factoid_value");
-}
-
-#####
-# Usage: &delFactoid($faqtoid);
-sub delFactoid {
-    my ($faqtoid) = @_;
-
-    &dbDel("factoids", "factoid_key",$faqtoid);
-    &status("DELETED '$faqtoid'");
-
-    return 1;
-}
-
 #####
 #
 sub checkTables {