From: dms Date: Sun, 24 Nov 2002 13:13:46 +0000 (+0000) Subject: - half-assed attempt to move over to new sql functions X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=fb9305a6b0381f3f19995543cef88da960c70e1a;p=infobot.git - half-assed attempt to move over to new sql functions git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@704 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 8d48eac..b7d5984 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -331,17 +331,19 @@ sub Modules { # even more uglier with channel/time arguments. my $c = $chan; # my $c = $chan || "PRIVATE"; - my $where = "type=".&dbQuote($type); - $where .= " AND channel=".&dbQuote($c) if (defined $c); + my $where = "type=".&sqlQuote($type); + $where .= " AND channel=".&sqlQuote($c) if (defined $c); &DEBUG("not using chan arg") if (!defined $c); - my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats" + my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats" ." WHERE ".$where ))[0]; if (!defined $arg or $arg =~ /^\s*$/) { # this is way fucking ugly. - my %hash = &dbGetCol("stats", "nick,counter", - $where." ORDER BY counter DESC LIMIT 3", 1); + my %hash = &sqlSelectColHash("stats", "nick,counter", + undef, + $where." ORDER BY counter DESC LIMIT 3", 1 + ); my $i; my @top; @@ -367,8 +369,8 @@ sub Modules { &pSReply("zero counter for \037$type\037."); } } else { - my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats". - " WHERE $where AND nick=".&dbQuote($arg) ))[0]; + my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats". + " WHERE $where AND nick=".&sqlQuote($arg) ))[0]; if (!defined $x) { # !defined. &pSReply("$arg has not said $type yet."); @@ -376,8 +378,9 @@ sub Modules { } # defined. - my @array = &dbGet("stats", "nick", - $where." ORDER BY counter", 1); + my @array = &sqlSelect("stats", "nick", undef, + $where." ORDER BY counter", 1 + ); my $good = 0; my $i = 0; for($i=0; $i $person } ); } if (scalar @seen < 2) { @@ -920,17 +923,20 @@ sub textstats_main { # even more uglier with channel/time arguments. my $c = $chan; # my $c = $chan || "PRIVATE"; - my $where = "channel=".&dbQuote($c) if (defined $c); &DEBUG("not using chan arg") if (!defined $c); - my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats" - ." WHERE ".$where ))[0]; + + # example of converting from RawReturn to sqlSelect. + my $where_href = (defined $c) ? { channel => $c } : ""; + my $sum = &sqlSelect("stats", "SUM(counter)", $where_href); if (!defined $arg or $arg =~ /^\s*$/) { # this is way fucking ugly. &DEBUG("_stats: !arg"); - my %hash = &dbGetCol("stats", "nick,counter", - $where." ORDER BY counter DESC LIMIT 3", 1); + my %hash = &sqlSelectColHash("stats", "nick,counter", + $where_href, + " ORDER BY counter DESC LIMIT 3", 1 + ); my $i; my @top; @@ -957,8 +963,9 @@ sub textstats_main { &pSReply("zero counter for \037$type\037."); } } else { - my %hash = &dbGetCol("stats", "type,counter", - "$where AND nick=".&dbQuote($arg) ); + my %hash = &sqlSelectColHash("stats", "type,counter", + $where_href, " AND nick=".&sqlQuote($arg) + ); # this is totally fucked... needs to be fixed... and cleaned up. my $total; my $good; @@ -968,7 +975,7 @@ sub textstats_main { foreach (keys %hash) { &DEBUG("_stats: hash{$_} => $hash{$_}"); # ranking. - my @array = &dbGet("stats", "nick", + my @array = &sqlSelect("stats", "nick", undef, $where." ORDER BY counter", 1); $good = 0; $ii = 0; diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 34456c6..b63c405 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -882,11 +882,11 @@ sub on_public { &VERB("textcounters: $x matched for $who",2); my $c = $chan || "PRIVATE"; - my ($v,$t) = &dbGet("stats", "counter,time", - "nick=". &dbQuote($who) - ." AND type=".&dbQuote($x) - ." AND channel=".&dbQuote($c) - ); + my ($v,$t) = &sqlSelect("stats", "counter,time", { + nick => $who, + type => $x, + channel => $c, + } ); $v++; # don't allow ppl to cheat the stats :-) @@ -902,10 +902,15 @@ sub on_public { counter => $v, ); - - &dbReplace("stats", "nick", %hash); - # does not work, atleast with old mysql!!! :( -# &dbReplace("stats", (nick => $who, type => $x, -counter => "counter+1") ); + if (0) { + &sqlReplace("stats", \%hash); + } else { + &sqlReplace("stats", { + nick => $who, + type => $x, + -counter => "counter+1", + } ); + } } } diff --git a/src/Misc.pl b/src/Misc.pl index 027a7a7..04ace3f 100644 --- a/src/Misc.pl +++ b/src/Misc.pl @@ -635,8 +635,10 @@ sub closeStats { foreach (keys %cmdstats) { my $type = $_; - my $i = &dbGet("stats", "counter", "nick=".&dbQuote($type). - " AND type='cmdstats'"); + my $i = &sqlSelect("stats", "counter", { + nick => $type, + type => "cmdstats", + } ); my $z = 0; $z++ unless ($i); @@ -649,7 +651,15 @@ sub closeStats { ); $hash{time} = time() if ($z); - &dbReplace("stats", "nick", %hash); + if (0) { + &sqlReplace("stats", %hash); + } else { + &sqlReplace("stats", { + nick => $type, + type => "cmdstats", + -counter => "counter+1", + } ); + } } }