/[BackupPC]/trunk/lib/BackupPC/SearchLib.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/SearchLib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by dpavlin, Sat Aug 20 16:40:11 2005 UTC revision 55 by dpavlin, Sun Aug 21 13:44:20 2005 UTC
# Line 7  use BackupPC::Attrib qw(:all); Line 7  use BackupPC::Attrib qw(:all);
7  use DBI;  use DBI;
8  use DateTime;  use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10    use Time::HiRes qw/time/;
11    
12  my $on_page = 100;  my $on_page = 100;
13  my $pager_pages = 10;  my $pager_pages = 10;
# Line 98  sub getFiles($$) { Line 99  sub getFiles($$) {
99                  files.date                      AS date,                  files.date                      AS date,
100                  files.type                      AS filetype,                  files.type                      AS filetype,
101                  files.size                      AS size,                  files.size                      AS size,
102            };
103    
104            my $sql_dvd_cols = qq{
105                  dvds.name                       AS dvd                  dvds.name                       AS dvd
106          };          };
107    
# Line 106  sub getFiles($$) { Line 110  sub getFiles($$) {
110                          INNER JOIN shares       ON files.shareID=shares.ID                          INNER JOIN shares       ON files.shareID=shares.ID
111                          INNER JOIN hosts        ON hosts.ID = shares.hostID                          INNER JOIN hosts        ON hosts.ID = shares.hostID
112                          INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID                          INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID
113            };
114    
115            my $sql_dvd_from = qq{
116                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid                          LEFT  JOIN dvds         ON dvds.ID = files.dvdid
117          };          };
118    
# Line 126  sub getFiles($$) { Line 133  sub getFiles($$) {
133    
134          my ($results) = $sth->fetchrow_array();          my ($results) = $sth->fetchrow_array();
135    
136          $sth = $dbh->prepare(qq{ select $sql_cols $sql_from $sql_where $sql_order });          $sth = $dbh->prepare(qq{ select $sql_cols $sql_dvd_cols $sql_from $sql_dvd_from $sql_where $sql_order });
137          $sth->execute( $offset );          $sth->execute( $offset );
138    
139          my @ret;          my @ret;
# Line 156  sub getFiles($$) { Line 163  sub getFiles($$) {
163  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
164    
165          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
166        my $sql = q{          my $sql = q{
167            SELECT          SELECT
168              hosts.ID         AS hostID,                  hosts.ID                AS hostid,
169              hosts.name       AS host,                  min(hosts.name)         AS host,
170              backups.num      AS backupno,                  backups.num             AS backupno,
171              backups.type     AS type,                  min(backups.type)       AS type,
172              backups.date     AS date                  min(backups.date)       AS date
173            FROM backups, shares, files, hosts          FROM backups, shares, files, hosts
174            WHERE          WHERE
175              backups.num    = files.backupNum  AND                  backups.num     = files.backupNum       AND
176              shares.ID      = files.shareID    AND                            shares.ID       = files.shareID         AND        
177              backups.hostID = shares.hostID    AND                  backups.hostID  = shares.hostID         AND
178              hosts.ID       = backups.hostID   AND                  hosts.ID        = backups.hostID        AND
179              files.dvdid    IS NULL                  files.dvdid     IS NULL
180            GROUP BY          GROUP BY
181              backups.hostID, backups.num                  backups.hostID, backups.num, hosts.id
182        };          };
183        my $st = $dbh -> prepare( $sql );          my $sth = $dbh->prepare( $sql );
184        my @ret = ();          my @ret;
185        $st -> execute();          $sth->execute();
186    
187        while ( my $row = $st -> fetchrow_hashref() )          while ( my $row = $sth->fetchrow_hashref() ) {      
188          {                            push(@ret, {
             push(@ret, {  
189                           'host'     => $row->{'host'},                           'host'     => $row->{'host'},
190                           'hostid'   => $row->{'hostID'},                           'hostid'   => $row->{'hostid'},
191                           'backupno' => $row->{'backupno'},                           'backupno' => $row->{'backupno'},
192                           'type'     => $row->{'type'},                           'type'     => $row->{'type'},
193                           'date'     => $row->{'date'}                           'date'     => $row->{'date'}
194                         }                         }
195              );                  );
196          }          }
197                
198        return @ret;                return @ret;      
199    }  }
200    
201  sub displayBackupsGrid()  sub displayBackupsGrid()
202    {    {
# Line 278  sub displayGrid($$$$) { Line 284  sub displayGrid($$$$) {
284                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};                  $retHTML .= qq{<input type="hidden" value="results" name="search_results">};
285          }          }
286    
287            my $start_t = time();
288    
289          my ($results, $files) = getFiles($where, $offset);          my ($results, $files) = getFiles($where, $offset);
290    
291            my $dur_t = time() - $start_t;
292            my $dur = sprintf("%0.4fs", $dur_t);
293    
294          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);          my ($from, $to) = (($offset * $on_page) + 1, ($offset * $on_page) + $on_page);
295    
296          $retHTML .= qq{          $retHTML .= qq{
297          <br/>Found $results files, showing $from - $to          <br/>Found <b>$results files</b> showing <b>$from - $to</b> (took $dur)
298          <table style="fview" width="100%">          <table style="fview" width="100%">
299                  <tr>                  <tr>
300                  <td class="tableheader">Share</td>                  <td class="tableheader">Share</td>

Legend:
Removed from v.51  
changed lines
  Added in v.55

  ViewVC Help
Powered by ViewVC 1.1.26