()
| 17854 | const dbg = 1 ? ()=>{} : (...args)=>debug("vtab",...args); |
| 17855 | |
| 17856 | const theModule = function f(){ |
| 17857 | return f.mod ??= new sqlite3.capi.sqlite3_module().setupModule({ |
| 17858 | catchExceptions: true, |
| 17859 | methods: { |
| 17860 | xConnect: function(pDb, pAux, argc, argv, ppVtab, pzErr){ |
| 17861 | dbg("xConnect"); |
| 17862 | try{ |
| 17863 | const xcol = []; |
| 17864 | Object.keys(cols).forEach((k)=>{ |
| 17865 | xcol.push(k+" "+cols[k].type); |
| 17866 | }); |
| 17867 | const rc = capi.sqlite3_declare_vtab( |
| 17868 | pDb, "CREATE TABLE ignored("+xcol.join(',')+")" |
| 17869 | ); |
| 17870 | if(0===rc){ |
| 17871 | const t = VT.xVtab.create(ppVtab); |
| 17872 | util.assert( |
| 17873 | (t === VT.xVtab.get(wasm.peekPtr(ppVtab))), |
| 17874 | "output pointer check failed" |
| 17875 | ); |
| 17876 | } |
| 17877 | return rc; |
| 17878 | }catch(e){ |
| 17879 | return VT.xError('xConnect', e, capi.SQLITE_ERROR); |
| 17880 | } |
| 17881 | }, |
| 17882 | xCreate: wasm.ptr.null, // eponymous only |
| 17883 | //xCreate: true, // copy xConnect, i.e. also eponymous only |
| 17884 | xDisconnect: function(pVtab){ |
| 17885 | dbg("xDisconnect",...arguments); |
| 17886 | VT.xVtab.dispose(pVtab); |
| 17887 | return 0; |
| 17888 | }, |
| 17889 | xOpen: function(pVtab, ppCursor){ |
| 17890 | dbg("xOpen",...arguments); |
| 17891 | VT.xCursor.create(ppCursor); |
| 17892 | return 0; |
| 17893 | }, |
| 17894 | xClose: function(pCursor){ |
| 17895 | dbg("xClose",...arguments); |
| 17896 | const c = VT.xCursor.unget(pCursor); |
| 17897 | delete c.vTabState; |
| 17898 | c.dispose(); |
| 17899 | return 0; |
| 17900 | }, |
| 17901 | xNext: function(pCursor){ |
| 17902 | dbg("xNext",...arguments); |
| 17903 | const c = VT.xCursor.get(pCursor); |
| 17904 | ++cursorState(c).rowid; |
| 17905 | return 0; |
| 17906 | }, |
| 17907 | xColumn: function(pCursor, pCtx, iCol){ |
| 17908 | dbg("xColumn",...arguments); |
| 17909 | //const c = VT.xCursor.get(pCursor); |
| 17910 | const st = cursorState(pCursor); |
| 17911 | const store = st.row(); |
| 17912 | util.assert(store, "Unexpected xColumn call"); |
| 17913 | switch(iCol){ |
no test coverage detected