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.

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.

Darn shame sqlite3 doesn't support stored procedures 'cause then it's more easily abstracted for portability up the SQL server engine curve.

On 2012-11-18, at 3:53, Gerald Weber <gerald.weber@besharp.at> wrote:

AFAIK, „if not exists“ and „or replace“ is not ansi sql  syntax, so you will get in trouble if

someone uses odbc to a db that doesn’t support non standard syntax.

 

The insert or replace could be replaced with the merge statement.

 

Von: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] Im Auftrag von Scott
Gesendet: Sonntag, 18. November 2012 02:42
An: FreeSWITCH Users Help
Betreff: [Freeswitch-users] Suggestion to harmonize 'hash' & 'db' insert method

 

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. 

NOTWITHSTANDING reasons-unknow-to-me, a remedy to harmonize the non-persistent 'hash' with the persistent 'db'  I *think* is straight forward ...

(1) At the call_limit.db schema-level, a one-time create UNIQUE COMPOUND index, as follows,

CREATE UNIQUE INDEX IF NOT EXISTS 'idx_db_data_HostRealmDK' ON 'db_data' ('hostname','realm','data_key');

(1) At the c-language embedded SQL string-level,

change the existing INSERT to be the following,

INSERT OR REPLACE INTO db_data (hostname,realm,data_key,data) VALUES (%s,%s,%s,%s);

The index will help speed UP the reads.  Neither change is "exotic" and should be portable across standard sql implementations.

;-) ... thoughts ?

Thanks,


_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org
http://www.freeswitchsolutions.com

FreeSWITCH-powered IP PBX: The CudaTel Communication Server
http://www.cudatel.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://wiki.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org