if (&IsParam("useStrict")) { use strict; }
#####
-# Usage: &setFactInfo($faqtoid, $type, $primval, $key, $val);
+# Usage: &setFactInfo($faqtoid, $key, $val);
sub setFactInfo {
&dbSet("factoids",
{ factoid_key => $_[0] },
#####
# 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);
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;
}
# 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);
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;
&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,
) );
}
# 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;
}
$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());
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;
}
$query .= " WHERE ".$where if ($where);
my %retval;
- &DEBUG("dbGetColNiceHash: query => '$query'.");
-
my $sth = $dbh->prepare($query);
&SQLDebug($query);
if (!$sth->execute) {
} 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);