xref: /netbsd-src/external/public-domain/sqlite/man/sqlite3_temp_directory.3 (revision b9988867a8ad969c45a52aa7628bc932ec98d46b)
1.Dd January 24, 2024
2.Dt SQLITE3_TEMP_DIRECTORY 3
3.Os
4.Sh NAME
5.Nm sqlite3_temp_directory
6.Nd name of the folder holding temporary files
7.Sh SYNOPSIS
8.In sqlite3.h
9.Vt char *sqlite3_temp_directory;
10.Sh DESCRIPTION
11If this global variable is made to point to a string which is the name
12of a folder (a.k.a.
13directory), then all temporary files created by SQLite when using a
14built-in VFS will be placed in that directory.
15If this variable is a NULL pointer, then SQLite performs a search for
16an appropriate temporary file directory.
17.Pp
18Applications are strongly discouraged from using this global variable.
19It is required to set a temporary folder on Windows Runtime (WinRT).
20But for all other platforms, it is highly recommended that applications
21neither read nor write this variable.
22This global variable is a relic that exists for backwards compatibility
23of legacy applications and should be avoided in new projects.
24.Pp
25It is not safe to read or modify this variable in more than one thread
26at a time.
27It is not safe to read or modify this variable if a database connection
28is being used at the same time in a separate thread.
29It is intended that this variable be set once as part of process initialization
30and before any SQLite interface routines have been called and that
31this variable remain unchanged thereafter.
32.Pp
33The temp_store_directory pragma may modify
34this variable and cause it to point to memory obtained from sqlite3_malloc.
35Furthermore, the temp_store_directory pragma
36always assumes that any string that this variable points to is held
37in memory obtained from sqlite3_malloc and the pragma
38may attempt to free that memory using sqlite3_free.
39Hence, if this variable is modified directly, either it should be made
40NULL or made to point to memory obtained from sqlite3_malloc
41or else the use of the temp_store_directory pragma
42should be avoided.
43Except when requested by the temp_store_directory pragma,
44SQLite does not free the memory that sqlite3_temp_directory points
45to.
46If the application wants that memory to be freed, it must do so itself,
47taking care to only do so after all database connection
48objects have been destroyed.
49.Pp
50\fBNote to Windows Runtime users:\fP  The temporary directory must be set
51prior to calling sqlite3_open or sqlite3_open_v2.
52Otherwise, various features that require the use of temporary files
53may fail.
54Here is an example of how to do this using C++ with the Windows Runtime:
55.Bd -ragged
56.Bd -literal
57LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
58TemporaryFolder->Path->Data(); char zPathBuf[MAX_PATH + 1]; memset(zPathBuf,
590, sizeof(zPathBuf)); WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf,
60sizeof(zPathBuf),       NULL, NULL); sqlite3_temp_directory = sqlite3_mprintf("%s",
61zPathBuf);
62.Ed
63.Pp
64.Ed
65.Pp
66.Sh IMPLEMENTATION NOTES
67These declarations were extracted from the
68interface documentation at line 6424.
69.Bd -literal
70SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
71.Ed
72.Sh SEE ALSO
73.Xr sqlite3 3 ,
74.Xr sqlite3_malloc 3 ,
75.Xr sqlite3_open 3 ,
76.Xr sqlite3_vfs 3
77