I've been staring at this for a while and am getting nowhere. Hope the list can help...
One of the guys is getting intermittent errors out of the script below. The error is
""Issuing rollback<> for database handle being DESTROY'd without explicit
disconnect<>."
The script:
#! /usr/local/bin/perl
use DBI;
use DBD::Oracle qw(:ora_types);
use utf8;
use FileHandle;
# Main
my ($dbh, $query, $sth, $rv, $song, $account_id, $win_dir, $account_name, $db_name,
$db_user, $db_password,
$db_file_path, $record_not_found, $conf_file_handle, $err_file_handle,
$out_file_handle, $file_name, $conf_file_name);
if($#ARGV != 4) {
print "Usage: $0 <WMA Directory> <Account Name> <Database> <DB User> <DB
Password>\n";
exit (1);
}
$ENV{NLS_LANG} = "AMERICAN_AMERICA.UTF8";
$win_dir = $ARGV[0];
$account_name = $ARGV[1];
$db_name = $ARGV[2];
$db_user = $ARGV[3];
$db_password = $ARGV[4];
$dbh = DBI->connect("DBI:Oracle:$db_name",$db_user,$db_password, { RaiseError => 1,
AutoCommit => 0 });
$dbh->{LongReadLen} = (1024 * 65);
$query = qq~ select cp.content_provider_id from im_content_provider cp where
cp.login_name = ? ~;
$sth = $dbh->prepare($query) or die "Connection to DB failed";
$rv = $sth->execute($account_name) or die "Execute Failed - $query - Account -
$ARGV[1]";
$account_id = $sth->fetchrow or die "Account Not Found - $account_name";
$sth->finish;
$query = qq~
select p.upc as sku, s.title as song_title, co.full_name as main_artist_name,
cy.name as copyright_text
from im_product p, im_album_song sa, im_song s, im_album a, im_collaborator
co, im_copyright cy
where p.file_path = ?
and sa.album_song_id = p.album_song_id
and s.song_id = sa.song_id
and a.album_id = sa.album_id
and a.content_provider_id = $account_id
and co.collaborator_id = s.main_artist_id
and cy.copyright_id = s.copyright_id
~;
$sth = $dbh->prepare($query) or die "Prepare Failed - $query";
opendir dir_handle, $win_dir or die "Failed to Open Directory $win_dir";
$out_file_handle = new FileHandle("> $win_dir/GetMetaData_OUT.csv") or die "File
Creation Failed - GetMetaData_OUT.csv - $!";
print $out_file_handle qq("SKU","Windows File Path","DB File Path","Song
Title","Main Artist Name","Copyright Text"\n);
$err_file_handle = new FileHandle("> $win_dir/GetMetaData_ERR.csv") or die "File
Creation Failed - GetMetaData_ERR.csv - $!";
print $err_file_handle qq("Windows File Path","DB File Path","Error Message"\n);
while($file_name = readdir dir_handle) {
if(!($file_name =~ /\.wma$/)) {
next;
}
$conf_file_name = $file_name;
$conf_file_name =~ s/\.wma$/\.conf/;
$db_file_path = qq(/opt/lmn/files/$account_name/wma/$file_name);
$record_not_found = 0;
$rv = $sth->execute($db_file_path) or die "Execute Failed - $query - File Path -
$db_file_path";
$song = $sth->fetchrow_hashref or $record_not_found = 1;
if($record_not_found) {
print $err_file_handle qq("$win_dir/$file_name","$db_file_path","Record Not
Found"\n);
next;
}
$conf_file_handle = new FileHandle("> $win_dir/$conf_file_name");
print $conf_file_handle qq(Title: $song->{SONG_TITLE}\n);
print $conf_file_handle qq(Author: $song->{MAIN_ARTIST_NAME}\n);
print $conf_file_handle qq(Copyright: $song->{COPYRIGHT_TEXT}\n);
print $conf_file_handle qq(Description: \n);
print $conf_file_handle qq(Rating: \n);
$conf_file_handle->close();
print $out_file_handle
qq("$song->{SKU}","$win_dir/$file_name","$db_file_path","$song->{SONG_TITLE}","$song->{MAIN_ARTIST_NAME}","$song->{COPYRIGHT_TEXT}"\n);
}
closedir dir_handle;
$sth->finish;
$out_file_handle->close();
$err_file_handle->close();
$dbh->disconnect;
--