On 29 Jun 2001 10:46:39 -0400, Kim Green wrote:
>
> Brett and Chas,
>
> I did create two file handles and alter my conditional statements, one to
> work when there is a variable, and one for when there's no variable. The
> first SQL statement should return everything for a given filename; the other
> should return everything for all filenames that meet the select criteria.
> Under the first condition, the script works and creates an output file. The
> second is still failing, as if it doesn't know what to do when $filename =
> 1. However, I did add a print $filename , and sure enough Filename = 1 when
> no parameter is given. Could you look at the script below to determine
> where the problem is?
>
> Here is a portion of the script:
<snip />
Your SQL is still expecting a variable replacement. A better way to
write this code is something like:
my $query = "
SELECT a.filename, a.size, a.date, b.owner, c.group
FROM filesystem a, outer owner b, outer group c
WHERE a.uid = b.uid
AND a.gid = b.gid";
my @query_options = (
" AND filename = ",
" AND size = ",
" AND date = "
);
my $i = 0;
#thanks go to Merlyn for making me think about @ARGV instead of using
#defined(ARGV[0])
$query .= $query_options[$i++] . shift while (@ARGV);
#the above line is equivilent to
#while (defined($ARGV[$i])) {
# $query = $query . $query_options[$i] . $ARGV[$i];
# $i++;
#}
#with the exception that @ARGV will be empty at the end of the loop
$sth = $dbh->prepare($query);
$sth->execute;
etc.
--
Today is Setting Orange, the 34th day of Confusion in the YOLD 3167
Hail Eris!