Skip to content

Commit 8c6c66c

Browse files
committed
sqlite: add limits property to DatabaseSync
1 parent 6218d14 commit 8c6c66c

File tree

5 files changed

+519
-0
lines changed

5 files changed

+519
-0
lines changed

doc/api/sqlite.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ changes:
155155
language features that allow ordinary SQL to deliberately corrupt the database file are disabled.
156156
The defensive flag can also be set using `enableDefensive()`.
157157
**Default:** `false`.
158+
* `limits` {Object} Configuration for various SQLite limits. These limits
159+
can be used to prevent excessive resource consumption when handling
160+
potentially malicious input. See [Run-Time Limits][] in the SQLite
161+
documentation for details. The following properties are supported:
162+
* `length` {number} Maximum length of a string or BLOB.
163+
* `sqlLength` {number} Maximum length of an SQL statement.
164+
* `column` {number} Maximum number of columns.
165+
* `exprDepth` {number} Maximum depth of expression tree.
166+
* `compoundSelect` {number} Maximum number of terms in compound SELECT.
167+
* `vdbeOp` {number} Maximum number of VDBE instructions.
168+
* `functionArg` {number} Maximum number of function arguments.
169+
* `attach` {number} Maximum number of attached databases.
170+
* `likePatternLength` {number} Maximum length of LIKE pattern.
171+
* `variableNumber` {number} Maximum number of SQL variables.
172+
* `triggerDepth` {number} Maximum trigger recursion depth.
158173

159174
Constructs a new `DatabaseSync` instance.
160175

@@ -443,6 +458,31 @@ added:
443458
* Type: {boolean} Whether the database is currently within a transaction. This method
444459
is a wrapper around [`sqlite3_get_autocommit()`][].
445460

461+
### `database.limits`
462+
463+
<!-- YAML
464+
added: REPLACEME
465+
-->
466+
467+
* Type: {Object}
468+
469+
An object for getting and setting SQLite database limits at runtime.
470+
Each property corresponds to an SQLite limit and can be read or written.
471+
472+
```js
473+
const db = new DatabaseSync(':memory:');
474+
475+
// Read current limit
476+
console.log(db.limits.length);
477+
478+
// Set a new limit
479+
db.limits.sqlLength = 100000;
480+
```
481+
482+
Available properties: `length`, `sqlLength`, `column`, `exprDepth`,
483+
`compoundSelect`, `vdbeOp`, `functionArg`, `attach`, `likePatternLength`,
484+
`variableNumber`, `triggerDepth`.
485+
446486
### `database.open()`
447487

448488
<!-- YAML
@@ -1455,6 +1495,7 @@ callback function to indicate what type of operation is being authorized.
14551495
[`ATTACH DATABASE`]: https://www.sqlite.org/lang_attach.html
14561496
[`PRAGMA foreign_keys`]: https://www.sqlite.org/pragma.html#pragma_foreign_keys
14571497
[`SQLITE_DBCONFIG_DEFENSIVE`]: https://www.sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive
1498+
[Run-Time Limits]: https://www.sqlite.org/c3ref/limit.html
14581499
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
14591500
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
14601501
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg

src/env_properties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
V(kill_signal_string, "killSignal") \
236236
V(kind_string, "kind") \
237237
V(last_insert_rowid_string, "lastInsertRowid") \
238+
V(limits_string, "limits") \
238239
V(length_string, "length") \
239240
V(library_string, "library") \
240241
V(loop_count, "loopCount") \
@@ -436,6 +437,7 @@
436437
V(sqlite_column_template, v8::DictionaryTemplate) \
437438
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
438439
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \
440+
V(sqlite_limits_template, v8::ObjectTemplate) \
439441
V(sqlite_session_constructor_template, v8::FunctionTemplate) \
440442
V(srv_record_template, v8::DictionaryTemplate) \
441443
V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \

0 commit comments

Comments
 (0)