Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: DBI - Table names & placeholders

by ikegami (Pope)
on Apr 24, 2010 at 09:04 UTC ( #836663=note: print w/replies, xml ) Need Help??


in reply to Re^2: DBI - Table names & placeholders
in thread DBI - Table names & placeholders

The bottom loop should be

for (@$sales_inserts) { my $table = shift(@$_); my $sth = $dbh->prepare(' INSERT INTO '.$dbh->quote_identifier($table).' ( ItemID, Day, Revenue, Count ) VALUES ( ?, ?, ?, ? ) '); $sth->execute(@$_); }
or
my %sth_cache; for (@$sales_inserts) { my $table = shift(@$_); my $sth = $sth_cache{$table} ||= $dbh->prepare(' INSERT INTO '.$dbh->quote_identifier($table).' ( ItemID, Day, Revenue, Count ) VALUES ( ?, ?, ?, ? ) '); $sth->execute(@$_); }

Replies are listed 'Best First'.
Re^4: DBI - Table names & placeholders
by McDarren (Abbot) on Apr 26, 2010 at 06:24 UTC
    Thanks.

    A variation on your first example did the trick for me. Still not exactly what I would have liked, but it gets the job done :)

    Cheers,
    Darren

      Still not exactly what I would have liked

      Maybe if you told us what you wanted?

        Well, it just irks me that I have to do a separate prepare and execute for every single row of data that I want to insert - as opposed to "prepare once, execute many times".

        But, it's no biggie - the job is done and the data is flowing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://836663]
help
Chatterbox?
[Lady_Aleena]: push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addition if $list_addition; #trying again
[shmem]: Discipulus: yummy. I like those. Didn't have them for some time now, forgot the name. Should go get some...
[shmem]: Lasy_Aleena: correct, although for clarity I'd use an if() block, not a statement modifier
[shmem]: this allows you to add an else if maintainance makes it neccesary
[Lady_Aleena]: shmem, okeydokey.
[shmem]: ...or logging or debugging or such

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2017-04-27 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (504 votes). Check out past polls.