]> git.donarmstrong.com Git - infobot.git/blobdiff - blootbot/src/dbi.pl
woot! %myModules is dead
[infobot.git] / blootbot / src / dbi.pl
index 6761b230051bb94155d8dee874df547199558e8a..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;
@@ -636,15 +636,10 @@ sub checkTables {
            $db{$_} = 1;
        }
 
-       # create database.
-       if (!scalar keys %db) {
-           &status("Creating database $param{'DBName'}...");
-           my $query = "CREATE DATABASE $param{'DBName'}";
-           &sqlRaw("create(db $param{'DBName'})", $query);
-       }
+       # create database not needed for SQLite
     }
 
-    foreach ( qw(factoids rootwarn seen stats botmail) ) {
+    foreach ( qw(botmail connections factoids rootwarn seen stats) ) {
        if (exists $db{$_}) {
            $cache{has_table}{$_} = 1;
            next;