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

I'm not sure how to test the function without packing parameters. And I certainly can't use it without packing parameters. I guess it doesn't really matter if the "prepare/execute" is faster if the cost of implementation is considerably higher.

Replies are listed 'Best First'.
Re^3: DBI do vs prepare
by chromatic (Archbishop) on Aug 14, 2006 at 00:37 UTC

    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 ); };
      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.