<div class="gmail_quote">On 18 November 2012 15:04, Yiftach Golan <span dir="ltr"><<a href="mailto:yiftah@choochee.com" target="_blank">yiftah@choochee.com</a>></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 "do not say anything that is different than what we did" 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're ok with our work-around. We just delete THEN insert. But we have more coming up and we enjoy seeing others' cleverness-es!<br>
<br><span style="background-color:rgb(192,192,192)"><span style="font-family:courier new,monospace"> <entry action="menu-exec-app" digits="0" param="db delete/ss_fmfm/${caller_id_number}"/><br>
<entry action="menu-exec-app" digits="0" param="db insert/ss_fmfm/${caller_id_number}/off"/><br> <entry action="menu-exec-app" digits="0" param="playback shout://<a href="http://translate.google.com/translate_tts?tl=en&q=Option:+now+$db(select/..">translate.google.com/translate_tts?tl=en&q=Option:+now+$db(select/..</a>."/><br>
<entry action="menu-exec-app" digits="1" param="db delete/ss_fmfm/${caller_id_number}"/><br> <entry action="menu-exec-app" digits="1" param="db insert/ss_fmfm/${caller_id_number}/on"/><br>
<entry action="menu-exec-app" digits="1" param="playback shout://<a href="http://translate.google.com/translate_tts?tl=en&q=Option:+now+${db(select/.">translate.google.com/translate_tts?tl=en&q=Option:+now+${db(select/.</a>."/><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 "MySQL" 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't assert "its" 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'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"><<a href="mailto:krice@freeswitch.org" target="_blank">krice@freeswitch.org</a>></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, "Scott" <<a href="http://8f27e956@gmail.com" target="_blank">8f27e956@gmail.com</a>> 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 'table' (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. "UPSERT" lol) stmt pair that follows,<br>
<br>
</font><font face="Courier New">BEGIN TRANSACTION; <br>
UPDATE 'table' SET data_value='value_data' WHERE hostname='value_hostname' AND realm='value_realm' AND data_key='value_data_key' ;<br>
INSERT INTO 'table' (hostname,realm,data_key,data_value) SELECT 'value_hostname', 'value_realm', 'value_data_key', 'value_data_value'<br>
WHERE NOT EXISTS (SELECT 1 FROM 'table' WHERE hostname='value_hostname' AND realm='value_realm' AND data_key='value_data_key' );<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't typically necessary but they're over-safe just in case the same record is attempted by another thread.<br>
<br>
I think this get's it done.<br>
<br>
:-)<br>
<br>
<br>
On 18 November 2012 06:25, S. Scott <<a href="http://8f27e956@gmail.com" target="_blank">8f27e956@gmail.com</a>> wrote:<br>
</font></span><blockquote><span style="font-size:11pt"><font face="Monaco, Courier New">The IF NOT EXITS term is easily omitted. It'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's ON DUPLICATE KEY UPDATE.<br>
<br>
Darn shame sqlite3 doesn't support stored procedures 'cause then it's more easily abstracted for portability up the SQL server engine curve.<br>
<br>
On 2012-11-18, at 3:53, Gerald Weber <<a href="http://gerald.weber@besharp.at" target="_blank">gerald.weber@besharp.at</a>> 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 'hash' & 'db' insert method<br>
</span></font><span style="font-size:11pt"> <br>
Are there reasons why the function 'hash' (non-persistent storage) and function 'db' (persistent storage) share a look-a-like user interface (e.g. select/insert/delete) but do not work-a-like. In particular, in 'hash', insert overwrites an identical realm/data_key pair whereas 'db' , in so far as I can tell, just blindly adds, and adds, adds, the insert(s). However, the 'db' 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 'hash' with the persistent 'db' 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 'idx_db_data_HostRealmDK' ON 'db_data' ('hostname','realm','data_key');<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 "exotic" 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>