Changeset 20 for trunk/DNSDB.pm


Ignore:
Timestamp:
10/15/09 13:23:51 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint, group mangling almost complete
also normalized *most* group* refs to use "group*" vs "grp*"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r19 r20  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName &getSOA
    26         &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
     25        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &groupName
     26        &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    2727        %typemap %reverse_typemap
    2828        );
     
    3030@EXPORT         = (); # Export nothing by default.
    3131%EXPORT_TAGS    = ( ALL => [qw(
    32                 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName
    33 &getSOA
    34                 &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
     32                &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren
     33                &groupName &getSOA &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    3534                %typemap %reverse_typemap
    3635                )]
     
    264263  $errstr = '';
    265264  my $dbh = shift;
    266   my $grpname = shift;
    267   my $pargrp = shift;
     265  my $groupname = shift;
     266  my $pargroup = shift;
    268267
    269268  # 0 indicates "template", hardcoded.
     
    279278  eval {
    280279    my $sth = $dbh->prepare("INSERT INTO groups (parent_group_id,group_name) VALUES (?,?)");
    281     $sth->execute($pargrp,$grpname);
     280    $sth->execute($pargroup,$groupname);
    282281
    283282    $sth = $dbh->prepare("SELECT group_id FROM groups WHERE group_name=?");
    284     $sth->execute($grpname);
    285     my ($grpid) = $sth->fetchrow_array();
     283    $sth->execute($groupname);
     284    my ($groupid) = $sth->fetchrow_array();
    286285
    287286    $sth = $dbh->prepare("INSERT INTO default_records (group_id,host,type,val,distance,weight,port,ttl) ".
    288         "VALUES ($grpid,?,?,?,?,?,?,?)");
     287        "VALUES ($groupid,?,?,?,?,?,?,?)");
    289288    if ($torc) {
    290289      my $sth2 = $dbh->prepare("SELECT host,type,val,distance,weight,port,ttl FROM default_records WHERE group_id=?");
     
    326325  $errstr = '';
    327326  my $dbh = shift;
    328   my $rootgrp = shift;
    329   my $grpdest = shift;
     327  my $rootgroup = shift;
     328  my $groupdest = shift;
    330329
    331330  # special break for default group;  otherwise we get stuck.
    332   if ($rootgrp == 1) {
     331  if ($rootgroup == 1) {
    333332    # by definition, group 1 is the Root Of All Groups
    334333    my $sth = $dbh->prepare("SELECT group_id FROM groups");
    335334    $sth->execute;
    336     my @grplist;
     335    my @grouplist;
    337336    while (my @this = $sth->fetchrow_array) {
    338       push @$grpdest, @this;
     337      push @$groupdest, @this;
    339338    }
    340339  } else {
    341340    my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE parent_group_id=?");
    342     $sth->execute($rootgrp);
     341    $sth->execute($rootgroup);
    343342    return if $sth->rows == 0;
    344     my @grplist;
    345     while (my ($grp) = $sth->fetchrow_array) {
    346       push @$grpdest, $grp;
    347       getChildren($dbh,$grp,$grpdest);
     343    my @grouplist;
     344    while (my ($group) = $sth->fetchrow_array) {
     345      push @$groupdest, $group;
     346      getChildren($dbh,$group,$groupdest);
    348347    }
    349348  }
     
    351350
    352351
    353 ## DNSDB::grpName()
     352## DNSDB::groupName()
    354353# Return the group name based on a group ID
    355354# Takes a database handle and the group ID
    356355# Returns the group name or undef on failure
    357 sub grpName {
    358   $errstr = '';
    359   my $dbh = shift;
    360   my $grpid = shift;
    361   my $sth = $dbh->prepare("select name from groups where group_id=?");
    362   $sth->execute($grpid);
    363   my ($grpname) = $sth->fetchrow_array();
    364   $errstr = $DBI::errstr if !$grpname;
    365   return $grpname if $grpname;
    366 } # end domainName
     356sub groupName {
     357  $errstr = '';
     358  my $dbh = shift;
     359  my $groupid = shift;
     360  my $sth = $dbh->prepare("SELECT group_name FROM groups WHERE group_id=?");
     361  $sth->execute($groupid);
     362  my ($groupname) = $sth->fetchrow_array();
     363  $errstr = $DBI::errstr if !$groupname;
     364  return $groupname if $groupname;
     365} # end groupName
    367366
    368367
Note: See TracChangeset for help on using the changeset viewer.