diff options
author | stephan <stephan@noemail.net> | 2022-05-23 01:11:49 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-05-23 01:11:49 +0000 |
commit | 71eacead7644d5bcbc1abfbaa022852998b84ae5 (patch) | |
tree | 7a335141aa4c95745fdfff00e8fe116fe795ce67 /ext/fiddle/sqlite3-api.js | |
parent | c21c0e2af9de95078a2358a3e090e0384e791966 (diff) | |
download | sqlite-71eacead7644d5bcbc1abfbaa022852998b84ae5.tar.gz sqlite-71eacead7644d5bcbc1abfbaa022852998b84ae5.zip |
WASM: removed the in64-related bindings, as MDN says that calling a wasm function which has an int64 type in its signature will currently throw because JS has no 64-bit integer support. Those bindings now use doubles and simply hope that the user doesn't exceed their integer precision (2^53-1, approx 9 quadrillion).
FossilOrigin-Name: 392e84828275ec203bc713d3a5d4790852add57539add6b29b5f6de1da2dc97a
Diffstat (limited to 'ext/fiddle/sqlite3-api.js')
-rw-r--r-- | ext/fiddle/sqlite3-api.js | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/ext/fiddle/sqlite3-api.js b/ext/fiddle/sqlite3-api.js index a8a697301..1a07e6d54 100644 --- a/ext/fiddle/sqlite3-api.js +++ b/ext/fiddle/sqlite3-api.js @@ -11,8 +11,8 @@ *********************************************************************** This file is intended to be loaded after loading sqlite3.wasm. It - sets one of any number of potential bindings using that API, this - one as closely matching the C-native API as is feasible. + sets up one of any number of potential bindings using that API, this + one as closely matching the C-native API as is feasible in JS. Note that this file is not named sqlite3.js because that file gets generated by emscripten as the JS-glue counterpart of sqlite3.wasm. @@ -49,7 +49,17 @@ - Except where noted in the non-goals, provide a more-or-less complete wrapper to the sqlite3 C API, insofar as WASM feature - parity with C allows for. + parity with C allows for. In fact, provide at least 3... + + - (1) The aforementioned C-style API. (2) An OO-style API on + top of that, designed to run in the same thread (main window or + Web Worker) as the C API. (3) A less-capable wrapper which can + work across the main window/worker boundary, where the sqlite3 API + is one of those and this wrapper is in the other. That + constellation places some considerable limitations on how the API + can be interacted with, but keeping the DB operations out of the + UI thread is generally desirable. + Non-goals: @@ -58,6 +68,9 @@ UTF16-related APIs will not be. They would add a complication to the bindings for no appreciable benefit. + - Supporting old or niche-market platforms. WASM is built for a + modern web and requires modern platforms. + */ (function(namespace){ /* For reference: sql.js does essentially everything we want and @@ -150,8 +163,8 @@ ["sqlite3_bind_blob","number",["number", "number", "number", "number", "number"]], ["sqlite3_bind_double","number",["number", "number", "number"]], ["sqlite3_bind_int","number",["number", "number", "number"]], - [/*Noting that wasm does not currently support 64-bit integers:*/ - "sqlite3_bind_int64","number",["number", "number", "number"]], + /*Noting that JS/wasm combo does not currently support 64-bit integers: + ["sqlite3_bind_int64","number",["number", "number", "number"]],*/ ["sqlite3_bind_null","void",["number"]], ["sqlite3_bind_parameter_count", "number", ["number"]], ["sqlite3_bind_parameter_index","number",["number", "string"]], @@ -165,8 +178,8 @@ ["sqlite3_column_count","number",["number"]], ["sqlite3_column_double","number",["number", "number"]], ["sqlite3_column_int","number",["number", "number"]], - [/*Noting that wasm does not currently support 64-bit integers:*/ - "sqlite3_column_int64","number",["number", "number"]], + /*Noting that JS/wasm combo does not currently support 64-bit integers: + ["sqlite3_column_int64","number",["number", "number"]],*/ ["sqlite3_column_name","string",["number", "number"]], ["sqlite3_column_text","string",["number", "number"]], ["sqlite3_column_type","number",["number", "number"]], @@ -661,7 +674,9 @@ case BindTypes.number: { const m = ((val === (val|0)) ? ((val & 0x00000000/*>32 bits*/) - ? S.sqlite3_bind_int64 + ? S.sqlite3_bind_double + /*It's illegal to bind a 64-bit int + from here*/ : S.sqlite3_bind_int) : S.sqlite3_bind_double); rc = m(stmt._pStmt, ndx, val); @@ -761,13 +776,17 @@ - null or undefined is bound as NULL. - - Numbers are bound as either doubles or integers: int64 if - they are larger than 0xEFFFFFFF, else int32. Booleans are - bound as integer 0 or 1. Note that doubles with no - fractional part are bound as integers. It is not expected - that that distinction is significant for the majority of - clients due to sqlite3's data typing model. This API does - not currently support the BigInt type. + - Numbers are bound as either doubles or integers: doubles + if they are larger than 32 bits, else double or int32, + depending on whether they have a fractional part. (It is, + as of this writing, illegal to call (from JS) a WASM + function which either takes or returns an int64.) + Booleans are bound as integer 0 or 1. It is not expected + the distinction of binding doubles which have no + fractional parts is integers is significant for the + majority of clients due to sqlite3's data typing + model. This API does not currently support the BigInt + type. - Strings are bound as strings (use bindAsBlob() to force blob binding). @@ -929,8 +948,11 @@ switch(undefined===asType ? S.sqlite3_column_type(this._pStmt, ndx) : asType){ - case S.SQLITE_INTEGER: - return S.sqlite3_column_int64(this._pStmt, ndx); + case S.SQLITE_INTEGER:{ + return 0 | S.sqlite3_column_double(this._pStmt, ndx); + /* ^^^^^^^^ strips any fractional part and handles + handles >32bits */ + } case S.SQLITE_FLOAT: return S.sqlite3_column_double(this._pStmt, ndx); case S.SQLITE_TEXT: |