Hello all again,
Solaris, Perl 5, Oracle 8.1.6
OK, so here I am... Now I am having issues accessing my database from my
Perl SQL query. I want to query my DB and put it's response into a variable
to be used later. I really think that I am structuring my perl query wrong.
How do I get my SELECT statement to work and put the query answer into a
variable? I don't have much experience with this. Again, I am running this
script against strings like:
/export/home/user/www/doc-root/directory/projects/19463/1_0001.doc
Below is my whole script thus far:
#USAGE: migratefiles Path
#
# ex: migratefiles
use DBI;
process_files($ARGV[0]);
#
----------------------------------------------------------------------------
sub process_files {
$dir=shift;
$_ = $dir;
if (!/\/$/) {
$dir = $dir."/";
}
@flist;
print "Specified Directory: $dir\n";
if (opendir(DIRH, "$dir")) {
@flist=readdir(DIRH);
closedir DIRH;
foreach $flist (@flist) { ## loop through directory list
$_ = $flist;
next if ($_ eq "." || $_ eq "..");
$projectDocDir = $dir.$_;
print "PROCESS: $projectDocDir\n";
##loop through files in project document directory
if (opendir(DIRH, "$projectDocDir")) {
@dirlist=readdir(DIRH);
closedir DIRH;
foreach $dirlist (@dirlist) { ## loop through Project Doc
directory list
$_ = $dirlist;
next if ($_ eq "." || $_ eq "..");
if (! -l "$projectDocDir/$_"){
print "$projectDocDir/$_\n";
}
##put yur filename with .dir in $_
##$docName =~ s/(.*)\.dir$/$1/; ## strip off ".dir"
$docName = substr($_, 0, length($_)-4);
$docFolder = "$projectDocDir/$_";
print "$docName , $docFolder\n";
##get the project id
$projectId = substr($projectDocDir, length($dir),
index($projectDocDir, "/", length($dir)-1));
print "$projectId\n";
## SQL query for folder OID
$rootDir = "directory/projects";
my $dbh = DBI->connect( 'dbi:Oracle:thedb',
'user',
'passwd',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";
my $sql = qq{ SELECT c.oid AS folder_oid
FROM dp_doc_folder_content c, bv_ep_proj_attach a
WHERE c.DOC_DELETED=0
AND c.DOC_OID=a.ASSOC_CONTENT
AND a.file_path = '$rootDir/$projectId/$docName' };
my $sth = $dbh->prepare ( $sql );
$sth->execute();
while( my@row = $sth->fetchrow_array )
{
my$oid=$row[0];
print "$oid\n";
}
$sth->finish();
$dbh->disconnect();
}
}
}
} else {
print "ERROR: can not read directory $dir\n";
}
}
# -------------------------------------------------------------------------
I appreciate all your help!! Thanks.
-garrett
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]