1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add JS bindings for sqlite3_value_text/blob_v2() and add basic JS tests for text_v2().

FossilOrigin-Name: 096c745f38c487c29948e4578fea61085f4a324b187d5b6e9ab32d7b14e503c3
This commit is contained in:
stephan
2025-06-30 23:49:21 +00:00
parent 59890ab8c7
commit 3cd904cc97
5 changed files with 63 additions and 12 deletions

View File

@ -3341,6 +3341,56 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
db.close();
})
////////////////////////////////////////////////////////////////////
.t("value_text_v2() and friends...", function(sqlite3){
const db = new sqlite3.oo1.DB();
db.exec(["create table t(a,b); insert into t(a,b) ",
"values(1,123),(2,null),(3,'hi world'),(4,X'232A')"]);
const P = wasm.pstack;
const stack = P.pointer;
let q;
try {
let sv, rc;
q = db.prepare("select a, b from t order by a");
let [ppOut,pnOut] = P.allocPtr(2);
const next = ()=>{
T.assert( q.step() );
sv = capi.sqlite3_column_value(q, 1);
T.assert( sv );
wasm.pokePtr(ppOut, 0);
wasm.poke32(pnOut, 0);
rc = capi.sqlite3_value_text_v2(sv, ppOut, pnOut);
T.assert( 0===rc );
return sv;
};
next();
T.assert( wasm.peekPtr(ppOut) )
.assert( 3===wasm.peek32(pnOut) )
.assert( '123' === wasm.cstrToJs(wasm.peekPtr(ppOut)) );
next();
T.assert( !wasm.peekPtr(ppOut) )
.assert( 0===wasm.peek32(pnOut) );
next();
T.assert( wasm.peekPtr(ppOut) )
.assert( 8===wasm.peek32(pnOut) )
.assert( 'hi world' === wasm.cstrToJs(wasm.peekPtr(ppOut)) )
;
next();
T.assert( wasm.peekPtr(ppOut) )
.assert( 2===wasm.peek32(pnOut) )
.assert( '#*' === wasm.cstrToJs(wasm.peekPtr(ppOut)) )
;
}finally{
if( q ) q.finalize();
db.close();
P.restore(stack);
}
})
/**
Ensure that certain Stmt members throw when called
via DB.exec().