in reply to Re: Multidimentional array help
in thread Multidimentional array help

I've been hammering away at this for a while and I'm stuck. Is there a way to simulate the actual execute by simply printing the string for each element in @dlrloc_array that would be run by the execute?
my @dlrloc_array = qw(A100 A200 A300 A400 A500 A600 A700 A800); my $dlrgrp_name = 'RUSH'; my $dlrdiv = 'PB'; my $dlrcountry = 'USA'; my $runDOW = 'WEDNESDAY'; my $daysofsupply = 45; my $ordertype = 'SEASONAL'; my $plannercode = 'M63'; my $size = @dlrloc_array; if ( $size > 0 ) { my $table = 'pac.promo_rpt'; my @fields = qw( dlrcode dlrgroup division country planner ordertype daysofsupply run_dow sof_or_excel abc_co +des ); my $fields = join(', ', @fields); my $places = join(', ', ('?') x @fields); my $sql = "INSERT into $table ($fields) values ($places)"; for my $a_val ( @dlrloc_array ) { $sth->execute( $a_val, $ordtype ); } }

Replies are listed 'Best First'.
Re^3: Multidimentional array help
by punkish (Priest) on Jun 01, 2007 at 03:39 UTC
    Now you have a question that is totally different from the original question. What you are asking for now are known as "bind variables." You need to do something like so (and, your code above is highly incomplete -- I will assume that you have better, more complete code in real life) --

    my $sth = $dbh->prepare(qq{ INSERT into pac.promo_rpt ( dlrcode, dlrgroup, division, country, planner, ordertype, daysofsupply, run_dow, sof_or_excel, abc_codes ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }); $sth->execute( $foo, $bar, $baz, $qux... );

    The number of bind variables in the execute step have to be the same and in the same order as represented by the ? in the prepared statement. Look up the docs on bind variables in DBI.pm.

    --

    when small people start casting long shadows, it is time to go to bed