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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.