I think pragma data_version only tells you if someone _else_ made any file 
updates.

Also I think total_changes will just tell you that the statement changed 
"something", but you still won't know if it was an insert or an update, or how 
many of each.

Doing a "select count(*) from ...;" both before and after will let you know how 
many were inserted, but not how many were updated. Though if you're only 
expecting a single row to be upserted that would work; if it's the same then it 
was an update, if different then an insert. But expensive to run yeah.


-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Simon Slavin
Sent: Friday, February 22, 2019 11:49 AM
To: SQLite mailing list
Subject: Re: [sqlite] Find if an upsert operation did an insert or an update.

On 22 Feb 2019, at 4:08pm, Constantine Yannakopoulos <alfasud...@gmail.com> 
wrote:

> I would like to find whether an upsert operation actually did an insert or an 
> update, preferably without having to execute extra SQL statements before or 
> after it.

Try

<https://sqlite.org/c3ref/total_changes.html>

int sqlite3_total_changes(sqlite3*);

However, note that this is sensitive to how you're structuring your 
transactions, and to whether another connection has changed the database.  Test 
it out for your use-pattern to see if it helps.

If not, then the cannonical method is probably

<https://sqlite.org/pragma.html#pragma_data_version>

which, of course, takes a SQL command.

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

Reply via email to