Re: [sqlite] Re: INSERT OR REPLACE without new rowid

2007-05-08 Thread Cesar Rodas

On 24/04/07, Igor Tandetnik <[EMAIL PROTECTED]> wrote:


Trey Mack <[EMAIL PROTECTED]>
wrote:
> I'd like to perform an update to a row if it exists (uniquely
> identified by 3 text columns), otherwise insert a new row with the
> right data. INSERT OR REPLACE looks good, but it generates a new
> primary key each time
> there is a conflict. If the row exists, I need to keep the original
> primary key
> (rowid).
>
> Any way to do this short of SELECT.. if (exists) UPDATE else INSERT ?


You can do

UPDATE ... WHERE keyfield='xxx';

then use sqlite3_changes to see whether any update has in fact taken
place, and run INSERT if not.

Igor Tandetnik



-
To unsubscribe, send email to [EMAIL PROTECTED]

-

This is a good solution!


Thanks for your idea man! ;)


--
Cesar Rodas
http://www.cesarodas.com/
Mobile Phone: 595 961 974165
Phone: 595 21 645590
[EMAIL PROTECTED]
[EMAIL PROTECTED]


[sqlite] Re: INSERT OR REPLACE without new rowid

2007-04-24 Thread Igor Tandetnik

Trey Mack <[EMAIL PROTECTED]>
wrote:

I'd like to perform an update to a row if it exists (uniquely
identified by 3 text columns), otherwise insert a new row with the
right data. INSERT OR REPLACE looks good, but it generates a new 
primary key each time
there is a conflict. If the row exists, I need to keep the original 
primary key

(rowid).

Any way to do this short of SELECT.. if (exists) UPDATE else INSERT ?



You can do

UPDATE ... WHERE keyfield='xxx';

then use sqlite3_changes to see whether any update has in fact taken 
place, and run INSERT if not.


Igor Tandetnik 



-
To unsubscribe, send email to [EMAIL PROTECTED]
-