[SR-Users] Loading keys with key_type="1" from database for htable - Module params help needed
damm at sipgate.de
Thu Aug 31 08:29:46 CEST 2017
adding to that, working with arrays in Kamailio is not really simple.
If in your database you have the following values:
key1 => value1
key1 => value2
key1 => value3
and have set those rows with an array type, the htable will look like
this after startup:
$sht(htableName=>key1) == "value1"
$sht(htableName=>key1) == "value2"
$sht(htableName=>key1) == "value3"
$sht(htableName=>key1::size) == 3
Now you can use the size helper variable and iterate over those array
entries. So far so good. The bad comes when manipulating those
entries. Suppose you want to delete value2 from your htable. After you
did that, the key1 entry will just be missing, you'll have a hole
in your numbering, and the size counter will still be at three. And if
you then want to add another entry to the htable, you will have to
find out the next free key number (3) yourself, and you will have to
incement the size helper variable manually.
And to make it worse, when writing back the htable on shutdown, those
array type rows in database will end up as regular entries having
key1 etc as key. The size helper row will be written into database,
So my recommendation would be to use the array stuff only on readonly
htables, but never on htables you manipulate inside Kamailio. There's
just too much that you have to think about.
On Wed, Aug 30, 2017 at 9:04 PM, Daniel-Constantin Mierla
<miconda at gmail.com> wrote:
> can you try with a single value column?
> The array type is something that was supposed to help keeping keys simpler
> in database, but the key is concatenated with the index, is not really an
> On 30.08.17 20:06, George Diamantopoulos wrote:
> Hello all, I'm becoming a regular here now, aren't I?
> So I have this table in mysql:
> | key_name | key_type | value1 | value2 | value3 |
> | key1 | 1 | valueA | valueF | valueK |
> | key1 | 1 | valueB | valueG | valueL |
> | key1 | 1 | valueC | valueH | valueM |
> | key2 | 1 | valueD | valueI | valueN |
> | key2 | 1 | valueE | valueJ | valueO |
> I was hoping I could have all this information available in an sht, where
> for example:
> $sht(a=>$key1), $sht(a=>$key1), etc
> would return:
> "valueA,valueF,valueK", "valueB,valueG,valueL" etc
> but I can't figure out how to setup htable to import this data on restart. I
> have tried various combinations of module parameters such as:
> modparam("htable", "htable",
> I'm either getting errors, or dumping htable will only show one of the value
> sets (key_type is not set to array).
> Does anyone have a working config to share? Thanks!
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> Daniel-Constantin Mierla
> www.twitter.com/miconda -- www.linkedin.com/in/miconda
> Kamailio Advanced Training - www.asipto.com
> Kamailio World Conference - www.kamailioworld.com
More information about the sr-users