aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-prologue.js
diff options
context:
space:
mode:
authordrh <>2022-11-24 01:41:44 +0000
committerdrh <>2022-11-24 01:41:44 +0000
commit4b1555a9fc77dfaca1ee3eab38a2ba424a9d4ad9 (patch)
tree9df8ca7ad4fb96cfb9b0c97497b10152cb758cae /ext/wasm/api/sqlite3-api-prologue.js
parent9b80cb5f39af66075762057df127ffbbb2c6ef2a (diff)
parentf1ce4f40c7a01fd272662ab42d24b1f3ba747069 (diff)
downloadsqlite-4b1555a9fc77dfaca1ee3eab38a2ba424a9d4ad9.tar.gz
sqlite-4b1555a9fc77dfaca1ee3eab38a2ba424a9d4ad9.zip
Merge the latest trunk changes into the agg-with-indexed-expr branch to
simplify diffs. FossilOrigin-Name: 38c3d3f1ed0fd2bb62aa8a7e5a27f2b247123e094e2fdb0a2475d788c3dfbc04
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index 8b2ce0936..1cddc8eaf 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -1307,17 +1307,24 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
};
/**
- Serializes the given `sqlite3*` pointer to a Uint8Array, as per
- sqlite3_serialize(). On success it returns a Uint8Array. On
- error it throws with a description of the problem.
+ A convenience wrapper around sqlite3_serialize() which serializes
+ the given `sqlite3*` pointer to a Uint8Array.
+
+ On success it returns a Uint8Array. If the schema is empty, an
+ empty array is returned.
+
+ `schema` is the schema to serialize. It may be a WASM C-string
+ pointer or a JS string. If it is falsy, it defaults to `"main"`.
+
+ On error it throws with a description of the problem.
*/
- capi.sqlite3_js_db_export = function(pDb){
+ capi.sqlite3_js_db_export = function(pDb, schema=0){
if(!pDb) toss3('Invalid sqlite3* argument.');
if(!wasm.bigIntEnabled) toss3('BigInt64 support is not enabled.');
- const stack = wasm.pstack.pointer;
+ const scope = wasm.scopedAllocPush();
let pOut;
try{
- const pSize = wasm.pstack.alloc(8/*i64*/ + wasm.ptrSizeof);
+ const pSize = wasm.scopedAlloc(8/*i64*/ + wasm.ptrSizeof);
const ppOut = pSize + 8;
/**
Maintenance reminder, since this cost a full hour of grief
@@ -1326,8 +1333,11 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
export reads a garbage size because it's not on an 8-byte
memory boundary!
*/
+ const zSchema = schema
+ ? (wasm.isPtr(schema) ? schema : wasm.scopedAllocCString(''+schema))
+ : 0;
let rc = wasm.exports.sqlite3_wasm_db_serialize(
- pDb, ppOut, pSize, 0
+ pDb, zSchema, ppOut, pSize, 0
);
if(rc){
toss3("Database serialization failed with code",
@@ -1341,7 +1351,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
return rc;
}finally{
if(pOut) wasm.exports.sqlite3_free(pOut);
- wasm.pstack.restore(stack);
+ wasm.scopedAllocPop(scope);
}
};