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

Diff of /Sprout/CustomAttributes.pm

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

revision 1.33, Tue Aug 12 06:06:02 2008 UTC revision 1.39, Mon Oct 20 17:37:49 2008 UTC
# Line 1083  Line 1083 
1083  sub GetAttributes {  sub GetAttributes {
1084      # Get the parameters.      # Get the parameters.
1085      my ($self, $objectID, $key, @values) = @_;      my ($self, $objectID, $key, @values) = @_;
1086        # Declare the return variable.
1087        my @retVal = ();
1088        # Insure we have at least some sort of filtering going on.
1089        if (! grep { defined $_ } $objectID, $key, @values) {
1090            Confess("No filters specified in GetAttributes call.");
1091        } else {
1092      # This hash will map value-table fields to patterns. We use it to build the      # This hash will map value-table fields to patterns. We use it to build the
1093      # SQL statement.      # SQL statement.
1094      my %data;      my %data;
# Line 1092  Line 1098 
1098      # in the normal way. If the user specifies a generic search or exact match for      # in the normal way. If the user specifies a generic search or exact match for
1099      # every alternative value (remember, the values may be specified as a list),      # every alternative value (remember, the values may be specified as a list),
1100      # then we can create SQL filtering for it. If any of the values are specified      # then we can create SQL filtering for it. If any of the values are specified
1101      # as a regular expression, however, that's a problem, because we need to read          # as a regular expression, however, that's more complicated, because
1102      # every value to verify a match.          # we need to read every value to verify a match.
1103      if (@values > 0) {          if (@values > 0 && defined $values[0]) {
1104          # Get the first value and put its alternatives in an array.          # Get the first value and put its alternatives in an array.
1105          my $valueParm = $values[0];          my $valueParm = $values[0];
1106          my @valueList;          my @valueList;
# Line 1161  Line 1167 
1167              }              }
1168          }          }
1169      }      }
     # Declare the return variable.  
     my @retVal = ();  
1170      # Now we loop through the tables of interest, performing queries.      # Now we loop through the tables of interest, performing queries.
1171      # Loop through the tables.      # Loop through the tables.
1172      for my $table (keys %tables) {      for my $table (keys %tables) {
# Line 1227  Line 1231 
1231                          # Here we have to select on both keys.                          # Here we have to select on both keys.
1232                          my ($subClause, $subValue) = _WherePart($table, 'subkey', $subKey);                          my ($subClause, $subValue) = _WherePart($table, 'subkey', $subKey);
1233                          push @pairFilters, "($realClause AND $subClause)";                          push @pairFilters, "($realClause AND $subClause)";
1234                          push @parms, $subValue;                              push @parms, $realValue, $subValue;
1235                      }                      }
1236                  }                  }
1237                  # Join the pair filters together to make a giant key filter.                  # Join the pair filters together to make a giant key filter.
# Line 1243  Line 1247 
1247              push @retVal, $self->_QueryResults($query, $table, @values);              push @retVal, $self->_QueryResults($query, $table, @values);
1248          }          }
1249      }      }
1250        }
1251      # The above loop ran the query for each necessary value table and merged the      # The above loop ran the query for each necessary value table and merged the
1252      # results into @retVal. Now we return the rows found.      # results into @retVal. Now we return the rows found.
1253      return @retVal;      return @retVal;
# Line 1979  Line 1984 
1984      my ($self, $query, $table, @values) = @_;      my ($self, $query, $table, @values) = @_;
1985      # Declare the return value.      # Declare the return value.
1986      my @retVal = ();      my @retVal = ();
1987        # We use this hash to check for duplicates.
1988        my %dupHash = ();
1989      # Get the number of value sections we have to match.      # Get the number of value sections we have to match.
1990      my $sectionCount = scalar(@values);      my $sectionCount = scalar(@values);
1991      # Loop through the assignments found.      # Loop through the assignments found.
# Line 2005  Line 2012 
2012                  # Here we have a regular expression match.                  # Here we have a regular expression match.
2013                  my $section = $sections[$i];                  my $section = $sections[$i];
2014                  $matching = eval("\$section =~ $value");                  $matching = eval("\$section =~ $value");
2015                } elsif (! defined $value) {
2016                    # Wild card. Skip it.
2017              } else {              } else {
2018                  # Here we have a normal match.                  # Here we have a normal match.
2019                  Trace("SQL match used.") if T(4);                  Trace("SQL match used.") if T(4);
2020                  $matching = _CheckSQLPattern($values[$i], $sections[$i]);                  $matching = _CheckSQLPattern($values[$i], $sections[$i]);
2021              }              }
2022          }          }
2023          # If we match, output this row to the return list.          # If we match, consider writing this row to the return list.
2024          if ($matching) {          if ($matching) {
2025                # Check for a duplicate.
2026                my $wholeThing = join($self->{splitter}, $id, $key, $valueString);
2027                if (! $dupHash{$wholeThing}) {
2028                    # It's okay, we're not a duplicate. Insure we don't duplicate this result.
2029                    $dupHash{$wholeThing} = 1;
2030              push @retVal, [$id, $key, @sections];              push @retVal, [$id, $key, @sections];
2031          }          }
2032      }      }
2033        }
2034      # Return the rows found.      # Return the rows found.
2035      return @retVal;      return @retVal;
2036  }  }
# Line 2201  Line 2216 
2216      # Copy the pattern into the return area.      # Copy the pattern into the return area.
2217      $escapedValue = $sqlPattern;      $escapedValue = $sqlPattern;
2218      # Check the pattern. Is it generic or exact?      # Check the pattern. Is it generic or exact?
2219      if ($sqlPattern =~ /%$/) {      if ($sqlPattern =~ /(.+)%$/) {
2220          # Yes, it is. We need a LIKE clause and we must escape the underscores          # Yes, it is. We need a LIKE clause and we must escape the underscores
2221          # and percents in the pattern.          # and percents in the pattern (except for the last one, of course).
2222            $escapedValue = $1;
2223          $escapedValue =~ s/(%|_)/\\$1/g;          $escapedValue =~ s/(%|_)/\\$1/g;
2224            $escapedValue .= "%";
2225          $sqlClause = "$tableName($fieldName) LIKE ?";          $sqlClause = "$tableName($fieldName) LIKE ?";
2226      } else {      } else {
2227          # No, it isn't. We use an equality clause.          # No, it isn't. We use an equality clause.

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.39

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3