I presume this happens the second time you call get_location_id sub?

seems that your $sth is scoped in eval block.

Anton

-----Original Message-----
From: tomasz konefal [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 3:07 PM
To: [EMAIL PROTECTED]
Subject: help! place holders aren't working


hello list,

   i'm having a devil of a time trying to figure out why my place 
holders aren't working.  if anyone could give me a clue to why i'm 
getting the error 'Can't call method "execute" on an undefined value 
at...' when i use place holders for the following subroutine, i would be 
very greatful.

   i'm using FreeTDS and Sybase with DBI to access a MSSQL2000 server. 
the query works if i do not use the ? place holders, but instead hard 
code the data into the query (eg. 'Toybox').  am i doing something 
wrong?  when the string from the die is returned the data is NOT empty.

thanks,
   twkonefal


---snip---
sub get_location_id {

     # we grab a location id from the database based on
     # form input and return the id

     my $form = shift;
     my $location_id;

     my $division    = %$form->{division};
     my $floor       = %$form->{floor};
     my $area        = %$form->{area};

     # set up query
     my $query = qq{
         SELECT LOCATION_SPECIFIC.SPECIFIC_ID
         FROM LOCATION_SPECIFIC INNER JOIN
         LOCATION_DIVISION ON LOCATION_SPECIFIC.DIVISION_ID = 
LOCATION_DIVISION.DIVISION_ID
         WHERE LOCATION_DIVISION.NAME = 'Toybox'
             AND LOCATION_SPECIFIC.FLOOR = 6
             AND LOCATION_SPECIFIC.AREA = ?
     };

     eval {
         my $sth = $MSDBH->prepare($query);
         $sth->execute(
             $area,
             #$floor,
             #$division,
         );
         ($location_id) = $sth->fetchrow_array;
     };

     if ($@) {
         my $err = "could not get location id for ".
             "division:[". $division. "]".
             "floor:[". $floor. "]".
             "area:[". $area. "]". $@;
         die $err;
     }

     return $location_id;
}
---snip---

-- 
"For, even if I believed in a natural right of property, independent of 
utility and anterior to legislation, I should still deny that this right 
could survive the original proprietor." -- Thomas Babington Macaulay

New Media Copyright Extensions Would Harm Canada: 
http://ansuz.sooke.bc.ca/icsub.html

Reply via email to