Advertisement
teuk

airtime_update_filesize.pl

Sep 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.29 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4. use strict;
  5. use warnings;
  6. use diagnostics;
  7. use DBI;
  8.  
  9. my $dbh = DBI->connect("dbi:Pg:dbname=airtime;host=localhost;port=5432;", "airtime", "airtime");
  10. my $sQuery = "SELECT cc_files.id as id_cc_files,cc_music_dirs.directory as dirname,filepath FROM cc_files,cc_music_dirs WHERE cc_files.directory=cc_music_dirs.id";
  11. my $sth = $dbh->prepare($sQuery);
  12. unless ($sth->execute()) {
  13.         print "SQL Error : " . $DBI::errstr . " Query : " . $sQuery . "\n";
  14. }
  15. else {
  16.         while (my $ref = $sth->fetchrow_hashref()) {
  17.                 my $id = $ref->{'id_cc_files'};
  18.                 my $filepath = $ref->{'filepath'};
  19.                 my $dirname = $ref->{'dirname'};
  20.  
  21.                 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$dirname/$filepath");
  22.                 print "$dirname/$filepath : $size bytes\n";
  23.                 $sQuery = "UPDATE cc_files SET filesize=? WHERE cc_files.id=?";
  24.                 my $sth2 = $dbh->prepare($sQuery);
  25.                 unless ($sth2->execute($size,$id)) {
  26.                         print "SQL Error : " . $DBI::errstr . " Query : " . $sQuery . "\n";
  27.                 }
  28.                 else {
  29.                         print "Updated row id : $id filesize=$size\n";
  30.                 }
  31.         }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement