From: timriker Date: Sat, 7 Dec 2002 05:11:35 +0000 (+0000) Subject: dbm -> sql X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=1c30b65aad211e585956587f774bc26bce946a15;p=infobot.git dbm -> sql git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@740 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 47dc9d3..7e5ccb6 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -348,7 +348,6 @@ sub Modules { my @top; # unfortunately we have to sort it again! - # todo: make dbGetCol return hash and array? too much effort. my $tp = 0; foreach $i (sort { $b <=> $a } keys %hash) { foreach (keys %{ $hash{$i} }) { @@ -941,7 +940,6 @@ sub textstats_main { my @top; # unfortunately we have to sort it again! - # todo: make dbGetCol return hash and array? too much effort. my $tp = 0; foreach $i (sort { $b <=> $a } keys %hash) { foreach (keys %{ $hash{$i} }) { diff --git a/src/Modules/botmail.pl b/src/Modules/botmail.pl index 0439f27..fcb5e8a 100644 --- a/src/Modules/botmail.pl +++ b/src/Modules/botmail.pl @@ -46,9 +46,9 @@ sub check { my($recipient, $always) = @_; $recipient ||= $::who; - # todo: simplify this select (use a diff function) - my %from = &::dbGetCol("botmail", "srcwho", - "dstwho=".&::dbQuote(lc $recipient),2); + my %from = &::sqlSelectColHash("botmail", "srcwho,time", { + dstwho => lc $recipient + } ); my $t = keys %from; my $from = join(", ", keys %from); @@ -64,17 +64,18 @@ sub check { sub next { my($recipient) = @_; - my %hash = &::dbGetColNiceHash("botmail", "*", - "dstwho=".&::dbQuote(lc $recipient) - ); + my %hash = &::sqlSelectRowHash("botmail", "*", { + dstwho => lc $recipient + } ); if (scalar (keys %hash) <= 1) { &::msg($recipient, "You have no botmail."); } else { + my $date = scalar(gmtime $hash{'time'}); my $ago = &::Time2String(time() - $hash{'time'}); - &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $hash{time} [$ago]:"); + &::msg($recipient, "From $hash{srcwho} ($hash{srcuh}) on $date ($ago ago):"); &::msg($recipient, $hash{'msg'}); - &::dbDel("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}}); + &::sqlDelete("botmail", { 'dstwho'=>$hash{dstwho}, 'srcwho'=>$hash{srcwho}}); } } @@ -84,30 +85,24 @@ sub add { my($recipient, $msg) = @_; &::DEBUG("botmail::add(@_)"); - if (lc $recipient eq $::who) { - &::msg($::who, "well... a botmail to oneself is stupid!"); - return; - } - # only support 1 botmail with unique dstwho/srcwho to have same # functionality as botmail from infobot. - my %hash = &::dbGetColNiceHash("botmail", "*", - "srcwho=".&::dbQuote(lc $::who)." AND ". - "dstwho=".&::dbQuote(lc $recipient) - ); + my %hash = &::sqlSelectRowHash("botmail", "*", { + srcwho => &::sqlQuote(lc $::who), + dstwho => &::sqlQuote(lc $recipient) + } ); if (scalar (keys %hash) > 1) { &::msg($::who, "$recipient already has a message queued from you"); return; } - &::dbSet("botmail", { + &::sqlReplace("botmail", { 'dstwho' => lc $recipient, 'srcwho' => lc $::who, - }, { - 'srcuh' => $::nuh, # will this work? - 'time' => time(), - 'msg' => $msg, + 'srcuh' => $::nuh, + 'time' => time(), + 'msg' => $msg, } ); &::msg($::who, "OK, $::who, I'll let $recipient know."); diff --git a/src/UserExtra.pl b/src/UserExtra.pl index 21dbfa0..e39fa2a 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -819,7 +819,6 @@ sub userCommands { return; - # todo: use dbGetColNiceHash(). my %hash = &sqlSelectColHash("stats", "nick,counter", { type => "cmdstats" }, 1); # ORDER won't be retained in a hash diff --git a/src/dbi.pl b/src/dbi.pl index d3c5aab..ac6f975 100644 --- a/src/dbi.pl +++ b/src/dbi.pl @@ -167,11 +167,11 @@ sub sqlSelectColHash { my %retval; if (defined $type and $type == 2) { - &DEBUG("dbgetcol: type 2!"); + &DEBUG("sqlSelectColHash: type 2!"); while (my @row = $sth->fetchrow_array) { $retval{$row[0]} = join(':', $row[1..$#row]); } - &DEBUG("dbgetcol: count => ".scalar(keys %retval) ); + &DEBUG("sqlSelectColHash: count => ".scalar(keys %retval) ); } elsif (defined $type and $type == 1) { while (my @row = $sth->fetchrow_array) { @@ -540,7 +540,7 @@ sub deleteTable { ##### # Usage: &searchTable($table, $select, $key, $str); -# Note: searchTable does dbQuote. +# Note: searchTable does sqlQuote. sub searchTable { my($table, $select, $key, $str) = @_; my $origStr = $str; @@ -548,7 +548,7 @@ sub searchTable { # allow two types of wildcards. if ($str =~ /^\^(.*)\$$/) { - &DEBUG("searchTable: should use dbGet(), heh."); + &FIXME("searchTable: can't do \"$str\""); $str = $1; } else { $str .= "%" if ($str =~ s/^\^//);