unlang, variable and SQL (freeradius 3.0.15)
Hi, I try to store result from SQL into local variable to eliminate running same queries at time. I prepare following scenario: 1/ define new attribute (will be used for store the result from SQL) in the dictionary, attribute type is string (e.g. ATTRIBUTE SQLRESULT 3000 string) 2/ in inner tunnel post-auth section: update control { &SQLRESULT = "%{sql::SELECT count(*) from some_table where .. .}" } if ( %{integer:SQLRESULT} == some_value ) { ... } elsif ( %{integer:SQLRESULT} == other_value ) { ... } in debug I can see, that the SQL return some value, and the value is filled into attribute &SQLRESULT, but afterwards condition do not match (attribute has no value) (10) EXPAND %{sql:SELECT count(*) from table where username = '% {User-Name}' ... (10) --> 2 (10) &SQLRESULT = 2 (10) } # update control = noop (10) if ("%{integer:SQLRESULT}" == 2) { (10) EXPAND %{integer:SQLRESULT} (10) --> (10) if ("%{integer:SQLRESULT}" == 2) -> FALSE Maybe I do not fully understand unlang. Is possible to store the result from SQL in some variable, and afterward use this variable in some conditions? Thank you for any suggestion, Petr Linke
On Oct 3, 2017, at 10:19 AM, <petr.linke@seznam.cz> <petr.linke@seznam.cz> wrote
I try to store result from SQL into local variable to eliminate running same queries at time.
I prepare following scenario:
1/ define new attribute (will be used for store the result from SQL) in the dictionary, attribute type is string (e.g. ATTRIBUTE SQLRESULT 3000 string) 2/ in inner tunnel post-auth section: update control { &SQLRESULT = "%{sql::SELECT count(*) from some_table where .. .}" }
Which places it into the control list.
if ( %{integer:SQLRESULT} == some_value ) {
Which looks for it in the request list. Use control:SQLRESULT instead. Also, if the attribute is an integer, just define it as an integer in the dictionaries. Don't define it as a string and then convert it to an integer. Alan DeKok.
---------- Original mail ---------- From: Alan DeKok <aland@deployingradius.com> To: FreeRadius users mailing list <freeradius-users@lists.freeradius.org> Date: 3. 10. 2017 16:55:57 Subject: Re: unlang, variable and SQL (freeradius 3.0.15) "On Oct 3, 2017, at 10:19 AM, <petr.linke@seznam.cz> <petr.linke@seznam.cz> wrote
I try to store result from SQL into local variable to eliminate running same queries at time.
I prepare following scenario:
1/ define new attribute (will be used for store the result from SQL) in the dictionary, attribute type is string (e.g. ATTRIBUTE SQLRESULT 3000 string) 2/ in inner tunnel post-auth section: update control { &SQLRESULT = "%{sql::SELECT count(*) from some_table where .. .}" }
Which places it into the control list.
if ( %{integer:SQLRESULT} == some_value ) {
Which looks for it in the request list. Use control:SQLRESULT instead. " Great, now all is OK, many thanks " Also, if the attribute is an integer, just define it as an integer in the dictionaries. Don't define it as a string and then convert it to an integer. " Yes, I know. This attribute was from my previous tests, and I was lazy to define new attribute :(. Only one simple question. If SQL query return more rows, is possible to store result from SQL in some special type of variable and use foreach statement to mine values from rows? Petr Linke
On Oct 3, 2017, at 11:51 AM, <petr.linke@seznam.cz> <petr.linke@seznam.cz> wrote:
Only one simple question. If SQL query return more rows, is possible to store result from SQL in some special type of variable and use foreach statement to mine values from rows?
Not really. That is supported in v4, tho. :( Alan DeKok.
participants (2)
-
Alan DeKok -
petr.linke@seznam.cz