in reply to Re: Optimization/Efficiency Question
in thread Optimization/Efficiency Question

Possibly so, I can't decipher whether it's somethin I'm doing in my Perl code, or if it's something to do with Access. I was asking for help with the Perl portion, if in fact that is what was the matter. thanks for the link though.

P.S. First person with the correct answer gets a booster seat for their birthday *cue evil music*
  • Comment on Re: Re: Optimization/Efficiency Question

Replies are listed 'Best First'.
3Re: Optimization/Efficiency Question
by bart (Canon) on Sep 13, 2003 at 01:37 UTC
    I don't get why you prepare the SELECT statement inside the loop. There's nothing variable in it... So put the prepare phase upfront.

    Also, you don't need separate prepare/execute/finish statements for an UPDATE query. You can replace it with one single do() (the DBI method).

    Alternatively, again, prepare the handle for the UPDATE query outside the loop. The code could look a bit like this:
    Version 1:

    $query = q{SELECT Referrals.1, Referrals.2, Referrals.3, Referrals.4, Referrals.5, Referrals.6, Referrals.7, Referrals.8, Referrals.9, Referrals.10, Referrals.11, Referrals.12, Referrals.13, Referrals.14, States.1 FROM Referrals INNER JOIN States On (Referrals.10 = States.1) WHERE AuditID = ?}; my $sth = $dbh->prepare($query); foreach my $audit (keys(%$audits)) { $sth->execute($audit); my @assign = $sth->fetchrow_array; $sth->finish(); $dbh->do(q{INSERT INTO report_printing_table (1,2,3,4,5,6,7,8,9,10,11,12,13) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)}, undef, $audit, @assign); }
    or Version 2:
    $query = q{SELECT Referrals.1, Referrals.2, Referrals.3, Referrals.4, Referrals.5, Referrals.6, Referrals.7, Referrals.8, Referrals.9, Referrals.10, Referrals.11, Referrals.12, Referrals.13, Referrals.14, States.1 FROM Referrals INNER JOIN States On (Referrals.10 = States.1) WHERE AuditID = ?}; my $sth = $dbh->prepare($query); my $updh = $dbh->prepare(q{INSERT INTO report_printing_table (1,2,3,4,5,6,7,8,9,10,11,12,13) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)}); foreach my $audit (keys(%$audits)) { $sth->execute($audit); my @assign = $sth->fetchrow_array; $sth->finish(); $updh->execute($audit, @assign); }
    There's no need for a finish() call for an UPDATE query.

    Maybe, just maybe, this also fixes your problem.

Re: Re: Re: Optimization/Efficiency Question
by Plankton (Vicar) on Sep 12, 2003 at 16:50 UTC
    I am not sure if this is a typo or not but you may want to look at this bit of code ...
    foreach my $audit (keys(%$audits)) { $query = q{ ... ); my $sth = $dbh->prepare($query); sth->execute($audit); ...
    It looks like you are setting up to run $query but you execute $audit. Maybe that is what you intended, but maybe its a typo.


    Well this stinks. dws has just pointed out that $audit is the query's parameters and not a typo.

    Plankton: 1% Evil, 99% Hot Gas.