Coverage Report

Created: 2024-05-21 06:46

/src/sqlite3/bld/sqlite3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
** This file is an amalgamation of many separate C source files from SQLite
3
** version 3.46.0.  By combining all the individual C code files into this
4
** single large file, the entire code can be compiled as a single translation
5
** unit.  This allows many compilers to do optimizations that would not be
6
** possible if the files were compiled separately.  Performance improvements
7
** of 5% or more are commonly seen when SQLite is compiled as a single
8
** translation unit.
9
**
10
** This file is all you need to compile SQLite.  To use SQLite in other
11
** programs, you need this file and the "sqlite3.h" header file that defines
12
** the programming interface to the SQLite library.  (If you do not have
13
** the "sqlite3.h" header file at hand, you will find a copy embedded within
14
** the text of this file.  Search for "Begin file sqlite3.h" to find the start
15
** of the embedded sqlite3.h header file.) Additional code files may be needed
16
** if you want a wrapper to interface SQLite with your choice of programming
17
** language. The code for the "sqlite3" command-line shell is also in a
18
** separate file. This file contains only code for the core SQLite library.
19
**
20
** The content in this amalgamation comes from Fossil check-in
21
** a60a0b75137c015e97b8dcd0070444fcb608.
22
*/
23
#define SQLITE_CORE 1
24
#define SQLITE_AMALGAMATION 1
25
#ifndef SQLITE_PRIVATE
26
# define SQLITE_PRIVATE static
27
#endif
28
/************** Begin file sqliteInt.h ***************************************/
29
/*
30
** 2001 September 15
31
**
32
** The author disclaims copyright to this source code.  In place of
33
** a legal notice, here is a blessing:
34
**
35
**    May you do good and not evil.
36
**    May you find forgiveness for yourself and forgive others.
37
**    May you share freely, never taking more than you give.
38
**
39
*************************************************************************
40
** Internal interface definitions for SQLite.
41
**
42
*/
43
#ifndef SQLITEINT_H
44
#define SQLITEINT_H
45
46
/* Special Comments:
47
**
48
** Some comments have special meaning to the tools that measure test
49
** coverage:
50
**
51
**    NO_TEST                     - The branches on this line are not
52
**                                  measured by branch coverage.  This is
53
**                                  used on lines of code that actually
54
**                                  implement parts of coverage testing.
55
**
56
**    OPTIMIZATION-IF-TRUE        - This branch is allowed to always be false
57
**                                  and the correct answer is still obtained,
58
**                                  though perhaps more slowly.
59
**
60
**    OPTIMIZATION-IF-FALSE       - This branch is allowed to always be true
61
**                                  and the correct answer is still obtained,
62
**                                  though perhaps more slowly.
63
**
64
**    PREVENTS-HARMLESS-OVERREAD  - This branch prevents a buffer overread
65
**                                  that would be harmless and undetectable
66
**                                  if it did occur.
67
**
68
** In all cases, the special comment must be enclosed in the usual
69
** slash-asterisk...asterisk-slash comment marks, with no spaces between the
70
** asterisks and the comment text.
71
*/
72
73
/*
74
** Make sure the Tcl calling convention macro is defined.  This macro is
75
** only used by test code and Tcl integration code.
76
*/
77
#ifndef SQLITE_TCLAPI
78
#  define SQLITE_TCLAPI
79
#endif
80
81
/*
82
** Include the header file used to customize the compiler options for MSVC.
83
** This should be done first so that it can successfully prevent spurious
84
** compiler warnings due to subsequent content in this file and other files
85
** that are included by this file.
86
*/
87
/************** Include msvc.h in the middle of sqliteInt.h ******************/
88
/************** Begin file msvc.h ********************************************/
89
/*
90
** 2015 January 12
91
**
92
** The author disclaims copyright to this source code.  In place of
93
** a legal notice, here is a blessing:
94
**
95
**    May you do good and not evil.
96
**    May you find forgiveness for yourself and forgive others.
97
**    May you share freely, never taking more than you give.
98
**
99
******************************************************************************
100
**
101
** This file contains code that is specific to MSVC.
102
*/
103
#ifndef SQLITE_MSVC_H
104
#define SQLITE_MSVC_H
105
106
#if defined(_MSC_VER)
107
#pragma warning(disable : 4054)
108
#pragma warning(disable : 4055)
109
#pragma warning(disable : 4100)
110
#pragma warning(disable : 4127)
111
#pragma warning(disable : 4130)
112
#pragma warning(disable : 4152)
113
#pragma warning(disable : 4189)
114
#pragma warning(disable : 4206)
115
#pragma warning(disable : 4210)
116
#pragma warning(disable : 4232)
117
#pragma warning(disable : 4244)
118
#pragma warning(disable : 4305)
119
#pragma warning(disable : 4306)
120
#pragma warning(disable : 4702)
121
#pragma warning(disable : 4706)
122
#endif /* defined(_MSC_VER) */
123
124
#if defined(_MSC_VER) && !defined(_WIN64)
125
#undef SQLITE_4_BYTE_ALIGNED_MALLOC
126
#define SQLITE_4_BYTE_ALIGNED_MALLOC
127
#endif /* defined(_MSC_VER) && !defined(_WIN64) */
128
129
#if !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800
130
#define HAVE_LOG2 0
131
#endif /* !defined(HAVE_LOG2) && defined(_MSC_VER) && _MSC_VER<1800 */
132
133
#endif /* SQLITE_MSVC_H */
134
135
/************** End of msvc.h ************************************************/
136
/************** Continuing where we left off in sqliteInt.h ******************/
137
138
/*
139
** Special setup for VxWorks
140
*/
141
/************** Include vxworks.h in the middle of sqliteInt.h ***************/
142
/************** Begin file vxworks.h *****************************************/
143
/*
144
** 2015-03-02
145
**
146
** The author disclaims copyright to this source code.  In place of
147
** a legal notice, here is a blessing:
148
**
149
**    May you do good and not evil.
150
**    May you find forgiveness for yourself and forgive others.
151
**    May you share freely, never taking more than you give.
152
**
153
******************************************************************************
154
**
155
** This file contains code that is specific to Wind River's VxWorks
156
*/
157
#if defined(__RTP__) || defined(_WRS_KERNEL)
158
/* This is VxWorks.  Set up things specially for that OS
159
*/
160
#include <vxWorks.h>
161
#include <pthread.h>  /* amalgamator: dontcache */
162
#define OS_VXWORKS 1
163
#define SQLITE_OS_OTHER 0
164
#define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1
165
#define SQLITE_OMIT_LOAD_EXTENSION 1
166
#define SQLITE_ENABLE_LOCKING_STYLE 0
167
#define HAVE_UTIME 1
168
#else
169
/* This is not VxWorks. */
170
0
#define OS_VXWORKS 0
171
#define HAVE_FCHOWN 1
172
#define HAVE_READLINK 1
173
#define HAVE_LSTAT 1
174
#endif /* defined(_WRS_KERNEL) */
175
176
/************** End of vxworks.h *********************************************/
177
/************** Continuing where we left off in sqliteInt.h ******************/
178
179
/*
180
** These #defines should enable >2GB file support on POSIX if the
181
** underlying operating system supports it.  If the OS lacks
182
** large file support, or if the OS is windows, these should be no-ops.
183
**
184
** Ticket #2739:  The _LARGEFILE_SOURCE macro must appear before any
185
** system #includes.  Hence, this block of code must be the very first
186
** code in all source files.
187
**
188
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
189
** on the compiler command line.  This is necessary if you are compiling
190
** on a recent machine (ex: Red Hat 7.2) but you want your code to work
191
** on an older machine (ex: Red Hat 6.0).  If you compile on Red Hat 7.2
192
** without this option, LFS is enable.  But LFS does not exist in the kernel
193
** in Red Hat 6.0, so the code won't work.  Hence, for maximum binary
194
** portability you should omit LFS.
195
**
196
** The previous paragraph was written in 2005.  (This paragraph is written
197
** on 2008-11-28.) These days, all Linux kernels support large files, so
198
** you should probably leave LFS enabled.  But some embedded platforms might
199
** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
200
**
201
** Similar is true for Mac OS X.  LFS is only supported on Mac OS X 9 and later.
202
*/
203
#ifndef SQLITE_DISABLE_LFS
204
# define _LARGE_FILE       1
205
# ifndef _FILE_OFFSET_BITS
206
#   define _FILE_OFFSET_BITS 64
207
# endif
208
# define _LARGEFILE_SOURCE 1
209
#endif
210
211
/* The GCC_VERSION and MSVC_VERSION macros are used to
212
** conditionally include optimizations for each of these compilers.  A
213
** value of 0 means that compiler is not being used.  The
214
** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
215
** optimizations, and hence set all compiler macros to 0
216
**
217
** There was once also a CLANG_VERSION macro.  However, we learn that the
218
** version numbers in clang are for "marketing" only and are inconsistent
219
** and unreliable.  Fortunately, all versions of clang also recognize the
220
** gcc version numbers and have reasonable settings for gcc version numbers,
221
** so the GCC_VERSION macro will be set to a correct non-zero value even
222
** when compiling with clang.
223
*/
224
#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
225
# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
226
#else
227
# define GCC_VERSION 0
228
#endif
229
#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
230
# define MSVC_VERSION _MSC_VER
231
#else
232
# define MSVC_VERSION 0
233
#endif
234
235
/*
236
** Some C99 functions in "math.h" are only present for MSVC when its version
237
** is associated with Visual Studio 2013 or higher.
238
*/
239
#ifndef SQLITE_HAVE_C99_MATH_FUNCS
240
# if MSVC_VERSION==0 || MSVC_VERSION>=1800
241
#  define SQLITE_HAVE_C99_MATH_FUNCS (1)
242
# else
243
#  define SQLITE_HAVE_C99_MATH_FUNCS (0)
244
# endif
245
#endif
246
247
/* Needed for various definitions... */
248
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
249
# define _GNU_SOURCE
250
#endif
251
252
#if defined(__OpenBSD__) && !defined(_BSD_SOURCE)
253
# define _BSD_SOURCE
254
#endif
255
256
/*
257
** Macro to disable warnings about missing "break" at the end of a "case".
258
*/
259
#if GCC_VERSION>=7000000
260
# define deliberate_fall_through __attribute__((fallthrough));
261
#else
262
# define deliberate_fall_through
263
#endif
264
265
/*
266
** For MinGW, check to see if we can include the header file containing its
267
** version information, among other things.  Normally, this internal MinGW
268
** header file would [only] be included automatically by other MinGW header
269
** files; however, the contained version information is now required by this
270
** header file to work around binary compatibility issues (see below) and
271
** this is the only known way to reliably obtain it.  This entire #if block
272
** would be completely unnecessary if there was any other way of detecting
273
** MinGW via their preprocessor (e.g. if they customized their GCC to define
274
** some MinGW-specific macros).  When compiling for MinGW, either the
275
** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be
276
** defined; otherwise, detection of conditions specific to MinGW will be
277
** disabled.
278
*/
279
#if defined(_HAVE_MINGW_H)
280
# include "mingw.h"
281
#elif defined(_HAVE__MINGW_H)
282
# include "_mingw.h"
283
#endif
284
285
/*
286
** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T
287
** define is required to maintain binary compatibility with the MSVC runtime
288
** library in use (e.g. for Windows XP).
289
*/
290
#if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \
291
    defined(_WIN32) && !defined(_WIN64) && \
292
    defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \
293
    defined(__MSVCRT__)
