]> git.donarmstrong.com Git - infobot.git/blobdiff - src/dbi.pl
scramble
[infobot.git] / src / dbi.pl
index f5565539924fc0eefa1dc70711de4be974384f72..f4c89d3a80e5caf2e096c6067b293b8feffafc0b 100644 (file)
@@ -514,9 +514,12 @@ sub sumKey {
 # Usage: &randKey($table, $select);
 sub randKey {
     my ($table, $select) = @_;
-    my $rand   = int(rand(&countKeys($table) - 1));
+    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;
@@ -636,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;