[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.33, Sat Jan 28 09:36:47 2006 UTC revision 1.36, Mon Jan 30 03:46:34 2006 UTC
# Line 1146  Line 1146 
1146                          # the current entity, so we need to stack it.                          # the current entity, so we need to stack it.
1147                          my @stackList = (@augmentedList, $toEntity);                          my @stackList = (@augmentedList, $toEntity);
1148                          push @fromPathList, \@stackList;                          push @fromPathList, \@stackList;
1149                        } else {
1150                            Trace("$toEntity ignored because it occurred previously.") if T(4);
1151                      }                      }
1152                  }                  }
1153              }              }
# Line 1171  Line 1173 
1173      for my $keyName ('to_link', 'from_link') {      for my $keyName ('to_link', 'from_link') {
1174          # Get the list for this key.          # Get the list for this key.
1175          my @pathList = @{$stackList{$keyName}};          my @pathList = @{$stackList{$keyName}};
1176            Trace(scalar(@pathList) . " entries in path list for $keyName.") if T(3);
1177          # Loop through this list.          # Loop through this list.
1178          while (my $path = pop @pathList) {          while (my $path = pop @pathList) {
1179              # Get the table whose rows are to be deleted.              # Get the table whose rows are to be deleted.
# Line 1180  Line 1183 
1183              my $stmt = "DELETE FROM $target";              my $stmt = "DELETE FROM $target";
1184              # If there's more than just the one table, we need a USING clause.              # If there's more than just the one table, we need a USING clause.
1185              if (@pathTables > 1) {              if (@pathTables > 1) {
1186                  $stmt .= " USING " . join(", ", @pathTables[0 .. ($#pathTables - 1)]);                  $stmt .= " USING " . join(", ", @pathTables);
1187              }              }
1188              # Now start the WHERE. The first thing is the ID field from the starting table. That              # Now start the WHERE. The first thing is the ID field from the starting table. That
1189              # starting table will either be the entity relation or one of the entity's              # starting table will either be the entity relation or one of the entity's
# Line 1191  Line 1194 
1194                  # Connect the current relationship to the preceding entity.                  # Connect the current relationship to the preceding entity.
1195                  my ($entity, $rel) = @pathTables[$i-1,$i];                  my ($entity, $rel) = @pathTables[$i-1,$i];
1196                  # The style of connection depends on the direction of the relationship.                  # The style of connection depends on the direction of the relationship.
1197                  $stmt .= " AND $entity.id = $rel.from_link";                  $stmt .= " AND $entity.id = $rel.$keyName";
1198                  if ($i + 1 <= $#pathTables) {                  if ($i + 1 <= $#pathTables) {
1199                      # Here there's a next entity, so connect that to the relationship's                      # Here there's a next entity, so connect that to the relationship's
1200                      # to-link.                      # to-link.
1201                      my $entity2 = $pathTables[$i+1];                      my $entity2 = $pathTables[$i+1];
1202                      $stmt .= " AND $rel.$keyName = $entity2.id";                      $stmt .= " AND $rel.to_link = $entity2.id";
1203                  }                  }
1204              }              }
1205              # Now we have our desired DELETE statement.              # Now we have our desired DELETE statement.
# Line 1206  Line 1209 
1209              } else {              } else {
1210                  # Here we can delete. Note that the SQL method dies with a confessing                  # Here we can delete. Note that the SQL method dies with a confessing
1211                  # if an error occurs, so we just go ahead and do it.                  # if an error occurs, so we just go ahead and do it.
1212                  Trace("Executing delete: $stmt") if T(3);                  Trace("Executing delete from $target using '$objectID'.") if T(3);
1213                  my $rv = $db->SQL($stmt, 0, [$objectID]);                  my $rv = $db->SQL($stmt, 0, $objectID);
1214                  # Accumulate the statistics for this delete. The only rows deleted                  # Accumulate the statistics for this delete. The only rows deleted
1215                  # are from the target table, so we use its name to record the                  # are from the target table, so we use its name to record the
1216                  # statistic.                  # statistic.

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.36

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3