[freeside-devel] FS::part_export::sqlradius::_export_replace

ivan ivan at 420.am
Mon May 13 18:36:16 PDT 2002


On Mon, May 13, 2002 at 06:24:04PM -0700, Kristian Hoffmann wrote:
> From around line 40 of sqlradius.pm...
> 
> ...
>     if ( grep { !exists $old{$_} #new attributes
>                 || $new{$_} ne $old{$_} #changed
>               } keys %new
>     ) {
>       my $error = $self->sqlradius_queue( $new->svcnum, 'insert',
>         $table, $new->username, %new );
>       return $error if $error;
>     }
> ...
> 
> 
> I was wondering why this just inserts changed records instead of updating
> or deleting and inserting.

>  Did you do that on purpose?  If I change any
> check or reply items, the old entries accumulate in the remote mysql
> database.

It shouldn't do that.  Although, admittedly, the naming of the `insert'
subroutine is confusing, take an actual look at the code - it's supposed
to attempt to update an existing value before inserting a new one:

  sub sqlradius_insert { #subroutine, not method
    my $dbh = sqlradius_connect(shift, shift, shift);
    my( $replycheck, $username, %attributes ) = @_;

    foreach my $attribute ( keys %attributes ) {
      my $u_sth = $dbh->prepare(
        "UPDATE rad$replycheck SET Value = ? WHERE UserName = ? AND Attribute = ?"    ) or die $dbh->errstr;
      my $i_sth = $dbh->prepare(
        "INSERT INTO rad$replycheck ( id, UserName, Attribute, Value ) ".
          "VALUES ( ?, ?, ?, ? )"
      ) or die $dbh->errstr;
      $u_sth->execute($attributes{$attribute}, $username, $attribute) > 0
        or $i_sth->execute( '', $username, $attribute, $attributes{$attribute} )
          or die "can't insert into rad$replycheck table: ". $i_sth->errstr;
    }
    $dbh->disconnect;
  }


-- 
_ivan



More information about the freeside-devel mailing list