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.
|
|---|