X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fdbi.pl;h=5071404081f3196205d72c7fd966e71c7bde0e3c;hb=f7cae48a17d6decd0a9bd997188271daa0a885b1;hp=f9f731930b5b39d9db54e997fe69506be77895f4;hpb=f3a7f67d07f3a8511e269ce55da6dc7d0c2087e6;p=infobot.git diff --git a/src/dbi.pl b/src/dbi.pl index f9f7319..5071404 100644 --- a/src/dbi.pl +++ b/src/dbi.pl @@ -88,12 +88,11 @@ sub sqlSelectMany { 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"); @@ -101,10 +100,8 @@ sub sqlSelectMany { } &SQLDebug($query); - if (!$sth->execute) { - &ERROR("sqlSelectMany: execute: '$query'"); - return; - } + + return if (!$sth->execute); return $sth; } @@ -240,7 +237,8 @@ sub sqlSet { 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. @@ -264,7 +262,7 @@ sub sqlUpdate { 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); @@ -560,7 +558,7 @@ sub searchTable { $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); @@ -643,10 +641,16 @@ sub checkTables { } } - foreach ( qw(factoids 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($_); } }