Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: DBI execute_array

by ikegami (Patriarch)
on Feb 11, 2009 at 14:52 UTC ( [id://743086]=note: print w/replies, xml ) Need Help??


in reply to DBI execute_array

Example from the docs:

my $sth = $dbh->prepare("INSERT INTO staff (first_name, last_name) VAL +UES (?, ?)"); my $tuples = $sth->execute_array( { ArrayTupleStatus => \my @tuple_status }, \@first_names, \@last_names, ); if ($tuples) { print "Successfully inserted $tuples records\n"; } else { for my $tuple (0..@last_names-1) { my $status = $tuple_status[$tuple]; $status = [0, "Skipped"] unless defined $status; next unless ref $status; printf "Failed to insert (%s, %s): %s\n", $first_names[$tuple], $last_names[$tuple], $status->[1]; } }

It inserts from @first_names and @last_names. You insert from @books.

my $sth = $dbh->prepare("INSERT INTO temp_selectedTitles VALUES (?)"); my $tuples = $sth->execute_array( { ArrayTupleStatus => \my @tuple_status }, \@books, ); if ($tuples) { print "Successfully inserted $tuples records\n"; } else { for my $tuple (0..$#books) { my $status = $tuple_status[$tuple]; $status = [0, "Skipped"] unless defined $status; next unless ref $status; printf "Failed to insert (%s): %s\n", $books[$tuple], $status->[1]; } }

Update: There's something buggy with the error reporting. The next will never execute. Does anyone know what they were trying to accomplish?

Update: No, it could still be executed, but it still looks very odd.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://743086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found