Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am dynamically creating an Oracle SQL statement based from $ARGV and then I create an excel spreadsheet from the return of the data from the statement.

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:

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
Which is generated from:
traffic_est_report.pl -c switch1,switch2 -d 01-Jul-2002 -H 10
I get the error:

execute called with 1 bind variables when 4 are needed at traffic_est_ +report.pl line 467.
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found