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

Diff of /Sprout/ERDB.pm

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

revision 1.48, Wed Jun 21 03:12:20 2006 UTC revision 1.55, Sat Jun 24 23:49:10 2006 UTC
# Line 1544  Line 1544 
1544      }      }
1545  }  }
1546    
1547    =head3 InsertValue
1548    
1549    C<< $erdb->InsertValue($entityID, $fieldName, $value); >>
1550    
1551    This method will insert a new value into the database. The value must be one
1552    associated with a secondary relation, since primary values cannot be inserted:
1553    they occur exactly once. Secondary values, on the other hand, can be missing
1554    or multiply-occurring.
1555    
1556    =over 4
1557    
1558    =item entityID
1559    
1560    ID of the object that is to receive the new value.
1561    
1562    =item fieldName
1563    
1564    Field name for the new value-- this includes the entity name, since
1565    field names are of the format I<objectName>C<(>I<fieldName>C<)>.
1566    
1567    =item value
1568    
1569    New value to be put in the field.
1570    
1571    =back
1572    
1573    =cut
1574    
1575    sub InsertValue {
1576        # Get the parameters.
1577        my ($self, $entityID, $fieldName, $value) = @_;
1578        # Parse the entity name and the real field name.
1579        if ($fieldName =~ /^([^(]+)\(([^)]+)\)/) {
1580            my $entityName = $1;
1581            my $fieldTitle = $2;
1582            # Get its descriptor.
1583            if (!$self->IsEntity($entityName)) {
1584                Confess("$entityName is not a valid entity.");
1585            } else {
1586                my $entityData = $self->{_metaData}->{Entities}->{$entityName};
1587                # Find the relation containing this field.
1588                my $fieldHash = $entityData->{Fields};
1589                if (! exists $fieldHash->{$fieldTitle}) {
1590                    Confess("$fieldTitle not found in $entityName.");
1591                } else {
1592                    my $relation = $fieldHash->{$fieldTitle}->{relation};
1593                    if ($relation eq $entityName) {
1594                        Confess("Cannot do InsertValue on primary field $fieldTitle of $entityName.");
1595                    } else {
1596                        # Now we can create an INSERT statement.
1597                        my $dbh = $self->{_dbh};
1598                        my $fixedName = _FixName($fieldTitle);
1599                        my $statement = "INSERT INTO $relation (id, $fixedName) VALUES(?, ?)";
1600                        # Execute the command.
1601                        $dbh->SQL($statement, 0, $entityID, $value);
1602                    }
1603                }
1604            }
1605        } else {
1606            Confess("$fieldName is not a valid field name.");
1607        }
1608    }
1609    
1610  =head3 InsertObject  =head3 InsertObject
1611    
1612  C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >>  C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >>
# Line 2001  Line 2064 
2064          push @retVal, \@rowData;          push @retVal, \@rowData;
2065          $fetched++;          $fetched++;
2066      }      }
2067        Trace("$fetched rows returned in GetAll.") if T(SQL => 4);
2068      # Return the resulting list.      # Return the resulting list.
2069      return @retVal;      return @retVal;
2070  }  }
2071    
2072    =head3 Exists
2073    
2074    C<< my $found = $sprout->Exists($entityName, $entityID); >>
2075    
2076    Return TRUE if an entity exists, else FALSE.
2077    
2078    =over 4
2079    
2080    =item entityName
2081    
2082    Name of the entity type (e.g. C<Feature>) relevant to the existence check.
2083    
2084    =item entityID
2085    
2086    ID of the entity instance whose existence is to be checked.
2087    
2088    =item RETURN
2089    
2090    Returns TRUE if the entity instance exists, else FALSE.
2091    
2092    =back
2093    
2094    =cut
2095    #: Return Type $;
2096    sub Exists {
2097        # Get the parameters.
2098        my ($self, $entityName, $entityID) = @_;
2099        # Check for the entity instance.
2100        Trace("Checking existence of $entityName with ID=$entityID.") if T(4);
2101        my $testInstance = $self->GetEntity($entityName, $entityID);
2102        # Return an existence indicator.
2103        my $retVal = ($testInstance ? 1 : 0);
2104        return $retVal;
2105    }
2106    
2107  =head3 EstimateRowSize  =head3 EstimateRowSize
2108    
2109  C<< my $rowSize = $erdb->EstimateRowSize($relName); >>  C<< my $rowSize = $erdb->EstimateRowSize($relName); >>
# Line 2195  Line 2294 
2294    
2295  =head3 ParseColumns  =head3 ParseColumns
2296    
2297  C<< my @columns = ERDB->ParseColumns($line); >>  C<< my @columns = ERDB::ParseColumns($line); >>
2298    
2299  Convert the specified data line to a list of columns.  Convert the specified data line to a list of columns.
2300    
# Line 2216  Line 2315 
2315    
2316  sub ParseColumns {  sub ParseColumns {
2317      # Get the parameters.      # Get the parameters.
2318      my ($self, $line) = @_;      my ($line) = @_;
2319      # Chop off the line-end.      # Chop off the line-end.
2320      chomp $line;      chomp $line;
2321      # Split it into a list.      # Split it into a list.

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.55

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3