mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add optional zSchema argument to sqlite3_js_db_export().
FossilOrigin-Name: 9c23644b1e5bf44bfb431a35fd1674c11ccb99e9eb0989f10175b0cb2a858eaa
This commit is contained in:
@ -1310,14 +1310,17 @@ 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.
|
||||
|
||||
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".
|
||||
*/
|
||||
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 +1329,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 +1347,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
return rc;
|
||||
}finally{
|
||||
if(pOut) wasm.exports.sqlite3_free(pOut);
|
||||
wasm.pstack.restore(stack);
|
||||
wasm.scopedAllocPop(scope);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -916,25 +916,27 @@ int sqlite3_wasm_db_export_chunked( sqlite3* pDb,
|
||||
}
|
||||
|
||||
/*
|
||||
** A proxy for sqlite3_serialize() which serializes the "main" schema
|
||||
** A proxy for sqlite3_serialize() which serializes the schema zSchema
|
||||
** of pDb, placing the serialized output in pOut and nOut. nOut may be
|
||||
** NULL. If pDb or pOut are NULL then SQLITE_MISUSE is returned. If
|
||||
** allocation of the serialized copy fails, SQLITE_NOMEM is returned.
|
||||
** On success, 0 is returned and `*pOut` will contain a pointer to the
|
||||
** memory unless mFlags includes SQLITE_SERIALIZE_NOCOPY and the
|
||||
** database has no contiguous memory representation, in which case
|
||||
** `*pOut` will be NULL but 0 will be returned.
|
||||
** NULL. If zSchema is NULL then "main" is assumed. If pDb or pOut are
|
||||
** NULL then SQLITE_MISUSE is returned. If allocation of the
|
||||
** serialized copy fails, SQLITE_NOMEM is returned. On success, 0 is
|
||||
** returned and `*pOut` will contain a pointer to the memory unless
|
||||
** mFlags includes SQLITE_SERIALIZE_NOCOPY and the database has no
|
||||
** contiguous memory representation, in which case `*pOut` will be
|
||||
** NULL but 0 will be returned.
|
||||
**
|
||||
** If `*pOut` is not NULL, the caller is responsible for passing it to
|
||||
** sqlite3_free() to free it.
|
||||
*/
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_serialize( sqlite3 *pDb, unsigned char **pOut,
|
||||
int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
||||
unsigned char **pOut,
|
||||
sqlite3_int64 *nOut, unsigned int mFlags ){
|
||||
unsigned char * z;
|
||||
if( !pDb || !pOut ) return SQLITE_MISUSE;
|
||||
if(nOut) *nOut = 0;
|
||||
z = sqlite3_serialize(pDb, "main", nOut, mFlags);
|
||||
z = sqlite3_serialize(pDb, zSchema ? zSchema : "main", nOut, mFlags);
|
||||
if( z || (SQLITE_SERIALIZE_NOCOPY & mFlags) ){
|
||||
*pOut = z;
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user