in reply to DBI execute() args in array format (or similar) possible?
I finally able to figure that since all the elements were correct, despite what some said (although, it is a good idea to check and make sure...which I do in other subroutines and I intend to do a more thorough check/match on the number of elements in the array to the num of '?' used in the query) that I should be able to pass that info onto the execute method. Anyhoo, after thinking about it and doing some tinkering, I finally got it to work out right. /me loves eval.
I also took the advice by perrin and fixed my var declarations for the shift statements.
Thanks again, everyone, for your input.
The magic line of code that solved my problem...
The code (sub routine) altogether now:$STH->execute(eval{join(',',@args),return(@args)});
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(eval{join(',',@args),return(@args)}); while ( my @arr = $STH->fetchrow_array() ) { print @arr,"\n"; push(@results,@arr); } $STH->finish(); print "@results\n"; return(1); }
I think I am going to run into some documentation that will assist me more in what it is I was trying to accomplish. Because, I think I read something today that looks like it is doing the same thing I was doing; calling the execute with an array with the data in it that should be executed. However, I haven't finished reading that stuff yet, so I am sticking with what I have until I get more info.
Feel free to continue to correct and offer suggestions. It is quite helpful and may spark a discussion that is useful for all.
_
_
_
_
_
_
_
_
_
_
- Jim
Insert clever comment here...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: DBI execute() args in array format (or similar) possible?
by dws (Chancellor) on Aug 12, 2002 at 22:37 UTC | |
by snafu (Chaplain) on Aug 13, 2002 at 03:53 UTC | |
by dws (Chancellor) on Aug 13, 2002 at 04:36 UTC | |
by snafu (Chaplain) on Aug 14, 2002 at 17:08 UTC | |
Re: Re: DBI execute() args in array format (or similar) possible?
by perrin (Chancellor) on Aug 12, 2002 at 22:26 UTC | |
by snafu (Chaplain) on Aug 12, 2002 at 22:33 UTC |