Skip to content

Commit 2bce512

Browse files
committed
document the need for finalizing prepared statements before closing the database
1 parent cf85619 commit 2bce512

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

docs/API.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ stmt.each([params...], callback, [complete]);
375375

376376
Finalizes the prepared statement, freeing resources.
377377

378+
> **Important:** You MUST finalize all prepared statements before closing the database.
379+
> If you attempt to close a database with unfinalized statements, you will get:
380+
> `SQLITE_BUSY: unable to close due to unfinalised statements`
381+
378382
```javascript
379383
stmt.finalize([callback]);
380384
```
@@ -762,6 +766,10 @@ const count = await stmt.each([params], callback);
762766

763767
Finalizes the statement.
764768

769+
> **Important:** You MUST finalize all prepared statements before closing the database.
770+
> If you attempt to close a database with unfinalized statements, you will get:
771+
> `SQLITE_BUSY: unable to close due to unfinalised statements`
772+
765773
```javascript
766774
await stmt.finalize();
767775
```

lib/promise/statement.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class SqliteStatement {
6060
/**
6161
* Finalizes a prepared statement (freeing any resource used by this statement)
6262
*
63+
* IMPORTANT: You MUST finalize all prepared statements before closing the database.
64+
* If you attempt to close a database with unfinalized statements, you will get:
65+
* SQLITE_BUSY: unable to close due to unfinalised statements
66+
*
6367
* @returns {Promise<void>}
6468
*/
6569
finalize() {

lib/sqlite3.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ export class SqliteStatement {
315315
callback?: (err: Error | null, row: T) => void,
316316
): Promise<number>;
317317

318+
/**
319+
* Finalizes the statement.
320+
* IMPORTANT: You MUST finalize all prepared statements before closing the database.
321+
* Otherwise you will get SQLITE_BUSY: unable to close due to unfinalised statements
322+
*/
318323
finalize(): Promise<void>;
319324
}
320325

0 commit comments

Comments
 (0)