Now, in creating this dynamic SQL statement I create the statement and attempt to plug in the values for the unknowns in the statement via the DBI::execute() method (it is a method, right? :) I always get the terminology wrong, so if I did, please forgive me) from the arguments off the command line. *This* is where I get my error. See below...
You will notice in the Perl code below that I am trying to execute that statement with the following:
Which is generated from:Preparing statement: select clli, traffic_date, count(distinct(traffic_hour)) from gvc_traffic30 where traffic_date in (?) and clli in (?,?) and traffic_hour in (?) and traffic_type = 'N' group by clli, traffic_date, traffic_hour running with args : 01-Jul-2002 switch1 switch2 10
I get the error:traffic_est_report.pl -c switch1,switch2 -d 01-Jul-2002 -H 10
Now, I know why I am getting this error; because I am trying to call execute with the args as an array vs listing the args out manually. I tried to call the function with a join() attempting to join @args with commas effectively turning the args into a scalar separated by commas but I couldn't fool the execute command this way.execute called with 1 bind variables when 4 are needed at traffic_est_ +report.pl line 467.
So, I ask my fellow monks this simple question...What do you suggest I do? I will never know exactly what the end user wants, so there really are no definites. The dynamic-ness of this is quite nice. This issue is the only stumbling block I have.
sub get_data { my ($statement) = shift; my ($clli_ref_args) = shift; my ($hour_ref_args) = shift; my ($date_ref_args) = shift; my ($start_date, $end_date); my (@results,@args); push(@args,@$date_ref_args) if ( $date_ref_args ); push(@args,@$clli_ref_args) if ( $clli_ref_args ); push(@args,@$hour_ref_args) if ( $hour_ref_args ); print "Preparing statement: $statement\n"; print "running with args : @args\n\n"; $STH = $DBH->prepare($statement) or warn("Unable to prep statement.\n"); $STH->execute(@args); while ( my @arr = $STH->fetchrow_array() ) { print @arr,"\n"; push(@results,@arr); } $STH->finish(); print "@results\n"; return(1); }
_
_
_
_
_
_
_
_
_
_
- Jim
Insert clever comment here...
In reply to DBI execute() args in array format (or similar) possible? by snafu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |