Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ changes:
database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`.
* `target` {string} Name of the target database. This can be `'main'` (the default primary database) or any other
database that have been added with [`ATTACH DATABASE`][] **Default:** `'main'`.
* `rate` {number} Number of pages to be transmitted in each batch of the backup. **Default:** `100`.
* `rate` {integer} Positive number of pages to be transmitted in each batch of the backup. **Default:** `100`.
* `progress` {Function} An optional callback function that will be called after each backup step. The argument passed
to this callback is an {Object} with `remainingPages` and `totalPages` properties, describing the current progress
of the backup operation.
Expand Down
6 changes: 6 additions & 0 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,12 @@ void Backup(const FunctionCallbackInfo<Value>& args) {
return;
}
rate = rate_v.As<Int32>()->Value();
if (rate <= 0) {
THROW_ERR_OUT_OF_RANGE(
env->isolate(),
"The \"options.rate\" argument must be a positive integer.");
return;
}
}

Local<Value> source_v;
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-sqlite-backup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ describe('backup()', () => {
message: 'The "options.rate" argument must be an integer.'
});

for (const rate of [0, -1]) {
t.assert.throws(() => {
backup(database, 'hello.db', { rate });
}, {
code: 'ERR_OUT_OF_RANGE',
message: 'The "options.rate" argument must be a positive integer.'
});
}

t.assert.throws(() => {
backup(database, 'hello.db', {
progress: 'invalid'
Expand Down
Loading