mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
Got JS non-eponymous vtable working thanks to a hint from Dan.
FossilOrigin-Name: 750719b4981df62fa2ff3665e6f559ec760609ad2493495628295ad9ae6024fc
This commit is contained in:
@ -520,10 +520,12 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
db is closed but before auxiliary state like this.filename is
|
||||
cleared.
|
||||
|
||||
Both onclose handlers are passed this object. If this db is not
|
||||
opened, neither of the handlers are called. Any exceptions the
|
||||
handlers throw are ignored because "destructors must not
|
||||
throw."
|
||||
Both onclose handlers are passed this object, with the onclose
|
||||
object as their "this," noting that the db will have been
|
||||
closed when onclose.after is called. If this db is not opened
|
||||
when close() is called, neither of the handlers are called. Any
|
||||
exceptions the handlers throw are ignored because "destructors
|
||||
must not throw."
|
||||
|
||||
Note that garbage collection of a db handle, if it happens at
|
||||
all, will never trigger close(), so onclose handlers are not a
|
||||
|
@ -339,8 +339,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
(sqlite3_vtab*) instance and returns the capi.sqlite3_vtab
|
||||
object created by the first form of this function, or undefined
|
||||
if that form has not been used. This is intended to be called
|
||||
from sqlite3_module methods which take a (sqlite3_vtab*) pointer
|
||||
_except_ for xDisconnect(), in which case use...
|
||||
from sqlite3_module methods which take a (sqlite3_vtab*)
|
||||
pointer _except_ for xDestroy() (if there is a distinct
|
||||
xCreate()) or xDisconnect() (if xCreate() is 0 or is the same
|
||||
as xConnect()), in which case use...
|
||||
|
||||
- wrapVtab(pVtab,true) as for the previous form, but removes the
|
||||
pointer-to-object mapping before returning. The caller must
|
||||
|
@ -999,13 +999,19 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
const db = this.db = new sqlite3.oo1.DB(dbFile, 0 ? 'ct' : 'c');
|
||||
db.onclose = {
|
||||
disposeThese: [],
|
||||
before: (db)=>{
|
||||
console.debug("db.onclose.before dropping modules");
|
||||
sqlite3.capi.sqlite3_drop_modules(db, 0);
|
||||
},
|
||||
after: function(){
|
||||
while(this.disposeThese.length){
|
||||
const v = this.disposeThese.shift();
|
||||
console.debug("db.onclose cleaning up:",v);
|
||||
console.debug("db.onclose.after cleaning up:",v);
|
||||
if(wasm.isPtr(v)) wasm.dealloc(v);
|
||||
else if(v instanceof sqlite3.StructBinder.StructType){
|
||||
v.dispose();
|
||||
}else if(v instanceof Function){
|
||||
try{v()} catch(e){/*ignored*/}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1867,7 +1873,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
.t({
|
||||
name: 'virtual table #2 (w/ automated exception wrapping)',
|
||||
name: 'virtual table #2 (non-eponymous w/ automated exception wrapping)',
|
||||
predicate: ()=>!!capi.sqlite3_index_info,
|
||||
test: function(sqlite3){
|
||||
warn("The vtab/module JS bindings are experimental and subject to change.");
|
||||
@ -1879,7 +1885,7 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
The vtab demonstrated here is a JS-ification of
|
||||
ext/misc/templatevtab.c.
|
||||
*/
|
||||
let throwOnConnect = 1 ? 0 : capi.SQLITE_CANTOPEN
|
||||
let throwOnCreate = 1 ? 0 : capi.SQLITE_CANTOPEN
|
||||
/* ^^^ just for testing exception wrapping. Note that sqlite
|
||||
always translates errors from a vtable to a generic
|
||||
SQLITE_ERROR unless it's from xConnect()/xCreate() and that
|
||||
@ -1889,10 +1895,18 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
catchExceptions: true,
|
||||
name: "vtab2test",
|
||||
methods:{
|
||||
xConnect: function(pDb, pAux, argc, argv, ppVtab, pzErr){
|
||||
console.debug("xConnect(",...arguments,")");
|
||||
const t = vth.xVtab();
|
||||
wasm.setPtrValue(ppVtab, t.pointer);
|
||||
T.assert(t === vth.xVtab(wasm.getPtrValue(ppVtab)));
|
||||
console.debug("xConnect(",...arguments,") ppVtab =",t.pointer);
|
||||
},
|
||||
xCreate: function(pDb, pAux, argc, argv, ppVtab, pzErr){
|
||||
if(throwOnConnect){
|
||||
console.debug("xCreate(",...arguments,")");
|
||||
if(throwOnCreate){
|
||||
sqlite3.SQLite3Error.toss(
|
||||
throwOnConnect,
|
||||
throwOnCreate,
|
||||
"Throwing a test exception."
|
||||
);
|
||||
}
|
||||
@ -1906,11 +1920,20 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
const t = vth.xVtab();
|
||||
wasm.setPtrValue(ppVtab, t.pointer);
|
||||
T.assert(t === vth.xVtab(wasm.getPtrValue(ppVtab)));
|
||||
console.debug("xCreate(",...arguments,") ppVtab =",t.pointer);
|
||||
}
|
||||
return rc;
|
||||
},
|
||||
xDisconnect: function(pVtab){
|
||||
console.debug("sqlite3_module::xDisconnect(",pVtab,")");
|
||||
const t = vth.xVtab(pVtab, true);
|
||||
T.assert(t);
|
||||
t.dispose();
|
||||
},
|
||||
xDestroy: function(pVtab){
|
||||
console.debug("sqlite3_module::xDestroy(",pVtab,")");
|
||||
const t = vth.xVtab(pVtab, true);
|
||||
T.assert(t);
|
||||
t.dispose();
|
||||
},
|
||||
xOpen: function(pVtab, ppCursor){
|
||||
@ -1945,12 +1968,10 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
xRowid: function(pCursor, ppRowid64){
|
||||
const c = vth.xCursor(pCursor);
|
||||
vth.xRowid(ppRowid64, c._rowId);
|
||||
c.dispose();
|
||||
},
|
||||
xEof: function(pCursor){
|
||||
const c = vth.xCursor(pCursor),
|
||||
rc = c._rowId>=10;
|
||||
c.dispose();
|
||||
return rc;
|
||||
},
|
||||
xFilter: function(pCursor, idxNum, idxCStr,
|
||||
@ -1959,7 +1980,6 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
c._rowId = 0;
|
||||
const list = vth.sqlite3ValuesToJs(argc, argv);
|
||||
T.assert(argc === list.length);
|
||||
c.dispose();
|
||||
},
|
||||
xBestIndex: function(pVtab, pIdxInfo){
|
||||
//const t = vth.xVtab(pVtab);
|
||||
@ -1970,54 +1990,21 @@ self.sqlite3InitModule = sqlite3InitModule;
|
||||
}
|
||||
}/*methods*/
|
||||
};
|
||||
const doEponymousOnly =
|
||||
/* Bug (somewhere): non-eponymous is behaving as is
|
||||
the call to sqlite3_create_module() is missing
|
||||
or failed:
|
||||
|
||||
SQL TRACE #63 create virtual table testvtab2 using vtab2test(arg1, arg2)
|
||||
|
||||
=> sqlite3 result code 1: no such module: vtab2test
|
||||
*/ true;
|
||||
modConfig.methods.xConnect =
|
||||
modConfig.methods.xCreate;
|
||||
if(doEponymousOnly){
|
||||
warn("Reminder: non-eponymous mode is still not working here.",
|
||||
"Details are in the code comments.");
|
||||
modConfig.methods.xCreate = 0;
|
||||
}else{
|
||||
/*(...args)=>{
|
||||
try{return modConfig.methods.xConnect(...args)}
|
||||
catch(e){return vth.xError('xConnect',e)}
|
||||
};*/
|
||||
}
|
||||
const tmplMod = vth.setupModule(modConfig);
|
||||
T.assert(tmplMod instanceof capi.sqlite3_module)
|
||||
.assert(1===tmplMod.$iVersion);
|
||||
if(doEponymousOnly){
|
||||
if(modConfig.methods.xCreate !== 0){
|
||||
T.assert(modConfig.methods.xCreate === modConfig.methods.xConnect)
|
||||
.assert(tmplMod.$xCreate === tmplMod.$xConnect);
|
||||
}else{
|
||||
T.assert(0 === tmplMod.$xCreate);
|
||||
}
|
||||
}else{
|
||||
//T.assert(tmplMod.$xCreate !== tmplMod.$xConnect);
|
||||
}
|
||||
this.db.onclose.disposeThese.push(tmplMod);
|
||||
this.db.checkRc(capi.sqlite3_create_module(
|
||||
this.db.pointer, modConfig.name, tmplMod.pointer, 0
|
||||
));
|
||||
if(!doEponymousOnly){
|
||||
this.db.exec([
|
||||
"create virtual table testvtab2 using ",
|
||||
modConfig.name,
|
||||
"(arg1, arg2)"
|
||||
]);
|
||||
}
|
||||
const list = this.db.selectArrays(
|
||||
["SELECT a,b FROM",
|
||||
(doEponymousOnly ? modConfig.name : "testvtab2"),
|
||||
" testvtab2",
|
||||
" where a<9999 and b>1 order by a, b"
|
||||
]/* Query is shaped so that it will ensure that some
|
||||
constraints end up in xBestIndex(). */
|
||||
|
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\ssome\sdead\sJS\scode\sand\stweak\ssome\sdocs.
|
||||
D 2022-12-08T04:19:38.945
|
||||
C Got\sJS\snon-eponymous\svtable\sworking\sthanks\sto\sa\shint\sfrom\sDan.
|
||||
D 2022-12-08T09:06:20.756
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -504,12 +504,12 @@ F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b
|
||||
F ext/wasm/api/pre-js.c-pp.js b88499dc303c21fc3f55f2c364a0f814f587b60a95784303881169f9e91c1d5f
|
||||
F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4
|
||||
F ext/wasm/api/sqlite3-api-glue.js 8fa55af37c9880f94a803f32591dc0304750cc2f750048daf41fe942757bee64
|
||||
F ext/wasm/api/sqlite3-api-oo1.js 416e6398721a4cbb80ddfa3d7b303216790f1d344efdbbc36239d39abc66aa27
|
||||
F ext/wasm/api/sqlite3-api-oo1.js e9e6da5f9e4d7d309fe4c338a22fb38575e831cddd10d6506fba7ddc180df6e6
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 1380e933325c11786b2afc93fc8ff88c2fd1ffeac3e0081da35e5a7317f20e09
|
||||
F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f
|
||||
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
|
||||
F ext/wasm/api/sqlite3-opfs-async-proxy.js 7795b84b66a7a8dedc791340709b310bb497c3c72a80bef364fa2a58e2ddae3f
|
||||
F ext/wasm/api/sqlite3-v-helper.js 963fb63493ce7efdae3c434e2dbd45e6a5c0b6566ea8ac533116941d03b9dc23
|
||||
F ext/wasm/api/sqlite3-v-helper.js ec03a222ad3551764626f14f38de1b1081bda509e098849502b498c041993a0f
|
||||
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 8ec510fee735c646fb18a3b99f0ca5ca461f9e066c43cdc404d7144f12ae6ed6
|
||||
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
||||
F ext/wasm/api/sqlite3-wasm.c 723522a6c2a2463884a83fa1cc7ae5770deaaf0856a1058cc1023b2bfa1c898b
|
||||
@ -555,7 +555,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
|
||||
F ext/wasm/test-opfs-vfs.js 44363db07b2a20e73b0eb1808de4400ca71b703af718d0fa6d962f15e73bf2ac
|
||||
F ext/wasm/tester1-worker.html d43f3c131d88f10d00aff3e328fed13c858d674ea2ff1ff90225506137f85aa9
|
||||
F ext/wasm/tester1.c-pp.html d34bef3d48e5cbc1c7c06882ad240fec49bf88f5f65696cc2c72c416933aa406
|
||||
F ext/wasm/tester1.c-pp.js cf8d0c4ecf255886b6cb7e0d8e5f54a091d06584f5f3b20bc8f2128692fffcdf
|
||||
F ext/wasm/tester1.c-pp.js 7e3cd6cbad34f44800b2ee3e03d12aa064c598156ee779cf5d5c562156ed83f5
|
||||
F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70
|
||||
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
|
||||
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
|
||||
@ -2067,8 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 6a0fefb93bcccd950df211cf5c2f49660c7b92115dd01b2b508a4ab9e3ab3d23
|
||||
R f94a2c459277216db79da2d45589f3a1
|
||||
P 0ee495452c014680697aa9035c245024df127a52d1820ab0e02580a015d96ecb
|
||||
R 09bfd5e1d5efadd7221593e29be578f6
|
||||
U stephan
|
||||
Z b8f7b8c54d4f2428fc7b85ce6a8bd62e
|
||||
Z 6e67580aa5c332587f0481ad10406d76
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
0ee495452c014680697aa9035c245024df127a52d1820ab0e02580a015d96ecb
|
||||
750719b4981df62fa2ff3665e6f559ec760609ad2493495628295ad9ae6024fc
|
Reference in New Issue
Block a user