1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

JS: add a mechanism to the Worker1 exec API to fetch the last_insert_rowid(), as requested in [forum:56bc35390183f5d5|forum post 56bc353901].

FossilOrigin-Name: c22c48360756b1c7e2f5a9c01aff799bc188e100d364931de0dc3686e5de57a9
This commit is contained in:
stephan
2025-02-09 02:41:35 +00:00
parent 3e06f2d79b
commit f858182689
5 changed files with 37 additions and 16 deletions

View File

@ -279,11 +279,11 @@
The arguments are in the same form accepted by oo1.DB.exec(), with
the exceptions noted below.
If the `countChanges` arguments property (added in version 3.43) is
truthy then the `result` property contained by the returned object
will have a `changeCount` property which holds the number of changes
made by the provided SQL. Because the SQL may contain an arbitrary
number of statements, the `changeCount` is calculated by calling
If `args.countChanges` (added in version 3.43) is truthy then the
`result` property contained by the returned object will have a
`changeCount` property which holds the number of changes made by the
provided SQL. Because the SQL may contain an arbitrary number of
statements, the `changeCount` is calculated by calling
`sqlite3_total_changes()` before and after the SQL is evaluated. If
the value of `countChanges` is 64 then the `changeCount` property
will be returned as a 64-bit integer in the form of a BigInt (noting
@ -292,6 +292,15 @@
calling `sqlite3_total_changes64()` before and after the SQL is
evaluated.
If the `args.lastInsertRowId` (added in version 3.50.0) is truthy
then the `result` property contained by the returned object will
have a `lastInsertRowId` will hold a BigInt-type value corresponding
to the result of sqlite3_last_insert_rowid(). This value is only
fetched once, after the SQL is run, regardless of how many
statements the SQL contains. This API has no idea whether the SQL
contains any INSERTs, so it is up to the client to apply/rely on
this property only when it makes sense to do so.
A function-type args.callback property cannot cross
the window/Worker boundary, so is not useful here. If
args.callback is a string then it is assumed to be a
@ -542,6 +551,12 @@ sqlite3.initWorker1API = function(){
if(undefined !== changeCount){
rc.changeCount = db.changes(true,64===rc.countChanges) - changeCount;
}
const lastInsertRowId = !!rc.lastInsertRowId
? sqlite3.capi.sqlite3_last_insert_rowid(db)
: undefined;
if( undefined!==lastInsertRowId ){
rc.lastInsertRowId = lastInsertRowId;
}
if(rc.callback instanceof Function){
rc.callback = theCallback;
/* Post a sentinel message to tell the client that the end