SQLite Forum

Number of rows changed using Promiser API
Login

Number of rows changed using Promiser API

(1) By Randy (randyl) on 2023-05-25 03:35:43 [source]

Hi,

Is it possible to get the number of rows changed by a DML statement when using the Promiser API? I was expecting some property in the exec response to have this info, but I can't find it in the docs. I do see the OO API has a changes() function, but it seems like that wouldn't help with promises, since another statement may have already executed.

Thanks

(2) By Stephan Beal (stephan) on 2023-05-25 09:59:24 in reply to 1 [link] [source]

I was expecting some property in the exec response to have this info, but I can't find it in the docs.

There is currently no way to get that info but i will look at adding a way to fit that in.

I do see the OO API has a changes() function, but it seems like that wouldn't help with promises, since another statement may have already executed.

That timing conflict is an inherent problem for asynchronous APIs like the Promiser, and it imposes a number of limitations on what can be done with the API. Transactions are another example which is difficult to do with that API.

(3) By Stephan Beal (stephan) on 2023-05-25 17:03:05 in reply to 2 [link] [source]

There is currently no way to get that info but i will look at adding a way to fit that in.

A new flag has been added to the exec message arguments of the Worker1 API (which is the basis for the Promiser API). If countChanges is truthy then the total number of changes made by the provided SQL is returned via the changeCount property of the result object. If countChanges is a literal 64 then the value is returned as a 64-bit BigInt (which will trigger an exception on BigInt-lacking builds).

Because the SQL can contain any number of statements, the resulting changeCount value is calculated by calling either sqlite3_total_changes() or sqlite3_total_changes64() before and after the SQL is evaluated, as opposed to using sqlite3_changes() or sqlite3_changes64().

Achtung: this is a preliminary interface change which is subject to tweaking until the 3.43 release, at which point it will be cemented in place. If you would like to see changes (haha!) made to this interface, please report them ASAP.

The prerelease snapshot has been updated to include this capability.

This will be included in version 3.43 but not in the 3.42.x patch series (where only fixes will be included).

(4) By Randy (randyl) on 2023-05-26 03:11:42 in reply to 3 [link] [source]

Awesome, thank you!