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

Diff of /Sprout/ERDBQuery.pm

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

revision 1.2, Thu Feb 5 06:50:51 2009 UTC revision 1.3, Mon Mar 2 22:17:49 2009 UTC
# Line 127  Line 127 
127  sub AnalyzeFieldName {  sub AnalyzeFieldName {
128      # Get the parameters.      # Get the parameters.
129      my ($self, $name) = @_;      my ($self, $name) = @_;
130        # Attempt to find the field's data.
131        my ($objectName, $fieldName, $type) = $self->CheckFieldName($name);
132        # Process errors.
133        if (! defined $objectName) {
134            Confess("Field identifier \"$name\" has an invalid format.");
135        } elsif (! defined $fieldName) {
136            Confess("Object name \"$objectName\" not found in query.");
137        } elsif (! defined $type) {
138            Confess("Field name \"$fieldName\" not found in \"$objectName\".");
139        }
140        # Return the results.
141        return ($objectName, $fieldName, $type);
142    }
143    
144    
145    =head3 CheckFieldName
146    
147        my ($objectName, $fieldName, $type) = $query->CheckFieldName($name);
148    
149    Analyze a field name (such as might be found in a [[ErdbPm#GetAll]]
150    parameter list) and return the real name of the relevant entity or
151    relationship, the field name itself, and the associated type object
152    (which will be a subclass of [[ERDBTypePm]]. Unlink L</AnalyzeFIeldName>,
153    this method always returns results. If the field name is invalid, one
154    or more of the three results will be undefined.
155    
156    =over 4
157    
158    =item name
159    
160    Field name to examine, in the standard field name format used by [[ErdbPm]].
161    
162    =item RETURN
163    
164    Returns a 3-tuple containing the name of the object containing the field, the
165    base field name, and a type object describing the field's type. If the field
166    descriptor is invalid, the returned object name will be undefined. If the object
167    name is invalid, the returned field name will be undefined, and if the field
168    name is invalid, the returned type will be undefined.
169    
170    =back
171    
172    =cut
173    
174    sub CheckFieldName {
175        # Get the parameters.
176        my ($self, $name) = @_;
177      # Declare the return variables.      # Declare the return variables.
178      my ($objectName, $fieldName, $type);      my ($objectName, $fieldName, $type);
179      # Get the relation map.      # Get the relation map.
# Line 135  Line 182 
182      # relation map.      # relation map.
183      my $defaultName = $map->[0][0];      my $defaultName = $map->[0][0];
184      # Parse the field name.      # Parse the field name.
185      my $alias;      my ($alias, $fieldThing) = ERDB::ParseFieldName($name, $defaultName);
186      ($alias, $fieldName) = ERDB::ParseFieldName($name, $defaultName);      # Only proceed if we could successfully parse the field. If we couldn't,
187      if (! defined $alias) {      # everything will be going back undefined.
188          Confess("Field identifier \"$name\" has an invalid format.");      if (defined $alias) {
     } else {  
189          # Find the alias in the relation map.          # Find the alias in the relation map.
190          my ($aliasTuple) = grep { $_->[0] eq $alias } @$map;          my ($aliasTuple) = grep { $_->[0] eq $alias } @$map;
191          if (! defined $aliasTuple) {          if (! defined $aliasTuple) {
192              Confess("Object name \"$alias\" not found in query.");              # We have a bad object name, so the object name is all
193                # we return.
194                $objectName = $alias;
195          } else {          } else {
196              # Get the real object name.              # Get the real object name.
197              my $objectName = $aliasTuple->[1];              $objectName = $aliasTuple->[1];
198                # Now it's safe to return the field name.
199                $fieldName = $fieldThing;
200              # Ask the database for the field descriptor. If the field name is              # Ask the database for the field descriptor. If the field name is
201              # invalid, this will throw an error.              # invalid, this will throw an error.
202              my $fieldData = $self->{_db}->_FindField($fieldName, $objectName);              my $fieldData = $self->{_db}->_CheckField($objectName, $fieldName);
203                # Only proceed if the field exists.
204                if (defined $fieldData) {
205              # Extract the field type.              # Extract the field type.
206              my $typeName = $fieldData->{type};              my $typeName = $fieldData->{type};
207              # Get the corresponding type object.              # Get the corresponding type object.
208              $type = ERDB::GetDataTypes()->{$typeName};              $type = ERDB::GetDataTypes()->{$typeName};
209                }
210          }          }
211      }      }
212      # Return the results.      # Return the results.

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3