NIPP, SCOTT V (SBCSI) [EMAIL PROTECTED] wrote:
>       I am working on a script to parse a series of text files and insert
> or update this data as appropriate into a couple of database tables.  I am
> stuck at a point with a couple of errors that are just confusing the hell
> out of me.  I keep going around in circles and I must be missing something
> here.  Please let me know if you can spot anything in this piece of code.
> This is a pair of subroutines from the script, and the place where the
> problems exist are in the fs_db_pop subroutine.  Here is the code with line
> numbers, and then the output/error messages.
> 
> 87  sub fs_db_pop {
>     88    $server = $name;
>     89    my $test2 = $dbh2->prepare("SELECT id FROM fsref WHERE server
> ='$serve
> r' AND fs_name = '$fs_name'");
>     90    $test2->execute();
>     91
>     92    $rows2 = $test2->rows();
>     93    print "Number of matching rows:  $rows2 \n";
>     94    if ($rows2 == 1) {
>     95      my $vals = $test2->fetchrow_hashref ('NAME_lc');
>     96      my $id = $vals->{id};
>     97      my $query = $dbh2->prepare("SELECT * FROM fsdata WHERE id
> ='$id'");
>     98      $query->execute();
>     99      while (my $ref2 = $query->fetchrow_hashref ('NAME_lc')) {
>    100        undef $set2;
>    101        foreach my $key2 (keys %$ref2) {
>    102          unless ($$key2 eq $ref2->{$key2}) {
>    103            $set2 .= " , " if $set2;
>    104            $set2 .= $key2 . "=\'$$key2\'";
>    105          }
                  ^ this ends the 'unless'
>    106      $query->finish();
              ^^^^^^^^^^^^^^^^ as stated before, this need to
go *AFTER* the fetchrow_hashref while loop - looks to me like
the end of that loop is below.

>    107        }
                ^ this ends the 'foreach'
>    108        if ($set2) {
>    109          print "Entry found in database.  Updating information for
> $id. \
> n";
>    110          my $sql2 = "UPDATE fsdata SET $set2 WHERE id = '$id'";
>    111          my $sth2 = $dbh2->prepare(qq{$sql2});
>    112          $sth2->execute();
>    113          $sth2->finish();
>    114        }
                ^ this ends the if ($set2)
>    115      }
              ^ THIS ends the while <===============
                so put the 'finish' after this.

Just personal preference here, but when you've got nested
blocks with lots of code in between, it makes the code
easier to read if you label the end blocks - something
like this:

     115      } ### end of while ###

I haven't read all the rest of your code, but start by
moving your 'finish'.

HTH.

-- 
Hardy Merrill
Red Hat, Inc.

>    116    } else {
>    117    undef $id;
>    118    $dbh2->do("INSERT INTO fsref VALUES('$id','$server','$fs_name')")
> or p
> rint "Error updating fsref table:  ", $dbh2->errstr, "\n";
>    119    $id = $dbh2->{mysql_insertid};
>    120    $dbh2->do("INSERT INTO fsdata
> VALUES('$id','$lvol','$stripe_num','$str
> ipe_size','$size','$owner','$group','$export')") or print "Error updating
> fsdata
>  table: ", $dbh2->errstr, "\n";
>    121    print "Entry not found in database.  Adding information for $id.
> \n";
>    122    }
>    123    $test2->finish();
>    124  }
>    125
>    126  sub filesystems {
>    127    # $fs_index = (split /\[|\]/)[1];
>    128    @fs_data = split(/:\s+/);
>    129    chomp($fs_data[1]);
>    130    # print "Test:  $fs_data[0] \n";
>    131    if ($fs_data[0] =~ /^Filesystem/) {
>    132      $fs_name = $fs_data[1];
>    133    } elsif ($fs_data[0] =~ /^Owner/) {
>    134      ($owner, $group) = split /\s+/, $fs_data[1], 2;
>    135    } elsif ($fs_data[0] =~ /^LvolN/) {
>    136      $lvol = $fs_data[1];
>    137    } elsif ($fs_data[0] =~ /^Exported/) {
>    138      $export = $fs_data[1];
>    139    } elsif ($fs_data[0] =~ /^LvolS\[/) {
>    140      $size = $fs_data[1];
>    141    } elsif ($fs_data[0] =~ /^LvolStN/) {
>    142      $stripe_num = $fs_data[1];
>    143      print "$stripe_num \n";
>    144    } elsif ($fs_data[0] =~ /^LvolStS/) {
>    145      $stripe_size = $fs_data[1];
>    146      fs_db_pop();
>    147      undef @fs_data;
>    148    }
>    149  }
> 
>       I mainly include the second subroutine because that is where the
> parsing of the data from the text file occurs.  It is working fine, but I
> thought it might be helpful to see it also.  The rest of the script mainly
> sets up the database connection strings, and handles adding/updating a
> seperate database table with other information.  Here is the output of the
> script:
> 
> Number of matching rows:  1 
> Entry found in database.  Updating information for 116. 
> DBD::mysql::st execute failed: You have an error in your SQL syntax near
> 'group=
> 'sys ' , lvol='/dev/vg02/lvol2 ' , stripe_num='4 ' , id='377140311' , size'
> at l
> ine 1 at ./sys_db_update-dev.pl line 112, <INV> line 1145.
> DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at
> ./sys_db_up
> date-dev.pl line 99, <INV> line 1145.
> 0  
> Number of matching rows:  1 
> Entry found in database.  Updating information for 117. 
> DBD::mysql::st execute failed: You have an error in your SQL syntax near
> 'group=
> 'root ' , lvol='/dev/vg00/home_tmp ' , stripe_num='0 ' , id='377140311' , '
> at l
> ine 1 at ./sys_db_update-dev.pl line 112, <INV> line 1153.
> DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at
> ./sys_db_up
> date-dev.pl line 99, <INV> line 1153.
> pyro found in database.  Updating information for pyro. 
> 
>       Hopefully this is enough information for someone to help figure out
> what I am doing wrong here.  Thanks in advance for the help.
> 
> Scott Nipp
> Phone:  (214) 858-1289
> E-mail:  [EMAIL PROTECTED]
> Web:  http:\\ldsa.sbcld.sbc.com

Reply via email to