xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_close.3 (revision b9988867a8ad969c45a52aa7628bc932ec98d46b)
1.Dd January 24, 2024
2.Dt SQLITE3_CLOSE 3
3.Os
4.Sh NAME
5.Nm sqlite3_close ,
6.Nm sqlite3_close_v2
7.Nd closing a database connection
8.Sh SYNOPSIS
9.In sqlite3.h
10.Ft int
11.Fo sqlite3_close
12.Fa "sqlite3*"
13.Fc
14.Ft int
15.Fo sqlite3_close_v2
16.Fa "sqlite3*"
17.Fc
18.Sh DESCRIPTION
19The sqlite3_close() and sqlite3_close_v2() routines are destructors
20for the sqlite3 object.
21Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK
22if the sqlite3 object is successfully destroyed and all associated
23resources are deallocated.
24.Pp
25Ideally, applications should finalize all prepared statements,
26close all BLOB handles, and finish all sqlite3_backup
27objects associated with the sqlite3 object prior to attempting
28to close the object.
29If the database connection is associated with unfinalized prepared
30statements, BLOB handlers, and/or unfinished sqlite3_backup objects
31then sqlite3_close() will leave the database connection open and return
32SQLITE_BUSY.
33If sqlite3_close_v2() is called with unfinalized prepared statements,
34unclosed BLOB handlers, and/or unfinished sqlite3_backups, it returns
35SQLITE_OK regardless, but instead of deallocating the database
36connection immediately, it marks the database connection as an unusable
37"zombie" and makes arrangements to automatically deallocate the database
38connection after all prepared statements are finalized, all BLOB handles
39are closed, and all backups have finished.
40The sqlite3_close_v2() interface is intended for use with host languages
41that are garbage collected, and where the order in which destructors
42are called is arbitrary.
43.Pp
44If an sqlite3 object is destroyed while a transaction is open,
45the transaction is automatically rolled back.
46.Pp
47The C parameter to sqlite3_close(C) and sqlite3_close_v2(C)
48must be either a NULL pointer or an sqlite3 object pointer obtained
49from
50.Fn sqlite3_open ,
51.Fn sqlite3_open16 ,
52or
53.Fn sqlite3_open_v2 ,
54and not previously closed.
55Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer argument
56is a harmless no-op.
57.Sh IMPLEMENTATION NOTES
58These declarations were extracted from the
59interface documentation at line 316.
60.Bd -literal
61SQLITE_API int sqlite3_close(sqlite3*);
62SQLITE_API int sqlite3_close_v2(sqlite3*);
63.Ed
64.Sh SEE ALSO
65.Xr sqlite3 3 ,
66.Xr sqlite3_backup 3 ,
67.Xr sqlite3_backup_init 3 ,
68.Xr sqlite3_blob 3 ,
69.Xr sqlite3_blob_close 3 ,
70.Xr sqlite3_finalize 3 ,
71.Xr sqlite3_open 3 ,
72.Xr sqlite3_stmt 3 ,
73.Xr SQLITE_OK 3
74