punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:
I need to do repeated insertions over many tables:
This is proving very slow, partly, I suspect, because of the new prepare for every insert. If I could use placeholders for both $table_name and $theValue, I could probably save a lot of time. Is there some way to do this, or can placeholders ony be used for the values?for $t (0 .. 1000) { $table_name = $tables[$t]; $theValue = $values[$t]; $sql = "INSERT INTO r".$table_name." VALUES ($theValue)"; $std = $dbh->prepare($sql) or die("Could not prepare! At table = +$table_name because " . $dbh->errstr); $std->execute() or die("Could not execute!" . $dbh->errstr); }
If I'm bothering the monastery with this, it's because I've already tried thihngs along the lines of
with dismal results.$sql = "INSERT INTO ? VALUES (?)"; $std = $dbh->prepare($sql) or die("Could not prepare! At table = $tabl +e_name because " . $dbh->errstr); for $t (0 .. 1000) { $table_name = r.$tables[$t]; $theValue = $values[$t]; $std->execute($table_name , $theValue) or die("Could not execute!" . $ +dbh->errstr); }
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI: Use placeholders for table name?
by perrin (Chancellor) on Dec 04, 2004 at 01:54 UTC | |
|
Re: DBI: Use placeholders for table name?
by Zaxo (Archbishop) on Dec 04, 2004 at 01:54 UTC | |
by dws (Chancellor) on Dec 05, 2004 at 00:11 UTC | |
|
Re: DBI: Use placeholders for table name?
by punch_card_don (Curate) on Dec 04, 2004 at 02:04 UTC | |
|
Re: DBI: Use placeholders for table name?
by Juerd (Abbot) on Dec 05, 2004 at 11:25 UTC |