sub delFactoid {
my ($faqtoid) = @_;
- &dbDel("factoids", "factoid_key",$faqtoid);
+ &dbDel("factoids", {"factoid_key"=>$faqtoid});
&status("DELETED $faqtoid");
return 1;
while (my @row = $sth->fetchrow_array) {
my ($nick,$time) = @row;
- &dbDel("seen","nick",$nick);
+ &dbDel("seen",{"nick"=>$nick});
$delete++;
}
$sth->finish;
my $ago = &::Time2String(time() - $hash{'time'});
&::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:");
&::msg($recipient, $hash{'msg'});
- #&::dbDel("botmail", "id", $hash{id}); # FIXME need a way to delete from 2 keys (hash)
+ &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}});
}
}
}
#####
-# Usage: &dbDel($table, $primkey, $primval, [$key]);
+# Usage: &dbDel($table, $primhash_ref);
# Note: dbDel does dbQuote
sub dbDel {
- my ($table, $primkey, $primval, $key) = @_;
-
- &dbRaw("Del", "DELETE FROM $table WHERE $primkey=".
- &dbQuote($primval)
+ my ($table, $phref) = @_;
+ my $where = join(' AND ', map {
+ $_."=".&dbQuote($phref->{$_})
+ } keys %{$phref}
);
+ &dbRaw("Del", "DELETE FROM $table WHERE $where");
+
return 1;
}
}
#####
-# Usage: &dbDel($table, $primkey, $primval, [$key]);
+# Usage: &dbDel($table, $primhash_ref);
+# Note: dbDel does dbQuote
sub dbDel {
- my ($table, $primkey, $primval, $key) = @_;
- &DEBUG("dbDel($table, $primkey, $primval);");
+ my ($table, $phref) = @_;
+ # FIXME does not really handle more than one key!
+ my $primval = join(':', values %{$phref});
if (!defined ${$table}{lc $primval}) {
&DEBUG("dbDel: lc $primval does not exist in $table.");
my ($table, $key, %hash) = @_;
&DEBUG("dbReplace($table, $key, %hash);");
- &dbDel($table, $key, $hash{$key}, %hash);
+ &dbDel($table, {$key=>$hash{$key}});
&dbInsert($table, $hash{$key}, %hash);
return 1;
}