Re: [sqlite] Equivalent syntax in sqlite

2017-04-26 Thread J Decker
If you change from an auto increment to a GUID/UUID  you can simply use
'REPLACE INTO' and you don't have to worry about the select, because you'll
already know the ID.

http://www.sqlitetutorial.net/sqlite-replace-statement/



On Wed, Apr 26, 2017 at 4:05 PM, Joseph L. Casale  wrote:

> From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org]
> On
> Behalf Of David Raymond
> Sent: Wednesday, April 26, 2017 3:00 PM
> To: SQLite mailing list 
> Subject: Re: [sqlite] Equivalent syntax in sqlite
>
> > With the comment that the insert or ignore method there will only work if
> > there's an explicit unique constraint on your given criteria.
>
> Yup, the table does have one. Thanks for the help guys.
> jlc
> ___
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Equivalent syntax in sqlite

2017-04-26 Thread Joseph L. Casale
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On
Behalf Of David Raymond
Sent: Wednesday, April 26, 2017 3:00 PM
To: SQLite mailing list 
Subject: Re: [sqlite] Equivalent syntax in sqlite
 
> With the comment that the insert or ignore method there will only work if
> there's an explicit unique constraint on your given criteria.

Yup, the table does have one. Thanks for the help guys.
jlc
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Equivalent syntax in sqlite

2017-04-26 Thread David Raymond
With the comment that the insert or ignore method there will only work if 
there's an explicit unique constraint on your given criteria.


-Original Message-
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Simon Slavin
Sent: Wednesday, April 26, 2017 4:46 PM
To: SQLite mailing list
Subject: Re: [sqlite] Equivalent syntax in sqlite


On 26 Apr 2017, at 9:42pm, Joseph L. Casale  wrote:

> Whats the trick with SQLites working set to format a single statement with 
> parameters
> where if a row exists for a given criteria, returns its Id, otherwise insert 
> and return the
> last_insert_rowid()?

It has to be two operations.

INSERT OR IGNORE INTO MyTable …;
SELECT rowid FROM MyTable WHERE …;

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


Re: [sqlite] Equivalent syntax in sqlite

2017-04-26 Thread Simon Slavin

On 26 Apr 2017, at 9:42pm, Joseph L. Casale  wrote:

> Whats the trick with SQLites working set to format a single statement with 
> parameters
> where if a row exists for a given criteria, returns its Id, otherwise insert 
> and return the
> last_insert_rowid()?

It has to be two operations.

INSERT OR IGNORE INTO MyTable …;
SELECT rowid FROM MyTable WHERE …;

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