Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:
I modified it a bit to get it to work (below). The above code doesn't set the $values variable correctly, that join doesn't work.my @records = ( ['value1', 'value2'], ...) ; my $values = join ", ", ("( ?, ? )" x @records); my $query = "INSERT INTO $table (field1, field2) VALUES $values"; my $sth = $dbh->prepare($query); $sth->execute(map { @$_ } @records);
That works although not as cool. I've never seen a list created quite like this before, and I am curious:my @list; foreach (@records) { push(@list,"( ?, ?, ? )"); } my $values = join(',', @list);
Can someone correct that bit to show what the original author was trying to do?join ", ", ("( ?, ? )" x @records);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Proper Syntax for DBI multiple row insert
by Mr. Muskrat (Canon) on Dec 11, 2015 at 16:03 UTC | |
by Rodster001 (Pilgrim) on Dec 22, 2015 at 03:33 UTC | |
|
Re: Proper Syntax for DBI multiple row insert
by runrig (Abbot) on Dec 10, 2015 at 23:50 UTC | |
|
Re: Proper Syntax for DBI multiple row insert
by jcb (Parson) on Dec 11, 2015 at 04:37 UTC | |
|
Re: Proper Syntax for DBI multiple row insert
by Apero (Scribe) on Dec 11, 2015 at 13:28 UTC | |
|
Re: Proper Syntax for DBI multiple row insert
by graff (Chancellor) on Dec 11, 2015 at 05:13 UTC |