in reply to Re^2: DBI do vs prepare
in thread DBI do vs prepare

I didn't test this code, but I rewrote it to be a lot more efficient and to copy a lot less information. I expect it to run substantially more quickly.

sub UpdateDBIar2 { my ($queries, $args) = @_; use DBI; my $dbh = DBI->connect( "dbi:mysql:database=SchoolToolsDev;host=localhost;user=stadmin;passwor +d=stadmin" ) or die "Couldn't connect to database $DBI::errstr\n"; for my $query ( @$queries ) { my $sth = $dbh->prepare($query); for my $arg (@$args) { $sth->execute( $arg ); } } } my $crCode1 = sub { my @result = ( 10734 .. 10845 ); my @queries = map { "UPDATE Tests SET $_ = '1' WHERE ID = ?" } qw( Baseline Q1 Q2 Q3 Q4 ); UpdateDBIar2( \@queries, \@result ); };

Replies are listed 'Best First'.
Re^4: DBI do vs prepare
by BrianC (Acolyte) on Aug 14, 2006 at 02:50 UTC
    Thank you for this. Unfortunately, my simplified version of the actual code does not tell you that the result set is different for each quarter. They are five different arrays coming from an html form. That's why I need the extra for loop. I also want it generalized for an arbitrary number of placeholders.