xref: /netbsd-src/external/public-domain/sqlite/man/SQLITE_CONFIG_SINGLETHREAD.3 (revision a24efa7dea9f1f56c3bdb15a927d3516792ace1c)
1.Dd $Mdocdate$
2.Dt SQLITE_CONFIG_SINGLETHREAD 3
3.Os
4.Sh NAME
5.Nm SQLITE_CONFIG_SINGLETHREAD ,
6.Nm SQLITE_CONFIG_MULTITHREAD ,
7.Nm SQLITE_CONFIG_SERIALIZED ,
8.Nm SQLITE_CONFIG_MALLOC ,
9.Nm SQLITE_CONFIG_GETMALLOC ,
10.Nm SQLITE_CONFIG_SCRATCH ,
11.Nm SQLITE_CONFIG_PAGECACHE ,
12.Nm SQLITE_CONFIG_HEAP ,
13.Nm SQLITE_CONFIG_MEMSTATUS ,
14.Nm SQLITE_CONFIG_MUTEX ,
15.Nm SQLITE_CONFIG_GETMUTEX ,
16.Nm SQLITE_CONFIG_LOOKASIDE ,
17.Nm SQLITE_CONFIG_PCACHE ,
18.Nm SQLITE_CONFIG_GETPCACHE ,
19.Nm SQLITE_CONFIG_LOG ,
20.Nm SQLITE_CONFIG_URI ,
21.Nm SQLITE_CONFIG_PCACHE2 ,
22.Nm SQLITE_CONFIG_GETPCACHE2 ,
23.Nm SQLITE_CONFIG_COVERING_INDEX_SCAN ,
24.Nm SQLITE_CONFIG_SQLLOG ,
25.Nm SQLITE_CONFIG_MMAP_SIZE ,
26.Nm SQLITE_CONFIG_WIN32_HEAPSIZE
27.Nd Configuration Options
28.Sh SYNOPSIS
29.Fd #define SQLITE_CONFIG_SINGLETHREAD
30.Fd #define SQLITE_CONFIG_MULTITHREAD
31.Fd #define SQLITE_CONFIG_SERIALIZED
32.Fd #define SQLITE_CONFIG_MALLOC
33.Fd #define SQLITE_CONFIG_GETMALLOC
34.Fd #define SQLITE_CONFIG_SCRATCH
35.Fd #define SQLITE_CONFIG_PAGECACHE
36.Fd #define SQLITE_CONFIG_HEAP
37.Fd #define SQLITE_CONFIG_MEMSTATUS
38.Fd #define SQLITE_CONFIG_MUTEX
39.Fd #define SQLITE_CONFIG_GETMUTEX
40.Fd #define SQLITE_CONFIG_LOOKASIDE
41.Fd #define SQLITE_CONFIG_PCACHE
42.Fd #define SQLITE_CONFIG_GETPCACHE
43.Fd #define SQLITE_CONFIG_LOG
44.Fd #define SQLITE_CONFIG_URI
45.Fd #define SQLITE_CONFIG_PCACHE2
46.Fd #define SQLITE_CONFIG_GETPCACHE2
47.Fd #define SQLITE_CONFIG_COVERING_INDEX_SCAN
48.Fd #define SQLITE_CONFIG_SQLLOG
49.Fd #define SQLITE_CONFIG_MMAP_SIZE
50.Fd #define SQLITE_CONFIG_WIN32_HEAPSIZE
51.Sh DESCRIPTION
52These constants are the available integer configuration options that
53can be passed as the first argument to the sqlite3_config()
54interface.
55.Pp
56New configuration options may be added in future releases of SQLite.
57Existing configuration options might be discontinued.
58Applications should check the return code from sqlite3_config()
59to make sure that the call worked.
60The sqlite3_config() interface will return a non-zero
61error code if a discontinued or unsupported configuration
62option is invoked.
63.Bl -tag -width Ds
64.It SQLITE_CONFIG_SINGLETHREAD
65There are no arguments to this option.
66This option sets the threading mode to Single-thread.
67In other words, it disables all mutexing and puts SQLite into a mode
68where it can only be used by a single thread.
69If SQLite is compiled with the  SQLITE_THREADSAFE=0
70compile-time option then it is not possible to change the threading mode
71from its default value of Single-thread and so sqlite3_config()
72will return SQLITE_ERROR if called with the SQLITE_CONFIG_SINGLETHREAD
73configuration option.
74.It SQLITE_CONFIG_MULTITHREAD
75There are no arguments to this option.
76This option sets the threading mode to Multi-thread.
77In other words, it disables mutexing on database connection
78and prepared statement objects.
79The application is responsible for serializing access to database connections
80and prepared statements.
81But other mutexes are enabled so that SQLite will be safe to use in
82a multi-threaded environment as long as no two threads attempt to use
83the same database connection at the same time.
84If SQLite is compiled with the  SQLITE_THREADSAFE=0
85compile-time option then it is not possible to set the Multi-thread
86threading mode and sqlite3_config() will
87return SQLITE_ERROR if called with the SQLITE_CONFIG_MULTITHREAD
88configuration option.
89.It SQLITE_CONFIG_SERIALIZED
90There are no arguments to this option.
91This option sets the threading mode to Serialized.
92In other words, this option enables all mutexes including the recursive
93mutexes on database connection and prepared statement
94objects.
95In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1)
96the SQLite library will itself serialize access to database connections
97and prepared statements so that the application
98is free to use the same database connection or the
99same prepared statement in different threads at the
100same time.
101If SQLite is compiled with the  SQLITE_THREADSAFE=0
102compile-time option then it is not possible to set the Serialized threading mode
103and sqlite3_config() will return SQLITE_ERROR
104if called with the SQLITE_CONFIG_SERIALIZED configuration option.
105.It SQLITE_CONFIG_MALLOC
106This option takes a single argument which is a pointer to an instance
107of the sqlite3_mem_methods structure.
108The argument specifies alternative low-level memory allocation routines
109to be used in place of the memory allocation routines built into SQLite.
110SQLite makes its own private copy of the content of the sqlite3_mem_methods
111structure before the sqlite3_config() call returns.
112.It SQLITE_CONFIG_GETMALLOC
113This option takes a single argument which is a pointer to an instance
114of the sqlite3_mem_methods structure.
115The sqlite3_mem_methods structure is filled with
116the currently defined memory allocation routines.
117This option can be used to overload the default memory allocation routines
118with a wrapper that simulations memory allocation failure or tracks
119memory usage, for example.
120.It SQLITE_CONFIG_MEMSTATUS
121This option takes single argument of type int, interpreted as a boolean,
122which enables or disables the collection of memory allocation statistics.
123When memory allocation statistics are disabled, the following SQLite
124interfaces become non-operational:
125.Bl -bullet
126.It
127sqlite3_memory_used()
128.It
129sqlite3_memory_highwater()
130.It
131sqlite3_soft_heap_limit64()
132.It
133sqlite3_status()
134.El
135.Pp
136Memory allocation statistics are enabled by default unless SQLite is
137compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
138which case memory allocation statistics are disabled by default.
139.It SQLITE_CONFIG_SCRATCH
140This option specifies a static memory buffer that SQLite can use for
141scratch memory.
142There are three arguments:  A pointer an 8-byte aligned memory buffer
143from which the scratch allocations will be drawn, the size of each
144scratch allocation (sz), and the maximum number of scratch allocations
145(N).
146The sz argument must be a multiple of 16.
147The first argument must be a pointer to an 8-byte aligned buffer of
148at least sz*N bytes of memory.
149SQLite will use no more than two scratch buffers per thread.
150So N should be set to twice the expected maximum number of threads.
151SQLite will never require a scratch buffer that is more than 6 times
152the database page size.
153If SQLite needs needs additional scratch memory beyond what is provided
154by this configuration option, then sqlite3_malloc()
155will be used to obtain the memory needed.
156.It SQLITE_CONFIG_PAGECACHE
157This option specifies a static memory buffer that SQLite can use for
158the database page cache with the default page cache implementation.
159This configuration should not be used if an application-define page
160cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
161There are three arguments to this option: A pointer to 8-byte aligned
162memory, the size of each page buffer (sz), and the number of pages
163(N).
164The sz argument should be the size of the largest database page (a
165power of two between 512 and 32768) plus a little extra for each page
166header.
167The page header size is 20 to 40 bytes depending on the host architecture.
168It is harmless, apart from the wasted memory, to make sz a little too
169large.
170The first argument should point to an allocation of at least sz*N bytes
171of memory.
172SQLite will use the memory provided by the first argument to satisfy
173its memory needs for the first N pages that it adds to cache.
174If additional page cache memory is needed beyond what is provided by
175this option, then SQLite goes to sqlite3_malloc() for
176the additional storage space.
177The pointer in the first argument must be aligned to an 8-byte boundary
178or subsequent behavior of SQLite will be undefined.
179.It SQLITE_CONFIG_HEAP
180This option specifies a static memory buffer that SQLite will use for
181all of its dynamic memory allocation needs beyond those provided for
182by SQLITE_CONFIG_SCRATCH and SQLITE_CONFIG_PAGECACHE.
183There are three arguments: An 8-byte aligned pointer to the memory,
184the number of bytes in the memory buffer, and the minimum allocation
185size.
186If the first pointer (the memory pointer) is NULL, then SQLite reverts
187to using its default memory allocator (the system malloc() implementation),
188undoing any prior invocation of SQLITE_CONFIG_MALLOC.
189If the memory pointer is not NULL and either SQLITE_ENABLE_MEMSYS3
190or SQLITE_ENABLE_MEMSYS5 are defined, then the
191alternative memory allocator is engaged to handle all of SQLites memory
192allocation needs.
193The first pointer (the memory pointer) must be aligned to an 8-byte
194boundary or subsequent behavior of SQLite will be undefined.
195The minimum allocation size is capped at 2**12.
196Reasonable values for the minimum allocation size are 2**5 through
1972**8.
198.It SQLITE_CONFIG_MUTEX
199This option takes a single argument which is a pointer to an instance
200of the sqlite3_mutex_methods structure.
201The argument specifies alternative low-level mutex routines to be used
202in place the mutex routines built into SQLite.
203SQLite makes a copy of the content of the sqlite3_mutex_methods
204structure before the call to sqlite3_config() returns.
205If SQLite is compiled with the  SQLITE_THREADSAFE=0
206compile-time option then the entire mutexing subsystem is omitted from
207the build and hence calls to sqlite3_config() with
208the SQLITE_CONFIG_MUTEX configuration option will return SQLITE_ERROR.
209.It SQLITE_CONFIG_GETMUTEX
210This option takes a single argument which is a pointer to an instance
211of the sqlite3_mutex_methods structure.
212The sqlite3_mutex_methods structure is filled
213with the currently defined mutex routines.
214This option can be used to overload the default mutex allocation routines
215with a wrapper used to track mutex usage for performance profiling
216or testing, for example.
217If SQLite is compiled with the  SQLITE_THREADSAFE=0
218compile-time option then the entire mutexing subsystem is omitted from
219the build and hence calls to sqlite3_config() with
220the SQLITE_CONFIG_GETMUTEX configuration option will return SQLITE_ERROR.
221.It SQLITE_CONFIG_LOOKASIDE
222This option takes two arguments that determine the default memory allocation
223for the lookaside memory allocator on each database connection.
224The first argument is the size of each lookaside buffer slot and the
225second is the number of slots allocated to each database connection.
226This option sets the <i>default</i> lookaside size.
227The SQLITE_DBCONFIG_LOOKASIDE verb to sqlite3_db_config()
228can be used to change the lookaside configuration on individual connections.
229.It SQLITE_CONFIG_PCACHE2
230This option takes a single argument which is a pointer to an sqlite3_pcache_methods2
231object.
232This object specifies the interface to a custom page cache implementation.
233SQLite makes a copy of the object and uses it for page cache memory
234allocations.
235.It SQLITE_CONFIG_GETPCACHE2
236This option takes a single argument which is a pointer to an sqlite3_pcache_methods2
237object.
238SQLite copies of the current page cache implementation into that object.
239.It SQLITE_CONFIG_LOG
240The SQLITE_CONFIG_LOG option is used to configure the SQLite global
241error log.
242( The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
243function with a call signature of void(*)(void*,int,const char*), and
244a pointer to void.
245If the function pointer is not NULL, it is invoked by sqlite3_log()
246to process each logging event.
247If the function pointer is NULL, the sqlite3_log() interface
248becomes a no-op.
249The void pointer that is the second argument to SQLITE_CONFIG_LOG is
250passed through as the first parameter to the application-defined logger
251function whenever that function is invoked.
252The second parameter to the logger function is a copy of the first
253parameter to the corresponding sqlite3_log() call and
254is intended to be a result code or an extended result code.
255The third parameter passed to the logger is log message after formatting
256via sqlite3_snprintf().
257The SQLite logging interface is not reentrant; the logger function
258supplied by the application must not invoke any SQLite interface.
259In a multi-threaded application, the application-defined logger function
260must be threadsafe.
261.It SQLITE_CONFIG_URI This option takes a single argument of type int.
262If non-zero, then URI handling is globally enabled.
263If the parameter is zero, then URI handling is globally disabled.
264If URI handling is globally enabled, all filenames passed to sqlite3_open(),
265sqlite3_open_v2(), sqlite3_open16()
266or specified as part of ATTACH commands are interpreted as URIs,
267regardless of whether or not the SQLITE_OPEN_URI flag
268is set when the database connection is opened.
269If it is globally disabled, filenames are only interpreted as URIs
270if the SQLITE_OPEN_URI flag is set when the database connection is
271opened.
272By default, URI handling is globally disabled.
273The default value may be changed by compiling with the SQLITE_USE_URI
274symbol defined.
275.It SQLITE_CONFIG_COVERING_INDEX_SCAN This option takes a single integer
276argument which is interpreted as a boolean in order to enable or disable
277the use of covering indices for full table scans in the query optimizer.
278The default setting is determined by the SQLITE_ALLOW_COVERING_INDEX_SCAN
279compile-time option, or is "on" if that compile-time option is omitted.
280The ability to disable the use of covering indices for full table scans
281is because some incorrectly coded legacy applications might malfunction
282when the optimization is enabled.
283Providing the ability to disable the optimization allows the older,
284buggy application code to work without change even with newer versions
285of SQLite.
286.It SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE These options are
287obsolete and should not be used by new code.
288They are retained for backwards compatibility but are now no-ops.
289.It SQLITE_CONFIG_SQLLOG This option is only available if sqlite is compiled
290with the SQLITE_ENABLE_SQLLOG pre-processor macro
291defined.
292The first argument should be a pointer to a function of type void(*)(void*,sqlite3*,const
293char*, int).
294The second should be of type (void*).
295The callback is invoked by the library in three separate circumstances,
296identified by the value passed as the fourth parameter.
297If the fourth parameter is 0, then the database connection passed as
298the second argument has just been opened.
299The third argument points to a buffer containing the name of the main
300database file.
301If the fourth parameter is 1, then the SQL statement that the third
302parameter points to has just been executed.
303Or, if the fourth parameter is 2, then the connection being passed
304as the second parameter is being closed.
305The third parameter is passed NULL In this case.
306An example of using this configuration option can be seen in the "test_sqllog.c"
307source file in the canonical SQLite source tree.
308.It SQLITE_CONFIG_MMAP_SIZE SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer
309(sqlite3_int64) values that are the default mmap size limit (the default
310setting for PRAGMA mmap_size) and the maximum allowed
311mmap size limit.
312The default setting can be overridden by each database connection using
313either the PRAGMA mmap_size command, or by using the
314SQLITE_FCNTL_MMAP_SIZE file control.
315The maximum allowed mmap size cannot be changed at run-time.
316Nor may the maximum allowed mmap size exceed the compile-time maximum
317mmap size set by the SQLITE_MAX_MMAP_SIZE compile-time
318option.
319If either argument to this option is negative, then that argument is
320changed to its compile-time default.
321.It SQLITE_CONFIG_WIN32_HEAPSIZE This option is only available if SQLite
322is compiled for Windows with the SQLITE_WIN32_MALLOC
323pre-processor macro defined.
324SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
325that specifies the maximum size of the created heap.
326.El
327.Pp
328.Sh SEE ALSO
329.Xr sqlite3 3 ,
330.Xr SQLITE_OK 3 ,
331.Xr SQLITE_IOERR_READ 3 ,
332.Xr sqlite3_stmt 3 ,
333.Xr SQLITE_OK 3 ,
334.Xr sqlite3_config 3 ,
335.Xr sqlite3_db_config 3 ,
336.Xr sqlite3_log 3 ,
337.Xr sqlite3_malloc 3 ,
338.Xr sqlite3_mem_methods 3 ,
339.Xr sqlite3_memory_used 3 ,
340.Xr sqlite3_mutex_methods 3 ,
341.Xr sqlite3_open 3 ,
342.Xr sqlite3_pcache_methods2 3 ,
343.Xr sqlite3_mprintf 3 ,
344.Xr sqlite3_soft_heap_limit64 3 ,
345.Xr sqlite3_status 3 ,
346.Xr SQLITE_CONFIG_SINGLETHREAD 3 ,
347.Xr SQLITE_DBCONFIG_LOOKASIDE 3 ,
348.Xr SQLITE_OK 3 ,
349.Xr SQLITE_FCNTL_LOCKSTATE 3 ,
350.Xr SQLITE_OPEN_READONLY 3
351