--- trunk/lib/BackupPC/SearchLib.pm 2005/08/21 14:26:23 58 +++ trunk/lib/BackupPC/SearchLib.pm 2005/08/21 15:29:24 59 @@ -16,25 +16,24 @@ my $db_user = $Conf{SearchUser} || ''; sub getUnits() { - my @ret = (); - my $tmp; - my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); - my $st = - $dbh->prepare( - " SELECT shares.ID AS ID, shares.share AS name FROM shares;"); - $st->execute(); - push (@ret, { 'ID' => '', 'name' => '-'}); - while ( $tmp = $st->fetchrow_hashref() ) { - push( @ret, { 'ID' => $tmp->{'ID'}, 'name' => $tmp->{'name'} } ); - } - $dbh->disconnect(); - return @ret; + my @ret; + + my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); + my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares} ); + $sth->execute(); + push @ret, { 'id' => '', 'share' => '-'}; # dummy any + + while ( my $row = $sth->fetchrow_hashref() ) { + push @ret, $row; + } + $dbh->disconnect(); + return @ret; } sub epoch_to_iso { my $t = shift || return; my $dt = DateTime->from_epoch( epoch => $t ) || return; -print STDERR "$t == ",$dt->epoch,"\n"; + print STDERR "BUG: $t != " . $dt->epoch . "\n" unless ($t == $dt->epoch); return $dt->ymd . ' ' . $dt->hms; } @@ -68,7 +67,7 @@ my $files_to = mk_epoch_date('search', 'to'); push @conditions, qq{ files.date <= $files_to } if ($files_to); - print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:",join(" | ",@conditions); + print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions); push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'}); @@ -99,9 +98,6 @@ files.date AS date, files.type AS filetype, files.size AS size, - }; - - my $sql_dvd_cols = qq{ dvds.name AS dvd }; @@ -121,21 +117,29 @@ my $sql_order = qq{ ORDER BY files.id - LIMIT $on_page - OFFSET ? + LIMIT $on_page + OFFSET ? }; + my $sql_count = qq{ select count(files.id) $sql_from $sql_where }; + my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order }; + $offset ||= 0; - $offset = ($offset * $on_page) + 1; + $offset = ($offset * $on_page); - my $sth = $dbh->prepare(qq{ select count(files.id) $sql_from $sql_where }); + my $sth = $dbh->prepare($sql_count); $sth->execute(); - my ($results) = $sth->fetchrow_array(); - $sth = $dbh->prepare(qq{ select $sql_cols $sql_dvd_cols $sql_from $sql_dvd_from $sql_where $sql_order }); + $sth = $dbh->prepare($sql_results); $sth->execute( $offset ); + if ($sth->rows != $results) { + my $bug = "$0 BUG: [[ $sql_count ]] = $results while [[ $sql_results ]] = " . $sth->rows; + $bug =~ s/\s+/ /gs; + print STDERR "$bug\n"; + } + my @ret; while (my $row = $sth->fetchrow_hashref()) { @@ -154,7 +158,7 @@ 'dvd' => $row->{'dvd'} }); } - + $sth->finish(); $dbh->disconnect(); return ($results, \@ret); @@ -290,12 +294,6 @@ my ($where, $addForm, $offset, $hilite) = @_; my $retHTML = ""; - if ($addForm) { - $retHTML .= qq{
}; - $retHTML.= qq{}; - $retHTML .= qq{}; - } - my $start_t = time(); my ($results, $files) = getFiles($where, $offset); @@ -305,6 +303,25 @@ my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page); + if ($results <= 0) { + $retHTML .= qq{ +

No results found...

+ }; + return $retHTML; + } else { + # DEBUG + #use Data::Dumper; + #$retHTML .= '
' . Dumper($files) . '
'; + } + + + if ($addForm) { + $retHTML .= qq{}; + $retHTML.= qq{}; + $retHTML .= qq{}; + } + + $retHTML .= qq{
Found $results files showing $from - $to (took $dur)