[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.4, Thu Jun 4 18:20:50 2009 UTC revision 1.5, Thu Jun 18 01:29:58 2009 UTC
# Line 113  Line 113 
113  TRUE if the user is privileged and can make unlimited queries. The default  TRUE if the user is privileged and can make unlimited queries. The default
114  is FALSE.  is FALSE.
115    
116    =item raw
117    
118    TRUE to return the results in raw form rather than in HTML form.
119    
120  =back  =back
121    
122  =cut  =cut
# Line 122  Line 126 
126      my ($class, $db, %options) = @_;      my ($class, $db, %options) = @_;
127      # Get the options.      # Get the options.
128      my $secure = $options{secure} || 0;      my $secure = $options{secure} || 0;
129        my $raw = $options{raw} || 0;
130      # Get access to the database.      # Get access to the database.
131      my $erdb;      my $erdb;
132      if (! ref $db) {      if (! ref $db) {
# Line 133  Line 138 
138      my $retVal = {      my $retVal = {
139                      erdb => $erdb,                      erdb => $erdb,
140                      secure => $secure,                      secure => $secure,
141                        raw => $raw,
142                   };                   };
143      # Bless and return it.      # Bless and return it.
144      bless $retVal, $class;      bless $retVal, $class;
# Line 334  Line 340 
340      my @items = $eq->GetRow();      my @items = $eq->GetRow();
341    
342  Get the next row of data from the query. Each row will consist of a list  Get the next row of data from the query. Each row will consist of a list
343  of HTML strings, one per result column, in the same order the field names  of HTML strings (in normal mode) or PERL objects (in raw mode), one per result
344  appeared when the query was submitted.  column, in the same order the field names appeared when the query was submitted.
345    
346  If the query is complete, an empty list will be returned.  If the query is complete, an empty list will be returned.
347    
# Line 361  Line 367 
367                  # Get the values for this field.                  # Get the values for this field.
368                  my @values = $record->Value($field->{name});                  my @values = $record->Value($field->{name});
369                  $self->AddStat(values => scalar(@values));                  $self->AddStat(values => scalar(@values));
370                  # Get the field type.                  # Are we returning raw data or HTML?
371                    if (! $self->{raw}) {
372                        # Here we are in HTML mode. Get the field type.
373                  my $type = $field->{type};                  my $type = $field->{type};
374                  # Convert the values to HTML and string them together.                  # Convert the values to HTML and string them together.
375                  my $cell = join("<br />", map { $type->html($_) } @values);                      my $cell = join("<br /><hr /><br />",
376                                        map { $type->html($_) } @values);
377                  # Put the result into the output list.                  # Put the result into the output list.
378                  push @retVal, $cell;                  push @retVal, $cell;
379                    } elsif ($field->{secondary}) {
380                        # This is a raw secondary field. It's returned as a list reference.
381                        push @retVal, \@values;
382                    } else {
383                        # This is a raw primary field. It's returned as a scalar.
384                        # Note that if the field is empty, we'll be stuffing an
385                        # undefined value in its position of this row.
386                        push @retVal, $values[0];
387                    }
388              }              }
389          }          }
390      }      }
# Line 472  Line 490 
490      if (! @parmStrings) {      if (! @parmStrings) {
491          push @pieces, "[]";          push @pieces, "[]";
492      } else {      } else {
493            # Here we have a list of parameters. The first begins with a left bracket.
494          push @pieces, "[" . shift(@parmStrings);          push @pieces, "[" . shift(@parmStrings);
495          push @pieces, @parmStrings;          # If there's more than one, we need to do some comma-joining.
496            while (my $piece = shift @parmStrings) {
497                # Put a comma at the end of the last piece.
498                $pieces[$#pieces] .= ",";
499                # Add the next piece.
500                push @pieces, $piece;
501            }
502            # Put a right bracket on the last piece.
503          $pieces[$#pieces] .= "]";          $pieces[$#pieces] .= "]";
504      }      }
505      # If this is a GetAll, the field names go in here, too.      # If this is a GetAll, the field names go in here, too.
# Line 584  Line 610 
610      return $retVal;      return $retVal;
611  }  }
612    
613    =head3 Messages
614    
615        my $messages = $eq->Messages();
616    
617    Return the error and status messages for the current query as a single string.
618    
619    =cut
620    
621    sub Messages {
622        # Get the parameters.
623        my ($self) = @_;
624        # Return the queued messages.
625        return join("\n", $self->{stats}->Messages());
626    }
627    
628    
629    
630  =head3 SplitFields  =head3 SplitFields
631    
632      my @fields = ERDBQueryConsole::SplitFields($fieldString);      my @fields = ERDBQueryConsole::SplitFields($fieldString);

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3