]> git.donarmstrong.com Git - infobot.git/commitdiff
- I borked DBCommon.pl by mistake (setFactInfo duplication).
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 5 Oct 2001 17:46:25 +0000 (17:46 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 5 Oct 2001 17:46:25 +0000 (17:46 +0000)
- added more variable checks to db_mysql.pl just in case they're
  undefined; removed main:: from functions.
- nasty eval code in Question.pl simplied. thanks lear!
- dbReplace arguments fixed up to match the 3 liner setFactInfo code.

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

src/Factoids/DBCommon.pl
src/Factoids/Question.pl
src/Factoids/Statement.pl
src/Factoids/Update.pl
src/db_mysql.pl

index eddd7fa61492b0caed8d59b970da060662bce08f..178847d7cd59713205f4b54123a6507b082ead2a 100644 (file)
@@ -8,7 +8,7 @@
 if (&IsParam("useStrict")) { use strict; }
 
 #####
-# Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val);
+# Usage: &setFactInfo($faqtoid, $key, $val);
 sub setFactInfo {
     &dbSet("factoids", 
        { factoid_key => $_[0] },
@@ -18,25 +18,19 @@ sub setFactInfo {
 
 #####
 # Usage: &getFactInfo($faqtoid, [$what]);
-sub main::getFactInfo {
+sub getFactInfo {
     return &dbGet("factoids", $_[1], "factoid_key=".&dbQuote($_[0]) );
 }
 
 #####
 # Usage: &getFactoid($faqtoid);
-sub main::getFactoid {
+sub getFactoid {
     return &getFactInfo($_[0], "factoid_value");
 }
 
-#####
-# Usage: &setFactInfo($faqtoid, $type, $what);
-sub main::setFactInfo {
-    &dbSet("factoids", "factoid_key", $_[0], $_[1], $_[2]);
-}
-
 ##### 
 # Usage: &delFactoid($faqtoid);
-sub main::delFactoid {
+sub delFactoid {
     my ($faqtoid) = @_;
 
     &dbDel("factoids", "factoid_key",$faqtoid);
index 93725e553cfd1a0b253c6d40decc27bf82c815f0..e05fe6ad782762969be397b1228de4a1bcb43776 100644 (file)
@@ -184,26 +184,18 @@ sub factoidArgs {
 
        s/^CMD: //i;
 #      &DEBUG("factarg: ''$str' =~ /^$_\$/'");
-       my @vals;
        my $arg = $_;
 
        # todo: <greycat> ~punish apt for (Eating) (Parentheses)
-       # how the hell do I fix the above?
+       # how the hell do I fix the above? -dms.
 
-       # todo: make eval work with $$i's :(
-       # fuck this is an ugly hack. it works though.
+       # eval (evil!) code. cleaned up courtesy of lear.
+       my @vals;
        eval {
-           if ($str =~ /^$arg$/i) {
-               for ($i=1; $i<=5; $i++) {
-                   $val = $$i;
-                   last unless (defined $val);
-
-                   push(@vals, $val);
-               }
-           }
+           @vals = ($str =~ /^$arg$/i);
        };
 
-       if ($@) {   # it failed!!!
+       if ($@) {
            &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
            next;
        }
@@ -229,7 +221,7 @@ sub factoidArgs {
 
        # update stats.
        my $count = &getFactInfo($q, "requested_count") || 0;
-       $count++;   
+       $count++;
        &setFactInfo($q, "requested_by", $nuh);
        &setFactInfo($q, "requested_time", time());
        &setFactInfo($q, "requested_count", $count);
index edd69cf179441edd25b31d6001a1bfa79746f734..6af6dc3086471d31efa4bfbd8eb95447b1931ad7 100644 (file)
@@ -56,10 +56,10 @@ sub doStatement {
        my($lhs, $mhs, $rhs) = ($`, $&, $');
 
        # allows factoid arguments to be updated. -lear.
-       $lhs =~ s/^(CMD: )?(.*)/$1 . lc $2/e;
+#      $lhs =~ s/^(CMD: )?(.*)/$1 . lc $2/e;
 
-       $lhs =~ tr/A-Z/a-z/;
-       $lhs =~ s/^(the|da|an?)\s+//i; # discard article
+       # discard article.
+       $lhs =~ s/^(the|da|an?)\s+//i;
 
        # remove excessive initial and final whitespaces.
        $lhs =~ s/^\s+|\s+$//g;
index 5df526a5fa53265e30db301c0e0d60b9d4573962..3030bef94d2095fcf328e293d6001b850b63e307 100644 (file)
@@ -107,16 +107,15 @@ sub update {
 
        &performAddressedReply("okay");
 
-       if (1) {        # old
-           &setFactInfo($lhs,"factoid_value", $rhs);
-           &setFactInfo($lhs,"created_by", $nuh);
-           &setFactInfo($lhs,"created_time", time());
+       if (0) {        # old
+           &setFactInfo($lhs, "factoid_value", $rhs);
+           &setFactInfo($lhs, "created_by",    $nuh);
+           &setFactInfo($lhs, "created_time",  time());
        } else {
-           ### BROKEN!!!
-           # I'd prefer to use dbReplace but it don't work.
            &dbReplace("factoids", "factoid_key", (
+               created_by      => $nuh,
+               created_time    => time(),      # modified time.
                factoid_key     => $lhs,
-               created_by      => time(),
                factoid_value   => $rhs,
            ) );
        }
@@ -130,6 +129,9 @@ sub update {
 
     # factoid exists.
     if ($exists eq $rhs) {
+       # this catches the following situation: (right or wrong?)
+       #    "test is test"
+       #    "test is also test"
        &performAddressedReply("i already had it that way");
        return 1;
     }
@@ -221,6 +223,7 @@ sub update {
        $count{'Update'}++;
        &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
 
+       # should dbReplace be used here?
        &delFactoid($lhs);
        &setFactInfo($lhs,"created_by", $nuh);
        &setFactInfo($lhs,"created_time", time());
index b4820513cba9a10bc24dd5f1fa183292b18b4fa4..1b3f3dc617a23ecaaf09fe970302d11ec0c556d3 100644 (file)
@@ -49,8 +49,13 @@ sub dbGet {
     my $query  = "SELECT $select FROM $table";
     $query     .= " WHERE $where" if ($where);
 
-    if (!defined $select) {
-       &WARN("dbGet: select == NULL. table => $table");
+    if (!defined $select or $select =~ /^\s*$/) {
+       &WARN("dbGet: select == NULL.");
+       return;
+    }
+
+    if (!defined $table or $table =~ /^\s*$/) {
+       &WARN("dbGet: table == NULL.");
        return;
     }
 
@@ -134,8 +139,6 @@ sub dbGetColNiceHash {
     $query     .= " WHERE ".$where if ($where);
     my %retval;
 
-    &DEBUG("dbGetColNiceHash: query => '$query'.");
-
     my $sth = $dbh->prepare($query);
     &SQLDebug($query);
     if (!$sth->execute) {
@@ -188,6 +191,21 @@ sub dbSet {
        } keys %{$phref}
     );
 
+    if (!defined $phref) {
+       &WARN("dbset: phref == NULL.");
+       return;
+    }
+
+    if (!defined $href) {
+       &WARN("dbset: href == NULL.");
+       return;
+    }
+
+    if (!defined $table) {
+       &WARN("dbset: table == NULL.");
+       return;
+    }
+
     my $result = &dbGet($table, join(',', keys %{$phref}), $where);
 
     my(@keys,@vals);