return;
}
- $query .= " WHERE" if (($where_href) || ($other));
if ($where_href) {
my $where = &hashref2where($where_href);
- $query .= " $where" if ($where);
+ $query .= " WHERE $where" if ($where);
}
- $query .= " $other" if $other;
+ $query .= " $other" if ($other);
if (!($sth = $dbh->prepare($query))) {
&ERROR("sqlSelectMany: prepare: $DBI::errstr");
}
&SQLDebug($query);
- if (!$sth->execute) {
- &ERROR("sqlSelectMany: execute: '$query'");
- return;
- }
+
+ return if (!$sth->execute);
return $sth;
}
my %retval;
if (defined $type and $type == 2) {
- &DEBUG("dbgetcol: type 2!");
+ &DEBUG("sqlSelectColHash: type 2!");
while (my @row = $sth->fetchrow_array) {
$retval{$row[0]} = join(':', $row[1..$#row]);
}
- &DEBUG("dbgetcol: count => ".scalar(keys %retval) );
+ &DEBUG("sqlSelectColHash: count => ".scalar(keys %retval) );
} elsif (defined $type and $type == 1) {
while (my @row = $sth->fetchrow_array) {
my $result = &sqlSelect($table, $k, $where_href);
# &DEBUG("result is not defined :(") if (!defined $result);
- if (1 or defined $result) {
+ # this was hardwired to use sqlUpdate. sqlite does not do inserts on sqlUpdate.
+ if (defined $result) {
&sqlUpdate($table, $data_href, $where_href);
} else {
# hack.
if (!defined $data_href or ref($data_href) ne "HASH") {
&WARN("sqlSet: data_href == NULL.");
- return;
+ return 0;
}
my $where = &hashref2where($where_href) if ($where_href);
sub countKeys {
my ($table, $col) = @_;
$col ||= "*";
- &DEBUG("&countKeys($table, $col);");
return (&sqlRawReturn("SELECT count($col) FROM $table"))[0];
}
#####
# Usage: &searchTable($table, $select, $key, $str);
-# Note: searchTable does dbQuote.
+# Note: searchTable does sqlQuote.
sub searchTable {
my($table, $select, $key, $str) = @_;
my $origStr = $str;
# allow two types of wildcards.
if ($str =~ /^\^(.*)\$$/) {
- &DEBUG("searchTable: should use dbGet(), heh.");
+ &FIXME("searchTable: can't do \"$str\"");
$str = $1;
} else {
$str .= "%" if ($str =~ s/^\^//);
$str =~ s/\*/%/g;
# end of string fix.
- my $query = "SELECT $select FROM $table WHERE $key LIKE ".
+ my $query = "SELECT $select FROM $table WHERE $key LIKE ".
&sqlQuote($str);
my $sth = $dbh->prepare($query);
foreach (@path) {
my $file = "$_/setup/$table.sql";
- &DEBUG("dbCT: table => '$table', file => '$file'");
next unless ( -f $file );
- &DEBUG("dbCT: found!!!");
-
open(IN, $file);
while (<IN>) {
chop;
}
}
- foreach ( qw(factoids freshmeat rootwarn seen stats botmail) ) {
- next if (exists $db{$_});
+ foreach ( qw(factoids factoidsmisc rootwarn seen stats botmail) ) {
+ if (exists $db{$_}) {
+ $cache{has_table}{$_} = 1;
+ next;
+ }
+
&status("checkTables: creating new table $_...");
+ $cache{create_table}{$_} = 1;
+
&sqlCreateTable($_);
}
}