return;
}
+ # text counters.
+ if ($_ = &getChanConf("ircTextCounters")) {
+ s/([^\w\s])/\\$1/g;
+ my $z = join '|', split ' ';
+
+ if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
+ my $type = $1;
+ my $arg = $3;
+
+ if (!defined $arg or $arg =~ /^\s*$/) {
+ my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".&dbQuote($type) ))[0];
+
+ if (defined $x) {
+ &pSReply("total count of '$type': $x");
+ } else {
+ &pSReply("zero counter for '$type'.");
+ }
+ } else {
+ my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".
+ &dbQuote($type)." AND nick=".&dbQuote($arg) ))[0];
+
+ if (defined $x) { # defined.
+ &pSReply("$arg has said $type $x times");
+ } else { # !defined.
+ &pSReply("$arg has not said $type yet.");
+ }
+ }
+
+ return;
+ }
+
+ if ($@) {
+ &DEBUG("regex failed: $@");
+ return;
+ }
+ }
+
# list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
if ($message =~ /^list(\S+)( (.*))?$/i) {
return unless (&hasParam("search"));
my $thiscmd = lc($1);
- my $args = $3;
- $args =~ s/\s+$//g;
- # suggested by asuffield nad \broken.
- if ($args =~ /^["']/ and $args =~ /["']$/) {
- &DEBUG("list*: removed quotes.");
- $args =~ s/^["']|["']$//g;
- }
-
- $thiscmd =~ s/^vals$/values/;
+ $thiscmd =~ s/^vals$/values/;
return if ($thiscmd ne "keys" && $thiscmd ne "values");
+ my $args = $3 || "";
+ $args =~ s/\s+$//g;
+
# Usage:
- if (!defined $args) {
+ if (!defined $args or $args =~ /^\s*$/) {
&help("list". $thiscmd);
return;
}
+ # suggested by asuffield and \broken.
+ if ($args =~ /^["']/ and $args =~ /["']$/) {
+ &DEBUG("list*: removed quotes.");
+ $args =~ s/^["']|["']$//g;
+ }
+
if (length $args == 1) {
&msg($who,"search string is too short.");
return;
if ($person eq "random") {
@seen = &randKey("seen", $select);
} else {
- @seen = &dbGet("seen", "nick", $person, $select);
+ @seen = &dbGet("seen", $select, "nick='$person'");
}
if (scalar @seen < 2) {
}
if (&IsChanConf("factoidArguments")) {
- # to make it eleeter, split each arg and use "blah OR blah or BLAH"
- # which will make it less than linear => quicker!
- # todo: cache this, update cache when altered.
- my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
-
- # from a design perspective, it's better to have the regex in
- # the factoid key to reduce repetitive processing.
-
- foreach (@list) {
- s/^CMD: //;
-# &DEBUG("factarg: ''$query[0]' =~ /^$_\$/'");
- my @vals;
- my $arg = $_;
-
- # todo: make eval work with $$i's :(
-# next unless (eval { $query[0] =~ /^$arg$/i });
- next unless ($query[0] =~ /^$arg$/i);
-
- if ($@) { # it failed!!!
- &WARN("factargs: regex failed! '$query[0]' =~ /^$_\$/");
- next;
- }
-
- for ($i=1; $i<=5; $i++) {
- $val = $$i;
- last unless (defined $val);
-
- push(@vals, $val);
- }
-# };
-
-
- &status("Question: factoid Arguments for '$query[0]'");
- # todo: use getReply() - need to modify it :(
- my $i = 0;
- my $result = &getFactoid("CMD: $_");
- $result =~ s/^\((.*?)\): //;
-
- foreach ( split(',', $1) ) {
- my $val = $vals[$i];
- if (!defined $val) {
- &status("factArgs: vals[$i] == undef; not SARing '$_' for '$query[0]'");
- next;
- }
-
- &status("factArgs: SARing '$_' to '$vals[$i]'.");
- $result =~ s/\Q$_\E/$vals[$i]/;
- $i++;
- }
-
- # nasty hack to get partial &getReply() functionality.
- $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
- $result =~ s/^\s*<reply>\s*//i;
-
- return $result;
- }
+ $result = &factoidArgs($query[0]);
+ return $result if (defined $result);
}
my @link;
return $reply;
}
+sub factoidArgs {
+ my($str) = @_;
+ my $result;
+
+ # to make it eleeter, split each arg and use "blah OR blah or BLAH"
+ # which will make it less than linear => quicker!
+ # todo: cache this, update cache when altered.
+ my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
+
+ # from a design perspective, it's better to have the regex in
+ # the factoid key to reduce repetitive processing.
+
+ foreach (@list) {
+ next if (/#DEL#/); # deleted.
+
+ s/^CMD: //;
+# &DEBUG("factarg: ''$str' =~ /^$_\$/'");
+ my @vals;
+ my $arg = $_;
+
+ # todo: make eval work with $$i's :(
+ eval {
+ if ($str =~ /^$arg$/i) {
+ for ($i=1; $i<=5; $i++) {
+ $val = $$i;
+ last unless (defined $val);
+
+ push(@vals, $val);
+ }
+ }
+ };
+
+ if ($@) { # it failed!!!
+ &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
+ next;
+ }
+
+ next unless (@vals);
+
+ &status("Question: factoid Arguments for '$str'");
+ # todo: use getReply() - need to modify it :(
+ my $i = 0;
+ $result = &getFactoid("CMD: $_");
+ $result =~ s/^\((.*?)\): //;
+
+ foreach ( split(',', $1) ) {
+ my $val = $vals[$i];
+ if (!defined $val) {
+ &status("factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
+ next;
+ }
+
+ if ($result = &substVars($result)) {
+ # hrm...
+ } else {
+ &status("factArgs: SARing '$_' to '$vals[$i]'.");
+ $result =~ s/\Q$_\E/$vals[$i]/;
+ $i++;
+ }
+ }
+
+ # nasty hack to get partial &getReply() functionality.
+ $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
+ $result =~ s/^\s*<reply>\s*//i;
+ $result = &SARit($result);
+# $result = &substVars($result);
+
+ return $result;
+ }
+
+ return;
+}
+
1;
$result =~ s/^\s*//;
}
- my $fauthor = &dbGet("factoids", "factoid_key", $message, "created_by");
- ### we need non-evaluating regex like in factoid sar.
- if ($msgType =~ /^private$/) {
- if (0 and defined $fauthor and $fauthor =~ /^\Q$who\E\!/i) {
- &status("Reply.pl: author requested own factoid in private; literal!");
- $literal = 1;
- }
- } else {
- my $done = 0;
-
- # (blah1|blah2)?
- while ($result =~ /\((.*?)\)\?/) {
- my $str = $1;
- if (rand() > 0.5) { # fix.
- &status("Factoid transform: keeping '$str'.");
- $result =~ s/\(\Q$str\E\)\?/$str/;
- } else { # remove
- &status("Factoid transform: removing '$str'.");
- $result =~ s/\(\Q$str\E\)\?\s?//;
- }
- $done++;
- last if ($done >= 10); # just in case.
- }
- $done = 0;
-
- # EG: (0-32768) => 6325
- ### TODO: (1-10,20-30,40) => 24
- while ($result =~ /\((\d+)-(\d+)\)/) {
- my ($lower,$upper) = ($1,$2);
- my $new = int(rand $upper-$lower) + $lower;
-
- &status("Reply.pl: SARing '$&' to '$new'.");
- $result =~ s/$&/$new/;
- $done++;
- last if ($done >= 10); # just in case.
- }
- $done = 0;
-
- # EG: (blah1|blah2|blah3|) => blah1
- while ($result =~ /.*\((.*\|.*?)\).*/) {
- $result = &smart_replace($result);
-
- $done++;
- last if ($done >= 10); # just in case.
- }
- &status("Reply.pl: $done SARs done.") if ($done);
- }
+ my $fauthor = &dbGet("factoids", "created_by", "factoid_key='$message'");
+ $result = &SARit($result);
- $reply = $result;
+ $reply = $result;
if ($result ne "") {
### AT LAST, REPEAT PREVENTION CODE REMOVED IN FAVOUR OF GLOBAL
### FLOOD REPETION AND PROTECTION. -20000124
# stats code.
- &setFactInfo($lhs,"requested_by", $nuh);
- &setFactInfo($lhs,"requested_time", time());
### FIXME: old mysql doesn't support
- ### "requested_count=requested_count+1".
+ ### "requested_count=requested_count+1".
my $count = &getFactInfo($lhs,"requested_count") || 0;
$count++;
- &setFactInfo($lhs,"requested_count", $count);
+ ### BROKEN!!!
+ if (1) { # old code.
+ &setFactInfo($lhs,"requested_by", $nuh);
+ &setFactInfo($lhs,"requested_time", time());
+ &setFactInfo($lhs,"requested_count", $count);
+ } else {
+ &dbReplace("factoids", (
+ factoid_key => $lhs,
+ requested_by => $nuh,
+ requested_time => time(),
+ requested_count => $count
+ ) );
+ }
# todo: rename $real to something else!
my $real = 0;
###
### $ SUBSTITUTION.
###
+
+ $reply = &substVars($reply);
+ $reply;
+}
+
+sub smart_replace {
+ my ($string) = @_;
+ my ($l,$r) = (0,0); # l = left, r = right.
+ my ($s,$t) = (0,0); # s = start, t = marker.
+ my $i = 0;
+ my $old = $string;
+ my @rand;
+
+ foreach (split //, $string) {
+
+ if ($_ eq "(") {
+### print "( l=>$l, r=>$r\n";
+
+ if (!$l and !$r) {
+# print "STARTING at $i\n";
+ $s = $i;
+ $t = $i;
+ }
+
+ $l++;
+ $r--;
+ }
+
+ if ($_ eq ")") {
+### print ") l=>$l, r=>$r\n";
+
+ $r++;
+ $l--;
+
+ if (!$l and !$r) {
+ my $substr = substr($old,$s,$i-$s+1);
+# print "STOP at $i $substr\n";
+ push(@rand, substr($old,$t+1,$i-$t-1) );
+
+ my $rand = $rand[rand @rand];
+ &status("SARing '$substr' to '$rand'.");
+ $string =~ s/\Q$substr\E/$rand/;
+ undef @rand;
+ }
+ }
+
+ if ($_ eq "|" and $l+$r== 0 and $l==1) {
+# print "| at $i (l=>$l,r=>$r)\n";
+ push(@rand, substr($old,$t+1,$i-$t-1) );
+ $t = $i;
+ }
+
+ $i++;
+ }
+
+ if ($old eq $string) {
+ &WARN("smart_replace: no subst made. (string => $string)");
+ }
+
+ return $string;
+}
+
+sub SARit {
+ my($txt) = @_;
+ my $done = 0;
+
+ # (blah1|blah2)?
+ while ($txt =~ /\((.*?)\)\?/) {
+ my $str = $1;
+ if (rand() > 0.5) { # fix.
+ &status("Factoid transform: keeping '$str'.");
+ $txt =~ s/\(\Q$str\E\)\?/$str/;
+ } else { # remove
+ &status("Factoid transform: removing '$str'.");
+ $txt =~ s/\(\Q$str\E\)\?\s?//;
+ }
+ $done++;
+ last if ($done >= 10); # just in case.
+ }
+ $done = 0;
+
+ # EG: (0-32768) => 6325
+ ### TODO: (1-10,20-30,40) => 24
+ while ($txt =~ /\((\d+)-(\d+)\)/) {
+ my ($lower,$upper) = ($1,$2);
+ my $new = int(rand $upper-$lower) + $lower;
+
+ &status("SARing '$&' to '$new' (2).");
+ $txt =~ s/$&/$new/;
+ $done++;
+ last if ($done >= 10); # just in case.
+ }
+ $done = 0;
+
+ # EG: (blah1|blah2|blah3|) => blah1
+ while ($txt =~ /.*\((.*\|.*?)\).*/) {
+ $txt = &smart_replace($txt);
+
+ $done++;
+ last if ($done >= 10); # just in case.
+ }
+ &status("Reply.pl: $done SARs done.") if ($done);
+
+ return $txt;
+}
+
+sub substVars {
+ my($reply) = @_;
+
# $date, $time.
my $date = scalar(localtime());
$date =~ s/\:\d+(\s+\w+)\s+\d+$/$1/;
$reply =~ s/\$memusage/$memusage/;
- $reply;
-}
-
-sub smart_replace {
- my ($string) = @_;
- my ($l,$r) = (0,0); # l = left, r = right.
- my ($s,$t) = (0,0); # s = start, t = marker.
- my $i = 0;
- my @rand;
- my $old = $string;
-
- foreach (split //, $string) {
-
- if ($_ eq "(") {
-### print "( l=>$l, r=>$r\n";
-
- if (!$l and !$r) {
-# print "STARTING at $i\n";
- $s = $i;
- $t = $i;
- }
-
- $l++;
- $r--;
- }
-
- if ($_ eq ")") {
-### print ") l=>$l, r=>$r\n";
-
- $r++;
- $l--;
-
- if (!$l and !$r) {
- my $substr = substr($old,$s,$i-$s+1);
-# print "STOP at $i $substr\n";
- push(@rand, substr($old,$t+1,$i-$t-1) );
-
- my $rand = $rand[rand @rand];
- &status("Reply.pl: SARing '$substr' to '$rand'.");
- $string =~ s/\Q$substr\E/$rand/;
- undef @rand;
- }
- }
-
- if ($_ eq "|" and $l+$r== 0 and $l==1) {
-# print "| at $i (l=>$l,r=>$r)\n";
- push(@rand, substr($old,$t+1,$i-$t-1) );
- $t = $i;
- }
-
- $i++;
- }
-
- if ($old eq $string) {
- &WARN("smart_replace: no subst made. (string => $string)");
- }
-
- return $string;
+ return $reply;
}
1;
# freshmeat
if (&IsChanConf("freshmeatForFactoid")) {
# todo: "name" is invalid for fm ][
- if (&dbGet("freshmeat", "name", $lhs, "name")) {
+ if (&dbGet("freshmeat", "name", "name='$lhs'")) {
&msg($who, "permission denied. (freshmeat)");
&status("alert: $who wanted to teach me something that freshmeat already has info on.");
return 1;
&performAddressedReply("okay");
- &setFactInfo($lhs,"created_by", $nuh);
- &setFactInfo($lhs,"created_time", time());
- &setFactInfo($lhs,"factoid_value", $rhs);
+ ### BROKEN!!!
+ if (1) { # old
+ &setFactInfo($lhs,"created_by", $nuh);
+ &setFactInfo($lhs,"created_time", time());
+ &setFactInfo($lhs,"factoid_value", $rhs);
+ } else {
+ &dbReplace("factoids", (
+ factoid_key => $lhs,
+ created_by => time(),
+ factoid_value => $rhs,
+ ) );
+ }
if (!defined $rhs or $rhs eq "") {
&ERROR("Update: rhs1 == NULL.");
if ( ($pubcount % $i) == 0 and $pubcount) {
sleep 1;
- $pubsleep++;
} elsif ($pubsize > $j) {
sleep 1;
$pubsize -= $j;
- $pubsleep++;
}
} else {
my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
if ( ($msgcount % $i) == 0 and $msgcount) {
sleep 1;
- $msgsleep++;
} elsif ($msgsize > $j) {
sleep 1;
$msgsize -= $j;
- $msgsleep++;
}
} else {
if ( ($notcount % $i) == 0 and $notcount) {
sleep 1;
- $notsleep++;
} elsif ($notsize > $j) {
sleep 1;
$notsize -= $j;
- $notsleep++;
}
} else {
}
return;
-
}
# !scalar @joinchan:
&DEBUG("FIXME: floodwho = ???");
}
- my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
+ my $val = &getChanConfDefault("floodRepeat", "2:5", $c);
my ($count, $interval) = split /:/, $val;
# flood repeat protection.
$userstats{lc $nick}{'Time'} = time();
}
-# if (&IsChanConf("hehCounter")) {
-# #...
-# }
+ # would this slow things down?
+ if ($_ = &getChanConf("ircTextCounters")) {
+ foreach (split /[\s]+/) {
+ next unless ($msg =~ /^\Q$_\E$/i);
+ &status("textcounters: $_ matched for $who");
+
+ my $v = &dbGet("stats", "counter", "nick='$who' and type='$msg'");
+ $v++;
+
+ &dbReplace("stats", (nick => $who, type => $_, counter => $v) );
+ # does not work, atleast with old mysql!!! :(
+# &dbReplace("stats", (nick => $who, type => $_, -counter => "counter+1") );
+ }
+ }
&hookMsg('public', $chan, $nick, $msg);
$chanstats{$chan}{'PublicMsg'}++;
my $time = time();
foreach (keys %seen) {
- my $delta_time = $time - &dbGet("seen", "NULL", $_, "time");
+ my $delta_time = $time - &dbGet("seen", "time", "nick='$_'");
next unless ($delta_time > $max_time);
&DEBUG("seenFlushOld: ".&Time2String($delta_time) );
if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
foreach $nick (keys %seencache) {
- my $retval = &dbReplace("seen", "nick", $nick, (
-### "nick" => $seencache{$nick}{'nick'},
+ my $retval = &dbReplace("seen", (
+ "nick" => $seencache{$nick}{'nick'},
"time" => $seencache{$nick}{'time'},
"host" => $seencache{$nick}{'host'},
"channel" => $seencache{$nick}{'chan'},
### old code.
###
- my $exists = &dbGet("seen","nick", $nick, "nick");
+ my $exists = &dbGet("seen", "nick", "nick='$nick'");
if (defined $exists and $exists) {
&dbUpdate("seen", "nick", $nick, (
delete $channels{''};
}
- &DEBUG("ircstats...");
- &DEBUG(" pubsleep: $pubsleep");
- &DEBUG(" msgsleep: $msgsleep");
- &DEBUG(" notsleep: $notsleep");
-
### USER FILE.
if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
&writeUserFile();
my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
my $stale = &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+ &DEBUG("stale => $stale");
my $time = time();
foreach (@list) {
my $agestr = &Time2String($time - $age);
&DEBUG("safedel: Removing '$_' for good. [$agestr old]");
+ last;
+
&delFactoid($_);
}
-
}
sub dccStatus {
my $refresh = &::getChanConfDefault("freshmeatRefreshInterval",
"", 24) * 60 * 60 * 7;
- my $last_refresh = &::dbGet("freshmeat", "projectname_short", "_", "latest_version");
+ my $last_refresh = &::dbGet("freshmeat", "latest_version", "projectname_short='_'");
my $renewtable = 0;
if (defined $last_refresh and $last_refresh =~ /^\d+$/) {
sub showPackage {
my ($pkg) = @_;
- my @fm = &::dbGet("freshmeat", "projectname_short", $pkg, "*");
+ my @fm = &::dbGet("freshmeat", "*", "projectname_short='$pkg'");
if (scalar @fm) { #1: perfect match of name.
my $retval;
s/æ/a/g;
s/ø/o/g;
s/ð/e/g;
+ s/ß//g;
+ s/·//g;
+ }
+
+ if ($str =~ s/\&(\S+);//g) {
+ &::DEBUG("fm: sarred $1 to ''.");
}
$p->parse($str, ProtocolEncoding => 'ISO-8859-1');
sub latest {
my($tchan, $flag) = @_;
- $chan ||= $tchan; # hack hack hack.
+ # hack hack hack.
+ $chan ||= $tchan;
+ $who ||= $::who;
# todo: if chan = undefined, guess.
# if (!exists $::news{$chan}) {
sub rootWarn {
my ($nick,$user,$host,$chan) = @_;
- my $attempt = &dbGet("rootwarn", "nick", lc($nick), "attempt") || 0;
+ my $attempt = &dbGet("rootwarn", "attempt", "nick='.lc($nick)."'") || 0;
my $warnmode = &getChanConf("rootWarnMode");
if ($attempt == 0) { # first timer.
return;
}
- if (lc($term) eq lc($who)) {
+ if (lc $term eq lc $who) {
&msg($who, "please don't karma yourself");
return;
}
- my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
+ my $karma = &dbGet("stats", "counter", "nick='$term' and type='karma'") || 0;
if ($inc eq '++') {
$karma++;
} else {
$karma--;
}
- &dbSet("karma", "nick",$term,"karma",$karma);
+ &dbSet("stats", "nick",$term, "type","karma");
+# &dbSet("stats", "nick",$term, "type","karma");
return;
}
return;
}
- if (&IsParam("factoidDeleteDelay")) {
+ if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) {
&msg($who, "cannot delete it ($faqtoid).");
return;
&status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
### TODO: check if the "backup" exists and overwrite it
my $check = &getFactoid("$faqtoid #DEL#");
- &DEBUG("Process: check => '$check'.");
- if (!$check) {
+ if (!defined $check or $check =~ /^\s*$/) {
if ($faqtoid !~ / #DEL#$/) {
- &DEBUG("Process: backing up $faqtoid to '$new'.");
my $new = $faqtoid." #DEL#";
+ &DEBUG("Process: backing up $faqtoid to '$new'.");
+
# this looks weird but does it work?
&setFactInfo($faqtoid, "factoid_key", $new);
&setFactInfo($new, "modified_by", $who);
if ($message =~ s/^un(forget|delete)\s+//i) {
return 'unforget: no addr' unless ($addressed);
- if (!&IsParam("factoidDeleteDelay")) {
+ my $i = 0;
+ $i++ if (&IsParam("factoidDeleteDelay"));
+ $i++ if (&IsChanConf("factoidDeleteDelay"));
+ if (!$i) {
&performReply("safe delete has been disable so what is there to undelete?");
return;
}
return;
}
- &DEBUG("unforget: check => $check");
if (defined $check) {
&performReply("cannot undeleted '$faqtoid' because it already exists?");
return;
sub karma {
my $target = lc( shift || $who );
- my $karma = &dbGet("karma", "nick",$target,"karma") || 0;
+ my $karma = &dbGet("stats", "counter", "nick='$target' and type='karma'") || 0;
if ($karma != 0) {
&pSReply("$target has karma of $karma");
$flag_quit $msgType
$utime_userfile $wtime_userfile $ucount_userfile
$utime_chanfile $wtime_chanfile $ucount_chanfile
- $pubsize $pubcount $pubtime $pubsleep
- $msgsize $msgcount $msgtime $msgsleep
- $notsize $notcount $nottime $notsleep
+ $pubsize $pubcount $pubtime
+ $msgsize $msgcount $msgtime
+ $notsize $notcount $nottime
);
# dynamic hash.
### more variables...
$msgtime = time();
$msgsize = 0;
-$msgcount = $msgsleep = 0;
+$msgcount = 0;
$pubtime = 0;
$pubsize = 0;
-$pubcount = $pubsleep = 0;
+$pubcount = 0;
$nottime = 0;
$notsize = 0;
-$notcount = $notsleep = 0;
+$notcount = 0;
###
if ( -d "CVS" ) {
use POSIX qw(strftime);
$param{tempDir} =~ s#\~/#$ENV{HOME}/#;
&status("Initial memory usage: $memusage kB");
+ &status("-------------------------------------------------------");
}
sub setupConfig {
my @retval;
my $i;
&DEBUG("dbGet($db, $key, $val, $select);");
+ # TODO: support change that's done for db_mysql!
if (!scalar @{ "${db}_format" }) {
&ERROR("dG: no valid format layout for $db.");
}
#####
-# Usage: &dbGet($table, $primkey, $primval, $select);
+# Usage: &dbGet($table, $select, $where);
sub dbGet {
- my ($table, $primkey, $primval, $select) = @_;
- my $query = "SELECT $select FROM $table WHERE $primkey=".
- &dbQuote($primval);
+ my ($table, $select, $where) = @_;
+ my $query = "SELECT $select FROM $table";
+ $query .= " WHERE $where" if ($where);
my $sth;
if (!($sth = $dbh->prepare($query))) {
&SQLDebug($query);
if (!$sth->execute) {
&ERROR("Get => '$query'");
- &ERROR("Get => $DBI::errstr");
+# &ERROR("Get => $DBI::errstr");
$sth->finish;
return 0;
}
my ($table, $primkey, $primval, $key, $val) = @_;
my $query;
- my $result = &dbGet($table,$primkey,$primval,$primkey);
+ my $result = &dbGet($table, $primkey, "$primkey='$primval'");
if (defined $result) {
$query = "UPDATE $table SET $key=".&dbQuote($val).
" WHERE $primkey=".&dbQuote($primval);
}
#####
-# Usage: &dbReplace($table, $primkey, $primval, %hash);
+# Usage: &dbReplace($table, %hash);
sub dbReplace {
- my ($table, $primkey, $primval, %hash) = @_;
+ my ($table, %hash) = @_;
my (@keys, @vals);
foreach (keys %hash) {
- push(@keys, $_);
- push(@vals, &dbQuote($hash{$_}));
+ if (s/^-//) { # as is.
+ push(@keys, $_);
+ push(@vals, $hash{'-'.$_});
+ } else {
+ push(@keys, $_);
+ push(@vals, &dbQuote($hash{$_}));
+ }
}
&dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys).
return 0;
}
+# &DEBUG("query => '$query'.");
+
&SQLDebug($query);
if (!$sth->execute) {
&ERROR("Raw($prefix): => '$query'");
-# &ERROR("Raw($prefix): $DBI::errstr");
+ # $DBI::errstr is printed as warning automatically.
$sth->finish;
return 0;
}
#####
# Usage: &getFactInfo($faqtoid, type);
sub getFactInfo {
- return &dbGet("factoids", "factoid_key", $_[0], $_[1]);
+ return &dbGet("factoids", $_[1], "factoid_key='$_[0]'");
}
#####
&DEBUG("found!!!");
open(IN, $file);
- $data = <IN>;
+ while (<IN>) {
+ chop;
+ $data .= $_;
+ }
$found++;
last;
&dbRaw("create(db $param{'DBName'})", $query);
}
- foreach ("factoids", "freshmeat", "karma", "rootwarn", "seen",
+ foreach ("factoids", "freshmeat", "rootwarn", "seen", "stats",
) {
next if (exists $db{$_});
&status(" creating new table $_...");