<div dir="ltr"><div>Hello,</div><div><br></div><div>Works like a charm!</div><div>Thank you Daniel.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 7 Aug 2020 at 13:30, Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Hello,</p>
    <p>use:</p>
    <p>modparam("htable", "htable",
"isp=>size=8;dbtable=isp;cols=ispname,ispip,ispuser,ipsprefix,ispprefix")<br>
    </p>
    <p>then you have the $sht(ispname) with value corresponding to
      "ispip,ispuser,ipsprefix,ispprefix" and then you can use
      {s.select,,0} to get ispname value, then {s.select,,1} to get
      ispip value, etc...</p>
    <p>An alternative would be to keep only two columns in database, one
      (the key) with ispname and the second (the value) all fields
      serialized in a json document and you use jansson to parse them in
      config.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div>On 07.08.20 13:06, Ilie Soltanici
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>Hello,</div>
        <div><br>
        </div>
        <div>What will be the best way to save ISP Information in
          Kamailio memory?</div>
        <div><br>
        </div>
        <div>I have the following information for each ISP into the DB:</div>
        <div><br>
        </div>
        <div><b>ISP Name |  ISP IP  | ISP Username | ISP Password | ISP
            Prefix</b></div>
        <div>ISP1          |  1.1.1.1 | user                  |
          pass                 | 1234<b><br>
          </b></div>
        <div><br>
        </div>
        <div>This info it's not changed/updated too often, so I want to
          avoid querying the DB on every call and get this info directly
          from the memory.</div>
        <div><br>
        </div>
        <div>I was thinking to use htable for that, so I created a
          htable as an array for that and loaded all the information
          there manually, something like that:</div>
        <div><br>
        </div>
        <div><b>kamcmd htable.sets isp ISP1[address] 1.1.1.1</b></div>
        <div><b>
            kamcmd htable.sets isp ISP1[username] user</b></div>
        <div><b>
            kamcmd htable.sets isp ISP1[password] pass</b></div>
        <div><b>
            kamcmd htable.sets isp ISP1[prefix] 1234 <br>
          </b></div>
        <div><b><br>
          </b></div>
        <div><b>$sht(
            isp =>
            ISP1[address]) == "1.1.1.1"</b></div>
        <div><b>
            $sht(
            isp =>
            ISP1[username]) == "user" <br>
          </b></div>
        <div><b>
            $sht(
            isp =>
            ISP1[password]) == "pass" <br>
          </b></div>
        <div><b>
            $sht(
            isp =>
            ISP1[prefix]) == "1234"
          </b>
        </div>
        <div><br>
        </div>
        <div>So far so good, I'm able to get this information from the
          htable and use it whenever I need it.</div>
        <div>Now, the problem comes when I want to load all this
          information automatically from the DB. How can I setup htable
          module to get the array key (address, username...) from the
          database automatically on server restart, and append this
          array_key to the column value?</div>
        <div><br>
        </div>
        <div>I've tried this way: <br>
        </div>
        <div>
          <div style="color:rgb(171,178,191);background-color:rgb(40,44,52);font-family:"Fira Code",Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(198,120,221)">modparam</span><span style="color:rgb(171,178,191)">(</span><span style="color:rgb(152,195,121)">"htable"</span><span style="color:rgb(171,178,191)">, </span><span style="color:rgb(152,195,121)">"htable"</span><span style="color:rgb(171,178,191)">, </span><span style="color:rgb(152,195,121)">"isp=>size=8;dbtable=isp;cols='trunk_name[address],trunk_address'"</span><span style="color:rgb(171,178,191)">)</span></div></div>
        </div>
        <div><br>
        </div>
        <div>But it's not working unfortunately, getting back this
          error: You have an error in your SQL syntax; check the manual
          that corresponds to your MariaDB server version for the right
          syntax to use near '[address]'</div>
        <div><br>
        </div>
        <div>If I'm setting this way:<br>
        </div>
        <div>
          <div style="color:rgb(171,178,191);background-color:rgb(40,44,52);font-family:"Fira Code",Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(198,120,221)">modparam</span><span style="color:rgb(171,178,191)">(</span><span style="color:rgb(152,195,121)">"htable"</span><span style="color:rgb(171,178,191)">, </span><span style="color:rgb(152,195,121)">"htable"</span><span style="color:rgb(171,178,191)">, </span><span style="color:rgb(152,195,121)">"isp=>size=8;dbtable=isp;cols='trunk_name,trunk_address'"</span><span style="color:rgb(171,178,191)">)</span></div></div>
        </div>
        <div><br>
        </div>
        <div>and setting trunk_name value to: ISP1[address], then it's
          working fine, but in this case I will have to create by one
          column for each array key, which may be confusing and it's a
          lot of unnecessarily information into the DB.</div>
        <div>Is it possible to do that, or better to trigger a script on
          each restart which will load this information from the DB into
          htable?</div>
        <div>Thanks<br>
        </div>
        <div><br>
        </div>
        <div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
Kamailio (SER) - Users Mailing List
<a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Funding: <a href="https://www.paypal.me/dcmierla" target="_blank">https://www.paypal.me/dcmierla</a></pre>
  </div>

</blockquote></div>