Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Nico Williams
On Mon, Apr 4, 2011 at 12:26 PM, Simon Slavin wrote: > But he's combining two INSERTs into one.  What I think he needs is first an > INSERT OR FAIL to possibly add a new person, and then an INSERT ... SELECT > which looks up that person's ID. I didn't see that in the

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Simon Slavin
On 4 Apr 2011, at 6:01pm, Nico Williams wrote: > On Mon, Apr 4, 2011 at 11:25 AM, Simon Slavin wrote: >> Probably not. Don't try to turn SQL into a procedural language. Do the >> SELECT that tells you whether the record exists and gives you the >> information you need

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Nico Williams
On Mon, Apr 4, 2011 at 11:25 AM, Simon Slavin wrote: > Probably not.  Don't try to turn SQL into a procedural language.  Do the > SELECT that tells you whether the record exists and gives you the information > you need if it does, then do whatever INSERTs you need to do.

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Simon Slavin
On 4 Apr 2011, at 4:26pm, Marcelo Serrano Zanetti wrote: > About the "new" item, yes I do compare some specific fields and not the > primary key. For example name and surname of a person ... I look in the > database for such a person ... if yes I return her id ... if not I > include her and

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Marcelo Serrano Zanetti
On 04/04/2011 05:16 PM, Robert Poor wrote: > @Marcelo: > > Going back to your original question: do you really only want to > insert one item at a time? If so, I think your question has been > answered reasonably well. > > BUT: if you have a large number of items, and you want to insert items >

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Robert Poor
@Marcelo: Going back to your original question: do you really only want to insert one item at a time? If so, I think your question has been answered reasonably well. BUT: if you have a large number of items, and you want to insert items that aren't yet in the table, then you can do it

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-04 Thread Marcelo Serrano Zanetti
On 04/03/2011 09:05 PM, Petite Abeille wrote: > On Apr 3, 2011, at 3:18 PM, Marcelo Serrano Zanetti wrote: > >> It does not work in this way ... could somebody tell me please what is >> the correct sintax or whether this is possible at all. > As mentioned, SQL is not a procedural language, so, no.

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Petite Abeille
On Apr 3, 2011, at 3:18 PM, Marcelo Serrano Zanetti wrote: > It does not work in this way ... could somebody tell me please what is > the correct sintax or whether this is possible at all. As mentioned, SQL is not a procedural language, so, no. That said, you can achieve the same effect with

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Nico Williams
On Sun, Apr 3, 2011 at 3:49 AM, Marcelo S Zanetti wrote: > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT itemID from tabel WHERE item==new ELSE > INSERT INTO table (item) VALUES (new) INSERT INTO t (item) SELECT :new WHERE NOT EXISTS (SELECT item FROM t

[sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo Serrano Zanetti
Hi I would like to do the following I have an item to insert in the table which will be inserted only if this item is not yet in that table otherwise I would like to return the item's key. like that IF 1==SELECT COUNT(*) from table WHERE item==new THEN SELECT itemID from tabel WHERE

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread BareFeetWare
On 03/04/2011, at 6:49 PM, Marcelo S Zanetti wrote: > I have an item to insert in the table which will be inserted only if this > item is not yet in that table otherwise I would like to return the item's key. > > like that > > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo Serrano Zanetti
On 04/03/2011 03:12 PM, Igor Tandetnik wrote: > Marcelo S Zanetti wrote: >> I >> have an item to insert in the table which will be inserted only if this >> item is not yet in that table otherwise I would like to return the >> item's key. >> >> like that >> >> IF 1==SELECT

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Igor Tandetnik
Marcelo S Zanetti wrote: > I > have an item to insert in the table which will be inserted only if this > item is not yet in that table otherwise I would like to return the > item's key. > > like that > > IF 1==SELECT COUNT(*) from table > WHERE item==new THEN SELECT itemID

Re: [sqlite] IF-THEN-ELSE sqlite

2011-04-03 Thread Marcelo S Zanetti
Hi I would like to do the following I have an item to insert in the table which will be inserted only if this item is not yet in that table otherwise I would like to return the item's key. like that IF 1==SELECT COUNT(*) from table WHERE item==new THEN SELECT itemID from tabel WHERE