[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.90, Fri Apr 27 22:19:49 2007 UTC revision 1.93, Mon Jul 16 20:04:50 2007 UTC
# Line 372  Line 372 
372                   'medium-string' =>                   'medium-string' =>
373                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, sort => "",                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, sort => "",
374                                 indexMod =>   0, notes => "character string, 0 to 160 characters"},                                 indexMod =>   0, notes => "character string, 0 to 160 characters"},
375                     'long-string' =>
376                                 { sqlType => 'VARCHAR(500)',       maxLen => 500,          avglen => 255, sort => "",
377                                   indexMod =>   0, notes => "character string, 0 to 500 characters"},
378                  );                  );
379    
380  # Table translating arities into natural language.  # Table translating arities into natural language.
# Line 1014  Line 1017 
1017              my $oldString = $fieldList->[$i];              my $oldString = $fieldList->[$i];
1018              if (length($oldString) > $maxLen) {              if (length($oldString) > $maxLen) {
1019                  # Here it's too big, so we truncate it.                  # Here it's too big, so we truncate it.
1020                  Trace("Truncating field $i in relation $relName to $maxLen characters from \"$oldString\".") if T(1);                  Trace("Truncating field $i ($fieldTypes->[$i]->{name}) in relation $relName to $maxLen characters from \"$oldString\".") if T(1);
1021                  $fieldList->[$i] = substr $oldString, 0, $maxLen;                  $fieldList->[$i] = substr $oldString, 0, $maxLen;
1022                  $retVal++;                  $retVal++;
1023              }              }
# Line 1561  Line 1564 
1564      my ($suffix, $mappedNameListRef, $mappedNameHashRef) =      my ($suffix, $mappedNameListRef, $mappedNameHashRef) =
1565          $self->_SetupSQL($objectNames, $filterClause);          $self->_SetupSQL($objectNames, $filterClause);
1566      # Create the query.      # Create the query.
1567      my $command = "SELECT DISTINCT " . join(".*, ", @{$mappedNameListRef}) .      my $command = "SELECT " . join(".*, ", @{$mappedNameListRef}) .
1568          ".* $suffix";          ".* $suffix";
1569      my $sth = $self->_GetStatementHandle($command, $params);      my $sth = $self->_GetStatementHandle($command, $params);
1570      # Now we create the relation map, which enables DBQuery to determine the order, name      # Now we create the relation map, which enables DBQuery to determine the order, name
# Line 1662  Line 1665 
1665              $self->_SetupSQL($objectNames, $filterClause, $matchClause);              $self->_SetupSQL($objectNames, $filterClause, $matchClause);
1666          # Create the query. Note that the match clause is inserted at the front of          # Create the query. Note that the match clause is inserted at the front of
1667          # the select fields.          # the select fields.
1668          my $command = "SELECT DISTINCT $matchClause, " . join(".*, ", @{$mappedNameListRef}) .          my $command = "SELECT $matchClause, " . join(".*, ", @{$mappedNameListRef}) .
1669              ".* $suffix";              ".* $suffix";
1670          my $sth = $self->_GetStatementHandle($command, \@myParams);          my $sth = $self->_GetStatementHandle($command, \@myParams);
1671          # Now we create the relation map, which enables DBQuery to determine the order, name          # Now we create the relation map, which enables DBQuery to determine the order, name
# Line 2063  Line 2066 
2066      $dbh->SQL($command, undef, @parms);      $dbh->SQL($command, undef, @parms);
2067  }  }
2068    
2069    =head3 DeleteLike
2070    
2071    C<< my $deleteCount = $erdb->DeleteLike($relName, $filter, \@parms); >>
2072    
2073    Delete all the relationship rows that satisfy a particular filter condition. Unlike a normal
2074    filter, only fields from the relationship itself can be used.
2075    
2076    =over 4
2077    
2078    =item relName
2079    
2080    Name of the relationship whose records are to be deleted.
2081    
2082    =item filter
2083    
2084    A filter clause (L</Get>-style) for the delete query.
2085    
2086    =item parms
2087    
2088    Reference to a list of parameters for the filter clause.
2089    
2090    =item RETURN
2091    
2092    Returns a count of the number of rows deleted.
2093    
2094    =back
2095    
2096    =cut
2097    
2098    sub DeleteLike {
2099        # Get the parameters.
2100        my ($self, $objectName, $filter, $parms) = @_;
2101        # Declare the return variable.
2102        my $retVal;
2103        # Insure the parms argument is an array reference if the caller left it off.
2104        if (! defined($parms)) {
2105            $parms = [];
2106        }
2107        # Insure we have a relationship. The main reason for this is if we delete an entity
2108        # instance we have to yank out a bunch of other stuff with it.
2109        if ($self->IsEntity($objectName)) {
2110            Confess("Cannot use DeleteLike on $objectName, because it is not a relationship.");
2111        } else {
2112            # Create the SQL command suffix to get the desierd records.
2113            my ($suffix) = $self->_SetupSQL([$objectName], $filter);
2114            # Convert it to a DELETE command.
2115            my $command = "DELETE $suffix";
2116            # Execute the command.
2117            my $dbh = $self->{_dbh};
2118            my $result = $dbh->SQL($command, 0, @{$parms});
2119            # Check the results. Note we convert the "0D0" result to a real zero.
2120            # A failure causes an abnormal termination, so the caller isn't going to
2121            # worry about it.
2122            if (! defined $result) {
2123                Confess("Error deleting from $objectName: " . $dbh->errstr());
2124            } elsif ($result == 0) {
2125                $retVal = 0;
2126            } else {
2127                $retVal = $result;
2128            }
2129        }
2130        # Return the result count.
2131        return $retVal;
2132    }
2133    
2134  =head3 SortNeeded  =head3 SortNeeded
2135    
2136  C<< my $parms = $erdb->SortNeeded($relationName); >>  C<< my $parms = $erdb->SortNeeded($relationName); >>
# Line 3059  Line 3127 
3127  fields specified returns multiple values, they are flattened in with the rest. For  fields specified returns multiple values, they are flattened in with the rest. For
3128  example, the following call will return a list of the features in a particular  example, the following call will return a list of the features in a particular
3129  spreadsheet cell, and each feature will be represented by a list containing the  spreadsheet cell, and each feature will be represented by a list containing the
3130  feature ID followed by all of its aliases.  feature ID followed by all of its essentiality determinations.
3131    
3132  C<< @query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(alias)']); >>  C<< @query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(essential)']); >>
3133    
3134  =over 4  =over 4
3135    
# Line 4192  Line 4260 
4260  sub _GetStatementHandle {  sub _GetStatementHandle {
4261      # Get the parameters.      # Get the parameters.
4262      my ($self, $command, $params) = @_;      my ($self, $command, $params) = @_;
4263        Confess("Invalid parameter list.") if (! defined($params) || ref($params) ne 'ARRAY');
4264      # Trace the query.      # Trace the query.
4265      Trace("SQL query: $command") if T(SQL => 3);      Trace("SQL query: $command") if T(SQL => 3);
4266      Trace("PARMS: '" . (join "', '", @{$params}) . "'") if (T(SQL => 4) && (@{$params} > 0));      Trace("PARMS: '" . (join "', '", @{$params}) . "'") if (T(SQL => 4) && (@{$params} > 0));

Legend:
Removed from v.1.90  
changed lines
  Added in v.1.93

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3