-
-
Couldn't load subscription status.
- Fork 33.6k
sqlite: allow setting defensive flag #60217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+130
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b493979
sqlite: allow setting defensive flag
louwers bafeb0a
test: add test for wrong argument type
louwers a1ea22d
sqlite: enable defensive mode by default
louwers 55176d3
sqlite: revert "sqlite: enable defensive mode by default"
louwers a522262
sqlite: add changes YAML
louwers af87669
doc: fix order changes list
louwers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 'use strict'; | ||
| const { skipIfSQLiteMissing } = require('../common/index.mjs'); | ||
| const { test } = require('node:test'); | ||
| const assert = require('node:assert'); | ||
| const { DatabaseSync } = require('node:sqlite'); | ||
| skipIfSQLiteMissing(); | ||
|
|
||
| function checkDefensiveMode(db) { | ||
| function journalMode() { | ||
| return db.prepare('PRAGMA journal_mode').get().journal_mode; | ||
| } | ||
|
|
||
| assert.strictEqual(journalMode(), 'memory'); | ||
| db.exec('PRAGMA journal_mode=OFF'); | ||
|
|
||
| switch (journalMode()) { | ||
| case 'memory': return true; // journal_mode unchanged, defensive mode must be active | ||
| case 'off': return false; // journal_mode now 'off', so defensive mode not active | ||
| default: throw new Error('unexpected journal_mode'); | ||
| } | ||
| } | ||
louwers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test('by default, defensive mode is off', (t) => { | ||
| const db = new DatabaseSync(':memory:'); | ||
| t.assert.strictEqual(checkDefensiveMode(db), false); | ||
| }); | ||
|
|
||
| test('when passing { defensive: true } as config, defensive mode is on', (t) => { | ||
| const db = new DatabaseSync(':memory:', { | ||
| defensive: true | ||
| }); | ||
| t.assert.strictEqual(checkDefensiveMode(db), true); | ||
| }); | ||
|
|
||
| test('defensive mode on after calling db.enableDefensive(true)', (t) => { | ||
| const db = new DatabaseSync(':memory:'); | ||
| db.enableDefensive(true); | ||
| t.assert.strictEqual(checkDefensiveMode(db), true); | ||
| }); | ||
|
|
||
| test('defensive mode should be off after calling db.enableDefensive(false)', (t) => { | ||
| const db = new DatabaseSync(':memory:', { | ||
| defensive: true | ||
| }); | ||
| db.enableDefensive(false); | ||
| t.assert.strictEqual(checkDefensiveMode(db), false); | ||
| }); | ||
|
|
||
| test('throws if options.defensive is provided but is not a boolean', (t) => { | ||
| t.assert.throws(() => { | ||
| new DatabaseSync(':memory:', { defensive: 42 }); | ||
| }, { | ||
| code: 'ERR_INVALID_ARG_TYPE', | ||
| message: 'The "options.defensive" argument must be a boolean.', | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.