[Bio] / Sprout / ERDBQuery.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDBQuery.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3, Mon Mar 2 22:17:49 2009 UTC revision 1.4, Mon Mar 23 19:36:37 2009 UTC
# Line 57  Line 57 
57      my ($self) = @_;      my ($self) = @_;
58      # Declare the return variable.      # Declare the return variable.
59      my $retVal;      my $retVal;
60      # Fetch the next row in the query result set.      # Do we have a statement handle?
61      my $sth = $self->{_sth};      my $sth = $self->{_sth};
62        if (! defined $sth) {
63            # No, so we have a prepared statement. Start the query.
64            $sth = $self->_Run();
65        }
66        # Fetch the next row in the query result set.
67      my @row = $sth->fetchrow;      my @row = $sth->fetchrow;
68      # Check to see if we got any results.      # Check to see if we got any results.
69      if (@row == 0) {      if (@row == 0) {
# Line 213  Line 218 
218      return ($objectName, $fieldName, $type);      return ($objectName, $fieldName, $type);
219  }  }
220    
   
221  =head2 Internal Methods  =head2 Internal Methods
222    
223  =head3 _new  =head3 _new
# Line 263  Line 267 
267      return $self;      return $self;
268  }  }
269    
270    =head3 _Prepare
271    
272        $query->_Prepare($command, $parms);
273    
274    Cache the SQL command and parameter list for this query. The information
275    can be used to run the query at a future point.
276    
277    =over 4
278    
279    =item command
280    
281    SQL command to execute for this query.
282    
283    =item parms
284    
285    Parameters to feed to the query.
286    
287    =back
288    
289    =cut
290    
291    sub _Prepare {
292        # Get the parameters.
293        my ($self, $command, $parms) = @_;
294        # Stash the SQL command and the parameters.
295        $self->{_sql} = $command;
296        $self->{_parms} = $parms;
297    }
298    
299    =head3 _Run
300    
301        $query->_Run();
302    
303    Run this query. This method is used the first time Fetch is called
304    on a prepared query.
305    
306    =cut
307    
308    sub _Run {
309        # Get the parameters.
310        my ($self) = @_;
311        # Declare the return variable.
312        my $retVal;
313        # Get the database object and the SQL command.
314        my $erdb = $self->{_db};
315        my $command = $self->{_sql};
316        # Insure both are valid.
317        if (! defined $erdb) {
318            Confess("No database available to run this query.");
319        } elsif (! defined $command) {
320            Confess("Attempt to get results from an unprepared query.");
321        } else {
322            # Get the parameters. If there are no parameters, we use an empty list.
323            my $parms = $self->{_parms} || [];
324            # Create the statement handle and run the query.
325            $retVal = $erdb->_GetStatementHandle($command, $parms);
326            # Save the statement handle for Fetch to use.
327            $self->{_sth} = $retVal;
328        }
329        # Return it.
330        return $retVal;
331    }
332    
333    
334  1;  1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3