]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/dbi.pl
debian -> Debian
[infobot.git] / blootbot / src / dbi.pl
index 36f92a19a280b14a0ab6a6cf5d32753570120a09..f4c89d3a80e5caf2e096c6067b293b8feffafc0b 100644 (file)
@@ -514,12 +514,12 @@ sub sumKey {
 # Usage: &randKey($table, $select);
 sub randKey {
     my ($table, $select) = @_;
-    my $rand   = int(rand(&countKeys($table) - 1));
-    my $query  = "SELECT $select FROM $table LIMIT $rand,1";
-    if ($param{DBType} =~ /^pg/i) {
-       $query =~ s/$rand,1/1,$rand/;
+    my $rand   = int(rand(&countKeys($table)));
+    my $query  = "SELECT $select FROM $table LIMIT 1 OFFSET $rand";
+    if ($param{DBType} =~ /^mysql$/i) {
+       # WARN: only newer MySQL supports "LIMIT limit OFFSET offset"
+       $query = "SELECT $select FROM $table LIMIT $rand,1";
     }
-
     my $sth    = $dbh->prepare($query);
     &SQLDebug($query);
     &WARN("randKey($query)") unless $sth->execute;
@@ -639,7 +639,7 @@ sub checkTables {
        # create database not needed for SQLite
     }
 
-    foreach ( qw(botmail factoids rootwarn seen stats) ) {
+    foreach ( qw(botmail connections factoids rootwarn seen stats) ) {
        if (exists $db{$_}) {
            $cache{has_table}{$_} = 1;
            next;