| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0876a29 commit 2989311
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -440,6 +440,11 @@ wrapper around [`sqlite3_create_function_v2()`][]. | |||
| 440 | 440 | ||
| 441 | 441 | <!-- YAML | |
| 442 | 442 | added: v24.10.0 | |
| 443 | + changes: | ||
| 444 | + - version: REPLACEME | ||
| 445 | + pr-url: https://github.com/nodejs/node/pull/65156 | ||
| 446 | + description: Accessing the invoking database connection from the authorizer | ||
| 447 | + callback now throws. | ||
| 443 | 448 | --> | |
| 444 | 449 | ||
| 445 | 450 | * `callback` {Function|null} The authorizer function to set, or `null` to | |
@@ -465,6 +470,31 @@ The callback must return one of the following constants: | |||
| 465 | 470 | * `SQLITE_DENY` - Deny the operation (causes an error). | |
| 466 | 471 | * `SQLITE_IGNORE` - Ignore the operation (silently skip). | |
| 467 | 472 | ||
| 473 | + SQLite requires that the authorizer callback not modify the database connection | ||
| 474 | + that invoked it, which includes preparing and stepping statements. Methods that | ||
| 475 | + would do so throw an error with code `ERR_INVALID_STATE` while the callback is | ||
| 476 | + on the stack, including `database.prepare()`, `database.exec()`, the execution | ||
| 477 | + methods of that connection's statements, iterators, and tag stores, and | ||
| 478 | + `database.setAuthorizer()` itself. Other connections remain usable. | ||
| 479 | + | ||
| 480 | + The callback can also be invoked from within `statement.run()`, | ||
| 481 | + `statement.get()`, and similar methods, because SQLite may re-prepare a | ||
| 482 | + statement during execution after a schema change. | ||
| 483 | + | ||
| 484 | + Separately, a statement that is currently being executed cannot be reentered. | ||
| 485 | + Calling `statement.close()` on it would free the virtual machine that is | ||
| 486 | + running, and re-running it through `statement.run()`, `statement.get()`, | ||
| 487 | + `statement.all()`, `statement.iterate()`, `iterator.next()`, | ||
| 488 | + `iterator.return()`, or the equivalent tag store methods would reset that | ||
| 489 | + virtual machine mid-execution. All of these throw an `ERR_INVALID_STATE` error | ||
| 490 | + instead. This applies to any callback SQLite invokes during execution, such as a | ||
| 491 | + user-defined function. Other statements on the connection remain usable. | ||
| 492 | + | ||
| 493 | + Operations that touch no SQLite state stay available from the callback: | ||
| 494 | + `sqlTagStore.clear()`, which only drops cached statements, and `next()` and | ||
| 495 | + `return()` on an already-drained iterator, which keep returning | ||
| 496 | + `{ done: true }`. | ||
| 497 | + | ||
| 468 | 498 | ```cjs | |
| 469 | 499 | const { DatabaseSync, constants } = require('node:sqlite'); | |
| 470 | 500 | const db = new DatabaseSync(':memory:'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments