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

Enhance oo1.DB.exec() to simplify returning whole result sets.

FossilOrigin-Name: 7b168ee2af09f04b41a6ef4c14ccaddc0c9b0bfe9dc1e6a86d8f5317606bd78d
This commit is contained in:
stephan
2023-01-28 05:09:26 +00:00
parent 65f7942d06
commit e84454ff16
5 changed files with 35 additions and 21 deletions

View File

@ -422,6 +422,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
default:
toss3("Invalid returnValue value:",opt.returnValue);
}
if(!opt.callback && !opt.returnValue && undefined!==opt.rowMode){
if(!opt.resultRows) opt.resultRows = [];
out.returnVal = ()=>opt.resultRows;
}
if(opt.callback || opt.resultRows){
switch((undefined===opt.rowMode)
? 'array' : opt.rowMode) {
@ -770,8 +774,11 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- `returnValue`: is a string specifying what this function
should return:
A) The default value is `"this"`, meaning that the
DB object itself should be returned.
A) The default value is (usually) `"this"`, meaning that the
DB object itself should be returned. The exceptions is if
the caller passes neither of `callback` nor `returnValue`
but does pass an explicit `rowMode` then the default
`returnValue` is `"resultRows"`, described below.
B) `"resultRows"` means to return the value of the
`resultRows` option. If `resultRows` is not set, this
@ -791,9 +798,6 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
- `callback` and `resultRows`: permit an array entries with
semantics similar to those described for `bind` above.
- If passed neither a callback nor returnValue but is passed a
rowMode, default to returning the result set.
*/
exec: function(/*(sql [,obj]) || (obj)*/){
affirmDbOpen(this);

View File

@ -1412,14 +1412,26 @@ self.sqlite3InitModule = sqlite3InitModule;
db.selectValue("SELECT "+Number.MIN_SAFE_INTEGER)).
assert(Number.MAX_SAFE_INTEGER ===
db.selectValue("SELECT "+Number.MAX_SAFE_INTEGER));
counter = 0;
db.exec({
let rv = db.exec({
sql: "SELECT a FROM t",
callback: ()=>(1===++counter),
});
T.assert(2===counter,
T.assert(db === rv)
.assert(2===counter,
"Expecting exec step() loop to stop if callback returns false.");
/** If exec() is passed neither callback nor returnValue but
is passed an explicit rowMode then the default returnValue
is the whole result set, as if an empty resultRows option
had been passed. */
rv = db.exec({
sql: "SELECT -1 UNION ALL SELECT -2 UNION ALL SELECT -3 ORDER BY 1 DESC",
rowMode: 0
});
T.assert(Array.isArray(rv)).assert(3===rv.length)
.assert(-1===rv[0]).assert(-3===rv[2]);
rv = db.exec("SELECT 1 WHERE 0",{rowMode: 0});
T.assert(Array.isArray(rv)).assert(0===rv.length);
if(wasm.bigIntEnabled && haveWasmCTests()){
const mI = wasm.xCall('sqlite3_wasm_test_int64_max');
const b = BigInt(Number.MAX_SAFE_INTEGER * 2);

View File

@ -26,9 +26,8 @@
workload with <code>interval=N</code> (milliseconds). Set the
number of worker iterations with <code>iterations=N</code>.
Enable OPFS VFS verbosity with <code>verbose=1-3</code> (output
goes to the dev console). Enable/disable "unlock ASAP" mode
(higher concurrency, lower speed)
with <code>unlock-asap=0-1</code>.
goes to the dev console). Disable/enable "unlock ASAP" mode
(higher concurrency, lower speed) with <code>unlock-asap=0-1</code>.
</p>
<p>Achtung: if it does not start to do anything within a couple of
seconds, check the dev console: Chrome sometimes fails to load

View File

@ -1,5 +1,5 @@
C Add\sJS\sbundler-friendly\sJS\sbuild.\sMinor\stest\scode\scleanups.
D 2023-01-28T04:20:46.205
C Enhance\soo1.DB.exec()\sto\ssimplify\sreturning\swhole\sresult\ssets.
D 2023-01-28T05:09:26.765
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -479,7 +479,7 @@ F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b
F ext/wasm/api/pre-js.c-pp.js 9ece5de1bb0509f0a8a360712fcc9c1291b9516c0be5bd66acedd6edbcec37a1
F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4
F ext/wasm/api/sqlite3-api-glue.js 0a93e58aabf52b32ddccbb107a1fd4552f2505e103ab63396c4d0a0743704785
F ext/wasm/api/sqlite3-api-oo1.js a3892fd79070d8c947205d8b90d8218cdb12e7fd5027dced5805dd387b590a36
F ext/wasm/api/sqlite3-api-oo1.js f85f4f939f67217d75898e3a32944dd8ae17f11c9a357e78a116150d038c0377
F ext/wasm/api/sqlite3-api-prologue.js 69a74f2777aaafafc07ad2c922674fe3197ef63c921a3262b4772f937e7eb14a
F ext/wasm/api/sqlite3-api-worker1.js c462199c40358f00f93e326206bddc756c52b93f2cb60ffb63f54fe4f9a9e977
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
@ -530,8 +530,8 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
F ext/wasm/test-opfs-vfs.js f09266873e1a34d9bdb6d3981ec8c9e382f31f215c9fd2f9016d2394b8ae9b7b
F ext/wasm/tester1-worker.html 258d08f1ba9cc2d455958751e26be833893cf9ff7853e9436e593e1f778a386b
F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2
F ext/wasm/tester1.c-pp.js f199ef496aec40a7ddedcc84f996117c911eac36d377913993d3f0261f9427ac
F ext/wasm/tests/opfs/concurrency/index.html 86d8ac435074d1e7007b91105f4897f368c165e8cecb6a9aa3d81f5cf5dcbe70
F ext/wasm/tester1.c-pp.js 483fc1393bff4d06e696e6b72ebd1daedb71a46e81cd33d9ede9ca2b5fb76f68
F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5
@ -2044,9 +2044,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 bd9613fd63193bd6b33798d83f0ef21987ba468b53d13a25a31cb9e9e5f20562 6a5c4f6b19aa0704efe7f789102f757a1ed05d6542f37c7aa37a4439783944a3
R 7e285c57f9c962c0e3cd104712b20885
T +closed 6a5c4f6b19aa0704efe7f789102f757a1ed05d6542f37c7aa37a4439783944a3 Closed\sby\sintegrate-merge.
P 24d3a53dea5e596230558e233cbbd9d0288b4c394cd5ea7b650fd99bff4cde2e
R 32ae67991ccd2fab1735177a69f90f3b
U stephan
Z 04a00083266e19e010eadc8bb14898d9
Z eea3cf1aefbfbb83af8cc08b772c2cf0
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
24d3a53dea5e596230558e233cbbd9d0288b4c394cd5ea7b650fd99bff4cde2e
7b168ee2af09f04b41a6ef4c14ccaddc0c9b0bfe9dc1e6a86d8f5317606bd78d