}
sub closeDB {
- if (!$dbh) {
- &WARN("closeDB: connection already closed?");
- return 0;
- }
+ return 0 unless ($dbh);
&status("Closed MySQL connection to $param{'SQLHost'}.");
$dbh->disconnect();
if (!$sth->execute) {
&ERROR("Get => '$query'");
&ERROR("Get => $DBI::errstr");
- return;
+ $sth->finish;
+ return 0;
}
my @retval = $sth->fetchrow_array;
if (!$sth->execute) {
&ERROR("GetCol => '$query'");
&ERROR("GetCol => $DBI::errstr");
+ $sth->finish;
return;
}
if (!$sth->execute) {
&ERROR("GRI => '$query'");
&ERROR("GRI => $DBI::errstr");
+ $sth->finish;
+ return;
}
my @cols;
return 1;
}
+#####
+# Usage: &dbReplace($table, $primkey, $primval, %hash);
+sub dbReplace {
+ my ($table, $primkey, $primval, %hash) = @_;
+ my (@keys, @vals);
+
+ foreach (keys %hash) {
+ &DEBUG("hash{$_} => $hash{$_}");
+ push(@keys, $_);
+ push(@vals, &dbQuote($hash{$_}));
+ }
+
+ &dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys).
+ ") VALUES (".join(',',@vals).") WHERE $primkey=".
+ &dbQuote($primval)
+ );
+
+ return 1;
+}
+
#####
# Usage: &dbSetRow($table, @values);
sub dbSetRow {
&SQLDebug($query);
if (!$sth->execute) {
&ERROR("Raw($prefix): => '$query'");
- &ERROR("Raw($prefix): $DBI::errstr");
+# &ERROR("Raw($prefix): $DBI::errstr");
+ $sth->finish;
return 0;
}
my ($faqtoid) = @_;
&dbDel("factoids", "factoid_key",$faqtoid);
- &status("DELETED $faqtoid");
+ &status("DELETED '$faqtoid'");
return 1;
}