# Splitted: SQLExtras.pl
#
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw($dbh $who);
+use vars qw(%param);
###
# Usage: &CmdFactInfo($faqtoid, $query);
sub CmdFactInfo {
my ($faqtoid, $query) = (lc $_[0], $_[1]);
+ $faqtoid =~ s/^cmd:/CMD:/;
my @array;
my $string = "";
return;
}
- my $i = 0;
- my %factinfo;
- my @factinfo = &getFactInfo($faqtoid,"*");
- foreach ( &dbGetColInfo("factoids") ) {
- $factinfo{$_} = $factinfo[$i] || '';
- $i++;
- }
+ my %factinfo = &sqlSelectRowHash("factoids", "*",
+ { factoid_key => $faqtoid }
+ );
# factoid does not exist.
- if (scalar @factinfo <= 1) {
+ if (scalar (keys %factinfo) <= 1) {
&performReply("there's no such factoid as \002$faqtoid\002");
return;
}
if ($time) {
if (time() - $time > 60*60*24*7) {
my $days = int( (time() - $time)/60/60/24 );
- $string .= " at \037". scalar(localtime $time). "\037" .
+ $string .= " at \037". scalar(gmtime $time). "\037" .
" ($days days)";
} else {
$string .= " ".&Time2String(time() - $time)." ago";
push(@array,$string);
}
- # modified:
-# if ($factinfo{'modified_by'}) {
-# $string = "last modified";
-#
-# my $time = $factinfo{'modified_time'};
-# if ($time) {
-# if (time() - $time > 60*60*24*7) {
-# $string .= " at \037". scalar(localtime $time). "\037";
-# } else {
-# $string .= " ".&Time2String(time() - $time)." ago";
-# }
-# }
-#
-# my @x;
-# foreach (split ",", $factinfo{'modified_by'}) {
-# /\!/;
-# push(@x, $`);
-# }
-# $string .= "by ".&IJoin(@x);
-#
-# $i++;
-# push(@array,$string);
-# }
+ # modified: (TimRiker asks "why do you keep turning this off?)
+ if ($factinfo{'modified_by'}) {
+ $string = "last modified";
+
+ my $time = $factinfo{'modified_time'};
+ if ($time) {
+ if (time() - $time > 60*60*24*7) {
+ $string .= " at \037". scalar(gmtime $time). "\037";
+ } else {
+ $string .= " ".&Time2String(time() - $time)." ago ";
+ }
+ }
+
+ $string .= " by ".(split ",", $factinfo{'modified_by'})[0];
+
+ push(@array,$string);
+ }
# requested:
if ($factinfo{'requested_by'}) {
$string .= "\002". $requested_count. "\002 ".
&fixPlural("time", $requested_count);
}
- }
-
- $string .= ", " if ($string ne "");
- my $requested_by = $factinfo{'requested_by'};
- $requested_by =~ /\!/;
- $string .= "last by $`";
+ my $requested_by = $factinfo{'requested_by'};
+ $requested_by =~ /\!/;
+ $string .= ", last by $`";
- my $requested_time = $factinfo{'requested_time'};
- if ($requested_time) {
- if (time() - $requested_time > 60*60*24*7) {
- $string .= " at \037". scalar(localtime $requested_time). "\037";
- } else {
- $string .= ", ".&Time2String(time() - $requested_time)." ago";
+ my $requested_time = $factinfo{'requested_time'};
+ if ($requested_time) {
+ if (time() - $requested_time > 60*60*24*7) {
+ $string .= " at \037". scalar(localtime $requested_time). "\037";
+ } else {
+ $string .= ", ".&Time2String(time() - $requested_time)." ago";
+ }
}
+ } else {
+ $string = "has not been requested yet";
}
- push(@array,$string);
+ push(@array, $string);
}
# locked:
return;
}
- &performStrictReply("$factinfo{'factoid_key'} -- ". join("; ", @array) .".");
+ &pSReply("$factinfo{'factoid_key'} -- ". join("; ", @array) .".");
return;
}
my ($type) = @_;
if ($type =~ /^author$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,created_by", "created_by IS NOT NULL");
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,created_by", undef,
+ "WHERE created_by IS NOT NULL"
+ );
my %author;
- foreach (keys %hash) {
- my $thisnuh = $hash{$_};
+ foreach my $factoid (keys %hash) {
+ my $thisnuh = $hash{$factoid};
$thisnuh =~ /^(\S+)!\S+@\S+$/;
$author{lc $1}++;
return &formListReply(0, $prefix, @list);
} elsif ($type =~ /^vandalism$/i) {
- &status("factstats(vandalism): starting...");
+ &status("factstats(vandalism): starting...");
my $start_time = &timeget();
- my %data = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
+ my %data = &sqlSelectColHash("factoids",
+ "factoid_key,factoid_value", undef,
+ "WHERE factoid_value IS NOT NULL"
+ );
my @list;
my $delta_time = &timedelta($start_time);
- &status(sprintf("factstats(vandalismbroken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
+ &status(sprintf("factstats(vandalism): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
$start_time = &timeget();
# parse the factoids.
}
$delta_time = &timedelta($start_time);
- &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0);
+ &status(sprintf("factstats(vandalism): %.02f sec to complete.", $delta_time)) if ($delta_time > 0);
# bail out on no results.
if (scalar @list == 0) {
return &formListReply(1, $prefix, @list);
} elsif ($type =~ /^total$/i) {
- &status("factstats(total): starting...");
+ &status("factstats(total): starting...");
my $start_time = &timeget();
my @list;
my $str;
push(@list, "total prepared for deletion - $str");
# total unique authors.
- foreach ( &dbRawReturn("SELECT created_by FROM factoids WHERE created_by IS NOT NULL") ) {
+ # TODO: convert to sqlSelectColHash ? (or ColArray?)
+ foreach ( &sqlRawReturn("SELECT created_by FROM factoids WHERE created_by IS NOT NULL") ) {
/^(\S+)!/;
my $nick = lc $1;
$hash{$nick}++;
undef %hash;
# total unique requesters.
- foreach ( &dbRawReturn("SELECT requested_by FROM factoids WHERE requested_by IS NOT NULL") ) {
+ foreach ( &sqlRawReturn("SELECT requested_by FROM factoids WHERE requested_by IS NOT NULL") ) {
/^(\S+)!/;
my $nick = lc $1;
$hash{$nick}++;
### end of "job".
my $delta_time = &timedelta($start_time);
- &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
+ &status(sprintf("factstats(broken): %.02f sec to retreive all factoids.", $delta_time)) if ($delta_time > 0);
$start_time = &timeget();
# bail out on no results.
}
# parse the results.
- my $prefix = "General factoid stiatistics ";
+ my $prefix = "General factoid statistics ";
return &formListReply(1, $prefix, @list);
} elsif ($type =~ /^deadredir$/i) {
for (@list) {
my $factoid = $_;
my $val = &getFactInfo($factoid, "factoid_value");
- if ($val =~ /^<REPLY> see( also)? (.*?)\.?$/i) {
+ if ($val =~ /^<REPLY> ?see( also)? (.*?)\.?$/i) {
my $redirf = lc $2;
my $redir = &getFactInfo($redirf, "factoid_value");
next if (defined $redir);
return &formListReply(1, $prefix, @newlist);
} elsif ($type =~ /^dup(licate|e)$/i) {
- &status("factstats(dupe): starting...");
+ &status("factstats(dupe): starting...");
my $start_time = &timeget();
- my %hash = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL", 1);
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,factoid_value", undef,
+ "WHERE factoid_value IS NOT NULL", 1
+ );
my $refs = 0;
my @list;
my $v;
&status("factstats(dupe): (good) dupe refs: $refs.");
my $delta_time = &timedelta($start_time);
- &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0);
+ &status(sprintf("factstats(dupe): %.02f sec to complete", $delta_time)) if ($delta_time > 0);
# bail out on no results.
if (scalar @list == 0) {
return &formListReply(1, $prefix, @list);
} elsif ($type =~ /^locked$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,locked_by", "locked_by IS NOT NULL");
+ my %hash = &sqlSelectColhash("factoids",
+ "factoid_key,locked_by", undef,
+ "WHERE locked_by IS NOT NULL"
+ );
my @list = keys %hash;
for (@list) {
return &formListReply(0, $prefix, @list);
} elsif ($type =~ /^new$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,created_time", "created_time IS NOT NULL");
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,created_time", undef,
+ "WHERE created_time IS NOT NULL"
+ );
my %age;
foreach (keys %hash) {
}
my $delta_time = sprintf("%.02fs", &timedelta($start_time) );
- &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0);
+ &status("factstats(partdupe): $delta_time sec to complete.") if ($delta_time > 0);
# bail out on no results.
if (scalar @list == 0) {
return &formListReply(1, $prefix, @list);
} elsif ($type =~ /^profanity$/i) {
- my %data = &dbGetCol("factoids", "factoid_key,factoid_value", "factoid_value IS NOT NULL");
+ my %data = &sqlSelectColHash("factoids",
+ "factoid_key,factoid_value", undef,
+ "WHERE factoid_value IS NOT NULL"
+ );
my @list;
foreach (keys %data) {
"factoid_value", "^<REPLY> see ");
my %redir;
my $f;
+ my $dangling = 0;
for (@list) {
my $factoid = $_;
if (defined $redirval) {
$redir{$redir}{$factoid} = 1;
} else {
- &WARN("factstats(redir): '$factoid' has loose link => '$redir'.");
+ &DEBUG("factstats(redir): '$factoid' has loose link => '$redir'.");
+ $dangling++;
}
}
}
}
# parse the results.
- my $prefix = "Redirections in factoids ";
+ my $prefix = "Redirections in factoids, $dangling dangling ";
return &formListReply(1, $prefix, @newlist);
} elsif ($type =~ /^request(ed)?$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,requested_count", "requested_count IS NOT NULL", 1);
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,requested_count", undef,
+ "WHERE requested_count IS NOT NULL", 1
+ );
if (!scalar keys %hash) {
return 'sorry, no factoids have been questioned.';
return &formListReply(0, $prefix, @list);
} elsif ($type =~ /^reqrate$/i) {
- my %hash = &dbGetCol("factoids",
- "factoid_key,(unix_timestamp() - created_time)/requested_count as rate",
- "requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1);
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,(unix_timestamp() - created_time)/requested_count as rate", undef,
+ "WHERE requested_by IS NOT NULL and created_time IS NOT NULL ORDER BY rate LIMIT 15", 1
+ );
my $rate;
my @list;
return &formListReply(0, $prefix, @list);
} elsif ($type =~ /^requesters?$/i) {
- my %hash = &dbGetCol("factoids", "factoid_key,requested_by", "requested_by IS NOT NULL");
+ my %hash = &sqlSelectColHash("factoids",
+ "factoid_key,requested_by", undef,
+ "WHERE requested_by IS NOT NULL"
+ );
my %requester;
foreach (keys %hash) {
for (@list) {
my $factoid = $_;
my $val = &getFactInfo($factoid, "factoid_value");
-
+
next unless ($val =~ /^see( also)? (.*?)\.?$/i);
my $redirf = lc $2;
} elsif ($type =~ /^(2|too)long$/i) {
my @list;
+ my $query;
# factoid_key.
$query = "SELECT factoid_key FROM factoids WHERE length(factoid_key) >= $param{'maxKeySize'}";
while (my @row = $sth->fetchrow_array) {
push(@list,$row[0]);
}
+ $sth->finish;
# factoid_value.
- my $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) >= $param{'maxDataSize'}";
+ $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) >= $param{'maxDataSize'}";
$sth = $dbh->prepare($query);
$sth->execute;
while (my @row = $sth->fetchrow_array) {
push(@list,sprintf("\002%s\002 - %s", length($row[1]), $row[0]));
}
+ $sth->finish;
if (scalar @list == 0) {
return "good. no factoids exceed length.";
return &formListReply(1, $prefix, @list);
} elsif ($type =~ /^unrequest(ed)?$/i) {
- my @list = &dbRawReturn("SELECT factoid_key FROM factoids WHERE requested_count IS NULL");
-
- for (@list) {
- s/([\,\;]+)/\037$1\037/g;
- }
+ # TODO: use sqlSelect()
+ my ($count) = &sqlRawReturn("SELECT COUNT(*) FROM factoids WHERE requested_count = '0'");
- my $prefix = "Unrequested factoids ";
- return &formListReply(0, $prefix, @list);
+ return "Unrequested factoids: $count";
}
return "error: invalid type => '$type'.";
sub CmdListAuth {
my ($query) = @_;
+ my $maxshow = &::getChanConfDefault('maxListReplyCount', 15);
my @list = &searchTable("factoids","factoid_key", "created_by", "^$query!");
+ @list=grep(!/\#DEL\#$/,@list) if (scalar(@list) > $maxshow);
my $prefix = "factoid author list by '$query' ";
&performStrictReply( &formListReply(1, $prefix, @list) );