]> git.donarmstrong.com Git - infobot.git/commitdiff
- half-assed attempt to move over to new sql functions
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 24 Nov 2002 13:13:46 +0000 (13:13 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sun, 24 Nov 2002 13:13:46 +0000 (13:13 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@704 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/IRC/IrcHooks.pl
src/Misc.pl

index 8d48eac309cceb6cde2635eebbcce5dc7c3f21bf..b7d598416851a7a6db28320755b03172383a732c 100644 (file)
@@ -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<scalar @array; $i++) {
@@ -619,12 +622,12 @@ sub seen {
 
     &seenFlush();      # very evil hack. oh well, better safe than sorry.
 
-    ### TODO: Support &dbGetColInfo(); like in &FactInfo();
+    # TODO: convert to &sqlSelectRowHash();
     my $select = "nick,time,channel,host,message";
     if ($person eq "random") {
        @seen = &randKey("seen", $select);
     } else {
-       @seen = &dbGet("seen", $select, "nick=".&dbQuote($person) );
+       @seen = &sqlSelect("seen", $select, { nick => $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;
index 34456c63216d41bf720d19f6ef65cc75807c9786..b63c4056c3887cd55a35ec0785eb3030b8314c89 100644 (file)
@@ -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",
+               } );
+           }
        }
     }
 
index 027a7a7cf113fcd1c73d4be4fe0f693224807de6..04ace3f0c307e6669a03302a1a32f8af0e3e829b 100644 (file)
@@ -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",
+           } );
+       }
     }
 }