List:MySQL and Perl« Previous MessageNext Message »
From:Gisbert W. Selke Date:February 2 2006 12:11pm
Subject:AW: <<Spam-Verdacht>>query inside a loop
View as plain text  
Hi, Sham --

What type of variable is bugs.bug_id? If  it is numeric, it should work (at
least after newline removal). If it is numeric, however, direct
interpolation gives you an unquoted string in your select statement, which
is illegal (or at least will give you unwanted results). Instead of trying
manual quoting, it would be a simpler and cleaner approach to do it like
this:

use DBI;
open F1, "filepath";
$"=",";
my @bugs = <F1>;
close(F1);
my $dbh = 
 
DBI->connect("DBI:mysql:database=Pbugs;host=appletest","username","password"
,
               {'RaiseError' => 1});
  my $sth = $dbh->prepare("select bug_id,short_desc,bug_status 
                          from bugs where
                          bug_id=?") or die "can't prepare statement";
foreach my $id(@bugs)
{
  chomp($id);
  $sth->execute($id);
  while(my @row = $sth->fetchrow_array()){
    open FILE, "filepath";
    @arr=<FILE>;
    splice(@arr,2,1);
    open FILE, ">filepath";
    print FILE @arr;
    chop(@arr);
    print FILE "@row\n";
    close(FILE); 
  }
}
$sth->finish();
$dbh->disconnect();

Hope this helps.

\Gisbert

Thread
AW: <<Spam-Verdacht>>query inside a loopGisbert W. Selke2 Feb