294
# define _USE_32BIT_TIME_T
295
#endif
296
297
/* Optionally #include a user-defined header, whereby compilation options
298
** may be set prior to where they take effect, but after platform setup.
299
** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
300
** file.
301
*/
302
#ifdef SQLITE_CUSTOM_INCLUDE
303
# define INC_STRINGIFY_(f) #f
304
# define INC_STRINGIFY(f) INC_STRINGIFY_(f)
305
# include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE)
306
#endif
307
308
/* The public SQLite interface.  The _FILE_OFFSET_BITS macro must appear
309
** first in QNX.  Also, the _USE_32BIT_TIME_T macro must appear first for
310
** MinGW.
311
*/
312
/************** Include sqlite3.h in the middle of sqliteInt.h ***************/
313
/************** Begin file sqlite3.h *****************************************/
314
/*
315
** 2001-09-15
316
**
317
** The author disclaims copyright to this source code.  In place of
318
** a legal notice, here is a blessing:
319
**
320
**    May you do good and not evil.
321
**    May you find forgiveness for yourself and forgive others.
322
**    May you share freely, never taking more than you give.
323
**
324
*************************************************************************
325
** This header file defines the interface that the SQLite library
326
** presents to client programs.  If a C-function, structure, datatype,
327
** or constant definition does not appear in this file, then it is
328
** not a published API of SQLite, is subject to change without
329
** notice, and should not be referenced by programs that use SQLite.
330
**
331
** Some of the definitions that are in this file are marked as
332
** "experimental".  Experimental interfaces are normally new
333
** features recently added to SQLite.  We do not anticipate changes
334
** to experimental interfaces but reserve the right to make minor changes
335
** if experience from use "in the wild" suggest such changes are prudent.
336
**
337
** The official C-language API documentation for SQLite is derived
338
** from comments in this file.  This file is the authoritative source
339
** on how SQLite interfaces are supposed to operate.
340
**
341
** The name of this file under configuration management is "sqlite.h.in".
342
** The makefile makes some minor changes to this file (such as inserting
343
** the version number) and changes its name to "sqlite3.h" as
344
** part of the build process.
345
*/
346
#ifndef SQLITE3_H
347
#define SQLITE3_H
348
#include <stdarg.h>     /* Needed for the definition of va_list */
349
350
/*
351
** Make sure we can call this stuff from C++.
352
*/
353
#if 0
354
extern "C" {
355
#endif
356
357
358
/*
359
** Facilitate override of interface linkage and calling conventions.
360
** Be aware that these macros may not be used within this particular
361
** translation of the amalgamation and its associated header file.
362
**
363
** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
364
** compiler that the target identifier should have external linkage.
365
**
366
** The SQLITE_CDECL macro is used to set the calling convention for
367
** public functions that accept a variable number of arguments.
368
**
369
** The SQLITE_APICALL macro is used to set the calling convention for
370
** public functions that accept a fixed number of arguments.
371
**
372
** The SQLITE_STDCALL macro is no longer used and is now deprecated.
373
**
374
** The SQLITE_CALLBACK macro is used to set the calling convention for
375
** function pointers.
376
**
377
** The SQLITE_SYSAPI macro is used to set the calling convention for
378
** functions provided by the operating system.
379
**
380
** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
381
** SQLITE_SYSAPI macros are used only when building for environments
382
** that require non-default calling conventions.
383
*/
384
#ifndef SQLITE_EXTERN
385
# define SQLITE_EXTERN extern
386
#endif
387
#ifndef SQLITE_API
388
# define SQLITE_API
389
#endif
390
#ifndef SQLITE_CDECL
391
# define SQLITE_CDECL
392
#endif
393
#ifndef SQLITE_APICALL
394
# define SQLITE_APICALL
395
#endif
396
#ifndef SQLITE_STDCALL
397
# define SQLITE_STDCALL SQLITE_APICALL
398
#endif
399
#ifndef SQLITE_CALLBACK
400
# define SQLITE_CALLBACK
401
#endif
402
#ifndef SQLITE_SYSAPI
403
# define SQLITE_SYSAPI
404
#endif
405
406
/*
407
** These no-op macros are used in front of interfaces to mark those
408
** interfaces as either deprecated or experimental.  New applications
409
** should not use deprecated interfaces - they are supported for backwards
410
** compatibility only.  Application writers should be aware that
411
** experimental interfaces are subject to change in point releases.
412
**
413
** These macros used to resolve to various kinds of compiler magic that
414
** would generate warning messages when they were used.  But that
415
** compiler magic ended up generating such a flurry of bug reports
416
** that we have taken it all out and gone back to using simple
417
** noop macros.
418
*/
419
#define SQLITE_DEPRECATED
420
#define SQLITE_EXPERIMENTAL
421
422
/*
423
** Ensure these symbols were not defined by some previous header file.
424
*/
425
#ifdef SQLITE_VERSION
426
# undef SQLITE_VERSION
427
#endif
428
#ifdef SQLITE_VERSION_NUMBER
429
# undef SQLITE_VERSION_NUMBER
430
#endif
431
432
/*
433
** CAPI3REF: Compile-Time Library Version Numbers
434
**
435
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
436
** evaluates to a string literal that is the SQLite version in the
437
** format "X.Y.Z" where X is the major version number (always 3 for
438
** SQLite3) and Y is the minor version number and Z is the release number.)^
439
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
440
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
441
** numbers used in [SQLITE_VERSION].)^
442
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
443
** be larger than the release from which it is derived.  Either Y will
444
** be held constant and Z will be incremented or else Y will be incremented
445
** and Z will be reset to zero.
446
**
447
** Since [version 3.6.18] ([dateof:3.6.18]),
448
** SQLite source code has been stored in the
449
** <a href="http://www.fossil-scm.org/">Fossil configuration management
450
** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
451
** a string which identifies a particular check-in of SQLite
452
** within its configuration management system.  ^The SQLITE_SOURCE_ID
453
** string contains the date and time of the check-in (UTC) and a SHA1
454
** or SHA3-256 hash of the entire source tree.  If the source code has
455
** been edited in any way since it was last checked in, then the last
456
** four hexadecimal digits of the hash may be modified.
457
**
458
** See also: [sqlite3_libversion()],
459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460
** [sqlite_version()] and [sqlite_source_id()].
461
*/
462
#define SQLITE_VERSION        "3.46.0"
463
0
#define SQLITE_VERSION_NUMBER 3046000
464
5.44k
#define SQLITE_SOURCE_ID      "2024-05-20 19:59:32 a60a0b75137c015e97b8dcd0070444fcb608f502ce88b2ee744dd6230dbdc120"
465
466
/*
467
** CAPI3REF: Run-Time Library Version Numbers
468
** KEYWORDS: sqlite3_version sqlite3_sourceid
469
**
470
** These interfaces provide the same information as the [SQLITE_VERSION],
471
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
472
** but are associated with the library instead of the header file.  ^(Cautious
473
** programmers might include assert() statements in their application to
474
** verify that values returned by these interfaces match the macros in
475
** the header, and thus ensure that the application is
476
** compiled with matching library and header files.
477
**
478
** <blockquote><pre>
479
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
480
** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
481
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
482
** </pre></blockquote>)^
483
**
484
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
485
** macro.  ^The sqlite3_libversion() function returns a pointer to the
486
** to the sqlite3_version[] string constant.  The sqlite3_libversion()
487
** function is provided for use in DLLs since DLL users usually do not have
488
** direct access to string constants within the DLL.  ^The
489
** sqlite3_libversion_number() function returns an integer equal to
490
** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns
491
** a pointer to a string constant whose value is the same as the
492
** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
493
** using an edited copy of [the amalgamation], then the last four characters
494
** of the hash might be different from [SQLITE_SOURCE_ID].)^
495
**
496
** See also: [sqlite_version()] and [sqlite_source_id()].
497
*/
498
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
499
SQLITE_API const char *sqlite3_libversion(void);
500
SQLITE_API const char *sqlite3_sourceid(void);
501
SQLITE_API int sqlite3_libversion_number(void);
502
503
/*
504
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
505
**
506
** ^The sqlite3_compileoption_used() function returns 0 or 1
507
** indicating whether the specified option was defined at
508
** compile time.  ^The SQLITE_ prefix may be omitted from the
509
** option name passed to sqlite3_compileoption_used().
510
**
511
** ^The sqlite3_compileoption_get() function allows iterating
512
** over the list of options that were defined at compile time by
513
** returning the N-th compile time option string.  ^If N is out of range,
514
** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_
515
** prefix is omitted from any strings returned by
516
** sqlite3_compileoption_get().
517
**
518
** ^Support for the diagnostic functions sqlite3_compileoption_used()
519
** and sqlite3_compileoption_get() may be omitted by specifying the
520
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
521
**
522
** See also: SQL functions [sqlite_compileoption_used()] and
523
** [sqlite_compileoption_get()] and the [compile_options pragma].
524
*/
525
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
526
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
527
SQLITE_API const char *sqlite3_compileoption_get(int N);
528
#else
529
# define sqlite3_compileoption_used(X) 0
530
# define sqlite3_compileoption_get(X)  ((void*)0)
531
#endif
532
533
/*
534
** CAPI3REF: Test To See If The Library Is Threadsafe
535
**
536
** ^The sqlite3_threadsafe() function returns zero if and only if
537
** SQLite was compiled with mutexing code omitted due to the
538
** [SQLITE_THREADSAFE] compile-time option being set to 0.
539
**
540
** SQLite can be compiled with or without mutexes.  When
541
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
542
** are enabled and SQLite is threadsafe.  When the
543
** [SQLITE_THREADSAFE] macro is 0,
544
** the mutexes are omitted.  Without the mutexes, it is not safe
545
** to use SQLite concurrently from more than one thread.
546
**
547
** Enabling mutexes incurs a measurable performance penalty.
548
** So if speed is of utmost importance, it makes sense to disable
549
** the mutexes.  But for maximum safety, mutexes should be enabled.
550
** ^The default behavior is for mutexes to be enabled.
551
**
552
** This interface can be used by an application to make sure that the
553
** version of SQLite that it is linking against was compiled with
554
** the desired setting of the [SQLITE_THREADSAFE] macro.
555
**
556
** This interface only reports on the compile-time mutex setting
557
** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
558
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
559
** can be fully or partially disabled using a call to [sqlite3_config()]
560
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
561
** or [SQLITE_CONFIG_SERIALIZED].  ^(The return value of the
562
** sqlite3_threadsafe() function shows only the compile-time setting of
563
** thread safety, not any run-time changes to that setting made by
564
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
565
** is unchanged by calls to sqlite3_config().)^
566
**
567
** See the [threading mode] documentation for additional information.
568
*/
569
SQLITE_API int sqlite3_threadsafe(void);
570
571
/*
572
** CAPI3REF: Database Connection Handle
573
** KEYWORDS: {database connection} {database connections}
574
**
575
** Each open SQLite database is represented by a pointer to an instance of
576
** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
577
** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
578
** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
579
** and [sqlite3_close_v2()] are its destructors.  There are many other
580
** interfaces (such as
581
** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
582
** [sqlite3_busy_timeout()] to name but three) that are methods on an
583
** sqlite3 object.
584
*/
585
typedef struct sqlite3 sqlite3;
586
587
/*
588
** CAPI3REF: 64-Bit Integer Types
589
** KEYWORDS: sqlite_int64 sqlite_uint64
590
**
591
** Because there is no cross-platform way to specify 64-bit integer types
592
** SQLite includes typedefs for 64-bit signed and unsigned integers.
593
**
594
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
595
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
596
** compatibility only.
597
**
598
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
599
** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
600
** sqlite3_uint64 and sqlite_uint64 types can store integer values
601
** between 0 and +18446744073709551615 inclusive.
602
*/
603
#ifdef SQLITE_INT64_TYPE
604
  typedef SQLITE_INT64_TYPE sqlite_int64;
605
# ifdef SQLITE_UINT64_TYPE
606
    typedef SQLITE_UINT64_TYPE sqlite_uint64;
607
# else
608
    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
609
# endif
610
#elif defined(_MSC_VER) || defined(__BORLANDC__)
611
  typedef __int64 sqlite_int64;
612
  typedef unsigned __int64 sqlite_uint64;
613
#else
614
  typedef long long int sqlite_int64;
615
  typedef unsigned long long int sqlite_uint64;
616
#endif
617
typedef sqlite_int64 sqlite3_int64;
618
typedef sqlite_uint64 sqlite3_uint64;
619
620
/*
621
** If compiling for a processor that lacks floating point support,
622
** substitute integer for floating-point.
623
*/
624
#ifdef SQLITE_OMIT_FLOATING_POINT
625
# define double sqlite3_int64
626
#endif
627
628
/*
629
** CAPI3REF: Closing A Database Connection
630
** DESTRUCTOR: sqlite3
631
**
632
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
633
** for the [sqlite3] object.
634
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
635
** the [sqlite3] object is successfully destroyed and all associated
636
** resources are deallocated.
637
**
638
** Ideally, applications should [sqlite3_finalize | finalize] all
639
** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and
640
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
641
** with the [sqlite3] object prior to attempting to close the object.
642
** ^If the database connection is associated with unfinalized prepared
643
** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
644
** sqlite3_close() will leave the database connection open and return
645
** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
646
** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
647
** it returns [SQLITE_OK] regardless, but instead of deallocating the database
648
** connection immediately, it marks the database connection as an unusable
649
** "zombie" and makes arrangements to automatically deallocate the database
650
** connection after all prepared statements are finalized, all BLOB handles
651
** are closed, and all backups have finished. The sqlite3_close_v2() interface
652
** is intended for use with host languages that are garbage collected, and
653
** where the order in which destructors are called is arbitrary.
654
**
655
** ^If an [sqlite3] object is destroyed while a transaction is open,
656
** the transaction is automatically rolled back.
657
**
658
** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
659
** must be either a NULL
660
** pointer or an [sqlite3] object pointer obtained
661
** from [sqlite3_open()], [sqlite3_open16()], or
662
** [sqlite3_open_v2()], and not previously closed.
663
** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
664
** argument is a harmless no-op.
665
*/
666
SQLITE_API int sqlite3_close(sqlite3*);
667
SQLITE_API int sqlite3_close_v2(sqlite3*);
668
669
/*
670
** The type for a callback function.
671
** This is legacy and deprecated.  It is included for historical
672
** compatibility and is not documented.
673
*/
674
typedef int (*sqlite3_callback)(void*,int,char**, char**);
675
676
/*
677
** CAPI3REF: One-Step Query Execution Interface
678
** METHOD: sqlite3
679
**
680
** The sqlite3_exec() interface is a convenience wrapper around
681
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
682
** that allows an application to run multiple statements of SQL
683
** without having to use a lot of C code.
684
**
685
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
686
** semicolon-separate SQL statements passed into its 2nd argument,
687
** in the context of the [database connection] passed in as its 1st
688
** argument.  ^If the callback function of the 3rd argument to
689
** sqlite3_exec() is not NULL, then it is invoked for each result row
690
** coming out of the evaluated SQL statements.  ^The 4th argument to
691
** sqlite3_exec() is relayed through to the 1st argument of each
692
** callback invocation.  ^If the callback pointer to sqlite3_exec()
693
** is NULL, then no callback is ever invoked and result rows are
694
** ignored.
695
**
696
** ^If an error occurs while evaluating the SQL statements passed into
697
** sqlite3_exec(), then execution of the current statement stops and
698
** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
699
** is not NULL then any error message is written into memory obtained
700
** from [sqlite3_malloc()] and passed back through the 5th parameter.
701
** To avoid memory leaks, the application should invoke [sqlite3_free()]
702
** on error message strings returned through the 5th parameter of
703
** sqlite3_exec() after the error message string is no longer needed.
704
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
705
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
706
** NULL before returning.
707
**
708
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
709
** routine returns SQLITE_ABORT without invoking the callback again and
710
** without running any subsequent SQL statements.
711
**
712
** ^The 2nd argument to the sqlite3_exec() callback function is the
713
** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
714
** callback is an array of pointers to strings obtained as if from
715
** [sqlite3_column_text()], one for each column.  ^If an element of a
716
** result row is NULL then the corresponding string pointer for the
717
** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
718
** sqlite3_exec() callback is an array of pointers to strings where each
719
** entry represents the name of corresponding result column as obtained
720
** from [sqlite3_column_name()].
721
**
722
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
723
** to an empty string, or a pointer that contains only whitespace and/or
724
** SQL comments, then no SQL statements are evaluated and the database
725
** is not changed.
726
**
727
** Restrictions:
728
**
729
** <ul>
730
** <li> The application must ensure that the 1st parameter to sqlite3_exec()
731
**      is a valid and open [database connection].
732
** <li> The application must not close the [database connection] specified by
733
**      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
734
** <li> The application must not modify the SQL statement text passed into
735
**      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
736
** <li> The application must not dereference the arrays or string pointers
737
**       passed as the 3rd and 4th callback parameters after it returns.
738
** </ul>
739
*/
740
SQLITE_API int sqlite3_exec(
741
  sqlite3*,                                  /* An open database */
742
  const char *sql,                           /* SQL to be evaluated */
743
  int (*callback)(void*,int,char**,char**),  /* Callback function */
744
  void *,                                    /* 1st argument to callback */
745
  char **errmsg                              /* Error msg written here */
746
);
747
748
/*
749
** CAPI3REF: Result Codes
750
** KEYWORDS: {result code definitions}
751
**
752
** Many SQLite functions return an integer result code from the set shown
753
** here in order to indicate success or failure.
754
**
755
** New error codes may be added in future versions of SQLite.
756
**
757
** See also: [extended result code definitions]
758
*/
759
2.19G
#define SQLITE_OK           0   /* Successful result */
760
/* beginning-of-error-codes */
761
154k
#define SQLITE_ERROR        1   /* Generic error */
762
0
#define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
763
0
#define SQLITE_PERM         3   /* Access permission denied */
764
212k
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
765
5.54M
#define SQLITE_BUSY         5   /* The database file is locked */
766
2.37k
#define SQLITE_LOCKED       6   /* A table in the database is locked */
767
8.64M
#define SQLITE_NOMEM        7   /* A malloc() failed */
768
69.7k
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
769
3.07M
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
770
45.0M
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
771
8.38k
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
772
458k
#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
773
23.3M
#define SQLITE_FULL        13   /* Insertion failed because database is full */
774
115k
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
775
0
#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
776
23.2M
#define SQLITE_EMPTY       16   /* Internal use only */
777
3.37M
#define SQLITE_SCHEMA      17   /* The database schema changed */
778
5.44k
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
779
92.8k
#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
780
25
#define SQLITE_MISMATCH    20   /* Data type mismatch */
781
0
#define SQLITE_MISUSE      21   /* Library used incorrectly */
782
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
783
2
#define SQLITE_AUTH        23   /* Authorization denied */
784
#define SQLITE_FORMAT      24   /* Not used */
785
0
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
786
191k
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
787
0
#define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
788
47.7k
#define SQLITE_WARNING     28   /* Warnings from sqlite3_log() */
789
7.19M
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
790
14.1M
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
791
/* end-of-error-codes */
792
793
/*
794
** CAPI3REF: Extended Result Codes
795
** KEYWORDS: {extended result code definitions}
796
**
797
** In its default configuration, SQLite API routines return one of 30 integer
798
** [result codes].  However, experience has shown that many of
799
** these result codes are too coarse-grained.  They do not provide as
800
** much information about problems as programmers might like.  In an effort to
801
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
802
** and later) include
803
** support for additional result codes that provide more detailed information
804
** about errors. These [extended result codes] are enabled or disabled
805
** on a per database connection basis using the
806
** [sqlite3_extended_result_codes()] API.  Or, the extended code for
807
** the most recent error can be obtained using
808
** [sqlite3_extended_errcode()].
809
*/
810
652
#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
811
22.8k
#define SQLITE_ERROR_RETRY             (SQLITE_ERROR | (2<<8))
812
#define SQLITE_ERROR_SNAPSHOT          (SQLITE_ERROR | (3<<8))
813
0
#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
814
33.2M
#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
815
0
#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
816
#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
817
#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
818
#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
819
0
#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
820
0
#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
821
0
#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
822
#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
823
#define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
824
121k
#define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
825
0
#define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
826
0
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
827
0
#define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
828
0
#define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
829
#define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
830
#define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
831
0
#define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
832
0
#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
833
#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
834
#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
835
0
#define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
836
#define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
837
0
#define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
838
#define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
839
#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
840
#define SQLITE_IOERR_AUTH              (SQLITE_IOERR | (28<<8))
841
#define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
842
#define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
843
#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
844
#define SQLITE_IOERR_DATA              (SQLITE_IOERR | (32<<8))
845
1.53k
#define SQLITE_IOERR_CORRUPTFS         (SQLITE_IOERR | (33<<8))
846
#define SQLITE_IOERR_IN_PAGE           (SQLITE_IOERR | (34<<8))
847
0
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
848
#define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
849
0
#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
850
0
#define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
851
#define SQLITE_BUSY_TIMEOUT            (SQLITE_BUSY   |  (3<<8))
852
#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
853
#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
854
#define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
855
#define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
856
#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
857
0
#define SQLITE_CANTOPEN_SYMLINK        (SQLITE_CANTOPEN | (6<<8))
858
#define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
859
0
#define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
860
1
#define SQLITE_CORRUPT_INDEX           (SQLITE_CORRUPT | (3<<8))
861
0
#define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
862
#define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
863
0
#define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
864
0
#define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
865
0
#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
866
0
#define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
867
12.9k
#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
868
4.08k
#define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
869
0
#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
870
1.60k
#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
871
#define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
872
10.8k
#define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
873
14.0k
#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
874
0
#define SQLITE_CONSTRAINT_TRIGGER      (SQLITE_CONSTRAINT | (7<<8))
875
24.1k
#define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
876
#define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
877
2.30k
#define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
878
0
#define SQLITE_CONSTRAINT_PINNED       (SQLITE_CONSTRAINT |(11<<8))
879
1
#define SQLITE_CONSTRAINT_DATATYPE     (SQLITE_CONSTRAINT |(12<<8))
880
0
#define SQLITE_NOTICE_RECOVER_WAL      (SQLITE_NOTICE | (1<<8))
881
0
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
882
#define SQLITE_NOTICE_RBU              (SQLITE_NOTICE | (3<<8))
883
2.94k
#define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
884
#define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
885
0
#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
886
0
#define SQLITE_OK_SYMLINK              (SQLITE_OK | (2<<8)) /* internal use only */
887
888
/*
889
** CAPI3REF: Flags For File Open Operations
890
**
891
** These bit values are intended for use in the
892
** 3rd parameter to the [sqlite3_open_v2()] interface and
893
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
894
**
895
** Only those flags marked as "Ok for sqlite3_open_v2()" may be
896
** used as the third argument to the [sqlite3_open_v2()] interface.
897
** The other flags have historically been ignored by sqlite3_open_v2(),
898
** though future versions of SQLite might change so that an error is
899
** raised if any of the disallowed bits are passed into sqlite3_open_v2().
900
** Applications should not depend on the historical behavior.
901
**
902
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
903
** [sqlite3_open_v2()] does *not* cause the underlying database file
904
** to be opened using O_EXCL.  Passing SQLITE_OPEN_EXCLUSIVE into
905
** [sqlite3_open_v2()] has historically be a no-op and might become an
906
** error in future versions of SQLite.
907
*/
908
275k
#define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
909
282k
#define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
910
282k
#define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
911
318k
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
912
300k
#define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
913
#define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
914
141k
#define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
915
252k
#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
916
417k
#define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
917
73.3k
#define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
918
219k
#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
919
89.2k
#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
920
32.1k
#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
921
49.0k
#define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
922
53.3k
#define SQLITE_OPEN_SUPER_JOURNAL    0x00004000  /* VFS only */
923
34.7k
#define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
924
34.7k
#define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
925
0
#define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
926
17.3k
#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
927
71.2k
#define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
928
0
#define SQLITE_OPEN_NOFOLLOW         0x01000000  /* Ok for sqlite3_open_v2() */
929
17.3k
#define SQLITE_OPEN_EXRESCODE        0x02000000  /* Extended result codes */
930
931
/* Reserved:                         0x00F00000 */
932
/* Legacy compatibility: */
933
#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
934
935
936
/*
937
** CAPI3REF: Device Characteristics
938
**
939
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
940
** object returns an integer which is a vector of these
941
** bit values expressing I/O characteristics of the mass storage
942
** device that holds the file that the [sqlite3_io_methods]
943
** refers to.
944
**
945
** The SQLITE_IOCAP_ATOMIC property means that all writes of
946
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
947
** mean that writes of blocks that are nnn bytes in size and
948
** are aligned to an address which is an integer multiple of
949
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
950
** that when data is appended to a file, the data is appended
951
** first then the size of the file is extended, never the other
952
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
953
** information is written to disk in the same order as calls
954
** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
955
** after reboot following a crash or power loss, the only bytes in a
956
** file that were written at the application level might have changed
957
** and that adjacent bytes, even bytes within the same sector are
958
** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
959
** flag indicates that a file cannot be deleted when open.  The
960
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
961
** read-only media and cannot be changed even by processes with
962
** elevated privileges.
963
**
964
** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
965
** filesystem supports doing multiple write operations atomically when those
966
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
967
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
968
*/
969
0
#define SQLITE_IOCAP_ATOMIC                 0x00000001
970
#define SQLITE_IOCAP_ATOMIC512              0x00000002
971
#define SQLITE_IOCAP_ATOMIC1K               0x00000004
972
#define SQLITE_IOCAP_ATOMIC2K               0x00000008
973
#define SQLITE_IOCAP_ATOMIC4K               0x00000010
974
#define SQLITE_IOCAP_ATOMIC8K               0x00000020
975
#define SQLITE_IOCAP_ATOMIC16K              0x00000040
976
#define SQLITE_IOCAP_ATOMIC32K              0x00000080
977
#define SQLITE_IOCAP_ATOMIC64K              0x00000100
978
0
#define SQLITE_IOCAP_SAFE_APPEND            0x00000200
979
0
#define SQLITE_IOCAP_SEQUENTIAL             0x00000400
980
257k
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
981
13.6k
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
982
0
#define SQLITE_IOCAP_IMMUTABLE              0x00002000
983
#define SQLITE_IOCAP_BATCH_ATOMIC           0x00004000
984
985
/*
986
** CAPI3REF: File Locking Levels
987
**
988
** SQLite uses one of these integer values as the second
989
** argument to calls it makes to the xLock() and xUnlock() methods
990
** of an [sqlite3_io_methods] object.  These values are ordered from
991
** lest restrictive to most restrictive.
992
**
993
** The argument to xLock() is always SHARED or higher.  The argument to
994
** xUnlock is either SHARED or NONE.
995
*/
996
#define SQLITE_LOCK_NONE          0       /* xUnlock() only */
997
0
#define SQLITE_LOCK_SHARED        1       /* xLock() or xUnlock() */
998
0
#define SQLITE_LOCK_RESERVED      2       /* xLock() only */
999
0
#define SQLITE_LOCK_PENDING       3       /* xLock() only */
1000
0
#define SQLITE_LOCK_EXCLUSIVE     4       /* xLock() only */
1001
1002
/*
1003
** CAPI3REF: Synchronization Type Flags
1004
**
1005
** When SQLite invokes the xSync() method of an
1006
** [sqlite3_io_methods] object it uses a combination of
1007
** these integer values as the second argument.
1008
**
1009
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
1010
** sync operation only needs to flush data to mass storage.  Inode
1011
** information need not be flushed. If the lower four bits of the flag
1012
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
1013
** If the lower four bits equal SQLITE_SYNC_FULL, that means
1014
** to use Mac OS X style fullsync instead of fsync().
1015
**
1016
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
1017
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
1018
** settings.  The [synchronous pragma] determines when calls to the
1019
** xSync VFS method occur and applies uniformly across all platforms.
1020
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
1021
** energetic or rigorous or forceful the sync operations are and
1022
** only make a difference on Mac OSX for the default SQLite code.
1023
** (Third-party VFS implementations might also make the distinction
1024
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
1025
** operating systems natively supported by SQLite, only Mac OSX
1026
** cares about the difference.)
1027
*/
1028
0
#define SQLITE_SYNC_NORMAL        0x00002
1029
0
#define SQLITE_SYNC_FULL          0x00003
1030
0
#define SQLITE_SYNC_DATAONLY      0x00010
1031
1032
/*
1033
** CAPI3REF: OS Interface Open File Handle
1034
**
1035
** An [sqlite3_file] object represents an open file in the
1036
** [sqlite3_vfs | OS interface layer].  Individual OS interface
1037
** implementations will
1038
** want to subclass this object by appending additional fields
1039
** for their own use.  The pMethods entry is a pointer to an
1040
** [sqlite3_io_methods] object that defines methods for performing
1041
** I/O operations on the open file.
1042
*/
1043
typedef struct sqlite3_file sqlite3_file;
1044
struct sqlite3_file {
1045
  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
1046
};
1047
1048
/*
1049
** CAPI3REF: OS Interface File Virtual Methods Object
1050
**
1051
** Every file opened by the [sqlite3_vfs.xOpen] method populates an
1052
** [sqlite3_file] object (or, more commonly, a subclass of the
1053
** [sqlite3_file] object) with a pointer to an instance of this object.
1054
** This object defines the methods used to perform various operations
1055
** against the open file represented by the [sqlite3_file] object.
1056
**
1057
** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
1058
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
1059
** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
1060
** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
1061
** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
1062
** to NULL.
1063
**
1064
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
1065
** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
1066
** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
1067
** flag may be ORed in to indicate that only the data of the file
1068
** and not its inode needs to be synced.
1069
**
1070
** The integer values to xLock() and xUnlock() are one of
1071
** <ul>
1072
** <li> [SQLITE_LOCK_NONE],
1073
** <li> [SQLITE_LOCK_SHARED],
1074
** <li> [SQLITE_LOCK_RESERVED],
1075
** <li> [SQLITE_LOCK_PENDING], or
1076
** <li> [SQLITE_LOCK_EXCLUSIVE].
1077
** </ul>
1078
** xLock() upgrades the database file lock.  In other words, xLock() moves the
1079
** database file lock in the direction NONE toward EXCLUSIVE. The argument to
1080
** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
1081
** SQLITE_LOCK_NONE.  If the database file lock is already at or above the
1082
** requested lock, then the call to xLock() is a no-op.
1083
** xUnlock() downgrades the database file lock to either SHARED or NONE.
1084
** If the lock is already at or below the requested lock state, then the call
1085
** to xUnlock() is a no-op.
1086
** The xCheckReservedLock() method checks whether any database connection,
1087
** either in this process or in some other process, is holding a RESERVED,
1088
** PENDING, or EXCLUSIVE lock on the file.  It returns true
1089
** if such a lock exists and false otherwise.
1090
**
1091
** The xFileControl() method is a generic interface that allows custom
1092
** VFS implementations to directly control an open file using the
1093
** [sqlite3_file_control()] interface.  The second "op" argument is an
1094
** integer opcode.  The third argument is a generic pointer intended to
1095
** point to a structure that may contain arguments or space in which to
1096
** write return values.  Potential uses for xFileControl() might be
1097
** functions to enable blocking locks with timeouts, to change the
1098
** locking strategy (for example to use dot-file locks), to inquire
1099
** about the status of a lock, or to break stale locks.  The SQLite
1100
** core reserves all opcodes less than 100 for its own use.
1101
** A [file control opcodes | list of opcodes] less than 100 is available.
1102
** Applications that define a custom xFileControl method should use opcodes
1103
** greater than 100 to avoid conflicts.  VFS implementations should
1104
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
1105
** recognize.
1106
**
1107
** The xSectorSize() method returns the sector size of the
1108
** device that underlies the file.  The sector size is the
1109
** minimum write that can be performed without disturbing
1110
** other bytes in the file.  The xDeviceCharacteristics()
1111
** method returns a bit vector describing behaviors of the
1112
** underlying device:
1113
**
1114
** <ul>
1115
** <li> [SQLITE_IOCAP_ATOMIC]
1116
** <li> [SQLITE_IOCAP_ATOMIC512]
1117
** <li> [SQLITE_IOCAP_ATOMIC1K]
1118
** <li> [SQLITE_IOCAP_ATOMIC2K]
1119
** <li> [SQLITE_IOCAP_ATOMIC4K]
1120
** <li> [SQLITE_IOCAP_ATOMIC8K]
1121
** <li> [SQLITE_IOCAP_ATOMIC16K]
1122
** <li> [SQLITE_IOCAP_ATOMIC32K]
1123
** <li> [SQLITE_IOCAP_ATOMIC64K]
1124
** <li> [SQLITE_IOCAP_SAFE_APPEND]
1125
** <li> [SQLITE_IOCAP_SEQUENTIAL]
1126
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
1127
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1128
** <li> [SQLITE_IOCAP_IMMUTABLE]
1129
** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
1130
** </ul>
1131
**
1132
** The SQLITE_IOCAP_ATOMIC property means that all writes of
1133
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
1134
** mean that writes of blocks that are nnn bytes in size and
1135
** are aligned to an address which is an integer multiple of
1136
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
1137
** that when data is appended to a file, the data is appended
1138
** first then the size of the file is extended, never the other
1139
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
1140
** information is written to disk in the same order as calls
1141
** to xWrite().
1142
**
1143
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
1144
** in the unread portions of the buffer with zeros.  A VFS that
1145
** fails to zero-fill short reads might seem to work.  However,
1146
** failure to zero-fill short reads will eventually lead to
1147
** database corruption.
1148
*/
1149
typedef struct sqlite3_io_methods sqlite3_io_methods;
1150
struct sqlite3_io_methods {
1151
  int iVersion;
1152
  int (*xClose)(sqlite3_file*);
1153
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
1154
  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
1155
  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
1156
  int (*xSync)(sqlite3_file*, int flags);
1157
  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
1158
  int (*xLock)(sqlite3_file*, int);
1159
  int (*xUnlock)(sqlite3_file*, int);
1160
  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
1161
  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
1162
  int (*xSectorSize)(sqlite3_file*);
1163
  int (*xDeviceCharacteristics)(sqlite3_file*);
1164
  /* Methods above are valid for version 1 */
1165
  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
1166
  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
1167
  void (*xShmBarrier)(sqlite3_file*);
1168
  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
1169
  /* Methods above are valid for version 2 */
1170
  int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
1171
  int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
1172
  /* Methods above are valid for version 3 */
1173
  /* Additional methods may be added in future releases */
1174
};
1175
1176
/*
1177
** CAPI3REF: Standard File Control Opcodes
1178
** KEYWORDS: {file control opcodes} {file control opcode}
1179
**
1180
** These integer constants are opcodes for the xFileControl method
1181
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
1182
** interface.
1183
**
1184
** <ul>
1185
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
1186
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
1187
** opcode causes the xFileControl method to write the current state of
1188
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
1189
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
1190
** into an integer that the pArg argument points to.
1191
** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
1192
**
1193
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
1194
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
1195
** layer a hint of how large the database file will grow to be during the
1196
** current transaction.  This hint is not guaranteed to be accurate but it
1197
** is often close.  The underlying VFS might choose to preallocate database
1198
** file space based on this hint in order to help writes to the database
1199
** file run faster.
1200
**
1201
** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
1202
** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
1203
** implements [sqlite3_deserialize()] to set an upper bound on the size
1204
** of the in-memory database.  The argument is a pointer to a [sqlite3_int64].
1205
** If the integer pointed to is negative, then it is filled in with the
1206
** current limit.  Otherwise the limit is set to the larger of the value
1207
** of the integer pointed to and the current database size.  The integer
1208
** pointed to is set to the new limit.
1209
**
1210
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
1211
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
1212
** extends and truncates the database file in chunks of a size specified
1213
** by the user. The fourth argument to [sqlite3_file_control()] should
1214
** point to an integer (type int) containing the new chunk-size to use
1215
** for the nominated database. Allocating database file space in large
1216
** chunks (say 1MB at a time), may reduce file-system fragmentation and
1217
** improve performance on some systems.
1218
**
1219
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
1220
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1221
** to the [sqlite3_file] object associated with a particular database
1222
** connection.  See also [SQLITE_FCNTL_JOURNAL_POINTER].
1223
**
1224
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
1225
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
1226
** to the [sqlite3_file] object associated with the journal file (either
1227
** the [rollback journal] or the [write-ahead log]) for a particular database
1228
** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
1229
**
1230
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
1231
** No longer in use.
1232
**
1233
** <li>[[SQLITE_FCNTL_SYNC]]
1234
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
1235
** sent to the VFS immediately before the xSync method is invoked on a
1236
** database file descriptor. Or, if the xSync method is not invoked
1237
** because the user has configured SQLite with
1238
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
1239
** of the xSync method. In most cases, the pointer argument passed with
1240
** this file-control is NULL. However, if the database file is being synced
1241
** as part of a multi-database commit, the argument points to a nul-terminated
1242
** string containing the transactions super-journal file name. VFSes that
1243
** do not need this signal should silently ignore this opcode. Applications
1244
** should not call [sqlite3_file_control()] with this opcode as doing so may
1245
** disrupt the operation of the specialized VFSes that do require it.
1246
**
1247
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
1248
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
1249
** and sent to the VFS after a transaction has been committed immediately
1250
** but before the database is unlocked. VFSes that do not need this signal
1251
** should silently ignore this opcode. Applications should not call
1252
** [sqlite3_file_control()] with this opcode as doing so may disrupt the
1253
** operation of the specialized VFSes that do require it.
1254
**
1255
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
1256
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
1257
** retry counts and intervals for certain disk I/O operations for the
1258
** windows [VFS] in order to provide robustness in the presence of
1259
** anti-virus programs.  By default, the windows VFS will retry file read,
1260
** file write, and file delete operations up to 10 times, with a delay
1261
** of 25 milliseconds before the first retry and with the delay increasing
1262
** by an additional 25 milliseconds with each subsequent retry.  This
1263
** opcode allows these two values (10 retries and 25 milliseconds of delay)
1264
** to be adjusted.  The values are changed for all database connections
1265
** within the same process.  The argument is a pointer to an array of two
1266
** integers where the first integer is the new retry count and the second
1267
** integer is the delay.  If either integer is negative, then the setting
1268
** is not changed but instead the prior value of that setting is written
1269
** into the array entry, allowing the current retry settings to be
1270
** interrogated.  The zDbName parameter is ignored.
1271
**
1272
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
1273
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
1274
** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
1275
** write ahead log ([WAL file]) and shared memory
1276
** files used for transaction control
1277
** are automatically deleted when the latest connection to the database
1278
** closes.  Setting persistent WAL mode causes those files to persist after
1279
** close.  Persisting the files is useful when other processes that do not
1280
** have write permission on the directory containing the database file want
1281
** to read the database file, as the WAL and shared memory files must exist
1282
** in order for the database to be readable.  The fourth parameter to
1283
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1284
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
1285
** WAL mode.  If the integer is -1, then it is overwritten with the current
1286
** WAL persistence setting.
1287
**
1288
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
1289
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
1290
** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
1291
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
1292
** xDeviceCharacteristics methods. The fourth parameter to
1293
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
1294
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
1295
** mode.  If the integer is -1, then it is overwritten with the current
1296
** zero-damage mode setting.
1297
**
1298
** <li>[[SQLITE_FCNTL_OVERWRITE]]
1299
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
1300
** a write transaction to indicate that, unless it is rolled back for some
1301
** reason, the entire database file will be overwritten by the current
1302
** transaction. This is used by VACUUM operations.
1303
**
1304
** <li>[[SQLITE_FCNTL_VFSNAME]]
1305
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1306
** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
1307
** final bottom-level VFS are written into memory obtained from
1308
** [sqlite3_malloc()] and the result is stored in the char* variable
1309
** that the fourth parameter of [sqlite3_file_control()] points to.
1310
** The caller is responsible for freeing the memory when done.  As with
1311
** all file-control actions, there is no guarantee that this will actually
1312
** do anything.  Callers should initialize the char* variable to a NULL
1313
** pointer in case this file-control is not implemented.  This file-control
1314
** is intended for diagnostic use only.
1315
**
1316
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1317
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1318
** [VFSes] currently in use.  ^(The argument X in
1319
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1320
** of type "[sqlite3_vfs] **".  This opcodes will set *X
1321
** to a pointer to the top-level VFS.)^
1322
** ^When there are multiple VFS shims in the stack, this opcode finds the
1323
** upper-most shim only.
1324
**
1325
** <li>[[SQLITE_FCNTL_PRAGMA]]
1326
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
1327
** file control is sent to the open [sqlite3_file] object corresponding
1328
** to the database file to which the pragma statement refers. ^The argument
1329
** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1330
** pointers to strings (char**) in which the second element of the array
1331
** is the name of the pragma and the third element is the argument to the
1332
** pragma or NULL if the pragma has no argument.  ^The handler for an
1333
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1334
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
1335
** or the equivalent and that string will become the result of the pragma or
1336
** the error message if the pragma fails. ^If the
1337
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1338
** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
1339
** file control returns [SQLITE_OK], then the parser assumes that the
1340
** VFS has handled the PRAGMA itself and the parser generates a no-op
1341
** prepared statement if result string is NULL, or that returns a copy
1342
** of the result string if the string is non-NULL.
1343
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1344
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1345
** that the VFS encountered an error while handling the [PRAGMA] and the
1346
** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
1347
** file control occurs at the beginning of pragma statement analysis and so
1348
** it is able to override built-in [PRAGMA] statements.
1349
**
1350
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
1351
** ^The [SQLITE_FCNTL_BUSYHANDLER]
1352
** file-control may be invoked by SQLite on the database file handle
1353
** shortly after it is opened in order to provide a custom VFS with access
1354
** to the connection's busy-handler callback. The argument is of type (void**)
1355
** - an array of two (void *) values. The first (void *) actually points
1356
** to a function of type (int (*)(void *)). In order to invoke the connection's
1357
** busy-handler, this function should be invoked with the second (void *) in
1358
** the array as the only argument. If it returns non-zero, then the operation
1359
** should be retried. If it returns zero, the custom VFS should abandon the
1360
** current operation.
1361
**
1362
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
1363
** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
1364
** to have SQLite generate a
1365
** temporary filename using the same algorithm that is followed to generate
1366
** temporary filenames for TEMP tables and other internal uses.  The
1367
** argument should be a char** which will be filled with the filename
1368
** written into memory obtained from [sqlite3_malloc()].  The caller should
1369
** invoke [sqlite3_free()] on the result to avoid a memory leak.
1370
**
1371
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
1372
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
1373
** maximum number of bytes that will be used for memory-mapped I/O.
1374
** The argument is a pointer to a value of type sqlite3_int64 that
1375
** is an advisory maximum number of bytes in the file to memory map.  The
1376
** pointer is overwritten with the old value.  The limit is not changed if
1377
** the value originally pointed to is negative, and so the current limit
1378
** can be queried by passing in a pointer to a negative number.  This
1379
** file-control is used internally to implement [PRAGMA mmap_size].
1380
**
1381
** <li>[[SQLITE_FCNTL_TRACE]]
1382
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
1383
** to the VFS about what the higher layers of the SQLite stack are doing.
1384
** This file control is used by some VFS activity tracing [shims].
1385
** The argument is a zero-terminated string.  Higher layers in the
1386
** SQLite stack may generate instances of this file control if
1387
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
1388
**
1389
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
1390
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1391
** pointer to an integer and it writes a boolean into that integer depending
1392
** on whether or not the file has been renamed, moved, or deleted since it
1393
** was first opened.
1394
**
1395
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
1396
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
1397
** underlying native file handle associated with a file handle.  This file
1398
** control interprets its argument as a pointer to a native file handle and
1399
** writes the resulting value there.
1400
**
1401
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1402
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
1403
** opcode causes the xFileControl method to swap the file handle with the one
1404
** pointed to by the pArg argument.  This capability is used during testing
1405
** and only needs to be supported when SQLITE_TEST is defined.
1406
**
1407
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1408
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1409
** be advantageous to block on the next WAL lock if the lock is not immediately
1410
** available.  The WAL subsystem issues this signal during rare
1411
** circumstances in order to fix a problem with priority inversion.
1412
** Applications should <em>not</em> use this file-control.
1413
**
1414
** <li>[[SQLITE_FCNTL_ZIPVFS]]
1415
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1416
** VFS should return SQLITE_NOTFOUND for this opcode.
1417
**
1418
** <li>[[SQLITE_FCNTL_RBU]]
1419
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1420
** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
1421
** this opcode.
1422
**
1423
** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1424
** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1425
** the file descriptor is placed in "batch write mode", which
1426
** means all subsequent write operations will be deferred and done
1427
** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
1428
** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1429
** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1430
** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1431
** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1432
** no VFS interface calls on the same [sqlite3_file] file descriptor
1433
** except for calls to the xWrite method and the xFileControl method
1434
** with [SQLITE_FCNTL_SIZE_HINT].
1435
**
1436
** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1437
** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1438
** operations since the previous successful call to
1439
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1440
** This file control returns [SQLITE_OK] if and only if the writes were
1441
** all performed successfully and have been committed to persistent storage.
1442
** ^Regardless of whether or not it is successful, this file control takes
1443
** the file descriptor out of batch write mode so that all subsequent
1444
** write operations are independent.
1445
** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1446
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1447
**
1448
** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1449
** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1450
** operations since the previous successful call to
1451
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1452
** ^This file control takes the file descriptor out of batch write mode
1453
** so that all subsequent write operations are independent.
1454
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1455
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1456
**
1457
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1458
** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
1459
** to block for up to M milliseconds before failing when attempting to
1460
** obtain a file lock using the xLock or xShmLock methods of the VFS.
1461
** The parameter is a pointer to a 32-bit signed integer that contains
1462
** the value that M is to be set to. Before returning, the 32-bit signed
1463
** integer is overwritten with the previous value of M.
1464
**
1465
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1466
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1467
** a database file.  The argument is a pointer to a 32-bit unsigned integer.
1468
** The "data version" for the pager is written into the pointer.  The
1469
** "data version" changes whenever any change occurs to the corresponding
1470
** database file, either through SQL statements on the same database
1471
** connection or through transactions committed by separate database
1472
** connections possibly in other processes. The [sqlite3_total_changes()]
1473
** interface can be used to find if any database on the connection has changed,
1474
** but that interface responds to changes on TEMP as well as MAIN and does
1475
** not provide a mechanism to detect changes to MAIN only.  Also, the
1476
** [sqlite3_total_changes()] interface responds to internal changes only and
1477
** omits changes made by other database connections.  The
1478
** [PRAGMA data_version] command provides a mechanism to detect changes to
1479
** a single attached database that occur due to other database connections,
1480
** but omits changes implemented by the database connection on which it is
1481
** called.  This file control is the only mechanism to detect changes that
1482
** happen either internally or externally and that are associated with
1483
** a particular attached database.
1484
**
1485
** <li>[[SQLITE_FCNTL_CKPT_START]]
1486
** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
1487
** in wal mode before the client starts to copy pages from the wal
1488
** file to the database file.
1489
**
1490
** <li>[[SQLITE_FCNTL_CKPT_DONE]]
1491
** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1492
** in wal mode after the client has finished copying pages from the wal
1493
** file to the database file, but before the *-shm file is updated to
1494
** record the fact that the pages have been checkpointed.
1495
**
1496
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1497
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1498
** whether or not there is a database client in another process with a wal-mode
1499
** transaction open on the database or not. It is only available on unix.The
1500
** (void*) argument passed with this file-control should be a pointer to a
1501
** value of type (int). The integer value is set to 1 if the database is a wal
1502
** mode database and there exists at least one client in another process that
1503
** currently has an SQL transaction open on the database. It is set to 0 if
1504
** the database is not a wal-mode db, or if there is no such connection in any
1505
** other process. This opcode cannot be used to detect transactions opened
1506
** by clients within the current process, only within other processes.
1507
**
1508
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1509
** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
1510
** [checksum VFS shim] only.
1511
**
1512
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1513
** If there is currently no transaction open on the database, and the
1514
** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
1515
** purges the contents of the in-memory page cache. If there is an open
1516
** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
1517
** </ul>
1518
*/
1519
0
#define SQLITE_FCNTL_LOCKSTATE               1
1520
#define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
1521
#define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
1522
0
#define SQLITE_FCNTL_LAST_ERRNO              4
1523
4.70M
#define SQLITE_FCNTL_SIZE_HINT               5
1524
0
#define SQLITE_FCNTL_CHUNK_SIZE              6
1525
75.1k
#define SQLITE_FCNTL_FILE_POINTER            7
1526
#define SQLITE_FCNTL_SYNC_OMITTED            8
1527
#define SQLITE_FCNTL_WIN32_AV_RETRY          9
1528
0
#define SQLITE_FCNTL_PERSIST_WAL            10
1529
0
#define SQLITE_FCNTL_OVERWRITE              11
1530
0
#define SQLITE_FCNTL_VFSNAME                12
1531
0
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
1532
74.3k
#define SQLITE_FCNTL_PRAGMA                 14
1533
257k
#define SQLITE_FCNTL_BUSYHANDLER            15
1534
0
#define SQLITE_FCNTL_TEMPFILENAME           16
1535
18.2k
#define SQLITE_FCNTL_MMAP_SIZE              18
1536
#define SQLITE_FCNTL_TRACE                  19
1537
0
#define SQLITE_FCNTL_HAS_MOVED              20
1538
4.31k
#define SQLITE_FCNTL_SYNC                   21
1539
150k
#define SQLITE_FCNTL_COMMIT_PHASETWO        22
1540
#define SQLITE_FCNTL_WIN32_SET_HANDLE       23
1541
#define SQLITE_FCNTL_WAL_BLOCK              24
1542
#define SQLITE_FCNTL_ZIPVFS                 25
1543
#define SQLITE_FCNTL_RBU                    26
1544
75.1k
#define SQLITE_FCNTL_VFS_POINTER            27
1545
75.1k
#define SQLITE_FCNTL_JOURNAL_POINTER        28
1546
#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
1547
0
#define SQLITE_FCNTL_PDB                    30
1548
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
1549
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
1550
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
1551
#define SQLITE_FCNTL_LOCK_TIMEOUT           34
1552
75.1k
#define SQLITE_FCNTL_DATA_VERSION           35
1553
0
#define SQLITE_FCNTL_SIZE_LIMIT             36
1554
0
#define SQLITE_FCNTL_CKPT_DONE              37
1555
75.1k
#define SQLITE_FCNTL_RESERVE_BYTES          38
1556
0
#define SQLITE_FCNTL_CKPT_START             39
1557
0
#define SQLITE_FCNTL_EXTERNAL_READER        40
1558
#define SQLITE_FCNTL_CKSM_FILE              41
1559
75.1k
#define SQLITE_FCNTL_RESET_CACHE            42
1560
1561
/* deprecated names */
1562
#define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
1563
#define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
1564
#define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
1565
1566
1567
/*
1568
** CAPI3REF: Mutex Handle
1569
**
1570
** The mutex module within SQLite defines [sqlite3_mutex] to be an
1571
** abstract type for a mutex object.  The SQLite core never looks
1572
** at the internal representation of an [sqlite3_mutex].  It only
1573
** deals with pointers to the [sqlite3_mutex] object.
1574
**
1575
** Mutexes are created using [sqlite3_mutex_alloc()].
1576
*/
1577
typedef struct sqlite3_mutex sqlite3_mutex;
1578
1579
/*
1580
** CAPI3REF: Loadable Extension Thunk
1581
**
1582
** A pointer to the opaque sqlite3_api_routines structure is passed as
1583
** the third parameter to entry points of [loadable extensions].  This
1584
** structure must be typedefed in order to work around compiler warnings
1585
** on some platforms.
1586
*/
1587
typedef struct sqlite3_api_routines sqlite3_api_routines;
1588
1589
/*
1590
** CAPI3REF: File Name
1591
**
1592
** Type [sqlite3_filename] is used by SQLite to pass filenames to the
1593
** xOpen method of a [VFS]. It may be cast to (const char*) and treated
1594
** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
1595
** may also be passed to special APIs such as:
1596
**
1597
** <ul>
1598
** <li>  sqlite3_filename_database()
1599
** <li>  sqlite3_filename_journal()
1600
** <li>  sqlite3_filename_wal()
1601
** <li>  sqlite3_uri_parameter()
1602
** <li>  sqlite3_uri_boolean()
1603
** <li>  sqlite3_uri_int64()
1604
** <li>  sqlite3_uri_key()
1605
** </ul>
1606
*/
1607
typedef const char *sqlite3_filename;
1608
1609
/*
1610
** CAPI3REF: OS Interface Object
1611
**
1612
** An instance of the sqlite3_vfs object defines the interface between
1613
** the SQLite core and the underlying operating system.  The "vfs"
1614
** in the name of the object stands for "virtual file system".  See
1615
** the [VFS | VFS documentation] for further information.
1616
**
1617
** The VFS interface is sometimes extended by adding new methods onto
1618
** the end.  Each time such an extension occurs, the iVersion field
1619
** is incremented.  The iVersion value started out as 1 in
1620
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1621
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1622
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
1623
** may be appended to the sqlite3_vfs object and the iVersion value
1624
** may increase again in future versions of SQLite.
1625
** Note that due to an oversight, the structure
1626
** of the sqlite3_vfs object changed in the transition from
1627
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1628
** and yet the iVersion field was not increased.
1629
**
1630
** The szOsFile field is the size of the subclassed [sqlite3_file]
1631
** structure used by this VFS.  mxPathname is the maximum length of
1632
** a pathname in this VFS.
1633
**
1634
** Registered sqlite3_vfs objects are kept on a linked list formed by
1635
** the pNext pointer.  The [sqlite3_vfs_register()]
1636
** and [sqlite3_vfs_unregister()] interfaces manage this list
1637
** in a thread-safe way.  The [sqlite3_vfs_find()] interface
1638
** searches the list.  Neither the application code nor the VFS
1639
** implementation should use the pNext pointer.
1640
**
1641
** The pNext field is the only field in the sqlite3_vfs
1642
** structure that SQLite will ever modify.  SQLite will only access
1643
** or modify this field while holding a particular static mutex.
1644
** The application should never modify anything within the sqlite3_vfs
1645
** object once the object has been registered.
1646
**
1647
** The zName field holds the name of the VFS module.  The name must
1648
** be unique across all VFS modules.
1649
**
1650
** [[sqlite3_vfs.xOpen]]
1651
** ^SQLite guarantees that the zFilename parameter to xOpen
1652
** is either a NULL pointer or string obtained
1653
** from xFullPathname() with an optional suffix added.
1654
** ^If a suffix is added to the zFilename parameter, it will
1655
** consist of a single "-" character followed by no more than
1656
** 11 alphanumeric and/or "-" characters.
1657
** ^SQLite further guarantees that
1658
** the string will be valid and unchanged until xClose() is
1659
** called. Because of the previous sentence,
1660
** the [sqlite3_file] can safely store a pointer to the
1661
** filename if it needs to remember the filename for some reason.
1662
** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1663
** must invent its own temporary name for the file.  ^Whenever the
1664
** xFilename parameter is NULL it will also be the case that the
1665
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1666
**
1667
** The flags argument to xOpen() includes all bits set in
1668
** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
1669
** or [sqlite3_open16()] is used, then flags includes at least
1670
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1671
** If xOpen() opens a file read-only then it sets *pOutFlags to
1672
** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
1673
**
1674
** ^(SQLite will also add one of the following flags to the xOpen()
1675
** call, depending on the object being opened:
1676
**
1677
** <ul>
1678
** <li>  [SQLITE_OPEN_MAIN_DB]
1679
** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
1680
** <li>  [SQLITE_OPEN_TEMP_DB]
1681
** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
1682
** <li>  [SQLITE_OPEN_TRANSIENT_DB]
1683
** <li>  [SQLITE_OPEN_SUBJOURNAL]
1684
** <li>  [SQLITE_OPEN_SUPER_JOURNAL]
1685
** <li>  [SQLITE_OPEN_WAL]
1686
** </ul>)^
1687
**
1688
** The file I/O implementation can use the object type flags to
1689
** change the way it deals with files.  For example, an application
1690
** that does not care about crash recovery or rollback might make
1691
** the open of a journal file a no-op.  Writes to this journal would
1692
** also be no-ops, and any attempt to read the journal would return
1693
** SQLITE_IOERR.  Or the implementation might recognize that a database
1694
** file will be doing page-aligned sector reads and writes in a random
1695
** order and set up its I/O subsystem accordingly.
1696
**
1697
** SQLite might also add one of the following flags to the xOpen method:
1698
**
1699
** <ul>
1700
** <li> [SQLITE_OPEN_DELETEONCLOSE]
1701
** <li> [SQLITE_OPEN_EXCLUSIVE]
1702
** </ul>
1703
**
1704
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1705
** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
1706
** will be set for TEMP databases and their journals, transient
1707
** databases, and subjournals.
1708
**
1709
** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1710
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1711
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1712
** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1713
** SQLITE_OPEN_CREATE, is used to indicate that file should always
1714
** be created, and that it is an error if it already exists.
1715
** It is <i>not</i> used to indicate the file should be opened
1716
** for exclusive access.
1717
**
1718
** ^At least szOsFile bytes of memory are allocated by SQLite
1719
** to hold the [sqlite3_file] structure passed as the third
1720
** argument to xOpen.  The xOpen method does not have to
1721
** allocate the structure; it should just fill it in.  Note that
1722
** the xOpen method must set the sqlite3_file.pMethods to either
1723
** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
1724
** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
1725
** element will be valid after xOpen returns regardless of the success
1726
** or failure of the xOpen call.
1727
**
1728
** [[sqlite3_vfs.xAccess]]
1729
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1730
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1731
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1732
** to test whether a file is at least readable.  The SQLITE_ACCESS_READ
1733
** flag is never actually used and is not implemented in the built-in
1734
** VFSes of SQLite.  The file is named by the second argument and can be a
1735
** directory. The xAccess method returns [SQLITE_OK] on success or some
1736
** non-zero error code if there is an I/O error or if the name of
1737
** the file given in the second argument is illegal.  If SQLITE_OK
1738
** is returned, then non-zero or zero is written into *pResOut to indicate
1739
** whether or not the file is accessible.
1740
**
1741
** ^SQLite will always allocate at least mxPathname+1 bytes for the
1742
** output buffer xFullPathname.  The exact size of the output buffer
1743
** is also passed as a parameter to both  methods. If the output buffer
1744
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1745
** handled as a fatal error by SQLite, vfs implementations should endeavor
1746
** to prevent this by setting mxPathname to a sufficiently large value.
1747
**
1748
** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1749
** interfaces are not strictly a part of the filesystem, but they are
1750
** included in the VFS structure for completeness.
1751
** The xRandomness() function attempts to return nBytes bytes
1752
** of good-quality randomness into zOut.  The return value is
1753
** the actual number of bytes of randomness obtained.
1754
** The xSleep() method causes the calling thread to sleep for at
1755
** least the number of microseconds given.  ^The xCurrentTime()
1756
** method returns a Julian Day Number for the current date and time as
1757
** a floating point value.
1758
** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1759
** Day Number multiplied by 86400000 (the number of milliseconds in
1760
** a 24-hour day).
1761
** ^SQLite will use the xCurrentTimeInt64() method to get the current
1762
** date and time if that method is available (if iVersion is 2 or
1763
** greater and the function pointer is not NULL) and will fall back
1764
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1765
**
1766
** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1767
** are not used by the SQLite core.  These optional interfaces are provided
1768
** by some VFSes to facilitate testing of the VFS code. By overriding
1769
** system calls with functions under its control, a test program can
1770
** simulate faults and error conditions that would otherwise be difficult
1771
** or impossible to induce.  The set of system calls that can be overridden
1772
** varies from one VFS to another, and from one version of the same VFS to the
1773
** next.  Applications that use these interfaces must be prepared for any
1774
** or all of these interfaces to be NULL or for their behavior to change
1775
** from one release to the next.  Applications must not attempt to access
1776
** any of these methods if the iVersion of the VFS is less than 3.
1777
*/
1778
typedef struct sqlite3_vfs sqlite3_vfs;
1779
typedef void (*sqlite3_syscall_ptr)(void);
1780
struct sqlite3_vfs {
1781
  int iVersion;            /* Structure version number (currently 3) */
1782
  int szOsFile;            /* Size of subclassed sqlite3_file */
1783
  int mxPathname;          /* Maximum file pathname length */
1784
  sqlite3_vfs *pNext;      /* Next registered VFS */
1785
  const char *zName;       /* Name of this virtual file system */
1786
  void *pAppData;          /* Pointer to application-specific data */
1787
  int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
1788
               int flags, int *pOutFlags);
1789
  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1790
  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
1791
  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
1792
  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
1793
  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
1794
  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
1795
  void (*xDlClose)(sqlite3_vfs*, void*);
1796
  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
1797
  int (*xSleep)(sqlite3_vfs*, int microseconds);
1798
  int (*xCurrentTime)(sqlite3_vfs*, double*);
1799
  int (*xGetLastError)(sqlite3_vfs*, int, char *);
1800
  /*
1801
  ** The methods above are in version 1 of the sqlite_vfs object
1802
  ** definition.  Those that follow are added in version 2 or later
1803
  */
1804
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1805
  /*
1806
  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1807
  ** Those below are for version 3 and greater.
1808
  */
1809
  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1810
  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1811
  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1812
  /*
1813
  ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1814
  ** New fields may be appended in future versions.  The iVersion
1815
  ** value will increment whenever this happens.
1816
  */
1817
};
1818
1819
/*
1820
** CAPI3REF: Flags for the xAccess VFS method
1821
**
1822
** These integer constants can be used as the third parameter to
1823
** the xAccess method of an [sqlite3_vfs] object.  They determine
1824
** what kind of permissions the xAccess method is looking for.
1825
** With SQLITE_ACCESS_EXISTS, the xAccess method
1826
** simply checks whether the file exists.
1827
** With SQLITE_ACCESS_READWRITE, the xAccess method
1828
** checks whether the named directory is both readable and writable
1829
** (in other words, if files can be added, removed, and renamed within
1830
** the directory).
1831
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1832
** [temp_store_directory pragma], though this could change in a future
1833
** release of SQLite.
1834
** With SQLITE_ACCESS_READ, the xAccess method
1835
** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
1836
** currently unused, though it might be used in a future release of
1837
** SQLite.
1838
*/
1839
0
#define SQLITE_ACCESS_EXISTS    0
1840
0
#define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
1841
#define SQLITE_ACCESS_READ      2   /* Unused */
1842
1843
/*
1844
** CAPI3REF: Flags for the xShmLock VFS method
1845
**
1846
** These integer constants define the various locking operations
1847
** allowed by the xShmLock method of [sqlite3_io_methods].  The
1848
** following are the only legal combinations of flags to the
1849
** xShmLock method:
1850
**
1851
** <ul>
1852
** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1853
** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1854
** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1855
** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1856
** </ul>
1857
**
1858
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1859
** was given on the corresponding lock.
1860
**
1861
** The xShmLock method can transition between unlocked and SHARED or
1862
** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
1863
** and EXCLUSIVE.
1864
*/
1865
0
#define SQLITE_SHM_UNLOCK       1
1866
0
#define SQLITE_SHM_LOCK         2
1867
0
#define SQLITE_SHM_SHARED       4
1868
0
#define SQLITE_SHM_EXCLUSIVE    8
1869
1870
/*
1871
** CAPI3REF: Maximum xShmLock index
1872
**
1873
** The xShmLock method on [sqlite3_io_methods] may use values
1874
** between 0 and this upper bound as its "offset" argument.
1875
** The SQLite core will never attempt to acquire or release a
1876
** lock outside of this range
1877
*/
1878
0
#define SQLITE_SHM_NLOCK        8
1879
1880
1881
/*
1882
** CAPI3REF: Initialize The SQLite Library
1883
**
1884
** ^The sqlite3_initialize() routine initializes the
1885
** SQLite library.  ^The sqlite3_shutdown() routine
1886
** deallocates any resources that were allocated by sqlite3_initialize().
1887
** These routines are designed to aid in process initialization and
1888
** shutdown on embedded systems.  Workstation applications using
1889
** SQLite normally do not need to invoke either of these routines.
1890
**
1891
** A call to sqlite3_initialize() is an "effective" call if it is
1892
** the first time sqlite3_initialize() is invoked during the lifetime of
1893
** the process, or if it is the first time sqlite3_initialize() is invoked
1894
** following a call to sqlite3_shutdown().  ^(Only an effective call
1895
** of sqlite3_initialize() does any initialization.  All other calls
1896
** are harmless no-ops.)^
1897
**
1898
** A call to sqlite3_shutdown() is an "effective" call if it is the first
1899
** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
1900
** an effective call to sqlite3_shutdown() does any deinitialization.
1901
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1902
**
1903
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1904
** is not.  The sqlite3_shutdown() interface must only be called from a
1905
** single thread.  All open [database connections] must be closed and all
1906
** other SQLite resources must be deallocated prior to invoking
1907
** sqlite3_shutdown().
1908
**
1909
** Among other things, ^sqlite3_initialize() will invoke
1910
** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
1911
** will invoke sqlite3_os_end().
1912
**
1913
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1914
** ^If for some reason, sqlite3_initialize() is unable to initialize
1915
** the library (perhaps it is unable to allocate a needed resource such
1916
** as a mutex) it returns an [error code] other than [SQLITE_OK].
1917
**
1918
** ^The sqlite3_initialize() routine is called internally by many other
1919
** SQLite interfaces so that an application usually does not need to
1920
** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
1921
** calls sqlite3_initialize() so the SQLite library will be automatically
1922
** initialized when [sqlite3_open()] is called if it has not be initialized
1923
** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1924
** compile-time option, then the automatic calls to sqlite3_initialize()
1925
** are omitted and the application must call sqlite3_initialize() directly
1926
** prior to using any other SQLite interface.  For maximum portability,
1927
** it is recommended that applications always invoke sqlite3_initialize()
1928
** directly prior to using any other SQLite interface.  Future releases
1929
** of SQLite may require this.  In other words, the behavior exhibited
1930
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1931
** default behavior in some future release of SQLite.
1932
**
1933
** The sqlite3_os_init() routine does operating-system specific
1934
** initialization of the SQLite library.  The sqlite3_os_end()
1935
** routine undoes the effect of sqlite3_os_init().  Typical tasks
1936
** performed by these routines include allocation or deallocation
1937
** of static resources, initialization of global variables,
1938
** setting up a default [sqlite3_vfs] module, or setting up
1939
** a default configuration using [sqlite3_config()].
1940
**
1941
** The application should never invoke either sqlite3_os_init()
1942
** or sqlite3_os_end() directly.  The application should only invoke
1943
** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
1944
** interface is called automatically by sqlite3_initialize() and
1945
** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
1946
** implementations for sqlite3_os_init() and sqlite3_os_end()
1947
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1948
** When [custom builds | built for other platforms]
1949
** (using the [SQLITE_OS_OTHER=1] compile-time
1950
** option) the application must supply a suitable implementation for
1951
** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
1952
** implementation of sqlite3_os_init() or sqlite3_os_end()
1953
** must return [SQLITE_OK] on success and some other [error code] upon
1954
** failure.
1955
*/
1956
SQLITE_API int sqlite3_initialize(void);
1957
SQLITE_API int sqlite3_shutdown(void);
1958
SQLITE_API int sqlite3_os_init(void);
1959
SQLITE_API int sqlite3_os_end(void);
1960
1961
/*
1962
** CAPI3REF: Configuring The SQLite Library
1963
**
1964
** The sqlite3_config() interface is used to make global configuration
1965
** changes to SQLite in order to tune SQLite to the specific needs of
1966
** the application.  The default configuration is recommended for most
1967
** applications and so this routine is usually not necessary.  It is
1968
** provided to support rare applications with unusual needs.
1969
**
1970
** <b>The sqlite3_config() interface is not threadsafe. The application
1971
** must ensure that no other SQLite interfaces are invoked by other
1972
** threads while sqlite3_config() is running.</b>
1973
**
1974
** The first argument to sqlite3_config() is an integer
1975
** [configuration option] that determines
1976
** what property of SQLite is to be configured.  Subsequent arguments
1977
** vary depending on the [configuration option]
1978
** in the first argument.
1979
**
1980
** For most configuration options, the sqlite3_config() interface
1981
** may only be invoked prior to library initialization using
1982
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1983
** The exceptional configuration options that may be invoked at any time
1984
** are called "anytime configuration options".
1985
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1986
** [sqlite3_shutdown()] with a first argument that is not an anytime
1987
** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE.
1988
** Note, however, that ^sqlite3_config() can be called as part of the
1989
** implementation of an application-defined [sqlite3_os_init()].
1990
**
1991
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1992
** ^If the option is unknown or SQLite is unable to set the option
1993
** then this routine returns a non-zero [error code].
1994
*/
1995
SQLITE_API int sqlite3_config(int, ...);
1996
1997
/*
1998
** CAPI3REF: Configure database connections
1999
** METHOD: sqlite3
2000
**
2001
** The sqlite3_db_config() interface is used to make configuration
2002
** changes to a [database connection].  The interface is similar to
2003
** [sqlite3_config()] except that the changes apply to a single
2004
** [database connection] (specified in the first argument).
2005
**
2006
** The second argument to sqlite3_db_config(D,V,...)  is the
2007
** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
2008
** that indicates what aspect of the [database connection] is being configured.
2009
** Subsequent arguments vary depending on the configuration verb.
2010
**
2011
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
2012
** the call is considered successful.
2013
*/
2014
SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
2015
2016
/*
2017
** CAPI3REF: Memory Allocation Routines
2018
**
2019
** An instance of this object defines the interface between SQLite
2020
** and low-level memory allocation routines.
2021
**
2022
** This object is used in only one place in the SQLite interface.
2023
** A pointer to an instance of this object is the argument to
2024
** [sqlite3_config()] when the configuration option is
2025
** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
2026
** By creating an instance of this object
2027
** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
2028
** during configuration, an application can specify an alternative
2029
** memory allocation subsystem for SQLite to use for all of its
2030
** dynamic memory needs.
2031
**
2032
** Note that SQLite comes with several [built-in memory allocators]
2033
** that are perfectly adequate for the overwhelming majority of applications
2034
** and that this object is only useful to a tiny minority of applications
2035
** with specialized memory allocation requirements.  This object is
2036
** also used during testing of SQLite in order to specify an alternative
2037
** memory allocator that simulates memory out-of-memory conditions in
2038
** order to verify that SQLite recovers gracefully from such
2039
** conditions.
2040
**
2041
** The xMalloc, xRealloc, and xFree methods must work like the
2042
** malloc(), realloc() and free() functions from the standard C library.
2043
** ^SQLite guarantees that the second argument to
2044
** xRealloc is always a value returned by a prior call to xRoundup.
2045
**
2046
** xSize should return the allocated size of a memory allocation
2047
** previously obtained from xMalloc or xRealloc.  The allocated size
2048
** is always at least as big as the requested size but may be larger.
2049
**
2050
** The xRoundup method returns what would be the allocated size of
2051
** a memory allocation given a particular requested size.  Most memory
2052
** allocators round up memory allocations at least to the next multiple
2053
** of 8.  Some allocators round up to a larger multiple or to a power of 2.
2054
** Every memory allocation request coming in through [sqlite3_malloc()]
2055
** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0,
2056
** that causes the corresponding memory allocation to fail.
2057
**
2058
** The xInit method initializes the memory allocator.  For example,
2059
** it might allocate any required mutexes or initialize internal data
2060
** structures.  The xShutdown method is invoked (indirectly) by
2061
** [sqlite3_shutdown()] and should deallocate any resources acquired
2062
** by xInit.  The pAppData pointer is used as the only parameter to
2063
** xInit and xShutdown.
2064
**
2065
** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
2066
** the xInit method, so the xInit method need not be threadsafe.  The
2067
** xShutdown method is only called from [sqlite3_shutdown()] so it does
2068
** not need to be threadsafe either.  For all other methods, SQLite
2069
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
2070
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
2071
** it is by default) and so the methods are automatically serialized.
2072
** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
2073
** methods must be threadsafe or else make their own arrangements for
2074
** serialization.
2075
**
2076
** SQLite will never invoke xInit() more than once without an intervening
2077
** call to xShutdown().
2078
*/
2079
typedef struct sqlite3_mem_methods sqlite3_mem_methods;
2080
struct sqlite3_mem_methods {
2081
  void *(*xMalloc)(int);         /* Memory allocation function */
2082
  void (*xFree)(void*);          /* Free a prior allocation */
2083
  void *(*xRealloc)(void*,int);  /* Resize an allocation */
2084
  int (*xSize)(void*);           /* Return the size of an allocation */
2085
  int (*xRoundup)(int);          /* Round up request size to allocation size */
2086
  int (*xInit)(void*);           /* Initialize the memory allocator */
2087
  void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
2088
  void *pAppData;                /* Argument to xInit() and xShutdown() */
2089
};
2090
2091
/*
2092
** CAPI3REF: Configuration Options
2093
** KEYWORDS: {configuration option}
2094
**
2095
** These constants are the available integer configuration options that
2096
** can be passed as the first argument to the [sqlite3_config()] interface.
2097
**
2098
** Most of the configuration options for sqlite3_config()
2099
** will only work if invoked prior to [sqlite3_initialize()] or after
2100
** [sqlite3_shutdown()].  The few exceptions to this rule are called
2101
** "anytime configuration options".
2102
** ^Calling [sqlite3_config()] with a first argument that is not an
2103
** anytime configuration option in between calls to [sqlite3_initialize()] and
2104
** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.
2105
**
2106
** The set of anytime configuration options can change (by insertions
2107
** and/or deletions) from one release of SQLite to the next.
2108
** As of SQLite version 3.42.0, the complete set of anytime configuration
2109
** options is:
2110
** <ul>
2111
** <li> SQLITE_CONFIG_LOG
2112
** <li> SQLITE_CONFIG_PCACHE_HDRSZ
2113
** </ul>
2114
**
2115
** New configuration options may be added in future releases of SQLite.
2116
** Existing configuration options might be discontinued.  Applications
2117
** should check the return code from [sqlite3_config()] to make sure that
2118
** the call worked.  The [sqlite3_config()] interface will return a
2119
** non-zero [error code] if a discontinued or unsupported configuration option
2120
** is invoked.
2121
**
2122
** <dl>
2123
** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
2124
** <dd>There are no arguments to this option.  ^This option sets the
2125
** [threading mode] to Single-thread.  In other words, it disables
2126
** all mutexing and puts SQLite into a mode where it can only be used
2127
** by a single thread.   ^If SQLite is compiled with
2128
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2129
** it is not possible to change the [threading mode] from its default
2130
** value of Single-thread and so [sqlite3_config()] will return
2131
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
2132
** configuration option.</dd>
2133
**
2134
** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
2135
** <dd>There are no arguments to this option.  ^This option sets the
2136
** [threading mode] to Multi-thread.  In other words, it disables
2137
** mutexing on [database connection] and [prepared statement] objects.
2138
** The application is responsible for serializing access to
2139
** [database connections] and [prepared statements].  But other mutexes
2140
** are enabled so that SQLite will be safe to use in a multi-threaded
2141
** environment as long as no two threads attempt to use the same
2142
** [database connection] at the same time.  ^If SQLite is compiled with
2143
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2144
** it is not possible to set the Multi-thread [threading mode] and
2145
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
2146
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
2147
**
2148
** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
2149
** <dd>There are no arguments to this option.  ^This option sets the
2150
** [threading mode] to Serialized. In other words, this option enables
2151
** all mutexes including the recursive
2152
** mutexes on [database connection] and [prepared statement] objects.
2153
** In this mode (which is the default when SQLite is compiled with
2154
** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
2155
** to [database connections] and [prepared statements] so that the
2156
** application is free to use the same [database connection] or the
2157
** same [prepared statement] in different threads at the same time.
2158
** ^If SQLite is compiled with
2159
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2160
** it is not possible to set the Serialized [threading mode] and
2161
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
2162
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
2163
**
2164
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
2165
** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
2166
** a pointer to an instance of the [sqlite3_mem_methods] structure.
2167
** The argument specifies
2168
** alternative low-level memory allocation routines to be used in place of
2169
** the memory allocation routines built into SQLite.)^ ^SQLite makes
2170
** its own private copy of the content of the [sqlite3_mem_methods] structure
2171
** before the [sqlite3_config()] call returns.</dd>
2172
**
2173
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
2174
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
2175
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
2176
** The [sqlite3_mem_methods]
2177
** structure is filled with the currently defined memory allocation routines.)^
2178
** This option can be used to overload the default memory allocation
2179
** routines with a wrapper that simulations memory allocation failure or
2180
** tracks memory usage, for example. </dd>
2181
**
2182
** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2183
** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
2184
** type int, interpreted as a boolean, which if true provides a hint to
2185
** SQLite that it should avoid large memory allocations if possible.
2186
** SQLite will run faster if it is free to make large memory allocations,
2187
** but some application might prefer to run slower in exchange for
2188
** guarantees about memory fragmentation that are possible if large
2189
** allocations are avoided.  This hint is normally off.
2190
** </dd>
2191
**
2192
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2193
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
2194
** interpreted as a boolean, which enables or disables the collection of
2195
** memory allocation statistics. ^(When memory allocation statistics are
2196
** disabled, the following SQLite interfaces become non-operational:
2197
**   <ul>
2198
**   <li> [sqlite3_hard_heap_limit64()]
2199
**   <li> [sqlite3_memory_used()]
2200
**   <li> [sqlite3_memory_highwater()]
2201
**   <li> [sqlite3_soft_heap_limit64()]
2202
**   <li> [sqlite3_status64()]
2203
**   </ul>)^
2204
** ^Memory allocation statistics are enabled by default unless SQLite is
2205
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
2206
** allocation statistics are disabled by default.
2207
** </dd>
2208
**
2209
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
2210
** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
2211
** </dd>
2212
**
2213
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
2214
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
2215
** that SQLite can use for the database page cache with the default page
2216
** cache implementation.
2217
** This configuration option is a no-op if an application-defined page
2218
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
2219
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
2220
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
2221
** and the number of cache lines (N).
2222
** The sz argument should be the size of the largest database page
2223
** (a power of two between 512 and 65536) plus some extra bytes for each
2224
** page header.  ^The number of extra bytes needed by the page header
2225
** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
2226
** ^It is harmless, apart from the wasted memory,
2227
** for the sz parameter to be larger than necessary.  The pMem
2228
** argument must be either a NULL pointer or a pointer to an 8-byte
2229
** aligned block of memory of at least sz*N bytes, otherwise
2230
** subsequent behavior is undefined.
2231
** ^When pMem is not NULL, SQLite will strive to use the memory provided
2232
** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
2233
** a page cache line is larger than sz bytes or if all of the pMem buffer
2234
** is exhausted.
2235
** ^If pMem is NULL and N is non-zero, then each database connection
2236
** does an initial bulk allocation for page cache memory
2237
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
2238
** of -1024*N bytes if N is negative, . ^If additional
2239
** page cache memory is needed beyond what is provided by the initial
2240
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
2241
** additional cache line. </dd>
2242
**
2243
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
2244
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
2245
** that SQLite will use for all of its dynamic memory allocation needs
2246
** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
2247
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
2248
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
2249
** [SQLITE_ERROR] if invoked otherwise.
2250
** ^There are three arguments to SQLITE_CONFIG_HEAP:
2251
** An 8-byte aligned pointer to the memory,
2252
** the number of bytes in the memory buffer, and the minimum allocation size.
2253
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
2254
** to using its default memory allocator (the system malloc() implementation),
2255
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
2256
** memory pointer is not NULL then the alternative memory
2257
** allocator is engaged to handle all of SQLites memory allocation needs.
2258
** The first pointer (the memory pointer) must be aligned to an 8-byte
2259
** boundary or subsequent behavior of SQLite will be undefined.
2260
** The minimum allocation size is capped at 2**12. Reasonable values
2261
** for the minimum allocation size are 2**5 through 2**8.</dd>
2262
**
2263
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
2264
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
2265
** pointer to an instance of the [sqlite3_mutex_methods] structure.
2266
** The argument specifies alternative low-level mutex routines to be used
2267
** in place the mutex routines built into SQLite.)^  ^SQLite makes a copy of
2268
** the content of the [sqlite3_mutex_methods] structure before the call to
2269
** [sqlite3_config()] returns. ^If SQLite is compiled with
2270
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2271
** the entire mutexing subsystem is omitted from the build and hence calls to
2272
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
2273
** return [SQLITE_ERROR].</dd>
2274
**
2275
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
2276
** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
2277
** is a pointer to an instance of the [sqlite3_mutex_methods] structure.  The
2278
** [sqlite3_mutex_methods]
2279
** structure is filled with the currently defined mutex routines.)^
2280
** This option can be used to overload the default mutex allocation
2281
** routines with a wrapper used to track mutex usage for performance
2282
** profiling or testing, for example.   ^If SQLite is compiled with
2283
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2284
** the entire mutexing subsystem is omitted from the build and hence calls to
2285
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
2286
** return [SQLITE_ERROR].</dd>
2287
**
2288
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
2289
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2290
** the default size of lookaside memory on each [database connection].
2291
** The first argument is the
2292
** size of each lookaside buffer slot and the second is the number of
2293
** slots allocated to each database connection.)^  ^(SQLITE_CONFIG_LOOKASIDE
2294
** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
2295
** option to [sqlite3_db_config()] can be used to change the lookaside
2296
** configuration on individual connections.)^ </dd>
2297
**
2298
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2299
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2300
** a pointer to an [sqlite3_pcache_methods2] object.  This object specifies
2301
** the interface to a custom page cache implementation.)^
2302
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2303
**
2304
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2305
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2306
** is a pointer to an [sqlite3_pcache_methods2] object.  SQLite copies of
2307
** the current page cache implementation into that object.)^ </dd>
2308
**
2309
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2310
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2311
** global [error log].
2312
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
2313
** function with a call signature of void(*)(void*,int,const char*),
2314
** and a pointer to void. ^If the function pointer is not NULL, it is
2315
** invoked by [sqlite3_log()] to process each logging event.  ^If the
2316
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
2317
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
2318
** passed through as the first parameter to the application-defined logger
2319
** function whenever that function is invoked.  ^The second parameter to
2320
** the logger function is a copy of the first parameter to the corresponding
2321
** [sqlite3_log()] call and is intended to be a [result code] or an
2322
** [extended result code].  ^The third parameter passed to the logger is
2323
** log message after formatting via [sqlite3_snprintf()].
2324
** The SQLite logging interface is not reentrant; the logger function
2325
** supplied by the application must not invoke any SQLite interface.
2326
** In a multi-threaded application, the application-defined logger
2327
** function must be threadsafe. </dd>
2328
**
2329
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
2330
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
2331
** If non-zero, then URI handling is globally enabled. If the parameter is zero,
2332
** then URI handling is globally disabled.)^ ^If URI handling is globally
2333
** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
2334
** [sqlite3_open16()] or
2335
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
2336
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
2337
** connection is opened. ^If it is globally disabled, filenames are
2338
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2339
** database connection is opened. ^(By default, URI handling is globally
2340
** disabled. The default value may be changed by compiling with the
2341
** [SQLITE_USE_URI] symbol defined.)^
2342
**
2343
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2344
** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
2345
** argument which is interpreted as a boolean in order to enable or disable
2346
** the use of covering indices for full table scans in the query optimizer.
2347
** ^The default setting is determined
2348
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2349
** if that compile-time option is omitted.
2350
** The ability to disable the use of covering indices for full table scans
2351
** is because some incorrectly coded legacy applications might malfunction
2352
** when the optimization is enabled.  Providing the ability to
2353
** disable the optimization allows the older, buggy application code to work
2354
** without change even with newer versions of SQLite.
2355
**
2356
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2357
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2358
** <dd> These options are obsolete and should not be used by new code.
2359
** They are retained for backwards compatibility but are now no-ops.
2360
** </dd>
2361
**
2362
** [[SQLITE_CONFIG_SQLLOG]]
2363
** <dt>SQLITE_CONFIG_SQLLOG
2364
** <dd>This option is only available if sqlite is compiled with the
2365
** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
2366
** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
2367
** The second should be of type (void*). The callback is invoked by the library
2368
** in three separate circumstances, identified by the value passed as the
2369
** fourth parameter. If the fourth parameter is 0, then the database connection
2370
** passed as the second argument has just been opened. The third argument
2371
** points to a buffer containing the name of the main database file. If the
2372
** fourth parameter is 1, then the SQL statement that the third parameter
2373
** points to has just been executed. Or, if the fourth parameter is 2, then
2374
** the connection being passed as the second parameter is being closed. The
2375
** third parameter is passed NULL In this case.  An example of using this
2376
** configuration option can be seen in the "test_sqllog.c" source file in
2377
** the canonical SQLite source tree.</dd>
2378
**
2379
** [[SQLITE_CONFIG_MMAP_SIZE]]
2380
** <dt>SQLITE_CONFIG_MMAP_SIZE
2381
** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
2382
** that are the default mmap size limit (the default setting for
2383
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
2384
** ^The default setting can be overridden by each database connection using
2385
** either the [PRAGMA mmap_size] command, or by using the
2386
** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
2387
** will be silently truncated if necessary so that it does not exceed the
2388
** compile-time maximum mmap size set by the
2389
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
2390
** ^If either argument to this option is negative, then that argument is
2391
** changed to its compile-time default.
2392
**
2393
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
2394
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
2395
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
2396
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
2397
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
2398
** that specifies the maximum size of the created heap.
2399
**
2400
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
2401
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
2402
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
2403
** is a pointer to an integer and writes into that integer the number of extra
2404
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
2405
** The amount of extra space required can change depending on the compiler,
2406
** target platform, and SQLite version.
2407
**
2408
** [[SQLITE_CONFIG_PMASZ]]
2409
** <dt>SQLITE_CONFIG_PMASZ
2410
** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
2411
** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
2412
** sorter to that integer.  The default minimum PMA Size is set by the
2413
** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
2414
** to help with sort operations when multithreaded sorting
2415
** is enabled (using the [PRAGMA threads] command) and the amount of content
2416
** to be sorted exceeds the page size times the minimum of the
2417
** [PRAGMA cache_size] setting and this value.
2418
**
2419
** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
2420
** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
2421
** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
2422
** becomes the [statement journal] spill-to-disk threshold.
2423
** [Statement journals] are held in memory until their size (in bytes)
2424
** exceeds this threshold, at which point they are written to disk.
2425
** Or if the threshold is -1, statement journals are always held
2426
** exclusively in memory.
2427
** Since many statement journals never become large, setting the spill
2428
** threshold to a value such as 64KiB can greatly reduce the amount of
2429
** I/O required to support statement rollback.
2430
** The default value for this setting is controlled by the
2431
** [SQLITE_STMTJRNL_SPILL] compile-time option.
2432
**
2433
** [[SQLITE_CONFIG_SORTERREF_SIZE]]
2434
** <dt>SQLITE_CONFIG_SORTERREF_SIZE
2435
** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
2436
** of type (int) - the new value of the sorter-reference size threshold.
2437
** Usually, when SQLite uses an external sort to order records according
2438
** to an ORDER BY clause, all fields required by the caller are present in the
2439
** sorted records. However, if SQLite determines based on the declared type
2440
** of a table column that its values are likely to be very large - larger
2441
** than the configured sorter-reference size threshold - then a reference
2442
** is stored in each sorted record and the required column values loaded
2443
** from the database as records are returned in sorted order. The default
2444
** value for this option is to never use this optimization. Specifying a
2445
** negative value for this option restores the default behavior.
2446
** This option is only available if SQLite is compiled with the
2447
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2448
**
2449
** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2450
** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
2451
** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
2452
** [sqlite3_int64] parameter which is the default maximum size for an in-memory
2453
** database created using [sqlite3_deserialize()].  This default maximum
2454
** size can be adjusted up or down for individual databases using the
2455
** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control].  If this
2456
** configuration setting is never used, then the default maximum is determined
2457
** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option.  If that
2458
** compile-time option is not set, then the default maximum is 1073741824.
2459
**
2460
** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2461
** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2462
** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2463
** for VIEWs to have a ROWID.  The capability can only be enabled if SQLite is
2464
** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2465
** defaults to on.  This configuration option queries the current setting or
2466
** changes the setting to off or on.  The argument is a pointer to an integer.
2467
** If that integer initially holds a value of 1, then the ability for VIEWs to
2468
** have ROWIDs is activated.  If the integer initially holds zero, then the
2469
** ability is deactivated.  Any other initial value for the integer leaves the
2470
** setting unchanged.  After changes, if any, the integer is written with
2471
** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off.  If SQLite
2472
** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2473
** recommended case) then the integer is always filled with zero, regardless
2474
** if its initial value.
2475
** </dl>
2476
*/
2477
0
#define SQLITE_CONFIG_SINGLETHREAD         1  /* nil */
2478
0
#define SQLITE_CONFIG_MULTITHREAD          2  /* nil */
2479
0
#define SQLITE_CONFIG_SERIALIZED           3  /* nil */
2480
2
#define SQLITE_CONFIG_MALLOC               4  /* sqlite3_mem_methods* */
2481
0
#define SQLITE_CONFIG_GETMALLOC            5  /* sqlite3_mem_methods* */
2482
#define SQLITE_CONFIG_SCRATCH              6  /* No longer used */
2483
0
#define SQLITE_CONFIG_PAGECACHE            7  /* void*, int sz, int N */
2484
#define SQLITE_CONFIG_HEAP                 8  /* void*, int nByte, int min */
2485
0
#define SQLITE_CONFIG_MEMSTATUS            9  /* boolean */
2486
0
#define SQLITE_CONFIG_MUTEX               10  /* sqlite3_mutex_methods* */
2487
0
#define SQLITE_CONFIG_GETMUTEX            11  /* sqlite3_mutex_methods* */
2488
/* previously SQLITE_CONFIG_CHUNKALLOC    12 which is now unused. */
2489
0
#define SQLITE_CONFIG_LOOKASIDE           13  /* int int */
2490
0
#define SQLITE_CONFIG_PCACHE              14  /* no-op */
2491
0
#define SQLITE_CONFIG_GETPCACHE           15  /* no-op */
2492
0
#define SQLITE_CONFIG_LOG                 16  /* xFunc, void* */
2493
0
#define SQLITE_CONFIG_URI                 17  /* int */
2494
2
#define SQLITE_CONFIG_PCACHE2             18  /* sqlite3_pcache_methods2* */
2495
0
#define SQLITE_CONFIG_GETPCACHE2          19  /* sqlite3_pcache_methods2* */
2496
0
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
2497
#define SQLITE_CONFIG_SQLLOG              21  /* xSqllog, void* */
2498
0
#define SQLITE_CONFIG_MMAP_SIZE           22  /* sqlite3_int64, sqlite3_int64 */
2499
#define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
2500
0
#define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
2501
0
#define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
2502
0
#define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
2503
0
#define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
2504
#define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
2505
0
#define SQLITE_CONFIG_MEMDB_MAXSIZE       29  /* sqlite3_int64 */
2506
0
#define SQLITE_CONFIG_ROWID_IN_VIEW       30  /* int* */
2507
2508
/*
2509
** CAPI3REF: Database Connection Configuration Options
2510
**
2511
** These constants are the available integer configuration options that
2512
** can be passed as the second argument to the [sqlite3_db_config()] interface.
2513
**
2514
** New configuration options may be added in future releases of SQLite.
2515
** Existing configuration options might be discontinued.  Applications
2516
** should check the return code from [sqlite3_db_config()] to make sure that
2517
** the call worked.  ^The [sqlite3_db_config()] interface will return a
2518
** non-zero [error code] if a discontinued or unsupported configuration option
2519
** is invoked.
2520
**
2521
** <dl>
2522
** [[SQLITE_DBCONFIG_LOOKASIDE]]
2523
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2524
** <dd> ^This option takes three additional arguments that determine the
2525
** [lookaside memory allocator] configuration for the [database connection].
2526
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2527
** pointer to a memory buffer to use for lookaside memory.
2528
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2529
** may be NULL in which case SQLite will allocate the
2530
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2531
** size of each lookaside buffer slot.  ^The third argument is the number of
2532
** slots.  The size of the buffer in the first argument must be greater than
2533
** or equal to the product of the second and third arguments.  The buffer
2534
** must be aligned to an 8-byte boundary.  ^If the second argument to
2535
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2536
** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
2537
** configuration for a database connection can only be changed when that
2538
** connection is not currently using lookaside memory, or in other words
2539
** when the "current value" returned by
2540
** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2541
** Any attempt to change the lookaside memory configuration when lookaside
2542
** memory is in use leaves the configuration unchanged and returns
2543
** [SQLITE_BUSY].)^</dd>
2544
**
2545
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2546
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2547
** <dd> ^This option is used to enable or disable the enforcement of
2548
** [foreign key constraints].  There should be two additional arguments.
2549
** The first argument is an integer which is 0 to disable FK enforcement,
2550
** positive to enable FK enforcement or negative to leave FK enforcement
2551
** unchanged.  The second parameter is a pointer to an integer into which
2552
** is written 0 or 1 to indicate whether FK enforcement is off or on
2553
** following this call.  The second parameter may be a NULL pointer, in
2554
** which case the FK enforcement setting is not reported back. </dd>
2555
**
2556
** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
2557
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2558
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2559
** There should be two additional arguments.
2560
** The first argument is an integer which is 0 to disable triggers,
2561
** positive to enable triggers or negative to leave the setting unchanged.
2562
** The second parameter is a pointer to an integer into which
2563
** is written 0 or 1 to indicate whether triggers are disabled or enabled
2564
** following this call.  The second parameter may be a NULL pointer, in
2565
** which case the trigger setting is not reported back.
2566
**
2567
** <p>Originally this option disabled all triggers.  ^(However, since
2568
** SQLite version 3.35.0, TEMP triggers are still allowed even if
2569
** this option is off.  So, in other words, this option now only disables
2570
** triggers in the main database schema or in the schemas of ATTACH-ed
2571
** databases.)^ </dd>
2572
**
2573
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2574
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2575
** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2576
** There should be two additional arguments.
2577
** The first argument is an integer which is 0 to disable views,
2578
** positive to enable views or negative to leave the setting unchanged.
2579
** The second parameter is a pointer to an integer into which
2580
** is written 0 or 1 to indicate whether views are disabled or enabled
2581
** following this call.  The second parameter may be a NULL pointer, in
2582
** which case the view setting is not reported back.
2583
**
2584
** <p>Originally this option disabled all views.  ^(However, since
2585
** SQLite version 3.35.0, TEMP views are still allowed even if
2586
** this option is off.  So, in other words, this option now only disables
2587
** views in the main database schema or in the schemas of ATTACH-ed
2588
** databases.)^ </dd>
2589
**
2590
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2591
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2592
** <dd> ^This option is used to enable or disable the
2593
** [fts3_tokenizer()] function which is part of the
2594
** [FTS3] full-text search engine extension.
2595
** There should be two additional arguments.
2596
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2597
** positive to enable fts3_tokenizer() or negative to leave the setting
2598
** unchanged.
2599
** The second parameter is a pointer to an integer into which
2600
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2601
** following this call.  The second parameter may be a NULL pointer, in
2602
** which case the new setting is not reported back. </dd>
2603
**
2604
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2605
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2606
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2607
** interface independently of the [load_extension()] SQL function.
2608
** The [sqlite3_enable_load_extension()] API enables or disables both the
2609
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2610
** There should be two additional arguments.
2611
** When the first argument to this interface is 1, then only the C-API is
2612
** enabled and the SQL function remains disabled.  If the first argument to
2613
** this interface is 0, then both the C-API and the SQL function are disabled.
2614
** If the first argument is -1, then no changes are made to state of either the
2615
** C-API or the SQL function.
2616
** The second parameter is a pointer to an integer into which
2617
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2618
** is disabled or enabled following this call.  The second parameter may
2619
** be a NULL pointer, in which case the new setting is not reported back.
2620
** </dd>
2621
**
2622
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2623
** <dd> ^This option is used to change the name of the "main" database
2624
** schema.  ^The sole argument is a pointer to a constant UTF8 string
2625
** which will become the new schema name in place of "main".  ^SQLite
2626
** does not make a copy of the new main schema name string, so the application
2627
** must ensure that the argument passed into this DBCONFIG option is unchanged
2628
** until after the database connection closes.
2629
** </dd>
2630
**
2631
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2632
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2633
** <dd> Usually, when a database in wal mode is closed or detached from a
2634
** database handle, SQLite checks if this will mean that there are now no
2635
** connections at all to the database. If so, it performs a checkpoint
2636
** operation before closing the connection. This option may be used to
2637
** override this behavior. The first parameter passed to this operation
2638
** is an integer - positive to disable checkpoints-on-close, or zero (the
2639
** default) to enable them, and negative to leave the setting unchanged.
2640
** The second parameter is a pointer to an integer
2641
** into which is written 0 or 1 to indicate whether checkpoints-on-close
2642
** have been disabled - 0 if they are not disabled, 1 if they are.
2643
** </dd>
2644
**
2645
** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2646
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2647
** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
2648
** a single SQL query statement will always use the same algorithm regardless
2649
** of values of [bound parameters].)^ The QPSG disables some query optimizations
2650
** that look at the values of bound parameters, which can make some queries
2651
** slower.  But the QPSG has the advantage of more predictable behavior.  With
2652
** the QPSG active, SQLite will always use the same query plan in the field as
2653
** was used during testing in the lab.
2654
** The first argument to this setting is an integer which is 0 to disable
2655
** the QPSG, positive to enable QPSG, or negative to leave the setting
2656
** unchanged. The second parameter is a pointer to an integer into which
2657
** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2658
** following this call.
2659
** </dd>
2660
**
2661
** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2662
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2663
** include output for any operations performed by trigger programs. This
2664
** option is used to set or clear (the default) a flag that governs this
2665
** behavior. The first parameter passed to this operation is an integer -
2666
** positive to enable output for trigger programs, or zero to disable it,
2667
** or negative to leave the setting unchanged.
2668
** The second parameter is a pointer to an integer into which is written
2669
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2670
** it is not disabled, 1 if it is.
2671
** </dd>
2672
**
2673
** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
2674
** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
2675
** [VACUUM] in order to reset a database back to an empty database
2676
** with no schema and no content. The following process works even for
2677
** a badly corrupted database file:
2678
** <ol>
2679
** <li> If the database connection is newly opened, make sure it has read the
2680
**      database schema by preparing then discarding some query against the
2681
**      database, or calling sqlite3_table_column_metadata(), ignoring any
2682
**      errors.  This step is only necessary if the application desires to keep
2683
**      the database in WAL mode after the reset if it was in WAL mode before
2684
**      the reset.
2685
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2686
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2687
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2688
** </ol>
2689
** Because resetting a database is destructive and irreversible, the
2690
** process requires the use of this obscure API and multiple steps to
2691
** help ensure that it does not happen by accident. Because this
2692
** feature must be capable of resetting corrupt databases, and
2693
** shutting down virtual tables may require access to that corrupt
2694
** storage, the library must abandon any installed virtual tables
2695
** without calling their xDestroy() methods.
2696
**
2697
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2698
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2699
** "defensive" flag for a database connection.  When the defensive
2700
** flag is enabled, language features that allow ordinary SQL to
2701
** deliberately corrupt the database file are disabled.  The disabled
2702
** features include but are not limited to the following:
2703
** <ul>
2704
** <li> The [PRAGMA writable_schema=ON] statement.
2705
** <li> The [PRAGMA journal_mode=OFF] statement.
2706
** <li> The [PRAGMA schema_version=N] statement.
2707
** <li> Writes to the [sqlite_dbpage] virtual table.
2708
** <li> Direct writes to [shadow tables].
2709
** </ul>
2710
** </dd>
2711
**
2712
** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2713
** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2714
** "writable_schema" flag. This has the same effect and is logically equivalent
2715
** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2716
** The first argument to this setting is an integer which is 0 to disable
2717
** the writable_schema, positive to enable writable_schema, or negative to
2718
** leave the setting unchanged. The second parameter is a pointer to an
2719
** integer into which is written 0 or 1 to indicate whether the writable_schema
2720
** is enabled or disabled following this call.
2721
** </dd>
2722
**
2723
** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2724
** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2725
** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2726
** the legacy behavior of the [ALTER TABLE RENAME] command such it
2727
** behaves as it did prior to [version 3.24.0] (2018-06-04).  See the
2728
** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2729
** additional information. This feature can also be turned on and off
2730
** using the [PRAGMA legacy_alter_table] statement.
2731
** </dd>
2732
**
2733
** [[SQLITE_DBCONFIG_DQS_DML]]
2734
** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2735
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2736
** the legacy [double-quoted string literal] misfeature for DML statements
2737
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2738
** default value of this setting is determined by the [-DSQLITE_DQS]
2739
** compile-time option.
2740
** </dd>
2741
**
2742
** [[SQLITE_DBCONFIG_DQS_DDL]]
2743
** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2744
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2745
** the legacy [double-quoted string literal] misfeature for DDL statements,
2746
** such as CREATE TABLE and CREATE INDEX. The
2747
** default value of this setting is determined by the [-DSQLITE_DQS]
2748
** compile-time option.
2749
** </dd>
2750
**
2751
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2752
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2753
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2754
** assume that database schemas are untainted by malicious content.
2755
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2756
** takes additional defensive steps to protect the application from harm
2757
** including:
2758
** <ul>
2759
** <li> Prohibit the use of SQL functions inside triggers, views,
2760
** CHECK constraints, DEFAULT clauses, expression indexes,
2761
** partial indexes, or generated columns
2762
** unless those functions are tagged with [SQLITE_INNOCUOUS].
2763
** <li> Prohibit the use of virtual tables inside of triggers or views
2764
** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2765
** </ul>
2766
** This setting defaults to "on" for legacy compatibility, however
2767
** all applications are advised to turn it off if possible. This setting
2768
** can also be controlled using the [PRAGMA trusted_schema] statement.
2769
** </dd>
2770
**
2771
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2772
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2773
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2774
** the legacy file format flag.  When activated, this flag causes all newly
2775
** created database file to have a schema format version number (the 4-byte
2776
** integer found at offset 44 into the database header) of 1.  This in turn
2777
** means that the resulting database file will be readable and writable by
2778
** any SQLite version back to 3.0.0 ([dateof:3.0.0]).  Without this setting,
2779
** newly created databases are generally not understandable by SQLite versions
2780
** prior to 3.3.0 ([dateof:3.3.0]).  As these words are written, there
2781
** is now scarcely any need to generate database files that are compatible
2782
** all the way back to version 3.0.0, and so this setting is of little
2783
** practical use, but is provided so that SQLite can continue to claim the
2784
** ability to generate new database files that are compatible with  version
2785
** 3.0.0.
2786
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2787
** the [VACUUM] command will fail with an obscure error when attempting to
2788
** process a table with generated columns and a descending index.  This is
2789
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2790
** either generated columns or descending indexes.
2791
** </dd>
2792
**
2793
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2794
** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2795
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2796
** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2797
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2798
** statistics. For statistics to be collected, the flag must be set on
2799
** the database handle both when the SQL statement is prepared and when it
2800
** is stepped. The flag is set (collection of statistics is enabled)
2801
** by default.  This option takes two arguments: an integer and a pointer to
2802
** an integer..  The first argument is 1, 0, or -1 to enable, disable, or
2803
** leave unchanged the statement scanstatus option.  If the second argument
2804
** is not NULL, then the value of the statement scanstatus setting after
2805
** processing the first argument is written into the integer that the second
2806
** argument points to.
2807
** </dd>
2808
**
2809
** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2810
** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2811
** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2812
** in which tables and indexes are scanned so that the scans start at the end
2813
** and work toward the beginning rather than starting at the beginning and
2814
** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2815
** same as setting [PRAGMA reverse_unordered_selects].  This option takes
2816
** two arguments which are an integer and a pointer to an integer.  The first
2817
** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2818
** reverse scan order flag, respectively.  If the second argument is not NULL,
2819
** then 0 or 1 is written into the integer that the second argument points to
2820
** depending on if the reverse scan order flag is set after processing the
2821
** first argument.
2822
** </dd>
2823
**
2824
** </dl>
2825
*/
2826
0
#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
2827
0
#define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
2828
17.3k
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
2829
17.3k
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
2830
17.3k
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2831
17.3k
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2832
17.3k
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
2833
17.3k
#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
2834
17.3k
#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
2835
17.3k
#define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
2836
17.3k
#define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
2837
17.3k
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
2838
17.3k
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE    1012 /* int int* */
2839
17.3k
#define SQLITE_DBCONFIG_DQS_DML               1013 /* int int* */
2840
17.3k
#define SQLITE_DBCONFIG_DQS_DDL               1014 /* int int* */
2841
17.3k
#define SQLITE_DBCONFIG_ENABLE_VIEW           1015 /* int int* */
2842
17.3k
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT    1016 /* int int* */
2843
17.3k
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA        1017 /* int int* */
2844
17.3k
#define SQLITE_DBCONFIG_STMT_SCANSTATUS       1018 /* int int* */
2845
17.3k
#define SQLITE_DBCONFIG_REVERSE_SCANORDER     1019 /* int int* */
2846
#define SQLITE_DBCONFIG_MAX                   1019 /* Largest DBCONFIG */
2847
2848
/*
2849
** CAPI3REF: Enable Or Disable Extended Result Codes
2850
** METHOD: sqlite3
2851
**
2852
** ^The sqlite3_extended_result_codes() routine enables or disables the
2853
** [extended result codes] feature of SQLite. ^The extended result
2854
** codes are disabled by default for historical compatibility.
2855
*/
2856
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
2857
2858
/*
2859
** CAPI3REF: Last Insert Rowid
2860
** METHOD: sqlite3
2861
**
2862
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2863
** has a unique 64-bit signed
2864
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2865
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2866
** names are not also used by explicitly declared columns. ^If
2867
** the table has a column of type [INTEGER PRIMARY KEY] then that column
2868
** is another alias for the rowid.
2869
**
2870
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2871
** the most recent successful [INSERT] into a rowid table or [virtual table]
2872
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2873
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2874
** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2875
** zero.
2876
**
2877
** As well as being set automatically as rows are inserted into database
2878
** tables, the value returned by this function may be set explicitly by
2879
** [sqlite3_set_last_insert_rowid()]
2880
**
2881
** Some virtual table implementations may INSERT rows into rowid tables as
2882
** part of committing a transaction (e.g. to flush data accumulated in memory
2883
** to disk). In this case subsequent calls to this function return the rowid
2884
** associated with these internal INSERT operations, which leads to
2885
** unintuitive results. Virtual table implementations that do write to rowid
2886
** tables in this way can avoid this problem by restoring the original
2887
** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2888
** control to the user.
2889
**
2890
** ^(If an [INSERT] occurs within a trigger then this routine will
2891
** return the [rowid] of the inserted row as long as the trigger is
2892
** running. Once the trigger program ends, the value returned
2893
** by this routine reverts to what it was before the trigger was fired.)^
2894
**
2895
** ^An [INSERT] that fails due to a constraint violation is not a
2896
** successful [INSERT] and does not change the value returned by this
2897
** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2898
** and INSERT OR ABORT make no changes to the return value of this
2899
** routine when their insertion fails.  ^(When INSERT OR REPLACE
2900
** encounters a constraint violation, it does not fail.  The
2901
** INSERT continues to completion after deleting rows that caused
2902
** the constraint problem so INSERT OR REPLACE will always change
2903
** the return value of this interface.)^
2904
**
2905
** ^For the purposes of this routine, an [INSERT] is considered to
2906
** be successful even if it is subsequently rolled back.
2907
**
2908
** This function is accessible to SQL statements via the
2909
** [last_insert_rowid() SQL function].
2910
**
2911
** If a separate thread performs a new [INSERT] on the same
2912
** database connection while the [sqlite3_last_insert_rowid()]
2913
** function is running and thus changes the last insert [rowid],
2914
** then the value returned by [sqlite3_last_insert_rowid()] is
2915
** unpredictable and might not equal either the old or the new
2916
** last insert [rowid].
2917
*/
2918
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2919
2920
/*
2921
** CAPI3REF: Set the Last Insert Rowid value.
2922
** METHOD: sqlite3
2923
**
2924
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2925
** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2926
** without inserting a row into the database.
2927
*/
2928
SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2929
2930
/*
2931
** CAPI3REF: Count The Number Of Rows Modified
2932
** METHOD: sqlite3
2933
**
2934
** ^These functions return the number of rows modified, inserted or
2935
** deleted by the most recently completed INSERT, UPDATE or DELETE
2936
** statement on the database connection specified by the only parameter.
2937
** The two functions are identical except for the type of the return value
2938
** and that if the number of rows modified by the most recent INSERT, UPDATE
2939
** or DELETE is greater than the maximum value supported by type "int", then
2940
** the return value of sqlite3_changes() is undefined. ^Executing any other
2941
** type of SQL statement does not modify the value returned by these functions.
2942
**
2943
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2944
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2945
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2946
**
2947
** Changes to a view that are intercepted by
2948
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2949
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2950
** DELETE statement run on a view is always zero. Only changes made to real
2951
** tables are counted.
2952
**
2953
** Things are more complicated if the sqlite3_changes() function is
2954
** executed while a trigger program is running. This may happen if the
2955
** program uses the [changes() SQL function], or if some other callback
2956
** function invokes sqlite3_changes() directly. Essentially:
2957
**
2958
** <ul>
2959
**   <li> ^(Before entering a trigger program the value returned by
2960
**        sqlite3_changes() function is saved. After the trigger program
2961
**        has finished, the original value is restored.)^
2962
**
2963
**   <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2964
**        statement sets the value returned by sqlite3_changes()
2965
**        upon completion as normal. Of course, this value will not include
2966
**        any changes performed by sub-triggers, as the sqlite3_changes()
2967
**        value will be saved and restored after each sub-trigger has run.)^
2968
** </ul>
2969
**
2970
** ^This means that if the changes() SQL function (or similar) is used
2971
** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2972
** returns the value as set when the calling statement began executing.
2973
** ^If it is used by the second or subsequent such statement within a trigger
2974
** program, the value returned reflects the number of rows modified by the
2975
** previous INSERT, UPDATE or DELETE statement within the same trigger.
2976
**
2977
** If a separate thread makes changes on the same database connection
2978
** while [sqlite3_changes()] is running then the value returned
2979
** is unpredictable and not meaningful.
2980
**
2981
** See also:
2982
** <ul>
2983
** <li> the [sqlite3_total_changes()] interface
2984
** <li> the [count_changes pragma]
2985
** <li> the [changes() SQL function]
2986
** <li> the [data_version pragma]
2987
** </ul>
2988
*/
2989
SQLITE_API int sqlite3_changes(sqlite3*);
2990
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
2991
2992
/*
2993
** CAPI3REF: Total Number Of Rows Modified
2994
** METHOD: sqlite3
2995
**
2996
** ^These functions return the total number of rows inserted, modified or
2997
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2998
** since the database connection was opened, including those executed as
2999
** part of trigger programs. The two functions are identical except for the
3000
** type of the return value and that if the number of rows modified by the
3001
** connection exceeds the maximum value supported by type "int", then
3002
** the return value of sqlite3_total_changes() is undefined. ^Executing
3003
** any other type of SQL statement does not affect the value returned by
3004
** sqlite3_total_changes().
3005
**
3006
** ^Changes made as part of [foreign key actions] are included in the
3007
** count, but those made as part of REPLACE constraint resolution are
3008
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
3009
** are not counted.
3010
**
3011
** The [sqlite3_total_changes(D)] interface only reports the number
3012
** of rows that changed due to SQL statement run against database
3013
** connection D.  Any changes by other database connections are ignored.
3014
** To detect changes against a database file from other database
3015
** connections use the [PRAGMA data_version] command or the
3016
** [SQLITE_FCNTL_DATA_VERSION] [file control].
3017
**
3018
** If a separate thread makes changes on the same database connection
3019
** while [sqlite3_total_changes()] is running then the value
3020
** returned is unpredictable and not meaningful.
3021
**
3022
** See also:
3023
** <ul>
3024
** <li> the [sqlite3_changes()] interface
3025
** <li> the [count_changes pragma]
3026
** <li> the [changes() SQL function]
3027
** <li> the [data_version pragma]
3028
** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
3029
** </ul>
3030
*/
3031
SQLITE_API int sqlite3_total_changes(sqlite3*);
3032
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
3033
3034
/*
3035
** CAPI3REF: Interrupt A Long-Running Query
3036
** METHOD: sqlite3
3037
**
3038
** ^This function causes any pending database operation to abort and
3039
** return at its earliest opportunity. This routine is typically
3040
** called in response to a user action such as pressing "Cancel"
3041
** or Ctrl-C where the user wants a long query operation to halt
3042
** immediately.
3043
**
3044
** ^It is safe to call this routine from a thread different from the
3045
** thread that is currently running the database operation.  But it
3046
** is not safe to call this routine with a [database connection] that
3047
** is closed or might close before sqlite3_interrupt() returns.
3048
**
3049
** ^If an SQL operation is very nearly finished at the time when
3050
** sqlite3_interrupt() is called, then it might not have an opportunity
3051
** to be interrupted and might continue to completion.
3052
**
3053
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
3054
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
3055
** that is inside an explicit transaction, then the entire transaction
3056
** will be rolled back automatically.
3057
**
3058
** ^The sqlite3_interrupt(D) call is in effect until all currently running
3059
** SQL statements on [database connection] D complete.  ^Any new SQL statements
3060
** that are started after the sqlite3_interrupt() call and before the
3061
** running statement count reaches zero are interrupted as if they had been
3062
** running prior to the sqlite3_interrupt() call.  ^New SQL statements
3063
** that are started after the running statement count reaches zero are
3064
** not effected by the sqlite3_interrupt().
3065
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
3066
** SQL statements is a no-op and has no effect on SQL statements
3067
** that are started after the sqlite3_interrupt() call returns.
3068
**
3069
** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
3070
** or not an interrupt is currently in effect for [database connection] D.
3071
** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
3072
*/
3073
SQLITE_API void sqlite3_interrupt(sqlite3*);
3074
SQLITE_API int sqlite3_is_interrupted(sqlite3*);
3075
3076
/*
3077
** CAPI3REF: Determine If An SQL Statement Is Complete
3078
**
3079
** These routines are useful during command-line input to determine if the
3080
** currently entered text seems to form a complete SQL statement or
3081
** if additional input is needed before sending the text into
3082
** SQLite for parsing.  ^These routines return 1 if the input string
3083
** appears to be a complete SQL statement.  ^A statement is judged to be
3084
** complete if it ends with a semicolon token and is not a prefix of a
3085
** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
3086
** string literals or quoted identifier names or comments are not
3087
** independent tokens (they are part of the token in which they are
3088
** embedded) and thus do not count as a statement terminator.  ^Whitespace
3089
** and comments that follow the final semicolon are ignored.
3090
**
3091
** ^These routines return 0 if the statement is incomplete.  ^If a
3092
** memory allocation fails, then SQLITE_NOMEM is returned.
3093
**
3094
** ^These routines do not parse the SQL statements thus
3095
** will not detect syntactically incorrect SQL.
3096
**
3097
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
3098
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
3099
** automatically by sqlite3_complete16().  If that initialization fails,
3100
** then the return value from sqlite3_complete16() will be non-zero
3101
** regardless of whether or not the input SQL is complete.)^
3102
**
3103
** The input to [sqlite3_complete()] must be a zero-terminated
3104
** UTF-8 string.
3105
**
3106
** The input to [sqlite3_complete16()] must be a zero-terminated
3107
** UTF-16 string in native byte order.
3108
*/
3109
SQLITE_API int sqlite3_complete(const char *sql);
3110
SQLITE_API int sqlite3_complete16(const void *sql);
3111
3112
/*
3113
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
3114
** KEYWORDS: {busy-handler callback} {busy handler}
3115
** METHOD: sqlite3
3116
**
3117
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
3118
** that might be invoked with argument P whenever
3119
** an attempt is made to access a database table associated with
3120
** [database connection] D when another thread
3121
** or process has the table locked.
3122
** The sqlite3_busy_handler() interface is used to implement
3123
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
3124
**
3125
** ^If the busy callback is NULL, then [SQLITE_BUSY]
3126
** is returned immediately upon encountering the lock.  ^If the busy callback
3127
** is not NULL, then the callback might be invoked with two arguments.
3128
**
3129
** ^The first argument to the busy handler is a copy of the void* pointer which
3130
** is the third argument to sqlite3_busy_handler().  ^The second argument to
3131
** the busy handler callback is the number of times that the busy handler has
3132
** been invoked previously for the same locking event.  ^If the
3133
** busy callback returns 0, then no additional attempts are made to
3134
** access the database and [SQLITE_BUSY] is returned
3135
** to the application.
3136
** ^If the callback returns non-zero, then another attempt
3137
** is made to access the database and the cycle repeats.
3138
**
3139
** The presence of a busy handler does not guarantee that it will be invoked
3140
** when there is lock contention. ^If SQLite determines that invoking the busy
3141
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
3142
** to the application instead of invoking the
3143
** busy handler.
3144
** Consider a scenario where one process is holding a read lock that
3145
** it is trying to promote to a reserved lock and
3146
** a second process is holding a reserved lock that it is trying
3147
** to promote to an exclusive lock.  The first process cannot proceed
3148
** because it is blocked by the second and the second process cannot
3149
** proceed because it is blocked by the first.  If both processes
3150
** invoke the busy handlers, neither will make any progress.  Therefore,
3151
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
3152
** will induce the first process to release its read lock and allow
3153
** the second process to proceed.
3154
**
3155
** ^The default busy callback is NULL.
3156
**
3157
** ^(There can only be a single busy handler defined for each
3158
** [database connection].  Setting a new busy handler clears any
3159
** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
3160
** or evaluating [PRAGMA busy_timeout=N] will change the
3161
** busy handler and thus clear any previously set busy handler.
3162
**
3163
** The busy callback should not take any actions which modify the
3164
** database connection that invoked the busy handler.  In other words,
3165
** the busy handler is not reentrant.  Any such actions
3166
** result in undefined behavior.
3167
**
3168
** A busy handler must not close the database connection
3169
** or [prepared statement] that invoked the busy handler.
3170
*/
3171
SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
3172
3173
/*
3174
** CAPI3REF: Set A Busy Timeout
3175
** METHOD: sqlite3
3176
**
3177
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
3178
** for a specified amount of time when a table is locked.  ^The handler
3179
** will sleep multiple times until at least "ms" milliseconds of sleeping
3180
** have accumulated.  ^After at least "ms" milliseconds of sleeping,
3181
** the handler returns 0 which causes [sqlite3_step()] to return
3182
** [SQLITE_BUSY].
3183
**
3184
** ^Calling this routine with an argument less than or equal to zero
3185
** turns off all busy handlers.
3186
**
3187
** ^(There can only be a single busy handler for a particular
3188
** [database connection] at any given moment.  If another busy handler
3189
** was defined  (using [sqlite3_busy_handler()]) prior to calling
3190
** this routine, that other busy handler is cleared.)^
3191
**
3192
** See also:  [PRAGMA busy_timeout]
3193
*/
3194
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3195
3196
/*
3197
** CAPI3REF: Convenience Routines For Running Queries
3198
** METHOD: sqlite3
3199
**
3200
** This is a legacy interface that is preserved for backwards compatibility.
3201
** Use of this interface is not recommended.
3202
**
3203
** Definition: A <b>result table</b> is memory data structure created by the
3204
** [sqlite3_get_table()] interface.  A result table records the
3205
** complete query results from one or more queries.
3206
**
3207
** The table conceptually has a number of rows and columns.  But
3208
** these numbers are not part of the result table itself.  These
3209
** numbers are obtained separately.  Let N be the number of rows
3210
** and M be the number of columns.
3211
**
3212
** A result table is an array of pointers to zero-terminated UTF-8 strings.
3213
** There are (N+1)*M elements in the array.  The first M pointers point
3214
** to zero-terminated strings that  contain the names of the columns.
3215
** The remaining entries all point to query results.  NULL values result
3216
** in NULL pointers.  All other values are in their UTF-8 zero-terminated
3217
** string representation as returned by [sqlite3_column_text()].
3218
**
3219
** A result table might consist of one or more memory allocations.
3220
** It is not safe to pass a result table directly to [sqlite3_free()].
3221
** A result table should be deallocated using [sqlite3_free_table()].
3222
**
3223
** ^(As an example of the result table format, suppose a query result
3224
** is as follows:
3225
**
3226
** <blockquote><pre>
3227
**        Name        | Age
3228
**        -----------------------
3229
**        Alice       | 43
3230
**        Bob         | 28
3231
**        Cindy       | 21
3232
** </pre></blockquote>
3233
**
3234
** There are two columns (M==2) and three rows (N==3).  Thus the
3235
** result table has 8 entries.  Suppose the result table is stored
3236
** in an array named azResult.  Then azResult holds this content:
3237
**
3238
** <blockquote><pre>
3239
**        azResult&#91;0] = "Name";
3240
**        azResult&#91;1] = "Age";
3241
**        azResult&#91;2] = "Alice";
3242
**        azResult&#91;3] = "43";
3243
**        azResult&#91;4] = "Bob";
3244
**        azResult&#91;5] = "28";
3245
**        azResult&#91;6] = "Cindy";
3246
**        azResult&#91;7] = "21";
3247
** </pre></blockquote>)^
3248
**
3249
** ^The sqlite3_get_table() function evaluates one or more
3250
** semicolon-separated SQL statements in the zero-terminated UTF-8
3251
** string of its 2nd parameter and returns a result table to the
3252
** pointer given in its 3rd parameter.
3253
**
3254
** After the application has finished with the result from sqlite3_get_table(),
3255
** it must pass the result table pointer to sqlite3_free_table() in order to
3256
** release the memory that was malloced.  Because of the way the
3257
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
3258
** function must not try to call [sqlite3_free()] directly.  Only
3259
** [sqlite3_free_table()] is able to release the memory properly and safely.
3260
**
3261
** The sqlite3_get_table() interface is implemented as a wrapper around
3262
** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
3263
** to any internal data structures of SQLite.  It uses only the public
3264
** interface defined here.  As a consequence, errors that occur in the
3265
** wrapper layer outside of the internal [sqlite3_exec()] call are not
3266
** reflected in subsequent calls to [sqlite3_errcode()] or
3267
** [sqlite3_errmsg()].
3268
*/
3269
SQLITE_API int sqlite3_get_table(
3270
  sqlite3 *db,          /* An open database */
3271
  const char *zSql,     /* SQL to be evaluated */
3272
  char ***pazResult,    /* Results of the query */
3273
  int *pnRow,           /* Number of result rows written here */
3274
  int *pnColumn,        /* Number of result columns written here */
3275
  char **pzErrmsg       /* Error msg written here */
3276
);
3277
SQLITE_API void sqlite3_free_table(char **result);
3278
3279
/*
3280
** CAPI3REF: Formatted String Printing Functions
3281
**
3282
** These routines are work-alikes of the "printf()" family of functions
3283
** from the standard C library.
3284
** These routines understand most of the common formatting options from
3285
** the standard library printf()
3286
** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
3287
** See the [built-in printf()] documentation for details.
3288
**
3289
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
3290
** results into memory obtained from [sqlite3_malloc64()].
3291
** The strings returned by these two routines should be
3292
** released by [sqlite3_free()].  ^Both routines return a
3293
** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
3294
** memory to hold the resulting string.
3295
**
3296
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
3297
** the standard C library.  The result is written into the
3298
** buffer supplied as the second parameter whose size is given by
3299
** the first parameter. Note that the order of the
3300
** first two parameters is reversed from snprintf().)^  This is an
3301
** historical accident that cannot be fixed without breaking
3302
** backwards compatibility.  ^(Note also that sqlite3_snprintf()
3303
** returns a pointer to its buffer instead of the number of
3304
** characters actually written into the buffer.)^  We admit that
3305
** the number of characters written would be a more useful return
3306
** value but we cannot change the implementation of sqlite3_snprintf()
3307
** now without breaking compatibility.
3308
**
3309
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
3310
** guarantees that the buffer is always zero-terminated.  ^The first
3311
** parameter "n" is the total size of the buffer, including space for
3312
** the zero terminator.  So the longest string that can be completely
3313
** written will be n-1 characters.
3314
**
3315
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
3316
**
3317
** See also:  [built-in printf()], [printf() SQL function]
3318
*/
3319
SQLITE_API char *sqlite3_mprintf(const char*,...);
3320
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3321
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3322
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3323
3324
/*
3325
** CAPI3REF: Memory Allocation Subsystem
3326
**
3327
** The SQLite core uses these three routines for all of its own
3328
** internal memory allocation needs. "Core" in the previous sentence
3329
** does not include operating-system specific [VFS] implementation.  The
3330
** Windows VFS uses native malloc() and free() for some operations.
3331
**
3332
** ^The sqlite3_malloc() routine returns a pointer to a block
3333
** of memory at least N bytes in length, where N is the parameter.
3334
** ^If sqlite3_malloc() is unable to obtain sufficient free
3335
** memory, it returns a NULL pointer.  ^If the parameter N to
3336
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
3337
** a NULL pointer.
3338
**
3339
** ^The sqlite3_malloc64(N) routine works just like
3340
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
3341
** of a signed 32-bit integer.
3342
**
3343
** ^Calling sqlite3_free() with a pointer previously returned
3344
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3345
** that it might be reused.  ^The sqlite3_free() routine is
3346
** a no-op if is called with a NULL pointer.  Passing a NULL pointer
3347
** to sqlite3_free() is harmless.  After being freed, memory
3348
** should neither be read nor written.  Even reading previously freed
3349
** memory might result in a segmentation fault or other severe error.
3350
** Memory corruption, a segmentation fault, or other severe error
3351
** might result if sqlite3_free() is called with a non-NULL pointer that
3352
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
3353
**
3354
** ^The sqlite3_realloc(X,N) interface attempts to resize a
3355
** prior memory allocation X to be at least N bytes.
3356
** ^If the X parameter to sqlite3_realloc(X,N)
3357
** is a NULL pointer then its behavior is identical to calling
3358
** sqlite3_malloc(N).
3359
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3360
** negative then the behavior is exactly the same as calling
3361
** sqlite3_free(X).
3362
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3363
** of at least N bytes in size or NULL if insufficient memory is available.
3364
** ^If M is the size of the prior allocation, then min(N,M) bytes
3365
** of the prior allocation are copied into the beginning of buffer returned
3366
** by sqlite3_realloc(X,N) and the prior allocation is freed.
3367
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3368
** prior allocation is not freed.
3369
**
3370
** ^The sqlite3_realloc64(X,N) interfaces works the same as
3371
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3372
** of a 32-bit signed integer.
3373
**
3374
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3375
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
3376
** sqlite3_msize(X) returns the size of that memory allocation in bytes.
3377
** ^The value returned by sqlite3_msize(X) might be larger than the number
3378
** of bytes requested when X was allocated.  ^If X is a NULL pointer then
3379
** sqlite3_msize(X) returns zero.  If X points to something that is not
3380
** the beginning of memory allocation, or if it points to a formerly
3381
** valid memory allocation that has now been freed, then the behavior
3382
** of sqlite3_msize(X) is undefined and possibly harmful.
3383
**
3384
** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
3385
** sqlite3_malloc64(), and sqlite3_realloc64()
3386
** is always aligned to at least an 8 byte boundary, or to a
3387
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3388
** option is used.
3389
**
3390
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3391
** must be either NULL or else pointers obtained from a prior
3392
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3393
** not yet been released.
3394
**
3395
** The application must not read or write any part of
3396
** a block of memory after it has been released using
3397
** [sqlite3_free()] or [sqlite3_realloc()].
3398
*/
3399
SQLITE_API void *sqlite3_malloc(int);
3400
SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
3401
SQLITE_API void *sqlite3_realloc(void*, int);
3402
SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
3403
SQLITE_API void sqlite3_free(void*);
3404
SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
3405
3406
/*
3407
** CAPI3REF: Memory Allocator Statistics
3408
**
3409
** SQLite provides these two interfaces for reporting on the status
3410
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
3411
** routines, which form the built-in memory allocation subsystem.
3412
**
3413
** ^The [sqlite3_memory_used()] routine returns the number of bytes
3414
** of memory currently outstanding (malloced but not freed).
3415
** ^The [sqlite3_memory_highwater()] routine returns the maximum
3416
** value of [sqlite3_memory_used()] since the high-water mark
3417
** was last reset.  ^The values returned by [sqlite3_memory_used()] and
3418
** [sqlite3_memory_highwater()] include any overhead
3419
** added by SQLite in its implementation of [sqlite3_malloc()],
3420
** but not overhead added by the any underlying system library
3421
** routines that [sqlite3_malloc()] may call.
3422
**
3423
** ^The memory high-water mark is reset to the current value of
3424
** [sqlite3_memory_used()] if and only if the parameter to
3425
** [sqlite3_memory_highwater()] is true.  ^The value returned
3426
** by [sqlite3_memory_highwater(1)] is the high-water mark
3427
** prior to the reset.
3428
*/
3429
SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
3430
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
3431
3432
/*
3433
** CAPI3REF: Pseudo-Random Number Generator
3434
**
3435
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3436
** select random [ROWID | ROWIDs] when inserting new records into a table that
3437
** already uses the largest possible [ROWID].  The PRNG is also used for
3438
** the built-in random() and randomblob() SQL functions.  This interface allows
3439
** applications to access the same PRNG for other purposes.
3440
**
3441
** ^A call to this routine stores N bytes of randomness into buffer P.
3442
** ^The P parameter can be a NULL pointer.
3443
**
3444
** ^If this routine has not been previously called or if the previous
3445
** call had N less than one or a NULL pointer for P, then the PRNG is
3446
** seeded using randomness obtained from the xRandomness method of
3447
** the default [sqlite3_vfs] object.
3448
** ^If the previous call to this routine had an N of 1 or more and a
3449
** non-NULL P then the pseudo-randomness is generated
3450
** internally and without recourse to the [sqlite3_vfs] xRandomness
3451
** method.
3452
*/
3453
SQLITE_API void sqlite3_randomness(int N, void *P);
3454
3455
/*
3456
** CAPI3REF: Compile-Time Authorization Callbacks
3457
** METHOD: sqlite3
3458
** KEYWORDS: {authorizer callback}
3459
**
3460
** ^This routine registers an authorizer callback with a particular
3461
** [database connection], supplied in the first argument.
3462
** ^The authorizer callback is invoked as SQL statements are being compiled
3463
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
3464
** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
3465
** and [sqlite3_prepare16_v3()].  ^At various
3466
** points during the compilation process, as logic is being created
3467
** to perform various actions, the authorizer callback is invoked to
3468
** see if those actions are allowed.  ^The authorizer callback should
3469
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
3470
** specific action but allow the SQL statement to continue to be
3471
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
3472
** rejected with an error.  ^If the authorizer callback returns
3473
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
3474
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
3475
** the authorizer will fail with an error message.
3476
**
3477
** When the callback returns [SQLITE_OK], that means the operation
3478
** requested is ok.  ^When the callback returns [SQLITE_DENY], the
3479
** [sqlite3_prepare_v2()] or equivalent call that triggered the
3480
** authorizer will fail with an error message explaining that
3481
** access is denied.
3482
**
3483
** ^The first parameter to the authorizer callback is a copy of the third
3484
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3485
** to the callback is an integer [SQLITE_COPY | action code] that specifies
3486
** the particular action to be authorized. ^The third through sixth parameters
3487
** to the callback are either NULL pointers or zero-terminated strings
3488
** that contain additional details about the action to be authorized.
3489
** Applications must always be prepared to encounter a NULL pointer in any
3490
** of the third through the sixth parameters of the authorization callback.
3491
**
3492
** ^If the action code is [SQLITE_READ]
3493
** and the callback returns [SQLITE_IGNORE] then the
3494
** [prepared statement] statement is constructed to substitute
3495
** a NULL value in place of the table column that would have
3496
** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
3497
** return can be used to deny an untrusted user access to individual
3498
** columns of a table.
3499
** ^When a table is referenced by a [SELECT] but no column values are
3500
** extracted from that table (for example in a query like
3501
** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
3502
** is invoked once for that table with a column name that is an empty string.
3503
** ^If the action code is [SQLITE_DELETE] and the callback returns
3504
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
3505
** [truncate optimization] is disabled and all rows are deleted individually.
3506
**
3507
** An authorizer is used when [sqlite3_prepare | preparing]
3508
** SQL statements from an untrusted source, to ensure that the SQL statements
3509
** do not try to access data they are not allowed to see, or that they do not
3510
** try to execute malicious statements that damage the database.  For
3511
** example, an application may allow a user to enter arbitrary
3512
** SQL queries for evaluation by a database.  But the application does
3513
** not want the user to be able to make arbitrary changes to the
3514
** database.  An authorizer could then be put in place while the
3515
** user-entered SQL is being [sqlite3_prepare | prepared] that
3516
** disallows everything except [SELECT] statements.
3517
**
3518
** Applications that need to process SQL from untrusted sources
3519
** might also consider lowering resource limits using [sqlite3_limit()]
3520
** and limiting database size using the [max_page_count] [PRAGMA]
3521
** in addition to using an authorizer.
3522
**
3523
** ^(Only a single authorizer can be in place on a database connection
3524
** at a time.  Each call to sqlite3_set_authorizer overrides the
3525
** previous call.)^  ^Disable the authorizer by installing a NULL callback.
3526
** The authorizer is disabled by default.
3527
**
3528
** The authorizer callback must not do anything that will modify
3529
** the database connection that invoked the authorizer callback.
3530
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3531
** database connections for the meaning of "modify" in this paragraph.
3532
**
3533
** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3534
** statement might be re-prepared during [sqlite3_step()] due to a
3535
** schema change.  Hence, the application should ensure that the
3536
** correct authorizer callback remains in place during the [sqlite3_step()].
3537
**
3538
** ^Note that the authorizer callback is invoked only during
3539
** [sqlite3_prepare()] or its variants.  Authorization is not
3540
** performed during statement evaluation in [sqlite3_step()], unless
3541
** as stated in the previous paragraph, sqlite3_step() invokes
3542
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3543
*/
3544
SQLITE_API int sqlite3_set_authorizer(
3545
  sqlite3*,
3546
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3547
  void *pUserData
3548
);
3549
3550
/*
3551
** CAPI3REF: Authorizer Return Codes
3552
**
3553
** The [sqlite3_set_authorizer | authorizer callback function] must
3554
** return either [SQLITE_OK] or one of these two constants in order
3555
** to signal SQLite whether or not the action is permitted.  See the
3556
** [sqlite3_set_authorizer | authorizer documentation] for additional
3557
** information.
3558
**
3559
** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
3560
** returned from the [sqlite3_vtab_on_conflict()] interface.
3561
*/
3562
3.89M
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
3563
5.47M
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
3564
3565
/*
3566
** CAPI3REF: Authorizer Action Codes
3567
**
3568
** The [sqlite3_set_authorizer()] interface registers a callback function
3569
** that is invoked to authorize certain SQL statement actions.  The
3570
** second parameter to the callback is an integer code that specifies
3571
** what action is being authorized.  These are the integer action codes that
3572
** the authorizer callback may be passed.
3573
**
3574
** These action code values signify what kind of operation is to be
3575
** authorized.  The 3rd and 4th parameters to the authorization
3576
** callback function will be parameters or NULL depending on which of these
3577
** codes is used as the second parameter.  ^(The 5th parameter to the
3578
** authorizer callback is the name of the database ("main", "temp",
3579
** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
3580
** is the name of the inner-most trigger or view that is responsible for
3581
** the access attempt or NULL if this access attempt is directly from
3582
** top-level SQL code.
3583
*/
3584
/******************************************* 3rd ************ 4th ***********/
3585
309k
#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
3586
490k
#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
3587
11.9k
#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
3588
490k
#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
3589
1.70k
#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
3590
490k
#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
3591
6.56k
#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
3592
490k
#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
3593
22.1k
#define SQLITE_DELETE                9   /* Table Name      NULL            */
3594
65
#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
3595
3.50k
#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
3596
39
#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
3597
85
#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
3598
121
#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
3599
0
#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
3600
191
#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
3601
1
#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
3602
1.05M
#define SQLITE_INSERT               18   /* Table Name      NULL            */
3603
74.3k
#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
3604
1.23M
#define SQLITE_READ                 20   /* Table Name      Column Name     */
3605
553k
#define SQLITE_SELECT               21   /* NULL            NULL            */
3606
36.9k
#define SQLITE_TRANSACTION          22   /* Operation       NULL            */
3607
601k
#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
3608
71.8k
#define SQLITE_ATTACH               24   /* Filename        NULL            */
3609
392
#define SQLITE_DETACH               25   /* Database Name   NULL            */
3610
1.47k
#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
3611
16.6k
#define SQLITE_REINDEX              27   /* Index Name      NULL            */
3612
11.9k
#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
3613
148
#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
3614
1
#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
3615
281k
#define SQLITE_FUNCTION             31   /* NULL            Function Name   */
3616
11.8k
#define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
3617
#define SQLITE_COPY                  0   /* No longer used */
3618
709
#define SQLITE_RECURSIVE            33   /* NULL            NULL            */
3619
3620
/*
3621
** CAPI3REF: Deprecated Tracing And Profiling Functions
3622
** DEPRECATED
3623
**
3624
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3625
** instead of the routines described here.
3626
**
3627
** These routines register callback functions that can be used for
3628
** tracing and profiling the execution of SQL statements.
3629
**
3630
** ^The callback function registered by sqlite3_trace() is invoked at
3631
** various times when an SQL statement is being run by [sqlite3_step()].
3632
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
3633
** SQL statement text as the statement first begins executing.
3634
** ^(Additional sqlite3_trace() callbacks might occur
3635
** as each triggered subprogram is entered.  The callbacks for triggers
3636
** contain a UTF-8 SQL comment that identifies the trigger.)^
3637
**
3638
** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3639
** the length of [bound parameter] expansion in the output of sqlite3_trace().
3640
**
3641
** ^The callback function registered by sqlite3_profile() is invoked
3642
** as each SQL statement finishes.  ^The profile callback contains
3643
** the original statement text and an estimate of wall-clock time
3644
** of how long that statement took to run.  ^The profile callback
3645
** time is in units of nanoseconds, however the current implementation
3646
** is only capable of millisecond resolution so the six least significant
3647
** digits in the time are meaningless.  Future versions of SQLite
3648
** might provide greater resolution on the profiler callback.  Invoking
3649
** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
3650
** profile callback.
3651
*/
3652
SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
3653
   void(*xTrace)(void*,const char*), void*);
