Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Re: Compound Sql Statement

by dbwiz (Curate)
on Feb 25, 2005 at 10:30 UTC ( [id://434514]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Compound Sql Statement

I have the feeling that you are using the wrong approach.

What about using an array of values and just one SQL statement with placeholders?

my @values = ( [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 'a', 'b', 'c' ] ); my $sql = "Insert into tableone values(?, ?, ?); my $loadHandle = $dbh->prepare($sql); for (@values) { $loadHandle->execute(@$_) or die "Could not execute SQL statement $sql " . " with values ( @$_ )... $DBI::errstr\n "; }

However, if what you want to do is execute different statements, here's another way:

my @SQL_statements = ( "create table x(i int)", "insert into x values (1)", "update x set i = i * 10 " ); $dbh->begin_work(); for (@SQL_statements) { eval { $dbh->do($_)}; if ($@) { $dbh->rollback(); die "error executing query '$_', $DBI::errstr\n"; } } $dbh->commit();

Replies are listed 'Best First'.
Re^2: Compound Sql Statement
by Doyle (Acolyte) on Feb 25, 2005 at 11:06 UTC
    Thanks everyone and a special thanks to dbwiz for coming up with the solution that worked for me. doyle

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://434514]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.