ejabberd - Comments for "Mod_muc - mnesia:dirty_select need help" https://www.ejabberd.im/node/4986 en And the revised https://www.ejabberd.im/node/4986#comment-57882 <p>And the revised version</p> <p>make_results({selected, ["name"], Items}) -&gt;<br /> [make_result(Item) || Item &lt;- Items] .</p> <p>make_result({Name}) -&gt;<br /> [{#muc_online_room{name_host = '$1', _ = '_'},<br /> [{'==', {element, 1, '$1'}, Name }],<br /> ['$_']}].</p> <p>Results = ejabberd_odbc:sql_query("suse1.local", ["SELECT name FROM location"]),<br /> ListOfRooms = make_results(Results),<br /> Pattern = lists:merge(ListOfRooms),<br /> mnesia:dirty_select(muc_online_room,Pattern).</p> Thu, 29 Sep 2011 15:44:00 +0000 scothost comment 57882 at https://www.ejabberd.im Hi Thanks for the reply I https://www.ejabberd.im/node/4986#comment-57881 <p>Hi</p> <p>Thanks for the reply</p> <p>I figured it out. The problem was generating the list in the first place. I ended up with the code below that "appears" to work</p> <p> make_results({selected, ["name"], Items}) -&gt;<br /> [make_result(Item) || Item &lt;- Items] .</p> <p> %% Execute the ODBC query and parse the result set<br /> Results = ejabberd_odbc:sql_query("suse1.local", ["SELECT name FROM loc"]),<br /> ListOfRooms = make_results(Results),</p> <p> RoomString1 = [],</p> <p> ListOfPatterns = lists:map(fun(X) -&gt;<br /> RoomString2 = [{#muc_online_room{name_host = '$1', _ = '_'},<br /> [{'==', {element, 1, '$1'}, X }],<br /> ['$_']}],<br /> string:concat(RoomString1,RoomString2)<br /> end, ListOfRooms),<br /> Pattern = lists:merge(ListOfPatterns),</p> <p> mnesia:dirty_select(muc_online_room,Pattern).</p> Thu, 29 Sep 2011 15:30:21 +0000 scothost comment 57881 at https://www.ejabberd.im You can specify a list of https://www.ejabberd.im/node/4986#comment-57880 <p>You can specify a list of matches in your match spec to be passed to <code>mnesia:dirty_select</code>:</p> <div class="codeblock"><code>[{#muc_online_room{name_host = &#039;$1&#039;, _ = &#039;_&#039;}, [{&#039;==&#039;, {element, 1, &#039;$1&#039;}, Room}], [&#039;$_&#039;]} || {Room} &lt;- Rooms]</code></div> <p>where <code>Rooms</code> is a list of rooms returned by your ODBC query. It is effectively the same as something like:</p> <div class="codeblock"><code>mnesia:dirty_select(muc_online_room,<br />&nbsp; [{#muc_online_room{name_host = &#039;$1&#039;, _ = &#039;_&#039;}, [{&#039;==&#039;, {element, 1, &#039;$1&#039;}, &quot;world&quot;}], [&#039;$_&#039;]},<br />&nbsp;&nbsp; {#muc_online_room{name_host = &#039;$1&#039;, _ = &#039;_&#039;}, [{&#039;==&#039;, {element, 1, &#039;$1&#039;}, &quot;world1&quot;}], [&#039;$_&#039;]},<br />&nbsp;&nbsp; {#muc_online_room{name_host = &#039;$1&#039;, _ = &#039;_&#039;}, [{&#039;==&#039;, {element, 1, &#039;$1&#039;}, &quot;test1&quot;}], [&#039;$_&#039;]}]).</code></div> <p>I can't vouch for the performance of a very long list of matches though, so test it with a long list.</p> Thu, 29 Sep 2011 13:11:38 +0000 skarab comment 57880 at https://www.ejabberd.im