<div class="gmail_quote">On 18 November 2012 15:04, Yiftach Golan <span dir="ltr">&lt;<a href="mailto:yiftah@choochee.com" target="_blank">yiftah@choochee.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We have the exact same problem and we solve it pretty nicely but due to the policy &quot;do not say anything that is different than what we did&quot; I will not put it in public if you want Scott we can continue with you and Ken in private <br>

</blockquote><div><br>Cool and kind of you.  Thanks, Yiftach.<br><br>Right now, on our easy stuff, we&#39;re ok with our work-around.  We just delete THEN insert.  But we have more coming up and we enjoy seeing others&#39; cleverness-es!<br>
<br><span style="background-color:rgb(192,192,192)"><span style="font-family:courier new,monospace">    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;0&quot; param=&quot;db delete/ss_fmfm/${caller_id_number}&quot;/&gt;<br>
    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;0&quot; param=&quot;db insert/ss_fmfm/${caller_id_number}/off&quot;/&gt;<br>    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;0&quot; param=&quot;playback shout://<a href="http://translate.google.com/translate_tts?tl=en&amp;q=Option:+now+$db(select/..">translate.google.com/translate_tts?tl=en&amp;q=Option:+now+$db(select/..</a>.&quot;/&gt;<br>
    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;1&quot; param=&quot;db delete/ss_fmfm/${caller_id_number}&quot;/&gt;<br>    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;1&quot; param=&quot;db insert/ss_fmfm/${caller_id_number}/on&quot;/&gt;<br>
    &lt;entry action=&quot;menu-exec-app&quot; digits=&quot;1&quot; param=&quot;playback shout://<a href="http://translate.google.com/translate_tts?tl=en&amp;q=Option:+now+${db(select/.">translate.google.com/translate_tts?tl=en&amp;q=Option:+now+${db(select/.</a>.&quot;/&gt;<br>
   <br></span></span><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also I would please like to ask you not to use inappropriate words like &quot;MySQL&quot; in this forum as it may cause people to feel uncomfortable </blockquote>
<div><br>Hmm?  I had no idea -- and how could one.  In my defense, I didn&#39;t assert &quot;its&quot; use.  I just showed (intended) its comparative syntax and the rest was English just being funny-that-way about nouns.  ;-)<br>
Not-so-understood, but nevertheless acknowledged and guided accordingly.<br><br>(I&#39;m actually a postgreSQL and huge DB2 EXPRESS-C fan!)<br><br>Again, thank you, on both counts.<br>/Scott<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  <br><div class="HOEnZb"><div class="h5"><div class="gmail_quote">On Sun, Nov 18, 2012 at 7:41 AM, Ken Rice <span dir="ltr">&lt;<a href="mailto:krice@freeswitch.org" target="_blank">krice@freeswitch.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>
<font face="Monaco, Courier New"><span style="font-size:11pt">You have to keep in mind that we have to support more then just mysql or sqlite with the the db interface... This means using SQL that’s common to ALL platforms include MSSQL, PostgreSQL, Oracle and any other database someone might want to use via ODBC... <br>


<br>
So to do this completely would require modification to the code on insert to first check if the row exists for the key, then deleting it, then inserting the new row...  This is going to be the most generic supportable method to make them work consistently across the board... <br>


<br>
However, Keep in mind that what you are calling a bug, could be treated by many people as a feature... Don’t allow me to create/replace and already existing key...<br>
<br>
<br>
<br>
<br>
On 11/18/12 7:26 AM, &quot;Scott&quot; &lt;<a href="http://8f27e956@gmail.com" target="_blank">8f27e956@gmail.com</a>&gt; wrote:<br>
<br>
</span></font><blockquote><font face="Monaco, Courier New"><span style="font-size:11pt">OK, with the one-time </span></font><span style="font-size:11pt"><font face="Courier New">CREATE UNIQUE INDEX on &#39;table&#39; (hostname,realm,data_key); </font><font face="Monaco, Courier New">stmt in place at the schema-level, a portable work-a-like of INSERT OR REPLACE stmt is the UPDATE-INSERT (i.e. &quot;UPSERT&quot; lol) stmt pair that follows,<br>


<br>
</font><font face="Courier New">BEGIN TRANSACTION;                                                                                                                 <br>
UPDATE &#39;table&#39; SET data_value=&#39;value_data&#39; WHERE hostname=&#39;value_hostname&#39; AND realm=&#39;value_realm&#39; AND data_key=&#39;value_data_key&#39; ;<br>
INSERT INTO &#39;table&#39; (hostname,realm,data_key,data_value) SELECT &#39;value_hostname&#39;, &#39;value_realm&#39;, &#39;value_data_key&#39;, &#39;value_data_value&#39;<br>
   WHERE NOT EXISTS (SELECT 1 FROM &#39;table&#39; WHERE hostname=&#39;value_hostname&#39; AND realm=&#39;value_realm&#39; AND data_key=&#39;value_data_key&#39; );<br>
COMMIT;                                                                                                                             <br>
</font><font face="Monaco, Courier New"><br>
The two WHERE clauses must be identical and the variables should be in the same order as the unique compound index is ordered.<br>
The UPDATE fails quietly and benignly if the record does NOT already exist and succeeds if it does.<br>
The INSERT ... WHERE NOT EXISTS stmt succeeds if the record does NOT already exist fails quietly and benignly if it does. <br>
The BEGIN and COMMIT aren&#39;t typically necessary but they&#39;re over-safe just in case the same record is attempted by another thread.<br>
<br>
I think this get&#39;s it done.<br>
<br>
:-)<br>
<br>
<br>
On 18 November 2012 06:25, S. Scott &lt;<a href="http://8f27e956@gmail.com" target="_blank">8f27e956@gmail.com</a>&gt; wrote:<br>
</font></span><blockquote><span style="font-size:11pt"><font face="Monaco, Courier New">The IF NOT EXITS term is easily omitted.  It&#39;s a helper term for batch scripted SQL to prevent an error being thrown in the case of the index already exists as in the case where the make schema script is run more than once.  Easily omitted and, perhaps more properly, replaced with a DROP INDEX stmt and CREATE UNIQUE INDEX stmt pair.<br>


<br>
Yeah, i checked further, the OR REPLACE modifier is a little more Hit/miss.  The capability is there typically present, but the syntax varies -- e.g sqlite3 ON REPLACE is mySQL&#39;s ON DUPLICATE KEY UPDATE.<br>
<br>
Darn shame sqlite3 doesn&#39;t support stored procedures &#39;cause then it&#39;s more easily abstracted for portability up the SQL server engine curve.<br>
<br>
On 2012-11-18, at 3:53, Gerald Weber &lt;<a href="http://gerald.weber@besharp.at" target="_blank">gerald.weber@besharp.at</a>&gt; wrote:<br>
<br>
</font></span><blockquote><span style="font-size:11pt"><font face="Monaco, Courier New">AFAIK, „if not exists“ and „or replace“ is not ansi sql  syntax, so you will get in trouble if <br>
someone uses odbc to a db that doesn’t support non standard syntax.<br>
 <br>
The insert or replace could be replaced with the merge statement.<br>
 <br>
</font></span><font face="Monaco, Courier New"><font><span style="font-size:10pt"><b>Von:</b> <a href="http://freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">mailto:freeswitch-users-bounces@lists.freeswitch.org</a>] <b>Im Auftrag von </b>Scott<br>