3654
SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3655
   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
3656
3657
/*
3658
** CAPI3REF: SQL Trace Event Codes
3659
** KEYWORDS: SQLITE_TRACE
3660
**
3661
** These constants identify classes of events that can be monitored
3662
** using the [sqlite3_trace_v2()] tracing logic.  The M argument
3663
** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
3664
** the following constants.  ^The first argument to the trace callback
3665
** is one of the following constants.
3666
**
3667
** New tracing constants may be added in future releases.
3668
**
3669
** ^A trace callback has four arguments: xCallback(T,C,P,X).
3670
** ^The T argument is one of the integer type codes above.
3671
** ^The C argument is a copy of the context pointer passed in as the
3672
** fourth argument to [sqlite3_trace_v2()].
3673
** The P and X arguments are pointers whose meanings depend on T.
3674
**
3675
** <dl>
3676
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
3677
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
3678
** first begins running and possibly at other times during the
3679
** execution of the prepared statement, such as at the start of each
3680
** trigger subprogram. ^The P argument is a pointer to the
3681
** [prepared statement]. ^The X argument is a pointer to a string which
3682
** is the unexpanded SQL text of the prepared statement or an SQL comment
3683
** that indicates the invocation of a trigger.  ^The callback can compute
3684
** the same text that would have been returned by the legacy [sqlite3_trace()]
3685
** interface by using the X argument when X begins with "--" and invoking
3686
** [sqlite3_expanded_sql(P)] otherwise.
3687
**
3688
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3689
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3690
** information as is provided by the [sqlite3_profile()] callback.
3691
** ^The P argument is a pointer to the [prepared statement] and the
3692
** X argument points to a 64-bit integer which is approximately
3693
** the number of nanoseconds that the prepared statement took to run.
3694
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3695
**
3696
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3697
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3698
** statement generates a single row of result.
3699
** ^The P argument is a pointer to the [prepared statement] and the
3700
** X argument is unused.
3701
**
3702
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
3703
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
3704
** connection closes.
3705
** ^The P argument is a pointer to the [database connection] object
3706
** and the X argument is unused.
3707
** </dl>
3708
*/
3709
1.28M
#define SQLITE_TRACE_STMT       0x01
3710
887k
#define SQLITE_TRACE_PROFILE    0x02
3711
775k
#define SQLITE_TRACE_ROW        0x04
3712
17.3k
#define SQLITE_TRACE_CLOSE      0x08
3713
3714
/*
3715
** CAPI3REF: SQL Trace Hook
3716
** METHOD: sqlite3
3717
**
3718
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
3719
** function X against [database connection] D, using property mask M
3720
** and context pointer P.  ^If the X callback is
3721
** NULL or if the M mask is zero, then tracing is disabled.  The
3722
** M argument should be the bitwise OR-ed combination of
3723
** zero or more [SQLITE_TRACE] constants.
3724
**
3725
** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3726
** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3727
** sqlite3_trace_v2(D,M,X,P) for the [database connection] D.  Each
3728
** database connection may have at most one trace callback.
3729
**
3730
** ^The X callback is invoked whenever any of the events identified by
3731
** mask M occur.  ^The integer return value from the callback is currently
3732
** ignored, though this may change in future releases.  Callback
3733
** implementations should return zero to ensure future compatibility.
3734
**
3735
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
3736
** ^The T argument is one of the [SQLITE_TRACE]
3737
** constants to indicate why the callback was invoked.
3738
** ^The C argument is a copy of the context pointer.
3739
** The P and X arguments are pointers whose meanings depend on T.
3740
**
3741
** The sqlite3_trace_v2() interface is intended to replace the legacy
3742
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
3743
** are deprecated.
3744
*/
3745
SQLITE_API int sqlite3_trace_v2(
3746
  sqlite3*,
3747
  unsigned uMask,
3748
  int(*xCallback)(unsigned,void*,void*,void*),
3749
  void *pCtx
3750
);
3751
3752
/*
3753
** CAPI3REF: Query Progress Callbacks
3754
** METHOD: sqlite3
3755
**
3756
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3757
** function X to be invoked periodically during long running calls to
3758
** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3759
** database connection D.  An example use for this
3760
** interface is to keep a GUI updated during a large query.
3761
**
3762
** ^The parameter P is passed through as the only parameter to the
3763
** callback function X.  ^The parameter N is the approximate number of
3764
** [virtual machine instructions] that are evaluated between successive
3765
** invocations of the callback X.  ^If N is less than one then the progress
3766
** handler is disabled.
3767
**
3768
** ^Only a single progress handler may be defined at one time per
3769
** [database connection]; setting a new progress handler cancels the
3770
** old one.  ^Setting parameter X to NULL disables the progress handler.
3771
** ^The progress handler is also disabled by setting N to a value less
3772
** than 1.
3773
**
3774
** ^If the progress callback returns non-zero, the operation is
3775
** interrupted.  This feature can be used to implement a
3776
** "Cancel" button on a GUI progress dialog box.
3777
**
3778
** The progress handler callback must not do anything that will modify
3779
** the database connection that invoked the progress handler.
3780
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3781
** database connections for the meaning of "modify" in this paragraph.
3782
**
3783
** The progress handler callback would originally only be invoked from the
3784
** bytecode engine.  It still might be invoked during [sqlite3_prepare()]
3785
** and similar because those routines might force a reparse of the schema
3786
** which involves running the bytecode engine.  However, beginning with
3787
** SQLite version 3.41.0, the progress handler callback might also be
3788
** invoked directly from [sqlite3_prepare()] while analyzing and generating
3789
** code for complex queries.
3790
*/
3791
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3792
3793
/*
3794
** CAPI3REF: Opening A New Database Connection
3795
** CONSTRUCTOR: sqlite3
3796
**
3797
** ^These routines open an SQLite database file as specified by the
3798
** filename argument. ^The filename argument is interpreted as UTF-8 for
3799
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3800
** order for sqlite3_open16(). ^(A [database connection] handle is usually
3801
** returned in *ppDb, even if an error occurs.  The only exception is that
3802
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3803
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3804
** object.)^ ^(If the database is opened (and/or created) successfully, then
3805
** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
3806
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3807
** an English language description of the error following a failure of any
3808
** of the sqlite3_open() routines.
3809
**
3810
** ^The default encoding will be UTF-8 for databases created using
3811
** sqlite3_open() or sqlite3_open_v2().  ^The default encoding for databases
3812
** created using sqlite3_open16() will be UTF-16 in the native byte order.
3813
**
3814
** Whether or not an error occurs when it is opened, resources
3815
** associated with the [database connection] handle should be released by
3816
** passing it to [sqlite3_close()] when it is no longer required.
3817
**
3818
** The sqlite3_open_v2() interface works like sqlite3_open()
3819
** except that it accepts two additional parameters for additional control
3820
** over the new database connection.  ^(The flags parameter to
3821
** sqlite3_open_v2() must include, at a minimum, one of the following
3822
** three flag combinations:)^
3823
**
3824
** <dl>
3825
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3826
** <dd>The database is opened in read-only mode.  If the database does
3827
** not already exist, an error is returned.</dd>)^
3828
**
3829
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3830
** <dd>The database is opened for reading and writing if possible, or
3831
** reading only if the file is write protected by the operating
3832
** system.  In either case the database must already exist, otherwise
3833
** an error is returned.  For historical reasons, if opening in
3834
** read-write mode fails due to OS-level permissions, an attempt is
3835
** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3836
** used to determine whether the database is actually
3837
** read-write.</dd>)^
3838
**
3839
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3840
** <dd>The database is opened for reading and writing, and is created if
3841
** it does not already exist. This is the behavior that is always used for
3842
** sqlite3_open() and sqlite3_open16().</dd>)^
3843
** </dl>
3844
**
3845
** In addition to the required flags, the following optional flags are
3846
** also supported:
3847
**
3848
** <dl>
3849
** ^(<dt>[SQLITE_OPEN_URI]</dt>
3850
** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3851
**
3852
** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3853
** <dd>The database will be opened as an in-memory database.  The database
3854
** is named by the "filename" argument for the purposes of cache-sharing,
3855
** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3856
** </dd>)^
3857
**
3858
** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3859
** <dd>The new database connection will use the "multi-thread"
3860
** [threading mode].)^  This means that separate threads are allowed
3861
** to use SQLite at the same time, as long as each thread is using
3862
** a different [database connection].
3863
**
3864
** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3865
** <dd>The new database connection will use the "serialized"
3866
** [threading mode].)^  This means the multiple threads can safely
3867
** attempt to use the same database connection at the same time.
3868
** (Mutexes will block any actual concurrency, but in this mode
3869
** there is no harm in trying.)
3870
**
3871
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3872
** <dd>The database is opened [shared cache] enabled, overriding
3873
** the default shared cache setting provided by
3874
** [sqlite3_enable_shared_cache()].)^
3875
** The [use of shared cache mode is discouraged] and hence shared cache
3876
** capabilities may be omitted from many builds of SQLite.  In such cases,
3877
** this option is a no-op.
3878
**
3879
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3880
** <dd>The database is opened [shared cache] disabled, overriding
3881
** the default shared cache setting provided by
3882
** [sqlite3_enable_shared_cache()].)^
3883
**
3884
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3885
** <dd>The database connection comes up in "extended result code mode".
3886
** In other words, the database behaves has if
3887
** [sqlite3_extended_result_codes(db,1)] where called on the database
3888
** connection as soon as the connection is created. In addition to setting
3889
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3890
** to return an extended result code.</dd>
3891
**
3892
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3893
** <dd>The database filename is not allowed to contain a symbolic link</dd>
3894
** </dl>)^
3895
**
3896
** If the 3rd parameter to sqlite3_open_v2() is not one of the
3897
** required combinations shown above optionally combined with other
3898
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3899
** then the behavior is undefined.  Historic versions of SQLite
3900
** have silently ignored surplus bits in the flags parameter to
3901
** sqlite3_open_v2(), however that behavior might not be carried through
3902
** into future versions of SQLite and so applications should not rely
3903
** upon it.  Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3904
** for sqlite3_open_v2().  The SQLITE_OPEN_EXCLUSIVE does *not* cause
3905
** the open to fail if the database already exists.  The SQLITE_OPEN_EXCLUSIVE
3906
** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3907
** by sqlite3_open_v2().
3908
**
3909
** ^The fourth parameter to sqlite3_open_v2() is the name of the
3910
** [sqlite3_vfs] object that defines the operating system interface that
3911
** the new database connection should use.  ^If the fourth parameter is
3912
** a NULL pointer then the default [sqlite3_vfs] object is used.
3913
**
3914
** ^If the filename is ":memory:", then a private, temporary in-memory database
3915
** is created for the connection.  ^This in-memory database will vanish when
3916
** the database connection is closed.  Future versions of SQLite might
3917
** make use of additional special filenames that begin with the ":" character.
3918
** It is recommended that when a database filename actually does begin with
3919
** a ":" character you should prefix the filename with a pathname such as
3920
** "./" to avoid ambiguity.
3921
**
3922
** ^If the filename is an empty string, then a private, temporary
3923
** on-disk database will be created.  ^This private database will be
3924
** automatically deleted as soon as the database connection is closed.
3925
**
3926
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3927
**
3928
** ^If [URI filename] interpretation is enabled, and the filename argument
3929
** begins with "file:", then the filename is interpreted as a URI. ^URI
3930
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3931
** set in the third argument to sqlite3_open_v2(), or if it has
3932
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3933
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3934
** URI filename interpretation is turned off
3935
** by default, but future releases of SQLite might enable URI filename
3936
** interpretation by default.  See "[URI filenames]" for additional
3937
** information.
3938
**
3939
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3940
** authority, then it must be either an empty string or the string
3941
** "localhost". ^If the authority is not an empty string or "localhost", an
3942
** error is returned to the caller. ^The fragment component of a URI, if
3943
** present, is ignored.
3944
**
3945
** ^SQLite uses the path component of the URI as the name of the disk file
3946
** which contains the database. ^If the path begins with a '/' character,
3947
** then it is interpreted as an absolute path. ^If the path does not begin
3948
** with a '/' (meaning that the authority section is omitted from the URI)
3949
** then the path is interpreted as a relative path.
3950
** ^(On windows, the first component of an absolute path
3951
** is a drive specification (e.g. "C:").)^
3952
**
3953
** [[core URI query parameters]]
3954
** The query component of a URI may contain parameters that are interpreted
3955
** either by SQLite itself, or by a [VFS | custom VFS implementation].
3956
** SQLite and its built-in [VFSes] interpret the
3957
** following query parameters:
3958
**
3959
** <ul>
3960
**   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3961
**     a VFS object that provides the operating system interface that should
3962
**     be used to access the database file on disk. ^If this option is set to
3963
**     an empty string the default VFS object is used. ^Specifying an unknown
3964
**     VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3965
**     present, then the VFS specified by the option takes precedence over
3966
**     the value passed as the fourth parameter to sqlite3_open_v2().
3967
**
3968
**   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3969
**     "rwc", or "memory". Attempting to set it to any other value is
3970
**     an error)^.
3971
**     ^If "ro" is specified, then the database is opened for read-only
3972
**     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3973
**     third argument to sqlite3_open_v2(). ^If the mode option is set to
3974
**     "rw", then the database is opened for read-write (but not create)
3975
**     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3976
**     been set. ^Value "rwc" is equivalent to setting both
3977
**     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
3978
**     set to "memory" then a pure [in-memory database] that never reads
3979
**     or writes from disk is used. ^It is an error to specify a value for
3980
**     the mode parameter that is less restrictive than that specified by
3981
**     the flags passed in the third parameter to sqlite3_open_v2().
3982
**
3983
**   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3984
**     "private". ^Setting it to "shared" is equivalent to setting the
3985
**     SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3986
**     sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3987
**     equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3988
**     ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3989
**     a URI filename, its value overrides any behavior requested by setting
3990
**     SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3991
**
3992
**  <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3993
**     [powersafe overwrite] property does or does not apply to the
3994
**     storage media on which the database file resides.
3995
**
3996
**  <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3997
**     which if set disables file locking in rollback journal modes.  This
3998
**     is useful for accessing a database on a filesystem that does not
3999
**     support locking.  Caution:  Database corruption might result if two
4000
**     or more processes write to the same database and any one of those
4001
**     processes uses nolock=1.
4002
**
4003
**  <li> <b>immutable</b>: ^The immutable parameter is a boolean query
4004
**     parameter that indicates that the database file is stored on
4005
**     read-only media.  ^When immutable is set, SQLite assumes that the
4006
**     database file cannot be changed, even by a process with higher
4007
**     privilege, and so the database is opened read-only and all locking
4008
**     and change detection is disabled.  Caution: Setting the immutable
4009
**     property on a database file that does in fact change can result
4010
**     in incorrect query results and/or [SQLITE_CORRUPT] errors.
4011
**     See also: [SQLITE_IOCAP_IMMUTABLE].
4012
**
4013
** </ul>
4014
**
4015
** ^Specifying an unknown parameter in the query component of a URI is not an
4016
** error.  Future versions of SQLite might understand additional query
4017
** parameters.  See "[query parameters with special meaning to SQLite]" for
4018
** additional information.
4019
**
4020
** [[URI filename examples]] <h3>URI filename examples</h3>
4021
**
4022
** <table border="1" align=center cellpadding=5>
4023
** <tr><th> URI filenames <th> Results
4024
** <tr><td> file:data.db <td>
4025
**          Open the file "data.db" in the current directory.
4026
** <tr><td> file:/home/fred/data.db<br>
4027
**          file:///home/fred/data.db <br>
4028
**          file://localhost/home/fred/data.db <br> <td>
4029
**          Open the database file "/home/fred/data.db".
4030
** <tr><td> file://darkstar/home/fred/data.db <td>
4031
**          An error. "darkstar" is not a recognized authority.
4032
** <tr><td style="white-space:nowrap">
4033
**          file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
4034
**     <td> Windows only: Open the file "data.db" on fred's desktop on drive
4035
**          C:. Note that the %20 escaping in this example is not strictly
4036
**          necessary - space characters can be used literally
4037
**          in URI filenames.
4038
** <tr><td> file:data.db?mode=ro&cache=private <td>
4039
**          Open file "data.db" in the current directory for read-only access.
4040
**          Regardless of whether or not shared-cache mode is enabled by
4041
**          default, use a private cache.
4042
** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
4043
**          Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
4044
**          that uses dot-files in place of posix advisory locking.
4045
** <tr><td> file:data.db?mode=readonly <td>
4046
**          An error. "readonly" is not a valid option for the "mode" parameter.
4047
**          Use "ro" instead:  "file:data.db?mode=ro".
4048
** </table>
4049
**
4050
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
4051
** query components of a URI. A hexadecimal escape sequence consists of a
4052
** percent sign - "%" - followed by exactly two hexadecimal digits
4053
** specifying an octet value. ^Before the path or query components of a
4054
** URI filename are interpreted, they are encoded using UTF-8 and all
4055
** hexadecimal escape sequences replaced by a single byte containing the
4056
** corresponding octet. If this process generates an invalid UTF-8 encoding,
4057
** the results are undefined.
4058
**
4059
** <b>Note to Windows users:</b>  The encoding used for the filename argument
4060
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
4061
** codepage is currently defined.  Filenames containing international
4062
** characters must be converted to UTF-8 prior to passing them into
4063
** sqlite3_open() or sqlite3_open_v2().
4064
**
4065
** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
4066
** prior to calling sqlite3_open() or sqlite3_open_v2().  Otherwise, various
4067
** features that require the use of temporary files may fail.
4068
**
4069
** See also: [sqlite3_temp_directory]
4070
*/
4071
SQLITE_API int sqlite3_open(
4072
  const char *filename,   /* Database filename (UTF-8) */
4073
  sqlite3 **ppDb          /* OUT: SQLite db handle */
4074
);
4075
SQLITE_API int sqlite3_open16(
4076
  const void *filename,   /* Database filename (UTF-16) */
4077
  sqlite3 **ppDb          /* OUT: SQLite db handle */
4078
);
4079
SQLITE_API int sqlite3_open_v2(
4080
  const char *filename,   /* Database filename (UTF-8) */
4081
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
4082
  int flags,              /* Flags */
4083
  const char *zVfs        /* Name of VFS module to use */
4084
);
4085
4086
/*
4087
** CAPI3REF: Obtain Values For URI Parameters
4088
**
4089
** These are utility routines, useful to [VFS|custom VFS implementations],
4090
** that check if a database file was a URI that contained a specific query
4091
** parameter, and if so obtains the value of that query parameter.
4092
**
4093
** The first parameter to these interfaces (hereafter referred to
4094
** as F) must be one of:
4095
** <ul>
4096
** <li> A database filename pointer created by the SQLite core and
4097
** passed into the xOpen() method of a VFS implementation, or
4098
** <li> A filename obtained from [sqlite3_db_filename()], or
4099
** <li> A new filename constructed using [sqlite3_create_filename()].
4100
** </ul>
4101
** If the F parameter is not one of the above, then the behavior is
4102
** undefined and probably undesirable.  Older versions of SQLite were
4103
** more tolerant of invalid F parameters than newer versions.
4104
**
4105
** If F is a suitable filename (as described in the previous paragraph)
4106
** and if P is the name of the query parameter, then
4107
** sqlite3_uri_parameter(F,P) returns the value of the P
4108
** parameter if it exists or a NULL pointer if P does not appear as a
4109
** query parameter on F.  If P is a query parameter of F and it
4110
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4111
** a pointer to an empty string.
4112
**
4113
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
4114
** parameter and returns true (1) or false (0) according to the value
4115
** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
4116
** value of query parameter P is one of "yes", "true", or "on" in any
4117
** case or if the value begins with a non-zero number.  The
4118
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4119
** query parameter P is one of "no", "false", or "off" in any case or
4120
** if the value begins with a numeric zero.  If P is not a query
4121
** parameter on F or if the value of P does not match any of the
4122
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4123
**
4124
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4125
** 64-bit signed integer and returns that integer, or D if P does not
4126
** exist.  If the value of P is something other than an integer, then
4127
** zero is returned.
4128
**
4129
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4130
** the value) of the N-th query parameter for filename F, or a NULL
4131
** pointer if N is less than zero or greater than the number of query
4132
** parameters minus 1.  The N value is zero-based so N should be 0 to obtain
4133
** the name of the first query parameter, 1 for the second parameter, and
4134
** so forth.
4135
**
4136
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4137
** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
4138
** is not a database file pathname pointer that the SQLite core passed
4139
** into the xOpen VFS method, then the behavior of this routine is undefined
4140
** and probably undesirable.
4141
**
4142
** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4143
** parameter can also be the name of a rollback journal file or WAL file
4144
** in addition to the main database file.  Prior to version 3.31.0, these
4145
** routines would only work if F was the name of the main database file.
4146
** When the F parameter is the name of the rollback journal or WAL file,
4147
** it has access to all the same query parameters as were found on the
4148
** main database file.
4149
**
4150
** See the [URI filename] documentation for additional information.
4151
*/
4152
SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
4153
SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
4154
SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
4155
SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
4156
4157
/*
4158
** CAPI3REF:  Translate filenames
4159
**
4160
** These routines are available to [VFS|custom VFS implementations] for
4161
** translating filenames between the main database file, the journal file,
4162
** and the WAL file.
4163
**
4164
** If F is the name of an sqlite database file, journal file, or WAL file
4165
** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
4166
** returns the name of the corresponding database file.
4167
**
4168
** If F is the name of an sqlite database file, journal file, or WAL file
4169
** passed by the SQLite core into the VFS, or if F is a database filename
4170
** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
4171
** returns the name of the corresponding rollback journal file.
4172
**
4173
** If F is the name of an sqlite database file, journal file, or WAL file
4174
** that was passed by the SQLite core into the VFS, or if F is a database
4175
** filename obtained from [sqlite3_db_filename()], then
4176
** sqlite3_filename_wal(F) returns the name of the corresponding
4177
** WAL file.
4178
**
4179
** In all of the above, if F is not the name of a database, journal or WAL
4180
** filename passed into the VFS from the SQLite core and F is not the
4181
** return value from [sqlite3_db_filename()], then the result is
4182
** undefined and is likely a memory access violation.
4183
*/
4184
SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
4185
SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
4186
SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
4187
4188
/*
4189
** CAPI3REF:  Database File Corresponding To A Journal
4190
**
4191
** ^If X is the name of a rollback or WAL-mode journal file that is
4192
** passed into the xOpen method of [sqlite3_vfs], then
4193
** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
4194
** object that represents the main database file.
4195
**
4196
** This routine is intended for use in custom [VFS] implementations
4197
** only.  It is not a general-purpose interface.
4198
** The argument sqlite3_file_object(X) must be a filename pointer that
4199
** has been passed into [sqlite3_vfs].xOpen method where the
4200
** flags parameter to xOpen contains one of the bits
4201
** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL].  Any other use
4202
** of this routine results in undefined and probably undesirable
4203
** behavior.
4204
*/
4205
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4206
4207
/*
4208
** CAPI3REF: Create and Destroy VFS Filenames
4209
**
4210
** These interfaces are provided for use by [VFS shim] implementations and
4211
** are not useful outside of that context.
4212
**
4213
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4214
** database filename D with corresponding journal file J and WAL file W and
4215
** with N URI parameters key/values pairs in the array P.  The result from
4216
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4217
** is safe to pass to routines like:
4218
** <ul>
4219
** <li> [sqlite3_uri_parameter()],
4220
** <li> [sqlite3_uri_boolean()],
4221
** <li> [sqlite3_uri_int64()],
4222
** <li> [sqlite3_uri_key()],
4223
** <li> [sqlite3_filename_database()],
4224
** <li> [sqlite3_filename_journal()], or
4225
** <li> [sqlite3_filename_wal()].
4226
** </ul>
4227
** If a memory allocation error occurs, sqlite3_create_filename() might
4228
** return a NULL pointer.  The memory obtained from sqlite3_create_filename(X)
4229
** must be released by a corresponding call to sqlite3_free_filename(Y).
4230
**
4231
** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
4232
** of 2*N pointers to strings.  Each pair of pointers in this array corresponds
4233
** to a key and value for a query parameter.  The P parameter may be a NULL
4234
** pointer if N is zero.  None of the 2*N pointers in the P array may be
4235
** NULL pointers and key pointers should not be empty strings.
4236
** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
4237
** be NULL pointers, though they can be empty strings.
4238
**
4239
** The sqlite3_free_filename(Y) routine releases a memory allocation
4240
** previously obtained from sqlite3_create_filename().  Invoking
4241
** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
4242
**
4243
** If the Y parameter to sqlite3_free_filename(Y) is anything other
4244
** than a NULL pointer or a pointer previously acquired from
4245
** sqlite3_create_filename(), then bad things such as heap
4246
** corruption or segfaults may occur. The value Y should not be
4247
** used again after sqlite3_free_filename(Y) has been called.  This means
4248
** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
4249
** then the corresponding [sqlite3_module.xClose() method should also be
4250
** invoked prior to calling sqlite3_free_filename(Y).
4251
*/
4252
SQLITE_API sqlite3_filename sqlite3_create_filename(
4253
  const char *zDatabase,
4254
  const char *zJournal,
4255
  const char *zWal,
4256
  int nParam,
4257
  const char **azParam
4258
);
4259
SQLITE_API void sqlite3_free_filename(sqlite3_filename);
4260
4261
/*
4262
** CAPI3REF: Error Codes And Messages
4263
** METHOD: sqlite3
4264
**
4265
** ^If the most recent sqlite3_* API call associated with
4266
** [database connection] D failed, then the sqlite3_errcode(D) interface
4267
** returns the numeric [result code] or [extended result code] for that
4268
** API call.
4269
** ^The sqlite3_extended_errcode()
4270
** interface is the same except that it always returns the
4271
** [extended result code] even when extended result codes are
4272
** disabled.
4273
**
4274
** The values returned by sqlite3_errcode() and/or
4275
** sqlite3_extended_errcode() might change with each API call.
4276
** Except, there are some interfaces that are guaranteed to never
4277
** change the value of the error code.  The error-code preserving
4278
** interfaces include the following:
4279
**
4280
** <ul>
4281
** <li> sqlite3_errcode()
4282
** <li> sqlite3_extended_errcode()
4283
** <li> sqlite3_errmsg()
4284
** <li> sqlite3_errmsg16()
4285
** <li> sqlite3_error_offset()
4286
** </ul>
4287
**
4288
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4289
** text that describes the error, as either UTF-8 or UTF-16 respectively,
4290
** or NULL if no error message is available.
4291
** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
4292
** ^(Memory to hold the error message string is managed internally.
4293
** The application does not need to worry about freeing the result.
4294
** However, the error string might be overwritten or deallocated by
4295
** subsequent calls to other SQLite interface functions.)^
4296
**
4297
** ^The sqlite3_errstr(E) interface returns the English-language text
4298
** that describes the [result code] E, as UTF-8, or NULL if E is not an
4299
** result code for which a text error message is available.
4300
** ^(Memory to hold the error message string is managed internally
4301
** and must not be freed by the application)^.
4302
**
4303
** ^If the most recent error references a specific token in the input
4304
** SQL, the sqlite3_error_offset() interface returns the byte offset
4305
** of the start of that token.  ^The byte offset returned by
4306
** sqlite3_error_offset() assumes that the input SQL is UTF8.
4307
** ^If the most recent error does not reference a specific token in the input
4308
** SQL, then the sqlite3_error_offset() function returns -1.
4309
**
4310
** When the serialized [threading mode] is in use, it might be the
4311
** case that a second error occurs on a separate thread in between
4312
** the time of the first error and the call to these interfaces.
4313
** When that happens, the second error will be reported since these
4314
** interfaces always report the most recent result.  To avoid
4315
** this, each thread can obtain exclusive use of the [database connection] D
4316
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
4317
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
4318
** all calls to the interfaces listed here are completed.
4319
**
4320
** If an interface fails with SQLITE_MISUSE, that means the interface
4321
** was invoked incorrectly by the application.  In that case, the
4322
** error code and message may or may not be set.
4323
*/
4324
SQLITE_API int sqlite3_errcode(sqlite3 *db);
4325
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
4326
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4327
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4328
SQLITE_API const char *sqlite3_errstr(int);
4329
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4330
4331
/*
4332
** CAPI3REF: Prepared Statement Object
4333
** KEYWORDS: {prepared statement} {prepared statements}
4334
**
4335
** An instance of this object represents a single SQL statement that
4336
** has been compiled into binary form and is ready to be evaluated.
4337
**
4338
** Think of each SQL statement as a separate computer program.  The
4339
** original SQL text is source code.  A prepared statement object
4340
** is the compiled object code.  All SQL must be converted into a
4341
** prepared statement before it can be run.
4342
**
4343
** The life-cycle of a prepared statement object usually goes like this:
4344
**
4345
** <ol>
4346
** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
4347
** <li> Bind values to [parameters] using the sqlite3_bind_*()
4348
**      interfaces.
4349
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
4350
** <li> Reset the prepared statement using [sqlite3_reset()] then go back
4351
**      to step 2.  Do this zero or more times.
4352
** <li> Destroy the object using [sqlite3_finalize()].
4353
** </ol>
4354
*/
4355
typedef struct sqlite3_stmt sqlite3_stmt;
4356
4357
/*
4358
** CAPI3REF: Run-time Limits
4359
** METHOD: sqlite3
4360
**
4361
** ^(This interface allows the size of various constructs to be limited
4362
** on a connection by connection basis.  The first parameter is the
4363
** [database connection] whose limit is to be set or queried.  The
4364
** second parameter is one of the [limit categories] that define a
4365
** class of constructs to be size limited.  The third parameter is the
4366
** new limit for that construct.)^
4367
**
4368
** ^If the new limit is a negative number, the limit is unchanged.
4369
** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
4370
** [limits | hard upper bound]
4371
** set at compile-time by a C preprocessor macro called
4372
** [limits | SQLITE_MAX_<i>NAME</i>].
4373
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
4374
** ^Attempts to increase a limit above its hard upper bound are
4375
** silently truncated to the hard upper bound.
4376
**
4377
** ^Regardless of whether or not the limit was changed, the
4378
** [sqlite3_limit()] interface returns the prior value of the limit.
4379
** ^Hence, to find the current value of a limit without changing it,
4380
** simply invoke this interface with the third parameter set to -1.
4381
**
4382
** Run-time limits are intended for use in applications that manage
4383
** both their own internal database and also databases that are controlled
4384
** by untrusted external sources.  An example application might be a
4385
** web browser that has its own databases for storing history and
4386
** separate databases controlled by JavaScript applications downloaded
4387
** off the Internet.  The internal databases can be given the
4388
** large, default limits.  Databases managed by external sources can
4389
** be given much smaller limits designed to prevent a denial of service
4390
** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
4391
** interface to further control untrusted SQL.  The size of the database
4392
** created by an untrusted script can be contained using the
4393
** [max_page_count] [PRAGMA].
4394
**
4395
** New run-time limit categories may be added in future releases.
4396
*/
4397
SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4398
4399
/*
4400
** CAPI3REF: Run-Time Limit Categories
4401
** KEYWORDS: {limit category} {*limit categories}
4402
**
4403
** These constants define various performance limits
4404
** that can be lowered at run-time using [sqlite3_limit()].
4405
** The synopsis of the meanings of the various limits is shown below.
4406
** Additional information is available at [limits | Limits in SQLite].
4407
**
4408
** <dl>
4409
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4410
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4411
**
4412
** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
4413
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
4414
**
4415
** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
4416
** <dd>The maximum number of columns in a table definition or in the
4417
** result set of a [SELECT] or the maximum number of columns in an index
4418
** or in an ORDER BY or GROUP BY clause.</dd>)^
4419
**
4420
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4421
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
4422
**
4423
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
4424
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
4425
**
4426
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
4427
** <dd>The maximum number of instructions in a virtual machine program
4428
** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
4429
** the equivalent tries to allocate space for more than this many opcodes
4430
** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
4431
**
4432
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
4433
** <dd>The maximum number of arguments on a function.</dd>)^
4434
**
4435
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
4436
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
4437
**
4438
** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
4439
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
4440
** <dd>The maximum length of the pattern argument to the [LIKE] or
4441
** [GLOB] operators.</dd>)^
4442
**
4443
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4444
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4445
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4446
**
4447
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4448
** <dd>The maximum depth of recursion for triggers.</dd>)^
4449
**
4450
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4451
** <dd>The maximum number of auxiliary worker threads that a single
4452
** [prepared statement] may start.</dd>)^
4453
** </dl>
4454
*/
4455
52.6M
#define SQLITE_LIMIT_LENGTH                    0
4456
1.58M
#define SQLITE_LIMIT_SQL_LENGTH                1
4457
2.72M
#define SQLITE_LIMIT_COLUMN                    2
4458
7.29M
#define SQLITE_LIMIT_EXPR_DEPTH                3
4459
1.18k
#define SQLITE_LIMIT_COMPOUND_SELECT           4
4460
1.37M
#define SQLITE_LIMIT_VDBE_OP                   5
4461
264k
#define SQLITE_LIMIT_FUNCTION_ARG              6
4462
35.7k
#define SQLITE_LIMIT_ATTACHED                  7
4463
1.84M
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
4464
19.6k
#define SQLITE_LIMIT_VARIABLE_NUMBER           9
4465
260k
#define SQLITE_LIMIT_TRIGGER_DEPTH            10
4466
90.3k
#define SQLITE_LIMIT_WORKER_THREADS           11
4467
4468
/*
4469
** CAPI3REF: Prepare Flags
4470
**
4471
** These constants define various flags that can be passed into
4472
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4473
** [sqlite3_prepare16_v3()] interfaces.
4474
**
4475
** New flags may be added in future releases of SQLite.
4476
**
4477
** <dl>
4478
** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
4479
** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
4480
** that the prepared statement will be retained for a long time and
4481
** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
4482
** and [sqlite3_prepare16_v3()] assume that the prepared statement will
4483
** be used just once or at most a few times and then destroyed using
4484
** [sqlite3_finalize()] relatively soon. The current implementation acts
4485
** on this hint by avoiding the use of [lookaside memory] so as not to
4486
** deplete the limited store of lookaside memory. Future versions of
4487
** SQLite may act on this hint differently.
4488
**
4489
** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
4490
** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
4491
** to be required for any prepared statement that wanted to use the
4492
** [sqlite3_normalized_sql()] interface.  However, the
4493
** [sqlite3_normalized_sql()] interface is now available to all
4494
** prepared statements, regardless of whether or not they use this
4495
** flag.
4496
**
4497
** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
4498
** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4499
** to return an error (error code SQLITE_ERROR) if the statement uses
4500
** any virtual tables.
4501
** </dl>
4502
*/
4503
1.30M
#define SQLITE_PREPARE_PERSISTENT              0x01
4504
#define SQLITE_PREPARE_NORMALIZE               0x02
4505
5.18k
#define SQLITE_PREPARE_NO_VTAB                 0x04
4506
4507
/*
4508
** CAPI3REF: Compiling An SQL Statement
4509
** KEYWORDS: {SQL statement compiler}
4510
** METHOD: sqlite3
4511
** CONSTRUCTOR: sqlite3_stmt
4512
**
4513
** To execute an SQL statement, it must first be compiled into a byte-code
4514
** program using one of these routines.  Or, in other words, these routines
4515
** are constructors for the [prepared statement] object.
4516
**
4517
** The preferred routine to use is [sqlite3_prepare_v2()].  The
4518
** [sqlite3_prepare()] interface is legacy and should be avoided.
4519
** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4520
** for special purposes.
4521
**
4522
** The use of the UTF-8 interfaces is preferred, as SQLite currently
4523
** does all parsing using UTF-8.  The UTF-16 interfaces are provided
4524
** as a convenience.  The UTF-16 interfaces work by converting the
4525
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4526
**
4527
** The first argument, "db", is a [database connection] obtained from a
4528
** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
4529
** [sqlite3_open16()].  The database connection must not have been closed.
4530
**
4531
** The second argument, "zSql", is the statement to be compiled, encoded
4532
** as either UTF-8 or UTF-16.  The sqlite3_prepare(), sqlite3_prepare_v2(),
4533
** and sqlite3_prepare_v3()
4534
** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
4535
** and sqlite3_prepare16_v3() use UTF-16.
4536
**
4537
** ^If the nByte argument is negative, then zSql is read up to the
4538
** first zero terminator. ^If nByte is positive, then it is the
4539
** number of bytes read from zSql.  ^If nByte is zero, then no prepared
4540
** statement is generated.
4541
** If the caller knows that the supplied string is nul-terminated, then
4542
** there is a small performance advantage to passing an nByte parameter that
4543
** is the number of bytes in the input string <i>including</i>
4544
** the nul-terminator.
4545
**
4546
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4547
** past the end of the first SQL statement in zSql.  These routines only
4548
** compile the first statement in zSql, so *pzTail is left pointing to
4549
** what remains uncompiled.
4550
**
4551
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
4552
** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
4553
** to NULL.  ^If the input text contains no SQL (if the input is an empty
4554
** string or a comment) then *ppStmt is set to NULL.
4555
** The calling procedure is responsible for deleting the compiled
4556
** SQL statement using [sqlite3_finalize()] after it has finished with it.
4557
** ppStmt may not be NULL.
4558
**
4559
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
4560
** otherwise an [error code] is returned.
4561
**
4562
** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
4563
** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
4564
** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
4565
** are retained for backwards compatibility, but their use is discouraged.
4566
** ^In the "vX" interfaces, the prepared statement
4567
** that is returned (the [sqlite3_stmt] object) contains a copy of the
4568
** original SQL text. This causes the [sqlite3_step()] interface to
4569
** behave differently in three ways:
4570
**
4571
** <ol>
4572
** <li>
4573
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
4574
** always used to do, [sqlite3_step()] will automatically recompile the SQL
4575
** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
4576
** retries will occur before sqlite3_step() gives up and returns an error.
4577
** </li>
4578
**
4579
** <li>
4580
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
4581
** [error codes] or [extended error codes].  ^The legacy behavior was that
4582
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
4583
** and the application would have to make a second call to [sqlite3_reset()]
4584
** in order to find the underlying cause of the problem. With the "v2" prepare
4585
** interfaces, the underlying reason for the error is returned immediately.
4586
** </li>
4587
**
4588
** <li>
4589
** ^If the specific value bound to a [parameter | host parameter] in the
4590
** WHERE clause might influence the choice of query plan for a statement,
4591
** then the statement will be automatically recompiled, as if there had been
4592
** a schema change, on the first [sqlite3_step()] call following any change
4593
** to the [sqlite3_bind_text | bindings] of that [parameter].
4594
** ^The specific value of a WHERE-clause [parameter] might influence the
4595
** choice of query plan if the parameter is the left-hand side of a [LIKE]
4596
** or [GLOB] operator or if the parameter is compared to an indexed column
4597
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4598
** </li>
4599
** </ol>
4600
**
4601
** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
4602
** the extra prepFlags parameter, which is a bit array consisting of zero or
4603
** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags.  ^The
4604
** sqlite3_prepare_v2() interface works exactly the same as
4605
** sqlite3_prepare_v3() with a zero prepFlags parameter.
4606
*/
4607
SQLITE_API int sqlite3_prepare(
4608
  sqlite3 *db,            /* Database handle */
4609
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4610
  int nByte,              /* Maximum length of zSql in bytes. */
4611
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4612
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4613
);
4614
SQLITE_API int sqlite3_prepare_v2(
4615
  sqlite3 *db,            /* Database handle */
4616
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4617
  int nByte,              /* Maximum length of zSql in bytes. */
4618
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4619
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4620
);
4621
SQLITE_API int sqlite3_prepare_v3(
4622
  sqlite3 *db,            /* Database handle */
4623
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4624
  int nByte,              /* Maximum length of zSql in bytes. */
4625
  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4626
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4627
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4628
);
4629
SQLITE_API int sqlite3_prepare16(
4630
  sqlite3 *db,            /* Database handle */
4631
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4632
  int nByte,              /* Maximum length of zSql in bytes. */
4633
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4634
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4635
);
4636
SQLITE_API int sqlite3_prepare16_v2(
4637
  sqlite3 *db,            /* Database handle */
4638
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4639
  int nByte,              /* Maximum length of zSql in bytes. */
4640
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4641
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4642
);
4643
SQLITE_API int sqlite3_prepare16_v3(
4644
  sqlite3 *db,            /* Database handle */
4645
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4646
  int nByte,              /* Maximum length of zSql in bytes. */
4647
  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4648
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4649
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4650
);
4651
4652
/*
4653
** CAPI3REF: Retrieving Statement SQL
4654
** METHOD: sqlite3_stmt
4655
**
4656
** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
4657
** SQL text used to create [prepared statement] P if P was
4658
** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
4659
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4660
** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
4661
** string containing the SQL text of prepared statement P with
4662
** [bound parameters] expanded.
4663
** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
4664
** string containing the normalized SQL text of prepared statement P.  The
4665
** semantics used to normalize a SQL statement are unspecified and subject
4666
** to change.  At a minimum, literal values will be replaced with suitable
4667
** placeholders.
4668
**
4669
** ^(For example, if a prepared statement is created using the SQL
4670
** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
4671
** and parameter :xyz is unbound, then sqlite3_sql() will return
4672
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4673
** will return "SELECT 2345,NULL".)^
4674
**
4675
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4676
** is available to hold the result, or if the result would exceed the
4677
** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4678
**
4679
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4680
** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
4681
** option causes sqlite3_expanded_sql() to always return NULL.
4682
**
4683
** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
4684
** are managed by SQLite and are automatically freed when the prepared
4685
** statement is finalized.
4686
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
4687
** is obtained from [sqlite3_malloc()] and must be freed by the application
4688
** by passing it to [sqlite3_free()].
4689
**
4690
** ^The sqlite3_normalized_sql() interface is only available if
4691
** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
4692
*/
4693
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
4694
SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
4695
#ifdef SQLITE_ENABLE_NORMALIZE
4696
SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
4697
#endif
4698
4699
/*
4700
** CAPI3REF: Determine If An SQL Statement Writes The Database
4701
** METHOD: sqlite3_stmt
4702
**
4703
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
4704
** and only if the [prepared statement] X makes no direct changes to
4705
** the content of the database file.
4706
**
4707
** Note that [application-defined SQL functions] or
4708
** [virtual tables] might change the database indirectly as a side effect.
4709
** ^(For example, if an application defines a function "eval()" that
4710
** calls [sqlite3_exec()], then the following SQL statement would
4711
** change the database file through side-effects:
4712
**
4713
** <blockquote><pre>
4714
**    SELECT eval('DELETE FROM t1') FROM t2;
4715
** </pre></blockquote>
4716
**
4717
** But because the [SELECT] statement does not change the database file
4718
** directly, sqlite3_stmt_readonly() would still return true.)^
4719
**
4720
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
4721
** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
4722
** since the statements themselves do not actually modify the database but
4723
** rather they control the timing of when other statements modify the
4724
** database.  ^The [ATTACH] and [DETACH] statements also cause
4725
** sqlite3_stmt_readonly() to return true since, while those statements
4726
** change the configuration of a database connection, they do not make
4727
** changes to the content of the database files on disk.
4728
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4729
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4730
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4731
** sqlite3_stmt_readonly() returns false for those commands.
4732
**
4733
** ^This routine returns false if there is any possibility that the
4734
** statement might change the database file.  ^A false return does
4735
** not guarantee that the statement will change the database file.
4736
** ^For example, an UPDATE statement might have a WHERE clause that
4737
** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4738
** be false.  ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4739
** read-only no-op if the table already exists, but
4740
** sqlite3_stmt_readonly() still returns false for such a statement.
4741
**
4742
** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
4743
** statement, then sqlite3_stmt_readonly(X) returns the same value as
4744
** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
4745
*/
4746
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4747
4748
/*
4749
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4750
** METHOD: sqlite3_stmt
4751
**
4752
** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4753
** prepared statement S is an EXPLAIN statement, or 2 if the
4754
** statement S is an EXPLAIN QUERY PLAN.
4755
** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4756
** an ordinary statement or a NULL pointer.
4757
*/
4758
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4759
4760
/*
4761
** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement
4762
** METHOD: sqlite3_stmt
4763
**
4764
** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN
4765
** setting for [prepared statement] S.  If E is zero, then S becomes
4766
** a normal prepared statement.  If E is 1, then S behaves as if
4767
** its SQL text began with "[EXPLAIN]".  If E is 2, then S behaves as if
4768
** its SQL text began with "[EXPLAIN QUERY PLAN]".
4769
**
4770
** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.
4771
** SQLite tries to avoid a reprepare, but a reprepare might be necessary
4772
** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.
4773
**
4774
** Because of the potential need to reprepare, a call to
4775
** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be
4776
** reprepared because it was created using [sqlite3_prepare()] instead of
4777
** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and
4778
** hence has no saved SQL text with which to reprepare.
4779
**
4780
** Changing the explain setting for a prepared statement does not change
4781
** the original SQL text for the statement.  Hence, if the SQL text originally
4782
** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
4783
** is called to convert the statement into an ordinary statement, the EXPLAIN
4784
** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)
4785
** output, even though the statement now acts like a normal SQL statement.
4786
**
4787
** This routine returns SQLITE_OK if the explain mode is successfully
4788
** changed, or an error code if the explain mode could not be changed.
4789
** The explain mode cannot be changed while a statement is active.
4790
** Hence, it is good practice to call [sqlite3_reset(S)]
4791
** immediately prior to calling sqlite3_stmt_explain(S,E).
4792
*/
4793
SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);
4794
4795
/*
4796
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4797
** METHOD: sqlite3_stmt
4798
**
4799
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
4800
** [prepared statement] S has been stepped at least once using
4801
** [sqlite3_step(S)] but has neither run to completion (returned
4802
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
4803
** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
4804
** interface returns false if S is a NULL pointer.  If S is not a
4805
** NULL pointer and is not a pointer to a valid [prepared statement]
4806
** object, then the behavior is undefined and probably undesirable.
4807
**
4808
** This interface can be used in combination [sqlite3_next_stmt()]
4809
** to locate all prepared statements associated with a database
4810
** connection that are in need of being reset.  This can be used,
4811
** for example, in diagnostic routines to search for prepared
4812
** statements that are holding a transaction open.
4813
*/
4814
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
4815
4816
/*
4817
** CAPI3REF: Dynamically Typed Value Object
4818
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
4819
**
4820
** SQLite uses the sqlite3_value object to represent all values
4821
** that can be stored in a database table. SQLite uses dynamic typing
4822
** for the values it stores.  ^Values stored in sqlite3_value objects
4823
** can be integers, floating point values, strings, BLOBs, or NULL.
4824
**
4825
** An sqlite3_value object may be either "protected" or "unprotected".
4826
** Some interfaces require a protected sqlite3_value.  Other interfaces
4827
** will accept either a protected or an unprotected sqlite3_value.
4828
** Every interface that accepts sqlite3_value arguments specifies
4829
** whether or not it requires a protected sqlite3_value.  The
4830
** [sqlite3_value_dup()] interface can be used to construct a new
4831
** protected sqlite3_value from an unprotected sqlite3_value.
4832
**
4833
** The terms "protected" and "unprotected" refer to whether or not
4834
** a mutex is held.  An internal mutex is held for a protected
4835
** sqlite3_value object but no mutex is held for an unprotected
4836
** sqlite3_value object.  If SQLite is compiled to be single-threaded
4837
** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
4838
** or if SQLite is run in one of reduced mutex modes
4839
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
4840
** then there is no distinction between protected and unprotected
4841
** sqlite3_value objects and they can be used interchangeably.  However,
4842
** for maximum code portability it is recommended that applications
4843
** still make the distinction between protected and unprotected
4844
** sqlite3_value objects even when not strictly required.
4845
**
4846
** ^The sqlite3_value objects that are passed as parameters into the
4847
** implementation of [application-defined SQL functions] are protected.
4848
** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4849
** are protected.
4850
** ^The sqlite3_value object returned by
4851
** [sqlite3_column_value()] is unprotected.
4852
** Unprotected sqlite3_value objects may only be used as arguments
4853
** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4854
** [sqlite3_value_dup()].
4855
** The [sqlite3_value_blob | sqlite3_value_type()] family of
4856
** interfaces require protected sqlite3_value objects.
4857
*/
4858
typedef struct sqlite3_value sqlite3_value;
4859
4860
/*
4861
** CAPI3REF: SQL Function Context Object
4862
**
4863
** The context in which an SQL function executes is stored in an
4864
** sqlite3_context object.  ^A pointer to an sqlite3_context object
4865
** is always first parameter to [application-defined SQL functions].
4866
** The application-defined SQL function implementation will pass this
4867
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4868
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4869
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4870
** and/or [sqlite3_set_auxdata()].
4871
*/
4872
typedef struct sqlite3_context sqlite3_context;
4873
4874
/*
4875
** CAPI3REF: Binding Values To Prepared Statements
4876
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4877
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4878
** METHOD: sqlite3_stmt
4879
**
4880
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4881
** literals may be replaced by a [parameter] that matches one of following
4882
** templates:
4883
**
4884
** <ul>
4885
** <li>  ?
4886
** <li>  ?NNN
4887
** <li>  :VVV
4888
** <li>  @VVV
4889
** <li>  $VVV
4890
** </ul>
4891
**
4892
** In the templates above, NNN represents an integer literal,
4893
** and VVV represents an alphanumeric identifier.)^  ^The values of these
4894
** parameters (also called "host parameter names" or "SQL parameters")
4895
** can be set using the sqlite3_bind_*() routines defined here.
4896
**
4897
** ^The first argument to the sqlite3_bind_*() routines is always
4898
** a pointer to the [sqlite3_stmt] object returned from
4899
** [sqlite3_prepare_v2()] or its variants.
4900
**
4901
** ^The second argument is the index of the SQL parameter to be set.
4902
** ^The leftmost SQL parameter has an index of 1.  ^When the same named
4903
** SQL parameter is used more than once, second and subsequent
4904
** occurrences have the same index as the first occurrence.
4905
** ^The index for named parameters can be looked up using the
4906
** [sqlite3_bind_parameter_index()] API if desired.  ^The index
4907
** for "?NNN" parameters is the value of NNN.
4908
** ^The NNN value must be between 1 and the [sqlite3_limit()]
4909
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
4910
**
4911
** ^The third argument is the value to bind to the parameter.
4912
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4913
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4914
** is ignored and the end result is the same as sqlite3_bind_null().
4915
** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4916
** it should be a pointer to well-formed UTF8 text.
4917
** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4918
** it should be a pointer to well-formed UTF16 text.
4919
** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4920
** it should be a pointer to a well-formed unicode string that is
4921
** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4922
** otherwise.
4923
**
4924
** [[byte-order determination rules]] ^The byte-order of
4925
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4926
** found in first character, which is removed, or in the absence of a BOM
4927
** the byte order is the native byte order of the host
4928
** machine for sqlite3_bind_text16() or the byte order specified in
4929
** the 6th parameter for sqlite3_bind_text64().)^
4930
** ^If UTF16 input text contains invalid unicode
4931
** characters, then SQLite might change those invalid characters
4932
** into the unicode replacement character: U+FFFD.
4933
**
4934
** ^(In those routines that have a fourth argument, its value is the
4935
** number of bytes in the parameter.  To be clear: the value is the
4936
** number of <u>bytes</u> in the value, not the number of characters.)^
4937
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4938
** is negative, then the length of the string is
4939
** the number of bytes up to the first zero terminator.
4940
** If the fourth parameter to sqlite3_bind_blob() is negative, then
4941
** the behavior is undefined.
4942
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4943
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4944
** that parameter must be the byte offset
4945
** where the NUL terminator would occur assuming the string were NUL
4946
** terminated.  If any NUL characters occurs at byte offsets less than
4947
** the value of the fourth parameter then the resulting string value will
4948
** contain embedded NULs.  The result of expressions involving strings
4949
** with embedded NULs is undefined.
4950
**
4951
** ^The fifth argument to the BLOB and string binding interfaces controls
4952
** or indicates the lifetime of the object referenced by the third parameter.
4953
** These three options exist:
4954
** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4955
** with it may be passed. ^It is called to dispose of the BLOB or string even
4956
** if the call to the bind API fails, except the destructor is not called if
4957
** the third parameter is a NULL pointer or the fourth parameter is negative.
4958
** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4959
** the application remains responsible for disposing of the object. ^In this
4960
** case, the object and the provided pointer to it must remain valid until
4961
** either the prepared statement is finalized or the same SQL parameter is
4962
** bound to something else, whichever occurs sooner.
4963
** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4964
** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4965
** object and pointer to it must remain valid until then. ^SQLite will then
4966
** manage the lifetime of its private copy.
4967
**
4968
** ^The sixth argument to sqlite3_bind_text64() must be one of
4969
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4970
** to specify the encoding of the text in the third parameter.  If
4971
** the sixth argument to sqlite3_bind_text64() is not one of the
4972
** allowed values shown above, or if the text encoding is different
4973
** from the encoding specified by the sixth parameter, then the behavior
4974
** is undefined.
4975
**
4976
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
4977
** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
4978
** (just an integer to hold its size) while it is being processed.
4979
** Zeroblobs are intended to serve as placeholders for BLOBs whose
4980
** content is later written using
4981
** [sqlite3_blob_open | incremental BLOB I/O] routines.
4982
** ^A negative value for the zeroblob results in a zero-length BLOB.
4983
**
4984
** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
4985
** [prepared statement] S to have an SQL value of NULL, but to also be
4986
** associated with the pointer P of type T.  ^D is either a NULL pointer or
4987
** a pointer to a destructor function for P. ^SQLite will invoke the
4988
** destructor D with a single argument of P when it is finished using
4989
** P.  The T parameter should be a static string, preferably a string
4990
** literal. The sqlite3_bind_pointer() routine is part of the
4991
** [pointer passing interface] added for SQLite 3.20.0.
4992
**
4993
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4994
** for the [prepared statement] or with a prepared statement for which
4995
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4996
** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
4997
** routine is passed a [prepared statement] that has been finalized, the
4998
** result is undefined and probably harmful.
4999
**
5000
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
5001
** ^Unbound parameters are interpreted as NULL.
5002
**
5003
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
5004
** [error code] if anything goes wrong.
5005
** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
5006
** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
5007
** [SQLITE_MAX_LENGTH].
5008
** ^[SQLITE_RANGE] is returned if the parameter
5009
** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
5010
**
5011
** See also: [sqlite3_bind_parameter_count()],
5012
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
5013
*/
5014
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
5015
SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
5016
                        void(*)(void*));
