Skip to content

Commit ee8f356

Browse files
committed
update sqlite limits to allow null for resetting to compile-time maximum
1 parent 5a16bdc commit ee8f356

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

doc/api/sqlite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,17 @@ console.log(db.limits.length);
479479

480480
// Set a new limit
481481
db.limits.sqlLength = 100000;
482+
483+
// Reset a limit to its compile-time maximum
484+
db.limits.sqlLength = null;
482485
```
483486

484487
Available properties: `length`, `sqlLength`, `column`, `exprDepth`,
485488
`compoundSelect`, `vdbeOp`, `functionArg`, `attach`, `likePatternLength`,
486489
`variableNumber`, `triggerDepth`.
487490

491+
Setting a property to `null` resets the limit to its compile-time maximum value.
492+
488493
### `database.open()`
489494

490495
<!-- YAML

src/node_sqlite.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <array>
1616
#include <cinttypes>
17+
#include <climits>
1718

1819
namespace node {
1920
namespace sqlite {
@@ -793,16 +794,21 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
793794
return Intercepted::kYes;
794795
}
795796

796-
if (!value->IsInt32()) {
797-
THROW_ERR_INVALID_ARG_TYPE(isolate, "Limit value must be an integer.");
798-
return Intercepted::kYes;
799-
}
800-
801-
int new_value = value.As<Int32>()->Value();
797+
int new_value;
802798

803-
// Validate non-negative
804-
if (new_value < 0) {
805-
THROW_ERR_OUT_OF_RANGE(isolate, "Limit value must be non-negative.");
799+
if (value->IsNull()) {
800+
// null resets the limit to the compile-time maximum
801+
new_value = INT_MAX;
802+
} else if (value->IsInt32()) {
803+
new_value = value.As<Int32>()->Value();
804+
// Validate non-negative
805+
if (new_value < 0) {
806+
THROW_ERR_OUT_OF_RANGE(isolate, "Limit value must be non-negative.");
807+
return Intercepted::kYes;
808+
}
809+
} else {
810+
THROW_ERR_INVALID_ARG_TYPE(
811+
isolate, "Limit value must be an integer or null.");
806812
return Intercepted::kYes;
807813
}
808814

test/parallel/test-sqlite-limits.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,26 @@ suite('DatabaseSync limits', () => {
8080
t.assert.strictEqual(db.limits.column, 50);
8181
});
8282

83+
test('null resets limit to maximum', (t) => {
84+
const db = new DatabaseSync(':memory:');
85+
const originalLength = db.limits.length;
86+
87+
// Set to a lower value
88+
db.limits.length = 100;
89+
t.assert.strictEqual(db.limits.length, 100);
90+
91+
// Reset to maximum using null
92+
db.limits.length = null;
93+
t.assert.strictEqual(db.limits.length, originalLength);
94+
});
95+
8396
test('throws on invalid argument type', (t) => {
8497
const db = new DatabaseSync(':memory:');
8598
t.assert.throws(() => {
8699
db.limits.length = 'invalid';
87100
}, {
88101
name: 'TypeError',
89-
message: /Limit value must be an integer/,
102+
message: /Limit value must be an integer or null/,
90103
});
91104
});
92105

0 commit comments

Comments
 (0)