]> git.donarmstrong.com Git - infobot.git/commitdiff
dbDel takes a hash, dbm untested
authortimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 22 Nov 2002 00:47:50 +0000 (00:47 +0000)
committertimriker <timriker@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 22 Nov 2002 00:47:50 +0000 (00:47 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@677 c11ca15a-4712-0410-83d8-924469b57eb5

src/Factoids/DBCommon.pl
src/IRC/Schedulers.pl
src/Modules/botmail.pl
src/dbi.pl
src/dbm.pl

index 709fd41b24181bc852234bb3696811da09f1fff9..646a21a6e280e9e5a069f3215a0b202bd7b9350b 100644 (file)
@@ -33,7 +33,7 @@ sub getFactoid {
 sub delFactoid {
     my ($faqtoid) = @_;
 
-    &dbDel("factoids", "factoid_key",$faqtoid);
+    &dbDel("factoids", {"factoid_key"=>$faqtoid});
     &status("DELETED $faqtoid");
  
     return 1;
index 18360d862814aa46bafc8513ad43cc1d7964a635..1de039f53e0c407d81f6e961ccc7a790f578bc7f 100644 (file)
@@ -260,7 +260,7 @@ sub seenFlushOld {
        while (my @row = $sth->fetchrow_array) {
            my ($nick,$time) = @row;
 
-           &dbDel("seen","nick",$nick);
+           &dbDel("seen",{"nick"=>$nick});
            $delete++;
        }
        $sth->finish;
index 6f5d10593b74c730dc1bacf2de9112f608ec2ca3..094e5f5adb71679ca9802284856e88941ab4196e 100644 (file)
@@ -66,7 +66,7 @@ sub next {
        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}});
     }
 }
 
index 0c9a3f525afaab53d73e7db848356a8fb417fd54..162fda1f7df2ef14e9acbbe48ef9c5a4cbe45b8b 100644 (file)
@@ -408,15 +408,17 @@ sub dbSetRow ($@$) {
 }
 
 #####
-# 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;
 }
 
index 63e6c81005c24dfa675759743aab3c6bdaeee1f0..eb66aa96c7a5e519e0a749c2a7fa113f52afea9a 100644 (file)
@@ -230,10 +230,12 @@ sub dbSetRow {
 }
 
 #####
-# 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.");
@@ -251,7 +253,7 @@ sub dbReplace {
     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;
 }