List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:July 8 2009 5:21am
Subject:Re: Triggers For Radius DB
View as plain text  
In the last episode (Jul 07), Marcel Grandemange said:
> I hope someone can assist me.  I have a freeradius server running off
> mysql.  Now I would like to use triggers to negate some of the traffic
> logged within it.  I tried to use following as trigger..
> 
> Create Trigger ftp
> BEFORE UPDATE ON radacct
> FOR EACH ROW
> BEGIN
> UPDATE radacct SET NEW.AcctInputOctets=(0 - NEW.AcctInputOctets) WHERE NASPortId=21;
> UPDATE radacct SET NEW.AcctOutputOctets=(0 - NEW.AcctOutputOctets) WHERE
> NASPortId=21;
> END;
>
> And Many variants of that but only ends up locking the db in someway with
> messages such as.
> 
> Tue Jul  7 23:34:12 2009 : Error: rlm_sql_mysql: Cannot store result
> Tue Jul  7 23:34:12 2009 : Error: rlm_sql_mysql: MySQL error 'Can't update table
> 'radacct' in stored function/trigger because it is already used by statement which invoked
> this stored function/trigger.'

You don't want to UPDATE the table, since as you have seen it will cause an
error.  The only row you can change in the table being modified in a trigger
is the active row itself, and you must change its values by SETting
NEW.fieldname:

IF NEW.NASPortID = 21 THEN
 SET NEW.AcctInputOctets=(0 - NEW.AcctInputOctets);
 SET NEW.AcctOutputOctets=(0 - NEW.AcctOutputOctets):
END IF;


-- 
	Dan Nelson
	dnelson@stripped
Thread
Triggers For Radius DBMarcel Grandemange7 Jul
  • Re: Triggers For Radius DBDan Nelson8 Jul
    • RE: Triggers For Radius DBMarcel Grandemange8 Jul