[sqlite] INSERT OR UPDATE?

2011-07-02 Thread KeithB
Is there any way to perform the equivalent of an INSERT OR UPDATE statement? I have something like this: CREATE TABLE t1 (id INTEGER PRIMARY KEY, value INTEGER); CREATE TABLE t2 (parent INTEGER REFERENCES t1 ON DELETE CASCADE, child INTEGER REFERENCES t1); INSERT INTO t1 VALUES(1,100); INSERT INT

Re: [sqlite] INSERT OR UPDATE?

2011-07-01 Thread BareFeetWare
On 02/07/2011, at 4:54 AM, KeithB wrote: > Is there any way to perform the equivalent of an INSERT OR UPDATE statement? > > I have something like this: > > CREATE TABLE t1 (id INTEGER PRIMARY KEY, value INTEGER); > CREATE TABLE t2 (parent INTEGER REFERENCES t1 ON DELETE CASCADE, child > INTEGER

Re: [sqlite] INSERT OR UPDATE?

2011-07-01 Thread Jim Morris
Or do an update and if no records are modified then do an insert. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Re: [sqlite] INSERT OR UPDATE?

2011-07-01 Thread Simon Slavin
On 1 Jul 2011, at 7:54pm, KeithB wrote: > Is there any way to perform the equivalent of an INSERT OR UPDATE statement? > > I have something like this: > > CREATE TABLE t1 (id INTEGER PRIMARY KEY, value INTEGER); > CREATE TABLE t2 (parent INTEGER REFERENCES t1 ON DELETE CASCADE, child > INTEGER

[sqlite] INSERT OR UPDATE?

2011-07-01 Thread KeithB
Is there any way to perform the equivalent of an INSERT OR UPDATE statement? I have something like this: CREATE TABLE t1 (id INTEGER PRIMARY KEY, value INTEGER); CREATE TABLE t2 (parent INTEGER REFERENCES t1 ON DELETE CASCADE, child INTEGER REFERENCES t1); INSERT INTO t1 VALUES(1,100); INSERT INT

Re: [sqlite] INSERT OR UPDATE

2010-11-12 Thread BareFeetWare
On 10/11/2010, at 7:19 PM, Michele Pradella wrote: > In-Reply-To: <4cda28ea.5030...@gmail.com> Firstly, please start a post to this mail list as a new message, not a reply to a previous unrelated message. That's known as "thread hijacking" and confuses discussions. > Hi all, I have to INSERT

Re: [sqlite] INSERT OR UPDATE

2010-11-10 Thread Simon Slavin
On 10 Nov 2010, at 8:19am, Michele Pradella wrote: > Hi all, I have to INSERT a row in a DB but I have first to check if the > Key I'm inserting already exist. > Now I'm doing a "SELECT count..." first to check if the key exist and > then INSERT or UPDATE records. > Do you know if there's a be

Re: [sqlite] INSERT OR UPDATE

2010-11-10 Thread Igor Tandetnik
Michele Pradella wrote: > Hi all, I have to INSERT a row in a DB but I have first to check if the > Key I'm inserting already exist. > Now I'm doing a "SELECT count..." first to check if the key exist and > then INSERT or UPDATE records. > Do you know if there's a better or faster way to do that?

[sqlite] INSERT OR UPDATE

2010-11-10 Thread Michele Pradella
Hi all, I have to INSERT a row in a DB but I have first to check if the Key I'm inserting already exist. Now I'm doing a "SELECT count..." first to check if the key exist and then INSERT or UPDATE records. Do you know if there's a better or faster way to do that? Perhaps with an ON CONFLICT

Re: [sqlite] Insert or Update (was: ON DELETE CASCADE along with ON CONFLICT REPLACE)

2010-10-19 Thread Pavel Ivanov
> 2. I suggest that you're better off doing the logic entirely in SQL, rather > than application code, for the sake of portability, data integrity and speed. I'd say this is a very bad advice for the developer using SQLite. First of all "insert or ignore" and "insert or replace" are not portable

Re: [sqlite] Insert or Update (was: ON DELETE CASCADE along with ON CONFLICT REPLACE)

2010-10-18 Thread Mihai Militaru
On Tue, 19 Oct 2010 10:54:13 +1100 BareFeetWare 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")

[sqlite] Insert or Update (was: ON DELETE CASCADE along with ON CONFLICT REPLACE)

2010-10-18 Thread BareFeetWare
On 19/10/2010, at 8:10 AM, NSRT Mail account. wrote: > I would use the update if I knew the entry already existed. In my application > however, it doesn't know if the entry already exists. I was looking for > something to replace MySQL's ON DUPLICATE KEY UPDATE. > > I modified my application to