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

Diff of /Sprout/ERDBQueryConsole.pm

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

revision 1.2, Thu Apr 2 01:38:55 2009 UTC revision 1.3, Thu May 28 18:07:36 2009 UTC
# Line 33  Line 33 
33  appears in two places: once as a SeedViewer page, and once as an NMPDR plugin  appears in two places: once as a SeedViewer page, and once as an NMPDR plugin
34  Wiki console. Each of these places is responsible for insuring that the user has  Wiki console. Each of these places is responsible for insuring that the user has
35  the proper credentials and then calling this package's main method. To construct  the proper credentials and then calling this package's main method. To construct
36  a console helper, simply pass in the database name and the user's security  a console helper object, simply pass in the database name and the user's security
37  level, then call L</Submit> to validate the parameters and build the query. If  level, then call L</Submit> to validate the parameters and build the query. If
38  there are problems, call L</Errors> to get a list of error messages. If  there are problems, call L</Errors> to get a list of error messages. If
39  everything went fine, call L</Headers> to get the names and styles for the result  everything went fine, call L</Headers> to get the names and styles for the result
# Line 143  Line 143 
143    
144  =head3 Submit  =head3 Submit
145    
146      my $okFlag = $eq->Submit($objects, $filterString, \@parms, \@fields, $limitNumber);      my $okFlag = $eq->Submit($objects, $filterString, \@parms, $fields, $limitNumber);
147    
148  Submit a query to the console. This method stores the relevant  Submit a query to the console. This method stores the relevant
149  information about the query and creates the query object. Other methods  information about the query and creates the query object. Other methods
# Line 168  Line 168 
168    
169  =item fields  =item fields
170    
171  List of result field names.  String containing the result field names.
172    
173  =item limitNumber  =item limitNumber
174    
175  Maximum number of rows for the query. If the user is not privileged,  Maximum number of rows for the query. If the user is not privileged,
176    all queries are limited to a maximum number of rows determined by
177    the C<$ERDBExtras::query_limit> parameter. If the user is privileged,
178    a false value (undefined of 0) indicates an unlimited query.
179    
180  =item RETURN  =item RETURN
181    
# Line 222  Line 225 
225              my $limitClause = "";              my $limitClause = "";
226              if (! $self->{secure}) {              if (! $self->{secure}) {
227                  # We do. Check for an existing limit.                  # We do. Check for an existing limit.
228                  if ($filterString =~ /(.+)\s+LIMIT\s+(\d+)(.*)/) {                  if ($filterString =~ /(.*)LIMIT\s+(\d+)(.*)/) {
229                      # Fix it if it's too big.                      # Fix it if it's too big.
230                      if ($2 >= $FIG_Config::query_limit) {                      if ($2 >= $ERDBExtras::query_limit) {
231                          $filterString = "$1 LIMIT $FIG_Config::query_limit$3";                          $filterString = "$1LIMIT $ERDBExtras::query_limit$3";
232                      }                      }
233                  } else {                  } else {
234                      # No limit present, so add one.                      # No limit present, so add one.
235                      $limitClause = " LIMIT $FIG_Config::query_limit";                      $limitClause = " LIMIT $ERDBExtras::query_limit";
236                  }                  }
237              } else {              } else {
238                  # Privileged users can request a different limit. Only use it                  # Privileged users can request a different limit. Only use it
239                  # if there is not already a limit in the filter clause.                  # if there is not already a limit in the filter clause.
240                  if ($limitNumber && $filterString !~ /\sLIMIT\s/) {                  if ($limitNumber && $filterString !~ /(?:^|\s)LIMIT\s/) {
241                      $limitClause = " LIMIT $limitNumber";                      $limitClause = " LIMIT $limitNumber";
242                      Trace("Limit clause for $limitNumber rows added to query.") if T(2);                      Trace("Limit clause for $limitNumber rows added to query.") if T(2);
243                  }                  }
# Line 439  Line 442 
442      my $parmsCount = scalar @$parms;      my $parmsCount = scalar @$parms;
443      for (my $i = 0; $i < $parmsCount; $i++) {      for (my $i = 0; $i < $parmsCount; $i++) {
444          if (defined $parameters[$i]) {          if (defined $parameters[$i]) {
445              push @parmStrings, '$' . $parameters[$i];              push @parmStrings, $parameters[$i];
446          } else {          } else {
447              push @parmStrings, Quotify($parms->[$i]);              push @parmStrings, Quotify($parms->[$i]);
448          }          }
# Line 452  Line 455 
455      # The result from the Get call depends on the type: a list for      # The result from the Get call depends on the type: a list for
456      # GetAll, a scalar for Get.      # GetAll, a scalar for Get.
457      my $getResultName = ($codeStyle eq 'Get' ? '$qh' : '@resultRows');      my $getResultName = ($codeStyle eq 'Get' ? '$qh' : '@resultRows');
458        # Not we compute the function name. It's the same as the code style
459        # unless we're doing a GetAll and there's only one field. In that case
460        # we do a GetFlat.
461        my $getName = ($codeStyle eq 'GetAll' && scalar(@$fields) == 1 ? 'GetFlat' : $codeStyle);
462      # Build the Get. It's multiple lines, so we need to compute how far to      # Build the Get. It's multiple lines, so we need to compute how far to
463      # indent the secondary lines. In addition, we need to decide here whether      # indent the secondary lines. In addition, we need to decide here whether
464      # we're doing a Get or a GetAll.      # we're doing a Get or a GetAll.
465      my $buffer = "my $getResultName = $dbObjectName->$codeStyle(";      my $buffer = "my $getResultName = $dbObjectName->$getName(";
466      my $continueTab = " " x length($buffer);      my $continueTab = " " x length($buffer);
467      # Now set up the buffer so that it has the Get call and the object      # Now set up the buffer so that it has the Get call and the object
468      # name string. This is the minimum content for the first line.      # name string. This is the minimum content for the first line.
# Line 473  Line 480 
480      if ($codeStyle eq 'GetAll') {      if ($codeStyle eq 'GetAll') {
481          # First, we need to put a comma at the end of the last parameter.          # First, we need to put a comma at the end of the last parameter.
482          $pieces[$#pieces] .= ", ";          $pieces[$#pieces] .= ", ";
483          # Now, we create a list of the field names. We use the qw          # Is this GetFlat?
484          # trick to make them into a list.          if ($getName eq 'GetFlat') {
485                # Yes, so we have a single field.
486                my $fieldName = $fields->[0]{name};
487                push @pieces, "'$fieldName'";
488            } else {
489                # No, so we create a list of the field names. We use the qw
490                # trick to do this.
491          my @quotedFields = map { $_->{name} } @$fields;          my @quotedFields = map { $_->{name} } @$fields;
492          $quotedFields[0] = "[qw(" . $quotedFields[0];          $quotedFields[0] = "[qw(" . $quotedFields[0];
493          $quotedFields[$#quotedFields] .= ")]";          $quotedFields[$#quotedFields] .= ")]";
# Line 483  Line 496 
496          }          }
497          push @pieces, @quotedFields;          push @pieces, @quotedFields;
498      }      }
499        }
500      # Put the statement terminator on the last piece.      # Put the statement terminator on the last piece.
501      $pieces[$#pieces] .= ");";      $pieces[$#pieces] .= ");";
502      # Loop through the pieces, building the code lines.      # Loop through the pieces, building the code lines.
# Line 526  Line 540 
540              # Output the statement.              # Output the statement.
541              push @codeLines, "$tab$statement";              push @codeLines, "$tab$statement";
542          }          }
543          # Close the fetch loop.          # Close the fetch loop. This next line looks strange, but it
544          push @codeLines, "$tab##TODO: Process data";          # is necessary to keep the Komodo TODO-hunter from flagging this
545            # line as an uncompleted task.
546            my $sharps = "##" . "TODO";
547            push @codeLines, "$tab##" . "TODO: Process data";
548          push @codeLines, "}";          push @codeLines, "}";
549                          }                          }
550      # Return the result.      # Return the result.
# Line 567  Line 584 
584      return $retVal;      return $retVal;
585  }  }
586    
587    =head3 SplitFields
588    
589        my @fields = ERDBQueryConsole::SplitFields($fieldString);
590    
591    Convert a field string to a list of field names. The string can be either
592    comma-delimited or space-delimited.
593    
594    =over 4
595    
596    =item fieldString
597    
598    String of field names.
599    
600    =item RETURN
601    
602    Returns a list of the field names culled from the string.
603    
604    =back
605    
606    =cut
607    
608    sub SplitFields {
609        # Get the parameters.
610        my ($fieldString) = @_;
611        # Declare the return variable.
612        my @retVal;
613        if ($fieldString =~ /,/) {
614            # We found a comma, so use the comma pattern.
615            push @retVal, split /\s*,\s*/, $fieldString;
616        } else {
617            # No commas, so use the space pattern.
618            push @retVal, split /\s+/, $fieldString;
619        }
620        # Return the result.
621        return @retVal;
622    }
623    
624  =head2 Internal Methods  =head2 Internal Methods
625    
# Line 678  Line 731 
731  }  }
732    
733    
734    
735    
736  1;  1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3