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

Diff of /Sprout/DBQuery.pm

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

revision 1.1, Sun Jan 23 16:12:29 2005 UTC revision 1.7, Tue Apr 10 05:52:48 2007 UTC
# Line 2  Line 2 
2    
3          use strict;          use strict;
4          use DBKernel;          use DBKernel;
5          use DBObject;      use ERDBObject;
6          use DBI;          use DBI;
         use Carp;  
7          use Tracer;          use Tracer;
8    
9  =head1 Entity-Relationship Database Package Query Iterator  =head1 Entity-Relationship Database Package Query Iterator
# Line 29  Line 28 
28  participate in the feature. This would return a relationship iterator. Each position in the  participate in the feature. This would return a relationship iterator. Each position in the
29  iterator would contain a single B<IsLocatedIn> instance and a single B<Contig> instance.  iterator would contain a single B<IsLocatedIn> instance and a single B<Contig> instance.
30    
31  At each point in the result set, the iterator returns a B<DBObject>. The DBObject allows the  At each point in the result set, the iterator returns a B<ERDBObject>. The ERDBObject allows the
32  client to access the fields of the current entity or relationship instance.  client to access the fields of the current entity or relationship instance.
33    
34  It is also possible to ask for many different objects in a single iterator by chaining long  It is also possible to ask for many different objects in a single iterator by chaining long
# Line 37  Line 36 
36  B<ERDB> object's C<Get> method.  B<ERDB> object's C<Get> method.
37    
38  Finally, objects of this type should never by created directly. Instead, they are created  Finally, objects of this type should never by created directly. Instead, they are created
39  by the aforementioned C<Get> method and the B<DBObject>'s C<Cross> method.  by the aforementioned C<Get> method and the B<ERDBObject>'s C<Cross> method.
40    
41  =head2 Public Methods  =head2 Public Methods
42    
# Line 45  Line 44 
44    
45  C<< my $dbObject = $dbQuery->Fetch(); >>  C<< my $dbObject = $dbQuery->Fetch(); >>
46    
47  Retrieve a record from this query. The record returned will be a B<DBObject>, which  Retrieve a record from this query. The record returned will be a B<ERDBObject>, which
48  may represent a single entity instance or a list of entity instances joined by relationships.  may represent a single entity instance or a list of entity instances joined by relationships.
49  The first time this method is called it will return the first result from query. After that it  The first time this method is called it will return the first result from query. After that it
50  will continue sequentially. It will return an undefined value if we've reached the end of the  will continue sequentially. It will return an undefined value if we've reached the end of the
# Line 55  Line 54 
54    
55  sub Fetch {  sub Fetch {
56          # Get the parameters;          # Get the parameters;
57          my $self = shift @_;      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.          # Fetch the next row in the query result set.
# Line 66  Line 65 
65                  Trace("No result from query.") if T(3);                  Trace("No result from query.") if T(3);
66                  # Here we have no result. If we're at the end of the result set, this is okay, because                  # Here we have no result. If we're at the end of the result set, this is okay, because
67                  # we'll be returning an undefined value in $retVal. If an error occurred, we need to abort.                  # we'll be returning an undefined value in $retVal. If an error occurred, we need to abort.
68                  if ($sth->err != 0) {          if ($sth->err) {
69                          Confess("FETCH error");                          Confess("FETCH error");
70                  }                  }
71          } else {          } else {
72                  # Here we have a result, so we need to turn it into an instance object.                  # Here we have a result, so we need to turn it into an instance object.
73                  $retVal = DBObject::_new($self->{_db}, $self->{_objectNames}, @row);          $retVal = ERDBObject::_new($self, @row);
74                  Trace("Row returned from query.") if T(4);                  Trace("Row returned from query.") if T(4);
75          }          }
76          # Return the result.          # Return the result.
# Line 96  Line 95 
95    
96  Statement handle for the SELECT clause generated by the query.  Statement handle for the SELECT clause generated by the query.
97    
98  =item objectName1, objectName2, ...  =item relationMap
99    
100  Names of the objects being retrieved.  Reference to a list of 2-tuples. Each tuple consists of an object name as used in the
101    query followed by the actual name of that object. This enables the B<ERDBObject> to
102    determine the order of the tables in the query and which object name belongs to each
103    mapped object name. Most of the time these two values are the same; however, if a
104    relation occurs twice in the query, the relation name in the field list and WHERE
105    clause will use a mapped name (generally the actual relation name with a numeric
106    suffix) that does not match the actual relation name.
107    
108    =item searchObject (optional)
109    
110    If specified, then the query is a full-text search, and the first field will be a
111    relevance indicator for the named table.
112    
113  =back  =back
114    
# Line 106  Line 116 
116    
117  sub _new {  sub _new {
118          # Get the parameters.          # Get the parameters.
119          my ($database, $sth, @objectNames) = @_;      my ($database, $sth, $relationMap, $searchObject) = @_;
120          # Create this object.          # Create this object.
121          my $self = { _db => $database, _sth => $sth, _objectNames => \@objectNames };      my $self = { _db => $database, _sth => $sth, _objectNames => $relationMap,
122                     _fullText => $searchObject };
123          # Bless and return it.          # Bless and return it.
124          bless $self;          bless $self;
125          return $self;          return $self;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.7

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3