<b>Gesendet:</b> Sonntag, 18. November 2012 02:42<br>
<b>An:</b> FreeSWITCH Users Help<br>
<b>Betreff:</b> [Freeswitch-users] Suggestion to harmonize &#39;hash&#39; &amp; &#39;db&#39; insert method<br>
</span></font><span style="font-size:11pt"> <br>
Are there reasons why the function &#39;hash&#39; (non-persistent storage) and function &#39;db&#39; (persistent storage) share a look-a-like user interface (e.g. select/insert/delete) but do not work-a-like.  In particular, in &#39;hash&#39;, insert overwrites an identical realm/data_key pair whereas &#39;db&#39; , in so far as I can tell, just blindly adds, and adds, adds, the insert(s).  However, the &#39;db&#39; select method returns one record only even if the db has accumulated many realm/data_key records, including data_value duplicates.  <br>


<br>
NOTWITHSTANDING reasons-unknow-to-me, a remedy to harmonize the non-persistent &#39;hash&#39; with the persistent &#39;db&#39;  I *think* is straight forward ...<br>
<br>
(1) At the call_limit.db schema-level, a one-time create UNIQUE COMPOUND index, as follows,<br>
<br>
CREATE UNIQUE INDEX IF NOT EXISTS &#39;idx_db_data_HostRealmDK&#39; ON &#39;db_data&#39; (&#39;hostname&#39;,&#39;realm&#39;,&#39;data_key&#39;);<br>
<br>
(1) At the c-language embedded SQL string-level,<br>
<br>
change the existing INSERT to be the following,<br>
<br>
INSERT OR REPLACE INTO db_data (hostname,realm,data_key,data) VALUES (%s,%s,%s,%s);<br>
<br>
The index will help speed UP the reads.  Neither change is &quot;exotic&quot; and should be portable across standard sql implementations.<br>
<br>
;-) ... thoughts ?<br>
<br>
Thanks,<br>
<br>
<br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="http://consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="http://FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</span></font></blockquote></blockquote><font face="Monaco, Courier New"><span style="font-size:11pt"><br>
<br>
<hr align="CENTER" size="3" width="95%"></span></font><font><font face="Consolas, Courier New, Courier"><span style="font-size:10pt">_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="http://consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="http://FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><span><font color="#888888"><br>
</font></span></span></font></font></blockquote><span><font color="#888888"><font><font face="Consolas, Courier New, Courier"><span style="font-size:10pt"><br>
</span></font></font><font face="Monaco, Courier New"><span style="font-size:11pt">-- <br>
Ken<br>
<font color="#0000FF"><u><a href="http://www.FreeSWITCH.org" target="_blank">http://www.FreeSWITCH.org</a><br>
<a href="http://www.ClueCon.com" target="_blank">http://www.ClueCon.com</a><br>
<a href="http://www.OSTAG.org" target="_blank">http://www.OSTAG.org</a><br>
</u></font><a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
</span></font>
</font></span></div>


<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org" target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>
</div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br>