]> git.donarmstrong.com Git - infobot.git/commitdiff
- modified db_mysql to allow eleet usage of dbSet
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 25 May 2001 12:37:34 +0000 (12:37 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 25 May 2001 12:37:34 +0000 (12:37 +0000)
- karma now works!
- if there's an attempt to use dbm, warn and prevent usage.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@496 c11ca15a-4712-0410-83d8-924469b57eb5

src/Factoids/DBCommon.pl
src/Modules/Freshmeat.pl
src/Modules/RootWarn.pl
src/Process.pl
src/db_mysql.pl
src/modules.pl

index fd98ece69c96b3d233101c26e411ab3e1b68cdd8..3ae369418753a59c10940135f9fcf05fe01f6d12 100644 (file)
@@ -8,9 +8,12 @@
 if (&IsParam("useStrict")) { use strict; }
 
 #####
-# Usage: &setFactInfo($faqtoid, $type, $what, ?, ?);
+# Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val);
 sub setFactInfo {
-    &dbSet("factoids", "factoid_key", $_[0], $_[1], $_[2]);
+    &dbSet("factoids", 
+       { factoid_key => $_[0] },
+       { $_[1] => $_[2] }
+    );
 }   
 
 #####
index 62f1952c5df8368bad52649d3ebbc99e34cbfc44..40c36fa236edd6896bb85df4b890a8f45d550227 100644 (file)
@@ -183,7 +183,10 @@ sub downloadIndex {
 
     ### lets get on with business.
     # set the last refresh time. fixes multiple spawn bug.
-    &::dbSet("freshmeat", "projectname_short", "_", "latest_version", time());
+    &::dbSet("freshmeat", 
+       { "projectname_short" => "_" },
+       { "latest_version" => time() }
+    );
 
     &::dbRaw("LOCK", "LOCK TABLES freshmeat WRITE");
     @cols      = &::dbGetColInfo("freshmeat");
@@ -235,7 +238,7 @@ sub downloadIndex {
                s/&middot;//g;
        }
 
-       if ($str =~ s/\&(\S+);//g) {
+       if (0 and $str =~ s/\&(\S+?);//g) {
            &::DEBUG("fm: sarred $1 to ''.");
        }
 
index 0cdc6a4502668d136e81b6c0f9e163efd2783d19..185130f31718077a5943afe73a2f2d123c70fb04 100644 (file)
@@ -46,10 +46,17 @@ sub rootWarn {
 
     $attempt++;
     ### TODO: OPTIMIZE THIS.
-    &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
-    &dbSet("rootwarn", "nick", lc($nick), "time", time());
-    &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
-    &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
+    if (1) {   # old
+       &dbSet("rootwarn", { nick => lc($nick) }, { attempt => $attempt });
+       &dbSet("rootwarn", { nick => lc($nick) }, { time => time() });
+       &dbSet("rootwarn", { nick => lc($nick) }, { host => $user."\@".$host });
+       &dbSet("rootwarn", { nick => lc($nick) }, { channel => $chan });
+    } else {   # new. replace.
+       &dbSet("rootwarn", "nick", lc($nick), "attempt", $attempt);
+       &dbSet("rootwarn", "nick", lc($nick), "time", time());
+       &dbSet("rootwarn", "nick", lc($nick), "host", $user."\@".$host);
+       &dbSet("rootwarn", "nick", lc($nick), "channel", $chan);
+    }
 
     return;
 }
index a685181327a36520db746b304e275ebcad5cc5db..925ae964cbfb17865cdbfcb8bacfcde04ceef2c7 100644 (file)
@@ -299,8 +299,10 @@ sub process {
            $karma--;
        }
 
-       &dbSet("stats", "nick",$term, "type","karma");
-#      &dbSet("stats", "nick",$term, "type","karma");
+       &dbSet("stats", 
+               { nick => $term, type => "karma" },
+               { counter => $karma }
+       );
 
        return;
     }
index d5f7b43f9960b878dcf3e807531a211160e32cb4..38b12296f6a88aa3c78156692fe0d60dfba52ea4 100644 (file)
@@ -48,14 +48,13 @@ sub dbGet {
 
     my $sth;
     if (!($sth = $dbh->prepare($query))) {
-       &ERROR("Get: $DBI::errstr");
+       &ERROR("Get: prepare: $DBI::errstr");
        return;
     }
 
     &SQLDebug($query);
     if (!$sth->execute) {
-       &ERROR("Get => '$query'");
-#      &ERROR("Get => $DBI::errstr");
+       &ERROR("Get: execute: '$query'");
        $sth->finish;
        return 0;
     }
@@ -83,8 +82,8 @@ sub dbGetCol {
     my $sth = $dbh->prepare($query);
     &SQLDebug($query);
     if (!$sth->execute) {
-       &ERROR("GetCol => '$query'");
-       &ERROR("GetCol => $DBI::errstr");
+       &ERROR("GetCol: execute: '$query'");
+#      &ERROR("GetCol => $DBI::errstr");
        $sth->finish;
        return;
     }
@@ -132,18 +131,45 @@ sub dbGetColInfo {
 }
 
 #####
-# Usage: &dbSet($table, $primkey, $primval, $key, $val);
+# Usage: &dbSet($table, $primhash_ref, $hash_ref);
 sub dbSet {
-    my ($table, $primkey, $primval, $key, $val) = @_;
-    my $query;
+    my ($table, $phref, $href) = @_;
+    my $where = join(' AND ', map {
+               $_."=".&dbQuote($phref->{$_})
+       } keys %{$phref}
+    );
+
+    my $result = &dbGet($table, join(',', keys %{$phref}), $where);
+
+    my(@keys,@vals);
+    foreach (keys %{$href}) {
+       push(@keys, $_);
+       push(@vals, &dbQuote($href->{$_}) );
+    }
 
-    my $result = &dbGet($table, $primkey, "$primkey='$primval'");
+    if (!@keys or !@vals) {
+       &WARN("dbset: keys or vals is NULL.");
+       return;
+    }
+
+    my $query;
     if (defined $result) {
-       $query = "UPDATE $table SET $key=".&dbQuote($val).
-               " WHERE $primkey=".&dbQuote($primval);
+       my @keyval;
+       for(my$i=0; $i<scalar @keys; $i++) {
+           push(@keyval, $keys[$i]."=".$vals[$i] );
+       }
+
+       $query = "UPDATE $table SET ".
+               join(' AND ', @keyval).
+               " WHERE ".$where;
     } else {
-       $query = "INSERT INTO $table ($primkey,$key) VALUES (".
-               &dbQuote($primval).",".&dbQuote($val).")";
+       foreach (keys %{$phref}) {
+           push(@keys, $_);
+           push(@vals, &dbQuote($phref->{$_}) );
+       }
+
+       $query = sprintf("INSERT INTO $table (%s) VALUES (%s)",
+               join(',',@keys), join(',',@vals) );
     }
 
     &dbRaw("Set", $query);
index 6aea9e0e2175e88608b7af4d8a14f3ad3e031c93..162279d65c6124a9c5e677edfeefe2dab5eb34f5 100644 (file)
@@ -110,7 +110,11 @@ sub loadDBModules {
     } elsif ($param{'DBType'} =~ /^dbm$/i) {
 
        &status("  using Berkeley DBM 1.85/2.0 support.");
-       require "$bot_src_dir/db_dbm.pl";
+       &ERROR("dbm support is broken... you want it, you fix it!");
+       &shutdown();
+       exit 1;
+
+#      require "$bot_src_dir/db_dbm.pl";
     } else {
 
        &status("DB support DISABLED.");