X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fdb_dbm.pl;h=909ed1858f107f0000d670c06a658c7b018a3bb7;hb=45ba7270eabca3ce9467bb7a1f52ce714f9d1a77;hp=f6823366a1d3ee81ddfffceabf476340042e4104;hpb=147fac0df7315c7b0b1cfe59dbc81f82241b9153;p=infobot.git diff --git a/src/db_dbm.pl b/src/db_dbm.pl index f682336..909ed18 100644 --- a/src/db_dbm.pl +++ b/src/db_dbm.pl @@ -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)) {