Changeset 556


Ignore:
Timestamp:
12/18/12 17:57:27 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Update addMaster() to handle new table logic and fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r555 r556  
    233233# elsewhere though;  legacy data may have traps and pitfalls in it to break this.
    234234# Thus the "routed" flag.
    235       $dbh->do("INSERT INTO freeblocks (cidr,maskbits,city,routed) VALUES (?,?,?,?)", undef,
    236         ($cidr, $cidr->masklen, '<NULL>', 'n') );
     235      $dbh->do("INSERT INTO freeblocks (cidr,maskbits,city,routed,parent,rdepth) VALUES (?,?,?,?,?,?)", undef,
     236        ($cidr, $cidr->masklen, '<NULL>', 'm', $cidr, 1) );
    237237
    238238      # If we get here, everything is happy.  Commit changes.
     
    264264
    265265      # collect the unrouted free blocks within the new master
    266       $sth = $dbh->prepare("SELECT cidr FROM freeblocks WHERE maskbits <= ? AND cidr <<= ? AND routed = 'n'");
     266      $sth = $dbh->prepare("SELECT cidr FROM freeblocks WHERE masklen(cidr) <= ? AND cidr <<= ? AND routed = 'm'");
    267267      $sth->execute($smallmask, $cidr);
    268268      while (my @data = $sth->fetchrow_array) {
     
    278278      # freeblocks
    279279      $sth = $dbh->prepare("DELETE FROM freeblocks WHERE cidr <<= ?");
    280       my $sth2 = $dbh->prepare("INSERT INTO freeblocks (cidr,maskbits,city,routed) VALUES (?,?,'<NULL>','n')");
     280      my $sth2 = $dbh->prepare("INSERT INTO freeblocks (cidr,maskbits,city,routed,parent,rdepth)".
     281        " VALUES (?,?,'<NULL>','m',?,1)");
    281282      foreach my $newblock (@blocklist) {
    282283        $sth->execute($newblock);
    283         $sth2->execute($newblock, $newblock->masklen);
    284       }
     284        $sth2->execute($newblock, $newblock->masklen, $cidr);
     285      }
     286
     287      # update parent relations at rdepth=1
     288      $dbh->do("UPDATE allocations SET parent = ? WHERE parent << ? AND rdepth=1", undef, ($cidr, $cidr) );
     289      $dbh->do("UPDATE freeblocks SET parent = ? WHERE parent << ? AND rdepth=1", undef, ($cidr, $cidr) );
    285290
    286291      # master
Note: See TracChangeset for help on using the changeset viewer.