in reply to Re: dbi placeholders
in thread dbi placeholders
Still rather inefficient. Why not use bind_columns?
my %foo; # Store here when fetching fields my $sth1 = $dbh->prepare ("select * from foo"); $sth1->execute; # added this line after [poj] spotting it was missing # store foo.blah into $foo{blah} $sth1->bind_columns (\@foo{@{$sth1->{NAME_lc}}}); my $sth2 = $dbh->prepare ("insert into bar (ape, monkey) values (?, ?) +"); # foo.morg => bar.ape, foo.jume => bar.monkey $sth2->bind_columns (\@foo{qw( morg jume )}); while ($sth1->fetch) { $sth2->execute; }
If both tables have the same fields
my %rec; my $sth1 = $dbh->prepare ("select * from foo"); my @fields = @{$sth1->{NAME_lc}}; $sth1->bind_columns (\@rec{@{$sth1->{NAME_lc}}}); my $sth2 = do { local $" = ", "; $dbh->prepare ("insert into bar (@fields) values (@{[('?')x@fields +]})"); }; $sth2->bind_columns (\@rec{@fields}); while ($sth1->fetch) { $sth2->execute; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: dbi placeholders
by fionbarr (Friar) on Aug 06, 2014 at 13:56 UTC | |
by Tux (Canon) on Aug 06, 2014 at 14:25 UTC | |
by fionbarr (Friar) on Aug 06, 2014 at 14:38 UTC | |
by poj (Abbot) on Aug 06, 2014 at 17:48 UTC | |
by marto (Cardinal) on Aug 06, 2014 at 14:43 UTC | |
by fionbarr (Friar) on Aug 06, 2014 at 15:00 UTC | |
by Tux (Canon) on Aug 06, 2014 at 14:47 UTC |