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
49 changes: 49 additions & 0 deletions doc/api/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ changes:
language features that allow ordinary SQL to deliberately corrupt the database file are disabled.
The defensive flag can also be set using `enableDefensive()`.
**Default:** `false`.
* `limits` {Object} Configuration for various SQLite limits. These limits
can be used to prevent excessive resource consumption when handling
potentially malicious input. See [Run-Time Limits][] and [Limit Constants][]
in the SQLite documentation for details. Default values are determined by
SQLite's compile-time defaults and may vary depending on how SQLite was
built. The following properties are supported:
* `length` {number} Maximum length of a string or BLOB.
* `sqlLength` {number} Maximum length of an SQL statement.
* `column` {number} Maximum number of columns.
* `exprDepth` {number} Maximum depth of expression tree.
* `compoundSelect` {number} Maximum number of terms in compound SELECT.
* `vdbeOp` {number} Maximum number of VDBE instructions.
* `functionArg` {number} Maximum number of function arguments.
* `attach` {number} Maximum number of attached databases.
* `likePatternLength` {number} Maximum length of LIKE pattern.
* `variableNumber` {number} Maximum number of SQL variables.
* `triggerDepth` {number} Maximum trigger recursion depth.

Constructs a new `DatabaseSync` instance.

Expand Down Expand Up @@ -443,6 +460,36 @@ added:
* Type: {boolean} Whether the database is currently within a transaction. This method
is a wrapper around [`sqlite3_get_autocommit()`][].

### `database.limits`

<!-- YAML
added: REPLACEME
-->

* Type: {Object}

An object for getting and setting SQLite database limits at runtime.
Each property corresponds to an SQLite limit and can be read or written.

```js
const db = new DatabaseSync(':memory:');

// Read current limit
console.log(db.limits.length);

// Set a new limit
db.limits.sqlLength = 100000;

// Reset a limit to its compile-time maximum
db.limits.sqlLength = null;
```

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

Setting a property to `null` resets the limit to its compile-time maximum value.

### `database.open()`

<!-- YAML
Expand Down Expand Up @@ -1450,6 +1497,8 @@ callback function to indicate what type of operation is being authorized.
[Changesets and Patchsets]: https://www.sqlite.org/sessionintro.html#changesets_and_patchsets
[Constants Passed To The Conflict Handler]: https://www.sqlite.org/session/c_changeset_conflict.html
[Constants Returned From The Conflict Handler]: https://www.sqlite.org/session/c_changeset_abort.html
[Limit Constants]: https://www.sqlite.org/c3ref/c_limit_attached.html
[Run-Time Limits]: https://www.sqlite.org/c3ref/limit.html
[SQL injection]: https://en.wikipedia.org/wiki/SQL_injection
[Type conversion between JavaScript and SQLite]: #type-conversion-between-javascript-and-sqlite
[`ATTACH DATABASE`]: https://www.sqlite.org/lang_attach.html
Expand Down
2 changes: 2 additions & 0 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
V(kill_signal_string, "killSignal") \
V(kind_string, "kind") \
V(last_insert_rowid_string, "lastInsertRowid") \
V(limits_string, "limits") \
V(length_string, "length") \
V(library_string, "library") \
V(loop_count, "loopCount") \
Expand Down Expand Up @@ -436,6 +437,7 @@
V(sqlite_column_template, v8::DictionaryTemplate) \
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
V(sqlite_statement_sync_iterator_constructor_template, v8::FunctionTemplate) \
V(sqlite_limits_template, v8::ObjectTemplate) \
V(sqlite_session_constructor_template, v8::FunctionTemplate) \
V(srv_record_template, v8::DictionaryTemplate) \
V(streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
Expand Down
Loading
Loading