From 7a714268b563bd76aeabc672d0b64bfad8495c74 Mon Sep 17 00:00:00 2001 From: timriker Date: Fri, 22 Nov 2002 00:47:50 +0000 Subject: [PATCH] dbDel takes a hash, dbm untested git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@677 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/Factoids/DBCommon.pl | 2 +- src/IRC/Schedulers.pl | 2 +- src/Modules/botmail.pl | 2 +- src/dbi.pl | 12 +++++++----- src/dbm.pl | 10 ++++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Factoids/DBCommon.pl b/src/Factoids/DBCommon.pl index 709fd41..646a21a 100644 --- a/src/Factoids/DBCommon.pl +++ b/src/Factoids/DBCommon.pl @@ -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; diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index 18360d8..1de039f 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -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; diff --git a/src/Modules/botmail.pl b/src/Modules/botmail.pl index 6f5d105..094e5f5 100644 --- a/src/Modules/botmail.pl +++ b/src/Modules/botmail.pl @@ -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}}); } } diff --git a/src/dbi.pl b/src/dbi.pl index 0c9a3f5..162fda1 100644 --- a/src/dbi.pl +++ b/src/dbi.pl @@ -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; } diff --git a/src/dbm.pl b/src/dbm.pl index 63e6c81..eb66aa9 100644 --- a/src/dbm.pl +++ b/src/dbm.pl @@ -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; } -- 2.39.2