5017
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
5018
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
5019
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
5020
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
5021
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
5022
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
5023
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
5024
                         void(*)(void*), unsigned char encoding);
5025
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
5026
SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
5027
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
5028
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
5029
5030
/*
5031
** CAPI3REF: Number Of SQL Parameters
5032
** METHOD: sqlite3_stmt
5033
**
5034
** ^This routine can be used to find the number of [SQL parameters]
5035
** in a [prepared statement].  SQL parameters are tokens of the
5036
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
5037
** placeholders for values that are [sqlite3_bind_blob | bound]
5038
** to the parameters at a later time.
5039
**
5040
** ^(This routine actually returns the index of the largest (rightmost)
5041
** parameter. For all forms except ?NNN, this will correspond to the
5042
** number of unique parameters.  If parameters of the ?NNN form are used,
5043
** there may be gaps in the list.)^
5044
**
5045
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5046
** [sqlite3_bind_parameter_name()], and
5047
** [sqlite3_bind_parameter_index()].
5048
*/
5049
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
5050
5051
/*
5052
** CAPI3REF: Name Of A Host Parameter
5053
** METHOD: sqlite3_stmt
5054
**
5055
** ^The sqlite3_bind_parameter_name(P,N) interface returns
5056
** the name of the N-th [SQL parameter] in the [prepared statement] P.
5057
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
5058
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
5059
** respectively.
5060
** In other words, the initial ":" or "$" or "@" or "?"
5061
** is included as part of the name.)^
5062
** ^Parameters of the form "?" without a following integer have no name
5063
** and are referred to as "nameless" or "anonymous parameters".
5064
**
5065
** ^The first host parameter has an index of 1, not 0.
5066
**
5067
** ^If the value N is out of range or if the N-th parameter is
5068
** nameless, then NULL is returned.  ^The returned string is
5069
** always in UTF-8 encoding even if the named parameter was
5070
** originally specified as UTF-16 in [sqlite3_prepare16()],
5071
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
5072
**
5073
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5074
** [sqlite3_bind_parameter_count()], and
5075
** [sqlite3_bind_parameter_index()].
5076
*/
5077
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
5078
5079
/*
5080
** CAPI3REF: Index Of A Parameter With A Given Name
5081
** METHOD: sqlite3_stmt
5082
**
5083
** ^Return the index of an SQL parameter given its name.  ^The
5084
** index value returned is suitable for use as the second
5085
** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
5086
** is returned if no matching parameter is found.  ^The parameter
5087
** name must be given in UTF-8 even if the original statement
5088
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
5089
** [sqlite3_prepare16_v3()].
5090
**
5091
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5092
** [sqlite3_bind_parameter_count()], and
5093
** [sqlite3_bind_parameter_name()].
5094
*/
5095
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
5096
5097
/*
5098
** CAPI3REF: Reset All Bindings On A Prepared Statement
5099
** METHOD: sqlite3_stmt
5100
**
5101
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
5102
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
5103
** ^Use this routine to reset all host parameters to NULL.
5104
*/
5105
SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
5106
5107
/*
5108
** CAPI3REF: Number Of Columns In A Result Set
5109
** METHOD: sqlite3_stmt
5110
**
5111
** ^Return the number of columns in the result set returned by the
5112
** [prepared statement]. ^If this routine returns 0, that means the
5113
** [prepared statement] returns no data (for example an [UPDATE]).
5114
** ^However, just because this routine returns a positive number does not
5115
** mean that one or more rows of data will be returned.  ^A SELECT statement
5116
** will always have a positive sqlite3_column_count() but depending on the
5117
** WHERE clause constraints and the table content, it might return no rows.
5118
**
5119
** See also: [sqlite3_data_count()]
5120
*/
5121
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
5122
5123
/*
5124
** CAPI3REF: Column Names In A Result Set
5125
** METHOD: sqlite3_stmt
5126
**
5127
** ^These routines return the name assigned to a particular column
5128
** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
5129
** interface returns a pointer to a zero-terminated UTF-8 string
5130
** and sqlite3_column_name16() returns a pointer to a zero-terminated
5131
** UTF-16 string.  ^The first parameter is the [prepared statement]
5132
** that implements the [SELECT] statement. ^The second parameter is the
5133
** column number.  ^The leftmost column is number 0.
5134
**
5135
** ^The returned string pointer is valid until either the [prepared statement]
5136
** is destroyed by [sqlite3_finalize()] or until the statement is automatically
5137
** reprepared by the first call to [sqlite3_step()] for a particular run
5138
** or until the next call to
5139
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
5140
**
5141
** ^If sqlite3_malloc() fails during the processing of either routine
5142
** (for example during a conversion from UTF-8 to UTF-16) then a
5143
** NULL pointer is returned.
5144
**
5145
** ^The name of a result column is the value of the "AS" clause for
5146
** that column, if there is an AS clause.  If there is no AS clause
5147
** then the name of the column is unspecified and may change from
5148
** one release of SQLite to the next.
5149
*/
5150
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
5151
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
5152
5153
/*
5154
** CAPI3REF: Source Of Data In A Query Result
5155
** METHOD: sqlite3_stmt
5156
**
5157
** ^These routines provide a means to determine the database, table, and
5158
** table column that is the origin of a particular result column in
5159
** [SELECT] statement.
5160
** ^The name of the database or table or column can be returned as
5161
** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
5162
** the database name, the _table_ routines return the table name, and
5163
** the origin_ routines return the column name.
5164
** ^The returned string is valid until the [prepared statement] is destroyed
5165
** using [sqlite3_finalize()] or until the statement is automatically
5166
** reprepared by the first call to [sqlite3_step()] for a particular run
5167
** or until the same information is requested
5168
** again in a different encoding.
5169
**
5170
** ^The names returned are the original un-aliased names of the
5171
** database, table, and column.
5172
**
5173
** ^The first argument to these interfaces is a [prepared statement].
5174
** ^These functions return information about the Nth result column returned by
5175
** the statement, where N is the second function argument.
5176
** ^The left-most column is column 0 for these routines.
5177
**
5178
** ^If the Nth column returned by the statement is an expression or
5179
** subquery and is not a column value, then all of these functions return
5180
** NULL.  ^These routines might also return NULL if a memory allocation error
5181
** occurs.  ^Otherwise, they return the name of the attached database, table,
5182
** or column that query result column was extracted from.
5183