]> git.donarmstrong.com Git - infobot.git/blobdiff - src/dbi.pl
If topicAuthor is on then show it in topic, otherwise just topic -- contribution...
[infobot.git] / src / dbi.pl
index b0abee1123faf984528142782e61edbf9b1d3f0e..bb3c396c9b38df6a134d1074b73cbdeae7777999 100644 (file)
@@ -19,7 +19,7 @@ package main;
 sub sqlOpenDB {
     my ($db, $type, $user, $pass, $no_fail) = @_;
     # this is a mess. someone fix it, please.
-    if ($type =~ /^SQLite$/i) {
+    if ($type =~ /^SQLite(2)?$/i) {
        $db = "dbname=$db.sqlite";
     } elsif ($type =~ /^pg/i) {
        $db = "dbname=$db";
@@ -293,12 +293,10 @@ sub sqlInsert {
        return;
     }
 
-    &sqlRaw("Insert($table)", sprintf(
+    return &sqlRaw("Insert($table)", sprintf(
        "INSERT %s INTO %s (%s) VALUES (%s)",
        ($other || ""), $table, join(',',@k), join(',',@v)
     ) );
-
-    return 1;
 }
 
 #####
@@ -514,9 +512,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;
@@ -626,7 +627,7 @@ sub checkTables {
        &status("Tables: ".join(',',@tables));
        @db{@tables} = (1) x @tables;
 
-    } elsif ($param{DBType} =~ /^SQLite$/i) {
+    } elsif ($param{DBType} =~ /^SQLite(2)?$/i) {
 
        # retrieve a list of db's from the server.
        foreach ( &sqlRawReturn("SELECT name FROM sqlite_master WHERE type='table'") ) {
@@ -636,7 +637,7 @@ sub checkTables {
        # create database not needed for SQLite
     }
 
-    foreach ( qw(botmail connections factoids rootwarn seen stats) ) {
+    foreach ( qw(botmail connections factoids rootwarn seen stats onjoin) ) {
        if (exists $db{$_}) {
            $cache{has_table}{$_} = 1;
            next;