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

Diff of /Sprout/ERDB.pm

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

revision 1.26, Tue Oct 18 06:47:46 2005 UTC revision 1.30, Wed Jan 11 19:39:03 2006 UTC
# Line 508  Line 508 
508          # Separate out the source, the target, and the join clause.          # Separate out the source, the target, and the join clause.
509          $joinKey =~ m!^([^/]+)/(.+)$!;          $joinKey =~ m!^([^/]+)/(.+)$!;
510          my ($sourceRelation, $targetRelation) = ($1, $2);          my ($sourceRelation, $targetRelation) = ($1, $2);
511          Trace("Join with key $joinKey is from $sourceRelation to $targetRelation.") if T(4);          Trace("Join with key $joinKey is from $sourceRelation to $targetRelation.") if T(Joins => 4);
512          my $source = $self->ComputeObjectSentence($sourceRelation);          my $source = $self->ComputeObjectSentence($sourceRelation);
513          my $target = $self->ComputeObjectSentence($targetRelation);          my $target = $self->ComputeObjectSentence($targetRelation);
514          my $clause = $joinTable->{$joinKey};          my $clause = $joinTable->{$joinKey};
# Line 851  Line 851 
851    
852  C<< "Genome(genus) = ? ORDER BY Genome(species)" >>  C<< "Genome(genus) = ? ORDER BY Genome(species)" >>
853    
854    Note that the case is important. Only an uppercase "ORDER BY" with a single space will
855    be processed. The idea is to make it less likely to find the verb by accident.
856    
857  The rules for field references in a sort order are the same as those for field references in the  The rules for field references in a sort order are the same as those for field references in the
858  filter clause in general; however, odd things may happen if a sort field is from a secondary  filter clause in general; however, odd things may happen if a sort field is from a secondary
859  relation.  relation.
# Line 877  Line 880 
880      my $dbh = $self->{_dbh};      my $dbh = $self->{_dbh};
881      my $command = "SELECT DISTINCT " . join('.*, ', @{$objectNames}) . ".* FROM " .      my $command = "SELECT DISTINCT " . join('.*, ', @{$objectNames}) . ".* FROM " .
882                  join(', ', @{$objectNames});                  join(', ', @{$objectNames});
     Trace("SQL = $command") if T(SQL => 4);  
883      # Check for a filter clause.      # Check for a filter clause.
884      if ($filterClause) {      if ($filterClause) {
885          # Here we have one, so we convert its field names and add it to the query. First,          # Here we have one, so we convert its field names and add it to the query. First,
# Line 960  Line 962 
962                  $lastObject = $thisObject;                  $lastObject = $thisObject;
963              }              }
964          }          }
965          # Now we need to handle the whole ORDER BY thing. We'll put the order by clause          # Now we need to handle the whole ORDER BY / LIMIT thing. The important part
966          # in the following variable.          # here is we want the filter clause to be empty if there's no WHERE filter.
967            # We'll put the ORDER BY / LIMIT clauses in the following variable.
968          my $orderClause = "";          my $orderClause = "";
969          # Locate the ORDER BY verb (if any).          # Locate the ORDER BY or LIMIT verbs (if any). We use a non-greedy
970          if ($filterString =~ m/^(.*)ORDER BY/g) {          # operator so that we find the first occurrence of either verb.
971              # Here we have an ORDER BY verb. Split it off of the filter string.          if ($filterString =~ m/^(.*?)\s*(ORDER BY|LIMIT)/g) {
972                # Here we have an ORDER BY or LIMIT verb. Split it off of the filter string.
973              my $pos = pos $filterString;              my $pos = pos $filterString;
974              $orderClause = substr($filterString, $pos);              $orderClause = $2 . substr($filterString, $pos);
975              $filterString = $1;              $filterString = $1;
976          }          }
977          # Add the filter and the join clauses (if any) to the SELECT command.          # Add the filter and the join clauses (if any) to the SELECT command.
# Line 977  Line 981 
981          if (@joinWhere) {          if (@joinWhere) {
982              $command .= " WHERE " . join(' AND ', @joinWhere);              $command .= " WHERE " . join(' AND ', @joinWhere);
983          }          }
984          # Add the sort clause (if any) to the SELECT command.          # Add the sort or limit clause (if any) to the SELECT command.
985          if ($orderClause) {          if ($orderClause) {
986              $command .= " ORDER BY $orderClause";              $command .= " $orderClause";
987          }          }
988      }      }
989      Trace("SQL query: $command") if T(3);      Trace("SQL query: $command") if T(SQL => 4);
990      Trace("PARMS: '" . (join "', '", @params) . "'") if (T(4) && (@params > 0));      Trace("PARMS: '" . (join "', '", @params) . "'") if (T(SQL => 4) && (@params > 0));
991      my $sth = $dbh->prepare_command($command);      my $sth = $dbh->prepare_command($command);
992      # Execute it with the parameters bound in.      # Execute it with the parameters bound in.
993      $sth->execute(@params) || Confess("SELECT error" . $sth->errstr());      $sth->execute(@params) || Confess("SELECT error" . $sth->errstr());
# Line 1294  Line 1298 
1298    
1299  =item RETURN  =item RETURN
1300    
1301  Returns a statistical object containing the number of records read and a list of  Returns a statistical object containing a list of the error messages.
 the error messages.  
1302    
1303  =back  =back
1304    
# Line 1568  Line 1571 
1571      } else {      } else {
1572          push @parmList, $parameterList;          push @parmList, $parameterList;
1573      }      }
     # Create the query.  
     my $query = $self->Get($objectNames, $filterClause, @parmList);  
     # Set up a counter of the number of records read.  
     my $fetched = 0;  
1574      # Insure the counter has a value.      # Insure the counter has a value.
1575      if (!defined $count) {      if (!defined $count) {
1576          $count = 0;          $count = 0;
1577      }      }
1578        # Add the row limit to the filter clause.
1579        if ($count > 0) {
1580            $filterClause .= " LIMIT $count";
1581        }
1582        # Create the query.
1583        my $query = $self->Get($objectNames, $filterClause, @parmList);
1584        # Set up a counter of the number of records read.
1585        my $fetched = 0;
1586      # Loop through the records returned, extracting the fields. Note that if the      # Loop through the records returned, extracting the fields. Note that if the
1587      # counter is non-zero, we stop when the number of records read hits the count.      # counter is non-zero, we stop when the number of records read hits the count.
1588      my @retVal = ();      my @retVal = ();
# Line 1637  Line 1644 
1644  =cut  =cut
1645    
1646  sub _GetLoadStats {  sub _GetLoadStats {
1647      return Stats->new('records');      return Stats->new();
1648  }  }
1649    
1650  =head3 GenerateFields  =head3 GenerateFields

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.30

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3