Changeset 147 for branches/sql-cleanup/cgi-bin/IPDB.pm
- Timestamp:
- 02/01/05 17:43:34 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sql-cleanup/cgi-bin/IPDB.pm
r135 r147 58 58 59 59 # Initialize alloctypes hashes 60 $sth = $dbh->prepare("select *from alloctypes order by listorder");60 $sth = $dbh->prepare("select type,listname,dispname,listorder from alloctypes order by listorder"); 61 61 $sth->execute; 62 62 while (my @data = $sth->fetchrow_array) { … … 68 68 69 69 # City and POP listings 70 $sth = $dbh->prepare("select *from cities order by city");70 $sth = $dbh->prepare("select city,routing from cities order by city"); 71 71 $sth->execute; 72 72 return (undef,$sth->errstr) if $sth->err; … … 79 79 80 80 # Master block list 81 $sth = $dbh->prepare("select *from masterblocks order by cidr");81 $sth = $dbh->prepare("select cidr from masterblocks order by cidr"); 82 82 $sth->execute; 83 83 for (my $i=0; my @data = $sth->fetchrow_array(); $i++) { … … 120 120 # Return here if we can't select. Note that this indicates a 121 121 # problem executing the select. 122 my $sth = $dbh->prepare( 'select cidr from masterblocks');122 my $sth = $dbh->prepare("select cidr from masterblocks"); 123 123 $sth->execute(); 124 124 return (undef,$DBI::errstr) if ($sth->err); … … 154 154 } else { 155 155 # it connects, try a stmt. 156 my $sth = $dbh->prepare( 'select cidr from masterblocks');156 my $sth = $dbh->prepare("select cidr from masterblocks"); 157 157 my $err = $sth->execute(); 158 158 … … 192 192 $msg = "Unable to assign static IP $cidr to $custid"; 193 193 eval { 194 # We'll just have to put up with the oddities caused by SQL (un)sort order 195 $sth = $dbh->prepare("select * from poolips where pool='$alloc_from'". 196 " and available='y' order by ip"); 197 $sth->execute; 198 194 # We have to do this in two parts because otherwise we lose 195 # the ability to return the IP assigned. Should that change, 196 # the commented SQL statement below may become usable. 199 197 # update poolips set custid='$custid',city='$city',available='n', 200 198 # description='$desc',notes='$notes',circuitid='$circid' 201 199 # where ip=(select ip from poolips where pool='$alloc_from' 202 200 # and available='y' order by ip limit 1); 203 ##err Need better handling here; what if there's no free IPs when this sub gets called? 201 202 $sth = $dbh->prepare("select ip from poolips where pool='$alloc_from'". 203 " and available='y' order by ip"); 204 $sth->execute; 205 204 206 my @data = $sth->fetchrow_array; 205 $cidr = $data[ 1]; # $cidr is already declared when we get here!207 $cidr = $data[0]; # $cidr is already declared when we get here! 206 208 207 209 $sth = $dbh->prepare("update poolips set custid='$custid',". … … 234 236 " where cidr='$cidr'"); 235 237 $sth->execute; 236 $sth = $dbh->prepare("insert into routed values ('$cidr',".237 238 $sth = $dbh->prepare("insert into routed (cidr,maskbits,city)". 239 " values ('$cidr',".$cidr->masklen.",'$city')"); 238 240 $sth->execute; 239 241 } else { … … 242 244 $sth->execute; 243 245 244 $sth = $dbh->prepare("insert into allocations values ('$cidr',". 245 "'$custid','$type','$city','$desc','$notes',". 246 $sth = $dbh->prepare("insert into allocations". 247 " (cidr,custid,type,city,description,notes,maskbits,circuitid)". 248 " values ('$cidr','$custid','$type','$city','$desc','$notes',". 246 249 $cidr->masklen.",'$circid')"); 247 250 $sth->execute; … … 297 300 # Insert the new freeblocks entries 298 301 # Note that non-routed blocks are assigned to <NULL> 299 $sth = $dbh->prepare("insert into freeblocks values (?, ?, '<NULL>','n')"); 302 # and use the default value for the routed column ('n') 303 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)". 304 " values (?, ?, '<NULL>')"); 300 305 foreach my $block (@newfreeblocks) { 301 306 $sth->execute("$block", $block->masklen); … … 303 308 304 309 # Insert the entry in the routed table 305 $sth = $dbh->prepare("insert into routed values ('$cidr',".306 310 $sth = $dbh->prepare("insert into routed (cidr,maskbits,city)". 311 " values ('$cidr',".$cidr->masklen.",'$city')"); 307 312 $sth->execute; 308 313 # Insert the (almost) same entry in the freeblocks table 309 $sth = $dbh->prepare("insert into freeblocks values ('$cidr',".310 314 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 315 " values ('$cidr',".$cidr->masklen.",'$city','y')"); 311 316 $sth->execute; 312 317 … … 314 319 315 320 # Insert the new freeblocks entries 316 $sth = $dbh->prepare("insert into freeblocks values (?, ?,".317 " (select city from routed where cidr >>= '$cidr'),'y')");321 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 322 " values (?, ?, (select city from routed where cidr >>= '$cidr'),'y')"); 318 323 foreach my $block (@newfreeblocks) { 319 324 $sth->execute("$block", $block->masklen); … … 321 326 322 327 # Insert the allocations entry 323 $sth = $dbh->prepare("insert into allocations values ('$cidr',". 324 "'$custid','$type','$city','$desc','$notes',".$cidr->masklen. 325 ",'$circid')"); 328 $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,". 329 "description,notes,maskbits,circuitid)". 330 " values ('$cidr','$custid','$type','$city','$desc','$notes',". 331 $cidr->masklen.",'$circid')"); 326 332 $sth->execute; 327 333 … … 365 371 366 372 # have to insert all pool IPs into poolips table as "unallocated". 367 $sth = $dbh->prepare("insert into poolips values ('$pool',".368 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')");373 $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,ptype)". 374 " values ('$pool', ?, '6750400', '$city', '$pooltype'"); 369 375 my @poolip_list = $pool->hostenum; 370 376 if ($class eq 'all') { # (DSL-ish block - *all* IPs available … … 455 461 $sth->execute; 456 462 # Set up query to start compacting free blocks. 457 $sth = $dbh->prepare("select *from freeblocks where ".463 $sth = $dbh->prepare("select cidr from freeblocks where ". 458 464 "maskbits<=".$cidr->masklen." and routed='n' order by maskbits desc"); 459 465 … … 470 476 471 477 # Set up query for compacting free blocks. 472 $sth = $dbh->prepare("select *from freeblocks where cidr <<= ".478 $sth = $dbh->prepare("select cidr from freeblocks where cidr <<= ". 473 479 "(select cidr from routed where cidr >>= '$cidr') ". 474 480 " and maskbits<=".$cidr->masklen." and routed='y' order by maskbits desc"); … … 513 519 # insert "new" freeblocks entry 514 520 if ($type eq 'rr') { 515 $sth = $dbh->prepare("insert into freeblocks values ('$cidr',".$cidr->masklen.516 " ,'<NULL>','n')");521 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)". 522 " values ('$cidr',".$cidr->masklen.",'<NULL>')"); 517 523 } else { 518 $sth = $dbh->prepare("insert into freeblocks values ('$cidr',".$cidr->masklen. 524 $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)". 525 " values ('$cidr',".$cidr->masklen. 519 526 ",(select city from routed where cidr >>= '$cidr'),'y')"); 520 527 }
Note:
See TracChangeset
for help on using the changeset viewer.