in reply to DBI - Handling NULL values
Yes. Use placeholders.
Then you will have to prepare the $insert, and execute that statement handle while passing in the variables:unshift @fields, qw(hostname host_id); my $insert = "INSERT IGNORE INTO $thisTable (" . join(", ", @fields) . + ") VALUES (" . join(",", ('?') x @fields) . ")"; while (my @row = $dbq->fetchrow_array) { my $this_insert = [ $site_hostname, $site_id, @row ]; push @central_insert, $this_insert; }
Of course, add in some error handling, and probably turn off autocommit if there's lots of inserts going on at a time.my $sth = $dbh->prepare($insert); $sth->execute(@$_) for @central_insert;
Try a Super Search for placeholders - should turn up a lot of hits.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI - Handling NULL values
by McDarren (Abbot) on Sep 29, 2005 at 06:03 UTC | |
|
Re^2: DBI - Handling NULL values
by davidrw (Prior) on Sep 29, 2005 at 12:33 UTC |