On 16 Mar 2018, at 10:24am, Robert M. Münch <robert.mue...@saphirion.com> wrote:

> for every column I don’t want to change I need to add a sub-select statement. 
> If I need to build this statement dynamically, IMO it would be better to 
> handle this code directly in code:
> 
> if(record-exists?){
>       UPDATE …
> } else {
>       INSERT …
> }

You can use INSERT OR IGNORE for this.  First, do an INSERT OR IGNORE command 
which will add a dummy entry, with the right key, if one doesn't already exist. 
 Then use an UPDATE command to update the row which now definitely exists.  If 
you wrap the two commands in a transaction then even if you get power-failure 
or crash, you will never get a dummy row with no data in the database:

    BEGIN
        INSERT OR IGNORE <get the key values correct here>
        UPDATE <set the data values here>
    COMMIT

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to