Are AVP arrays still the only way to create a list of scalars as of K 3.0.0? Or are there other, more graceful ways to accommodate this need now?
AVPs are a very useful feature, though the syntax is not documented in 'avpops' or the cookbook except rather incidentally:
$var(i) = 0;
while(is_avp_set("$(avp(s:somename)[$var(i)])")) { xlog("L_INFO", "Value at index $var(i): $(avp(s:somename)][$var(i)])\n"); $var(i) = $var(i) + 1; }
Is there a better way to handle this now, perhaps via some features imported from SER? Script variables ($var(...)) do not support subscripts judging by the cookbook; do they? Are there other options I am unaware of?
Thanks,
Hello,
On 02/22/2010 12:33 PM, Alex Balashov wrote:
Are AVP arrays still the only way to create a list of scalars as of K 3.0.0? Or are there other, more graceful ways to accommodate this need now?
AVPs are a very useful feature, though the syntax is not documented in 'avpops' or the cookbook except rather incidentally:
$var(i) = 0;
while(is_avp_set("$(avp(s:somename)[$var(i)])")) { xlog("L_INFO", "Value at index $var(i): $(avp(s:somename)][$var(i)])\n"); $var(i) = $var(i) + 1; }
Is there a better way to handle this now, perhaps via some features imported from SER? Script variables ($var(...)) do not support subscripts judging by the cookbook; do they?
no, they are single-value variables.
Are there other options I am unaware of?
There is no dedicated array type. In some cases you can use a hash table and simulate an array by key value:
$var(i) = 0; $sht(a=>[$var(i)]) = 1; $var(i) = 1; $sht(a=>[$var(i)]) = 2;
But it is only about how you define the keys, not a real array behind.
Cheers, Daniel
On Wednesday 24 February 2010, Daniel-Constantin Mierla wrote:
Is there a better way to handle this now, perhaps via some features imported from SER? Script variables ($var(...)) do not support subscripts judging by the cookbook; do they?
no, they are single-value variables.
Are there other options I am unaware of?
There is no dedicated array type. In some cases you can use a hash table and simulate an array by key value:
$var(i) = 0; $sht(a=>[$var(i)]) = 1; $var(i) = 1; $sht(a=>[$var(i)]) = 2;
But it is only about how you define the keys, not a real array behind.
Hi Daniel, Hi Alex,
we've a simple and small module that implements a matrix like this:
+---+----+--------+ | A | B | result | +---+----+--------+ | 1 | 9 | 2 | | 2 | 69 | 1 | | 2 | 13 | 3 | +---+----+--------+
The matrix is read from a database and cached in memory, there is a FIFO command that can be used to reload it. There is a query command that uses a given A and B and stores the result in an AVP. If there is interest in this I could try to merge this into the repository.
Cheers,
Henning
On 02/24/2010 08:01 AM, Henning Westerholt wrote:
The matrix is read from a database and cached in memory, there is a FIFO command that can be used to reload it. There is a query command that uses a given A and B and stores the result in an AVP. If there is interest in this I could try to merge this into the repository.
I vote yes! But what would be ideal is to be able to fetch sqlops results into such a "matrix."
On 02/24/2010 02:15 PM, Alex Balashov wrote:
On 02/24/2010 08:01 AM, Henning Westerholt wrote:
The matrix is read from a database and cached in memory, there is a FIFO command that can be used to reload it. There is a query command that uses a given A and B and stores the result in an AVP. If there is interest in this I could try to merge this into the repository.
I vote yes! But what would be ideal is to be able to fetch sqlops results into such a "matrix."
sqlops result is a matrix. You can access row and column by index. Or you look for something else?
Cheers, Daniel
On 02/24/2010 11:20 AM, Daniel-Constantin Mierla wrote:
sqlops result is a matrix. You can access row and column by index. Or you look for something else?
I look for something that's transaction-persistent so that I can iterate over it in failure routes, and as far as I know $dbr() is not transaction-persistent.
Typical situation is a list of gateways in descending order of priority is retrieved from a database along with various other attributes. The only way I know to deal with that is to buffer the results from $dbr() into an array of AVPs and then cycle through them using a global AVP as an array index.
On 02/24/2010 05:21 PM, Alex Balashov wrote:
On 02/24/2010 11:20 AM, Daniel-Constantin Mierla wrote:
sqlops result is a matrix. You can access row and column by index. Or you look for something else?
I look for something that's transaction-persistent so that I can iterate over it in failure routes, and as far as I know $dbr() is not transaction-persistent.
$dbr() is in private memory.
Typical situation is a list of gateways in descending order of priority is retrieved from a database along with various other attributes. The only way I know to deal with that is to buffer the results from $dbr() into an array of AVPs
xavp might be better structured for this case.
and then cycle through them using a global AVP as an array index.
Not sure I get it here. If you need only one global index, then you can use $shv() to store it. If you need it per transaction, then an normal avp should be used.
Cheers, Daniel
On 02/24/2010 11:31 AM, Daniel-Constantin Mierla wrote:
On 02/24/2010 05:21 PM, Alex Balashov wrote:
$dbr() is in private memory.
Yep, that's not going to work. I need a copy of a result set per transaction.
xavp might be better structured for this case.
My understanding is that xavp is in development and is not in 3.0.0, correct?
Not sure I get it here. If you need only one global index, then you can use $shv() to store it. If you need it per transaction, then an normal avp should be used.
I need it per transaction. Every transaction has a unique list of gateways that may be associated with it, not determinate. Very, very custom LCR.
On 02/24/2010 05:36 PM, Alex Balashov wrote:
On 02/24/2010 11:31 AM, Daniel-Constantin Mierla wrote:
On 02/24/2010 05:21 PM, Alex Balashov wrote:
$dbr() is in private memory.
Yep, that's not going to work. I need a copy of a result set per transaction.
xavp might be better structured for this case.
My understanding is that xavp is in development and is not in 3.0.0, correct?
The code is available but not enabled by default. You need to recompile with -DWITH_XAVP.
Not sure I get it here. If you need only one global index, then you can use $shv() to store it. If you need it per transaction, then an normal avp should be used.
I need it per transaction. Every transaction has a unique list of gateways that may be associated with it, not determinate. Very, very custom LCR.
You can delete avps as you use them, in case you don't need them in future steps, avoiding the need of index variable. Still, if the index is per transaction, then it has to be stored in an usual avp, not in a global avp.
Cheers, Daniel
Hello,
On 02/24/2010 02:01 PM, Henning Westerholt wrote:
On Wednesday 24 February 2010, Daniel-Constantin Mierla wrote:
Is there a better way to handle this now, perhaps via some features imported from SER? Script variables ($var(...)) do not support subscripts judging by the cookbook; do they?
no, they are single-value variables.
Are there other options I am unaware of?
There is no dedicated array type. In some cases you can use a hash table and simulate an array by key value:
$var(i) = 0; $sht(a=>[$var(i)]) = 1; $var(i) = 1; $sht(a=>[$var(i)]) = 2;
But it is only about how you define the keys, not a real array behind.
Hi Daniel, Hi Alex,
we've a simple and small module that implements a matrix like this:
+---+----+--------+ | A | B | result | +---+----+--------+ | 1 | 9 | 2 | | 2 | 69 | 1 | | 2 | 13 | 3 | +---+----+--------+
The matrix is read from a database and cached in memory, there is a FIFO command that can be used to reload it. There is a query command that uses a given A and B and stores the result in an AVP. If there is interest in this I could try to merge this into the repository.
can the matrix be loaded only from db? I guess data is in shared memory. Would be good to be able to set records from script as well.
Cheers, Daniel