<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    It looks like the parentheses don't match on line 5.<br>
    <br>
    John<br>
    <br>
    <div class="moz-cite-prefix">On 12/10/14 11:45, Bernhard Wendel
      wrote:<br>
    </div>
    <blockquote cite="mid:543A5BC6.1030006@sessionbird.com" type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=windows-1252">
      Hi,<br>
      <br>
      I'm using the following Lua-Script to check whether a conference
      exists and only let a caller join if so.<br>
      The script is called via the following dialplan <i>&lt;action
        application="lua" data="/path/to/script.lua $1" /&gt;</i><i> </i>,
      where $1 is the destination number.<br>
      <br>
      <br>
      <ol>
        <li>-- Connect to a database</li>
        <li>local dbh = freeswitch.Dbh("pgsql://hostaddr=127.0.0.1
          dbname=database user=username password='password'
          application_name='my-lua-script'")</li>
        <li>assert(dbh:connected());</li>
        <li>-- Execute SQL</li>
        <li>dbh:query(string.format("SELECT COUNT(*) as \"MyCount\" FROM
          \"MyTable\" WHERE ColA = '%s'", argv[1]), function(row)</li>
        <li>    --freeswitch.consoleLog("INFO", "Results: " ..
          row.MyCount)</li>
        <li>    </li>
        <li>    dbh:release()</li>
        <li>    </li>
        <li>    if (row.MyCount== '1') then</li>
        <li>        freeswitch.consoleLog("INFO", "User is joining
          conference at " .. argv[1])</li>
        <li>        </li>
        <li>        session:answer()</li>
        <li>        session:execute("conference", argv[1] ..
          "@wideband")</li>
        <li>    end</li>
        <li>    session:hangup()</li>
        <li>end)</li>
      </ol>
      <br>
      Line 8 instructs FS to return the postgres-Connection back to the
      pool - which is as expected. When a user now leaves the
      conference, FS throws this errors:<br>
      <br>
      2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:694
      CoreSession::hangup<br>
      2014-10-12 10:32:30.065924 [CRIT] switch_pgsql.c:368 An error
      occurred trying to consume input for query (200): connection
      pointer is NULL<br>
      2014-10-12 10:32:30.065924 [CRIT] switch_pgsql.c:122 No DB
      Connection<br>
      2014-10-12 10:32:30.065924 [ERR] switch_core_sqldb.c:1177 ERR:
      [SELECT COUNT(*) as "MyCount" FROM "MyTable" WHERE ColA =
      'conf-1234'][connection pointer is NULL]<br>
      2014-10-12 10:32:30.065924 [ERR] freeswitch_lua.cpp:446 DBH NOT
      Connected.<br>
      2014-10-12 10:32:30.065924 [DEBUG] switch_cpp.cpp:1075 <a
        moz-do-not-send="true" class="moz-txt-link-abbreviated"
        href="mailto:sofia/internal/Alice@my.pbx.com">sofia/internal/Alice@my.pbx.com</a>
      destroy/unlink session from object<br>
      <br>
      Now, I could live with that. BUT: The problem is, that sometimes,
      when a user leaves the conference, FS crashes.<br>
      I've narrowed down the main cause to the above lua script. If I
      comment line 8 out, FS stops crashing. This will also stop FS from
      reusing Database-Connections. <br>
      <br>
      Now my questions:<br>
      <ol>
        <li>I don't use `dbh` after line 8. So where does the error come
          from?</li>
        <li>How can I stop the error?</li>
        <li>How can I rewrite the lua script to have both a)
          non-crashing FS and b) reusing of connection?</li>
      </ol>
      <p><br>
        Regards,<br>
        Bernhard<br>
      </p>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_________________________________________________________________________
Professional FreeSWITCH Consulting Services: 
<a class="moz-txt-link-abbreviated" href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a>

Official FreeSWITCH Sites
<a class="moz-txt-link-freetext" href="http://www.freeswitch.org">http://www.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://confluence.freeswitch.org">http://confluence.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://www.cluecon.com">http://www.cluecon.com</a>

FreeSWITCH-powered IP PBX: The CudaTel Communication Server
<a class="moz-txt-link-freetext" href="http://www.cudatel.com">http://www.cudatel.com</a>

FreeSWITCH-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a class="moz-txt-link-freetext" href="http://www.freeswitch.org">http://www.freeswitch.org</a></pre>
    </blockquote>
    <br>
  </body>
</html>