[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.37, Mon Jan 30 04:04:32 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.
1180              my @pathTables = @{$path};              my @pathTables = @{$path};
1181              # Start the DELETE statement.              # Start the DELETE statement. We need to call DBKernel because the
1182                # syntax of a DELETE-USING varies among DBMSs.
1183              my $target = $pathTables[$#pathTables];              my $target = $pathTables[$#pathTables];
1184              my $stmt = "DELETE FROM $target";              my $stmt = $db->SetUsing(@pathTables);
             # If there's more than just the one table, we need a USING clause.  
             if (@pathTables > 1) {  
                 $stmt .= " USING " . join(", ", @pathTables[0 .. ($#pathTables - 1)]);  
             }  
1185              # 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
1186              # 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
1187              # sub-relations.              # sub-relations.
# Line 1191  Line 1191 
1191                  # Connect the current relationship to the preceding entity.                  # Connect the current relationship to the preceding entity.
1192                  my ($entity, $rel) = @pathTables[$i-1,$i];                  my ($entity, $rel) = @pathTables[$i-1,$i];
1193                  # The style of connection depends on the direction of the relationship.                  # The style of connection depends on the direction of the relationship.
1194                  $stmt .= " AND $entity.id = $rel.from_link";                  $stmt .= " AND $entity.id = $rel.$keyName";
1195                  if ($i + 1 <= $#pathTables) {                  if ($i + 1 <= $#pathTables) {
1196                      # 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
1197                      # to-link.                      # to-link.
1198                      my $entity2 = $pathTables[$i+1];                      my $entity2 = $pathTables[$i+1];
1199                      $stmt .= " AND $rel.$keyName = $entity2.id";                      $stmt .= " AND $rel.to_link = $entity2.id";
1200                  }                  }
1201              }              }
1202              # Now we have our desired DELETE statement.              # Now we have our desired DELETE statement.
# Line 1206  Line 1206 
1206              } else {              } else {
1207                  # 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
1208                  # if an error occurs, so we just go ahead and do it.                  # if an error occurs, so we just go ahead and do it.
1209                  Trace("Executing delete: $stmt") if T(3);                  Trace("Executing delete from $target using '$objectID'.") if T(3);
1210                  my $rv = $db->SQL($stmt, 0, [$objectID]);                  my $rv = $db->SQL($stmt, 0, $objectID);
1211                  # Accumulate the statistics for this delete. The only rows deleted                  # Accumulate the statistics for this delete. The only rows deleted
1212                  # 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
1213                  # statistic.                  # statistic.

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3