]> git.donarmstrong.com Git - infobot.git/blobdiff - src/db_dbm.pl
add initial SQLite support
[infobot.git] / src / db_dbm.pl
index f6823366a1d3ee81ddfffceabf476340042e4104..909ed1858f107f0000d670c06a658c7b018a3bb7 100644 (file)
@@ -12,7 +12,6 @@ if (&IsParam('useStrict')) { use strict;}
 
 use vars qw(%factoids %freshmeat %seen %rootwarn);     # db hash.
 
-
 {
     my %formats = (
        'factoids', [
@@ -29,18 +28,11 @@ use vars qw(%factoids %freshmeat %seen %rootwarn);  # db hash.
            'locked_time'
        ],
        'freshmeat', [
-           'name',
-           'stable',
-           'devel',
-           'section',
+           'projectname_short',
+           'latest_version',
            'license',
-           'homepage',
-           'download',
-           'changelog',
-           'deb',
-           'rpm',
-           'link',
-           'oneliner'
+           'url_homepage',
+           'desc_short'
        ],
        'rootwarn', [
            'nick',
@@ -144,14 +136,14 @@ sub dbGet {
        return(@retval);
     }
 
-    &DEBUG("dbGet: select => '$select'.");
+    &DEBUG("dbGet: select=>'$select'.");
     my @array = split "$;", ${"$table"}{lc $val};
-    unshift(@array,$key);
+    unshift(@array,$val);
     for (0 .. $#format) {
        my $str = $format[$_];
        next unless (grep /^$str$/, split(/\,/, $select));
        $array[$_] ||= '';
-       &DEBUG("dG: pushing '$array[$_]'.");
+       &DEBUG("dG: '$format[$_]'=>'$array[$_]'.");
        push(@retval, $array[$_]);
     }
 
@@ -210,13 +202,13 @@ sub dbInsert {
        $array[$i - 1]=$hash{$col};
        $array[$i - 1]='' unless $array[$i - 1];
        delete $hash{$col};
-       &DEBUG("dbI: setting $table->$primkey\{$col\} => '$array[$i - 1]'.");
+       &DEBUG("dbI: '$col'=>'$array[$i - 1]'");
     }
 
     if (scalar keys %hash) {
        &ERROR("dbI: not added...");
        foreach (keys %hash) {
-           &ERROR("dbI:   '$_' => '$hash{$_}'");
+           &ERROR("dbI: '$_'=>'$hash{$_}'");
        }
        return 0;
     }
@@ -227,7 +219,7 @@ sub dbInsert {
 }
 
 sub dbUpdate {
-    &FIXME("STUB: &dbUpdate(@_); => somehow use dbInsert!");
+    &FIXME("STUB: &dbUpdate(@_);=>somehow use dbInsert!");
 }
 
 #####
@@ -267,7 +259,7 @@ sub dbDel {
     &DEBUG("dbDel($table, $primkey, $primval);");
 
     if (!defined ${$table}{lc $primval}) {
-       &WARN("dbDel: lc $primval does not exist in $table.");
+       &DEBUG("dbDel: lc $primval does not exist in $table.");
     } else {
        delete ${$table}{lc $primval};
     }
@@ -296,6 +288,7 @@ sub dbSet {
     my $where = $key . "=" . $phref->{$key};
 
     my %hash = &dbGetColNiceHash($table, "*", $where);
+    $hash{$key}=$phref->{$key};
     foreach (keys %{$href}) {
        &DEBUG("dbSet: setting $_=${$href}{$_}");
        $hash{$_} = ${$href}{$_};
@@ -327,15 +320,30 @@ sub getKeys {
 }
 
 sub randKey {
-    &FIXME("STUB: &randKey(@_);");
+    &DEBUG("STUB: &randKey(@_);");
+    my @format = &dbGetColInfo($table);
+    if (!scalar @format) {
+       return;
+    }
+
+    my $rand = int(rand(&countKeys($table) - 1));
+    my @keys = keys %{$table};
+    &dbGet($table, '*', "@format[0]=@keys[$rand]");
+}
+
+#####
+# Usage: &deleteTable($table);
+sub deleteTable {
+    my ($table) = @_;
+    &FIXME("STUB: deleteTable($table)");
 }
 
 ##### $select is misleading???
 # Usage: &searchTable($table, $returnkey, $primkey, $str);
 sub searchTable {
+    my ($table, $primkey, $key, $str) = @_;
     &FIXME("STUB: searchTable($table, $primkey, $key, $str)");
     return;
-    my ($table, $primkey, $key, $str) = @_;
     &DEBUG("searchTable($table, $primkey, $key, $str)");
 
     if (!scalar &dbGetColInfo($table)) {