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;
}
}
}
$uquery .= "$keys[-1] = $vals[-1], ";
}
- $uquery = ~s/, $/ $where;/;
+ $uquery =~ s/, $/ $where;/;
$iquery .= "(". join(',',@keys) .") VALUES (". join(',',@vals) .");";
&DEBUG($squery) if (0);
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 {