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

Kristian Hoffmann khoff at pc-intouch.com
Mon May 13 20:41:45 PDT 2002


Aha!  See below...

On Mon, 13 May 2002, ivan wrote:

> 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;
> >     }
> > ...

If any items have been updated, it passes the hash containing all the
check/reply items.  But then... (lower)


> 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;
>   }

When it does and UPDATE on any of the items that haven't changed, the
return value is 0 because nothing was changed.  It then falls through to
the INSERT and adds a duplicate row.  If you specify
"mysql_client_found_rows=1" in the datasrc, DBD::mysql::execute returns
the number of rows that were matched, not updated, when doing an UPDATE.

Soooo, update TFM or TFS?

-Kristian




More information about the freeside-devel mailing list