On Tue, 19 Oct 2010 10:54:13 +1100
BareFeetWare <list....@tandb.com.au> wrote:

> -- alternatively you could do this, which will update the existing
> row, if exists, or insert a new one if it doesn't:
> 
> update users set "name" = 'Joe C', "type" = 4, where "id" = 1;
> insert or ignore into users ("id", "type", "name") values (1, 4, 'Joe
> C');

What about using a trigger which automatically updates right before the
insertion? I'm using this trigger:

CREATE TRIGGER users_update_existing
        BEFORE INSERT
        ON users
BEGIN
        UPDATE users
                SET type=NEW.type, id=NEW.id
                WHERE name=NEW.name;
END

...then in my code I use only:

INSERT OR IGNORE
        INTO users(name,type,id)
        VALUES(?,?,?);

It works very well so far, I'm just curious if you can forsee any
drawback in this approach.

-- 
Mihai Militaru <mihai.milit...@gmx.com>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to