Coverage Report

Created: 2024-02-28 06:22

/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
** 2dfc427f676255cbe189a26bfec2405d41d3.
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
1.32k
#define SQLITE_SOURCE_ID      "2024-02-28 01:12:21 2dfc427f676255cbe189a26bfec2405d41d31ccc4512c55b31e6e633261d7a23"
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
1.38G
#define SQLITE_OK           0   /* Successful result */
760
/* beginning-of-error-codes */
761
548k
#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
38.2k
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
765
3.67M
#define SQLITE_BUSY         5   /* The database file is locked */
766
661
#define SQLITE_LOCKED       6   /* A table in the database is locked */
767
4.31M
#define SQLITE_NOMEM        7   /* A malloc() failed */
768
28.4k
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
769
6.89M
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
770
21.2M
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
771
41.4k
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
772
266k
#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
773
14.7M
#define SQLITE_FULL        13   /* Insertion failed because database is full */
774
58.0k
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
775
0
#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
776
17.1M
#define SQLITE_EMPTY       16   /* Internal use only */
777
1.36M
#define SQLITE_SCHEMA      17   /* The database schema changed */
778
2.24k
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
779
28.7k
#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
780
18
#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
0
#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
73.5k
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
787
0
#define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
788
11.0k
#define SQLITE_WARNING     28   /* Warnings from sqlite3_log() */
789
2.75M
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
790
6.46M
#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
183
#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
811
11.7k
#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
13.7M
#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
58.2k
#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
816
#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
3.15k
#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
868
291
#define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
869
0
#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
870
250
#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
871
#define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
872
2.13k
#define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
873
4.79k
#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
874
0
#define SQLITE_CONSTRAINT_TRIGGER      (SQLITE_CONSTRAINT | (7<<8))
875
5.56k
#define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
876
#define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
877
1.26k
#define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
878
0
#define SQLITE_CONSTRAINT_PINNED       (SQLITE_CONSTRAINT |(11<<8))
879
0
#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
841
#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
69.2k
#define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
909
69.7k
#define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
910
69.7k
#define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
911
87.9k
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
912
79.8k
#define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
913
#define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
914
67.5k
#define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
915
60.3k
#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
916
136k
#define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
917
35.9k
#define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
918
45.5k
#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
919
42.7k
#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
920
16.3k
#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
921
22.6k
#define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
922
26.4k
#define SQLITE_OPEN_SUPER_JOURNAL    0x00004000  /* VFS only */
923
20.2k
#define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
924
20.2k
#define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
925
0
#define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
926
10.1k
#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
927
34.5k
#define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
928
0
#define SQLITE_OPEN_NOFOLLOW         0x01000000  /* Ok for sqlite3_open_v2() */
929
10.1k
#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
61.1k
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
981
6.24k
#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
1.91M
#define SQLITE_FCNTL_SIZE_HINT               5
1524
0
#define SQLITE_FCNTL_CHUNK_SIZE              6
1525
70.0k
#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
69.7k
#define SQLITE_FCNTL_PRAGMA                 14
1533
61.1k
#define SQLITE_FCNTL_BUSYHANDLER            15
1534
0
#define SQLITE_FCNTL_TEMPFILENAME           16
1535
5.64k
#define SQLITE_FCNTL_MMAP_SIZE              18
1536
#define SQLITE_FCNTL_TRACE                  19
1537
0
#define SQLITE_FCNTL_HAS_MOVED              20
1538
1.79k
#define SQLITE_FCNTL_SYNC                   21
1539
61.5k
#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
70.0k
#define SQLITE_FCNTL_VFS_POINTER            27
1545
70.0k
#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
70.0k
#define SQLITE_FCNTL_DATA_VERSION           35
1553
0
#define SQLITE_FCNTL_SIZE_LIMIT             36
1554
0
#define SQLITE_FCNTL_CKPT_DONE              37
1555
70.0k
#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
70.0k
#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
** </dl>
2460
*/
2461
0
#define SQLITE_CONFIG_SINGLETHREAD         1  /* nil */
2462
0
#define SQLITE_CONFIG_MULTITHREAD          2  /* nil */
2463
0
#define SQLITE_CONFIG_SERIALIZED           3  /* nil */
2464
2
#define SQLITE_CONFIG_MALLOC               4  /* sqlite3_mem_methods* */
2465
0
#define SQLITE_CONFIG_GETMALLOC            5  /* sqlite3_mem_methods* */
2466
#define SQLITE_CONFIG_SCRATCH              6  /* No longer used */
2467
0
#define SQLITE_CONFIG_PAGECACHE            7  /* void*, int sz, int N */
2468
#define SQLITE_CONFIG_HEAP                 8  /* void*, int nByte, int min */
2469
0
#define SQLITE_CONFIG_MEMSTATUS            9  /* boolean */
2470
0
#define SQLITE_CONFIG_MUTEX               10  /* sqlite3_mutex_methods* */
2471
0
#define SQLITE_CONFIG_GETMUTEX            11  /* sqlite3_mutex_methods* */
2472
/* previously SQLITE_CONFIG_CHUNKALLOC    12 which is now unused. */
2473
0
#define SQLITE_CONFIG_LOOKASIDE           13  /* int int */
2474
0
#define SQLITE_CONFIG_PCACHE              14  /* no-op */
2475
0
#define SQLITE_CONFIG_GETPCACHE           15  /* no-op */
2476
0
#define SQLITE_CONFIG_LOG                 16  /* xFunc, void* */
2477
0
#define SQLITE_CONFIG_URI                 17  /* int */
2478
2
#define SQLITE_CONFIG_PCACHE2             18  /* sqlite3_pcache_methods2* */
2479
0
#define SQLITE_CONFIG_GETPCACHE2          19  /* sqlite3_pcache_methods2* */
2480
0
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
2481
#define SQLITE_CONFIG_SQLLOG              21  /* xSqllog, void* */
2482
0
#define SQLITE_CONFIG_MMAP_SIZE           22  /* sqlite3_int64, sqlite3_int64 */
2483
#define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
2484
0
#define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
2485
0
#define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
2486
0
#define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
2487
0
#define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
2488
#define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
2489
0
#define SQLITE_CONFIG_MEMDB_MAXSIZE       29  /* sqlite3_int64 */
2490
2491
/*
2492
** CAPI3REF: Database Connection Configuration Options
2493
**
2494
** These constants are the available integer configuration options that
2495
** can be passed as the second argument to the [sqlite3_db_config()] interface.
2496
**
2497
** New configuration options may be added in future releases of SQLite.
2498
** Existing configuration options might be discontinued.  Applications
2499
** should check the return code from [sqlite3_db_config()] to make sure that
2500
** the call worked.  ^The [sqlite3_db_config()] interface will return a
2501
** non-zero [error code] if a discontinued or unsupported configuration option
2502
** is invoked.
2503
**
2504
** <dl>
2505
** [[SQLITE_DBCONFIG_LOOKASIDE]]
2506
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2507
** <dd> ^This option takes three additional arguments that determine the
2508
** [lookaside memory allocator] configuration for the [database connection].
2509
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2510
** pointer to a memory buffer to use for lookaside memory.
2511
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2512
** may be NULL in which case SQLite will allocate the
2513
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2514
** size of each lookaside buffer slot.  ^The third argument is the number of
2515
** slots.  The size of the buffer in the first argument must be greater than
2516
** or equal to the product of the second and third arguments.  The buffer
2517
** must be aligned to an 8-byte boundary.  ^If the second argument to
2518
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2519
** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
2520
** configuration for a database connection can only be changed when that
2521
** connection is not currently using lookaside memory, or in other words
2522
** when the "current value" returned by
2523
** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2524
** Any attempt to change the lookaside memory configuration when lookaside
2525
** memory is in use leaves the configuration unchanged and returns
2526
** [SQLITE_BUSY].)^</dd>
2527
**
2528
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2529
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2530
** <dd> ^This option is used to enable or disable the enforcement of
2531
** [foreign key constraints].  There should be two additional arguments.
2532
** The first argument is an integer which is 0 to disable FK enforcement,
2533
** positive to enable FK enforcement or negative to leave FK enforcement
2534
** unchanged.  The second parameter is a pointer to an integer into which
2535
** is written 0 or 1 to indicate whether FK enforcement is off or on
2536
** following this call.  The second parameter may be a NULL pointer, in
2537
** which case the FK enforcement setting is not reported back. </dd>
2538
**
2539
** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
2540
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2541
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2542
** There should be two additional arguments.
2543
** The first argument is an integer which is 0 to disable triggers,
2544
** positive to enable triggers or negative to leave the setting unchanged.
2545
** The second parameter is a pointer to an integer into which
2546
** is written 0 or 1 to indicate whether triggers are disabled or enabled
2547
** following this call.  The second parameter may be a NULL pointer, in
2548
** which case the trigger setting is not reported back.
2549
**
2550
** <p>Originally this option disabled all triggers.  ^(However, since
2551
** SQLite version 3.35.0, TEMP triggers are still allowed even if
2552
** this option is off.  So, in other words, this option now only disables
2553
** triggers in the main database schema or in the schemas of ATTACH-ed
2554
** databases.)^ </dd>
2555
**
2556
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2557
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2558
** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2559
** There should be two additional arguments.
2560
** The first argument is an integer which is 0 to disable views,
2561
** positive to enable views 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 views are disabled or enabled
2564
** following this call.  The second parameter may be a NULL pointer, in
2565
** which case the view setting is not reported back.
2566
**
2567
** <p>Originally this option disabled all views.  ^(However, since
2568
** SQLite version 3.35.0, TEMP views are still allowed even if
2569
** this option is off.  So, in other words, this option now only disables
2570
** views in the main database schema or in the schemas of ATTACH-ed
2571
** databases.)^ </dd>
2572
**
2573
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2574
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2575
** <dd> ^This option is used to enable or disable the
2576
** [fts3_tokenizer()] function which is part of the
2577
** [FTS3] full-text search engine extension.
2578
** There should be two additional arguments.
2579
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2580
** positive to enable fts3_tokenizer() or negative to leave the setting
2581
** unchanged.
2582
** The second parameter is a pointer to an integer into which
2583
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2584
** following this call.  The second parameter may be a NULL pointer, in
2585
** which case the new setting is not reported back. </dd>
2586
**
2587
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2588
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2589
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2590
** interface independently of the [load_extension()] SQL function.
2591
** The [sqlite3_enable_load_extension()] API enables or disables both the
2592
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2593
** There should be two additional arguments.
2594
** When the first argument to this interface is 1, then only the C-API is
2595
** enabled and the SQL function remains disabled.  If the first argument to
2596
** this interface is 0, then both the C-API and the SQL function are disabled.
2597
** If the first argument is -1, then no changes are made to state of either the
2598
** C-API or the SQL function.
2599
** The second parameter is a pointer to an integer into which
2600
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2601
** is disabled or enabled following this call.  The second parameter may
2602
** be a NULL pointer, in which case the new setting is not reported back.
2603
** </dd>
2604
**
2605
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2606
** <dd> ^This option is used to change the name of the "main" database
2607
** schema.  ^The sole argument is a pointer to a constant UTF8 string
2608
** which will become the new schema name in place of "main".  ^SQLite
2609
** does not make a copy of the new main schema name string, so the application
2610
** must ensure that the argument passed into this DBCONFIG option is unchanged
2611
** until after the database connection closes.
2612
** </dd>
2613
**
2614
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2615
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2616
** <dd> Usually, when a database in wal mode is closed or detached from a
2617
** database handle, SQLite checks if this will mean that there are now no
2618
** connections at all to the database. If so, it performs a checkpoint
2619
** operation before closing the connection. This option may be used to
2620
** override this behavior. The first parameter passed to this operation
2621
** is an integer - positive to disable checkpoints-on-close, or zero (the
2622
** default) to enable them, and negative to leave the setting unchanged.
2623
** The second parameter is a pointer to an integer
2624
** into which is written 0 or 1 to indicate whether checkpoints-on-close
2625
** have been disabled - 0 if they are not disabled, 1 if they are.
2626
** </dd>
2627
**
2628
** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2629
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2630
** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
2631
** a single SQL query statement will always use the same algorithm regardless
2632
** of values of [bound parameters].)^ The QPSG disables some query optimizations
2633
** that look at the values of bound parameters, which can make some queries
2634
** slower.  But the QPSG has the advantage of more predictable behavior.  With
2635
** the QPSG active, SQLite will always use the same query plan in the field as
2636
** was used during testing in the lab.
2637
** The first argument to this setting is an integer which is 0 to disable
2638
** the QPSG, positive to enable QPSG, or negative to leave the setting
2639
** unchanged. The second parameter is a pointer to an integer into which
2640
** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2641
** following this call.
2642
** </dd>
2643
**
2644
** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2645
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2646
** include output for any operations performed by trigger programs. This
2647
** option is used to set or clear (the default) a flag that governs this
2648
** behavior. The first parameter passed to this operation is an integer -
2649
** positive to enable output for trigger programs, or zero to disable it,
2650
** or negative to leave the setting unchanged.
2651
** The second parameter is a pointer to an integer into which is written
2652
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2653
** it is not disabled, 1 if it is.
2654
** </dd>
2655
**
2656
** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
2657
** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
2658
** [VACUUM] in order to reset a database back to an empty database
2659
** with no schema and no content. The following process works even for
2660
** a badly corrupted database file:
2661
** <ol>
2662
** <li> If the database connection is newly opened, make sure it has read the
2663
**      database schema by preparing then discarding some query against the
2664
**      database, or calling sqlite3_table_column_metadata(), ignoring any
2665
**      errors.  This step is only necessary if the application desires to keep
2666
**      the database in WAL mode after the reset if it was in WAL mode before
2667
**      the reset.
2668
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2669
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2670
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2671
** </ol>
2672
** Because resetting a database is destructive and irreversible, the
2673
** process requires the use of this obscure API and multiple steps to
2674
** help ensure that it does not happen by accident. Because this
2675
** feature must be capable of resetting corrupt databases, and
2676
** shutting down virtual tables may require access to that corrupt
2677
** storage, the library must abandon any installed virtual tables
2678
** without calling their xDestroy() methods.
2679
**
2680
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2681
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2682
** "defensive" flag for a database connection.  When the defensive
2683
** flag is enabled, language features that allow ordinary SQL to
2684
** deliberately corrupt the database file are disabled.  The disabled
2685
** features include but are not limited to the following:
2686
** <ul>
2687
** <li> The [PRAGMA writable_schema=ON] statement.
2688
** <li> The [PRAGMA journal_mode=OFF] statement.
2689
** <li> The [PRAGMA schema_version=N] statement.
2690
** <li> Writes to the [sqlite_dbpage] virtual table.
2691
** <li> Direct writes to [shadow tables].
2692
** </ul>
2693
** </dd>
2694
**
2695
** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2696
** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2697
** "writable_schema" flag. This has the same effect and is logically equivalent
2698
** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2699
** The first argument to this setting is an integer which is 0 to disable
2700
** the writable_schema, positive to enable writable_schema, or negative to
2701
** leave the setting unchanged. The second parameter is a pointer to an
2702
** integer into which is written 0 or 1 to indicate whether the writable_schema
2703
** is enabled or disabled following this call.
2704
** </dd>
2705
**
2706
** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2707
** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2708
** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2709
** the legacy behavior of the [ALTER TABLE RENAME] command such it
2710
** behaves as it did prior to [version 3.24.0] (2018-06-04).  See the
2711
** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2712
** additional information. This feature can also be turned on and off
2713
** using the [PRAGMA legacy_alter_table] statement.
2714
** </dd>
2715
**
2716
** [[SQLITE_DBCONFIG_DQS_DML]]
2717
** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2718
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2719
** the legacy [double-quoted string literal] misfeature for DML statements
2720
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2721
** default value of this setting is determined by the [-DSQLITE_DQS]
2722
** compile-time option.
2723
** </dd>
2724
**
2725
** [[SQLITE_DBCONFIG_DQS_DDL]]
2726
** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2727
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2728
** the legacy [double-quoted string literal] misfeature for DDL statements,
2729
** such as CREATE TABLE and CREATE INDEX. The
2730
** default value of this setting is determined by the [-DSQLITE_DQS]
2731
** compile-time option.
2732
** </dd>
2733
**
2734
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2735
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2736
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2737
** assume that database schemas are untainted by malicious content.
2738
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2739
** takes additional defensive steps to protect the application from harm
2740
** including:
2741
** <ul>
2742
** <li> Prohibit the use of SQL functions inside triggers, views,
2743
** CHECK constraints, DEFAULT clauses, expression indexes,
2744
** partial indexes, or generated columns
2745
** unless those functions are tagged with [SQLITE_INNOCUOUS].
2746
** <li> Prohibit the use of virtual tables inside of triggers or views
2747
** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2748
** </ul>
2749
** This setting defaults to "on" for legacy compatibility, however
2750
** all applications are advised to turn it off if possible. This setting
2751
** can also be controlled using the [PRAGMA trusted_schema] statement.
2752
** </dd>
2753
**
2754
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2755
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2756
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2757
** the legacy file format flag.  When activated, this flag causes all newly
2758
** created database file to have a schema format version number (the 4-byte
2759
** integer found at offset 44 into the database header) of 1.  This in turn
2760
** means that the resulting database file will be readable and writable by
2761
** any SQLite version back to 3.0.0 ([dateof:3.0.0]).  Without this setting,
2762
** newly created databases are generally not understandable by SQLite versions
2763
** prior to 3.3.0 ([dateof:3.3.0]).  As these words are written, there
2764
** is now scarcely any need to generate database files that are compatible
2765
** all the way back to version 3.0.0, and so this setting is of little
2766
** practical use, but is provided so that SQLite can continue to claim the
2767
** ability to generate new database files that are compatible with  version
2768
** 3.0.0.
2769
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2770
** the [VACUUM] command will fail with an obscure error when attempting to
2771
** process a table with generated columns and a descending index.  This is
2772
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2773
** either generated columns or descending indexes.
2774
** </dd>
2775
**
2776
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2777
** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2778
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2779
** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2780
** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2781
** statistics. For statistics to be collected, the flag must be set on
2782
** the database handle both when the SQL statement is prepared and when it
2783
** is stepped. The flag is set (collection of statistics is enabled)
2784
** by default.  This option takes two arguments: an integer and a pointer to
2785
** an integer..  The first argument is 1, 0, or -1 to enable, disable, or
2786
** leave unchanged the statement scanstatus option.  If the second argument
2787
** is not NULL, then the value of the statement scanstatus setting after
2788
** processing the first argument is written into the integer that the second
2789
** argument points to.
2790
** </dd>
2791
**
2792
** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2793
** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2794
** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2795
** in which tables and indexes are scanned so that the scans start at the end
2796
** and work toward the beginning rather than starting at the beginning and
2797
** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2798
** same as setting [PRAGMA reverse_unordered_selects].  This option takes
2799
** two arguments which are an integer and a pointer to an integer.  The first
2800
** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2801
** reverse scan order flag, respectively.  If the second argument is not NULL,
2802
** then 0 or 1 is written into the integer that the second argument points to
2803
** depending on if the reverse scan order flag is set after processing the
2804
** first argument.
2805
** </dd>
2806
**
2807
** </dl>
2808
*/
2809
0
#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
2810
0
#define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
2811
10.1k
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
2812
10.1k
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
2813
10.1k
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2814
10.1k
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2815
10.1k
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
2816
10.1k
#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
2817
10.1k
#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
2818
10.1k
#define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
2819
10.1k
#define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
2820
10.1k
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
2821
10.1k
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE    1012 /* int int* */
2822
10.1k
#define SQLITE_DBCONFIG_DQS_DML               1013 /* int int* */
2823
10.1k
#define SQLITE_DBCONFIG_DQS_DDL               1014 /* int int* */
2824
10.1k
#define SQLITE_DBCONFIG_ENABLE_VIEW           1015 /* int int* */
2825
10.1k
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT    1016 /* int int* */
2826
10.1k
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA        1017 /* int int* */
2827
10.1k
#define SQLITE_DBCONFIG_STMT_SCANSTATUS       1018 /* int int* */
2828
10.1k
#define SQLITE_DBCONFIG_REVERSE_SCANORDER     1019 /* int int* */
2829
#define SQLITE_DBCONFIG_MAX                   1019 /* Largest DBCONFIG */
2830
2831
/*
2832
** CAPI3REF: Enable Or Disable Extended Result Codes
2833
** METHOD: sqlite3
2834
**
2835
** ^The sqlite3_extended_result_codes() routine enables or disables the
2836
** [extended result codes] feature of SQLite. ^The extended result
2837
** codes are disabled by default for historical compatibility.
2838
*/
2839
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
2840
2841
/*
2842
** CAPI3REF: Last Insert Rowid
2843
** METHOD: sqlite3
2844
**
2845
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2846
** has a unique 64-bit signed
2847
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2848
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2849
** names are not also used by explicitly declared columns. ^If
2850
** the table has a column of type [INTEGER PRIMARY KEY] then that column
2851
** is another alias for the rowid.
2852
**
2853
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2854
** the most recent successful [INSERT] into a rowid table or [virtual table]
2855
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2856
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2857
** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2858
** zero.
2859
**
2860
** As well as being set automatically as rows are inserted into database
2861
** tables, the value returned by this function may be set explicitly by
2862
** [sqlite3_set_last_insert_rowid()]
2863
**
2864
** Some virtual table implementations may INSERT rows into rowid tables as
2865
** part of committing a transaction (e.g. to flush data accumulated in memory
2866
** to disk). In this case subsequent calls to this function return the rowid
2867
** associated with these internal INSERT operations, which leads to
2868
** unintuitive results. Virtual table implementations that do write to rowid
2869
** tables in this way can avoid this problem by restoring the original
2870
** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2871
** control to the user.
2872
**
2873
** ^(If an [INSERT] occurs within a trigger then this routine will
2874
** return the [rowid] of the inserted row as long as the trigger is
2875
** running. Once the trigger program ends, the value returned
2876
** by this routine reverts to what it was before the trigger was fired.)^
2877
**
2878
** ^An [INSERT] that fails due to a constraint violation is not a
2879
** successful [INSERT] and does not change the value returned by this
2880
** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2881
** and INSERT OR ABORT make no changes to the return value of this
2882
** routine when their insertion fails.  ^(When INSERT OR REPLACE
2883
** encounters a constraint violation, it does not fail.  The
2884
** INSERT continues to completion after deleting rows that caused
2885
** the constraint problem so INSERT OR REPLACE will always change
2886
** the return value of this interface.)^
2887
**
2888
** ^For the purposes of this routine, an [INSERT] is considered to
2889
** be successful even if it is subsequently rolled back.
2890
**
2891
** This function is accessible to SQL statements via the
2892
** [last_insert_rowid() SQL function].
2893
**
2894
** If a separate thread performs a new [INSERT] on the same
2895
** database connection while the [sqlite3_last_insert_rowid()]
2896
** function is running and thus changes the last insert [rowid],
2897
** then the value returned by [sqlite3_last_insert_rowid()] is
2898
** unpredictable and might not equal either the old or the new
2899
** last insert [rowid].
2900
*/
2901
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2902
2903
/*
2904
** CAPI3REF: Set the Last Insert Rowid value.
2905
** METHOD: sqlite3
2906
**
2907
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2908
** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2909
** without inserting a row into the database.
2910
*/
2911
SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2912
2913
/*
2914
** CAPI3REF: Count The Number Of Rows Modified
2915
** METHOD: sqlite3
2916
**
2917
** ^These functions return the number of rows modified, inserted or
2918
** deleted by the most recently completed INSERT, UPDATE or DELETE
2919
** statement on the database connection specified by the only parameter.
2920
** The two functions are identical except for the type of the return value
2921
** and that if the number of rows modified by the most recent INSERT, UPDATE
2922
** or DELETE is greater than the maximum value supported by type "int", then
2923
** the return value of sqlite3_changes() is undefined. ^Executing any other
2924
** type of SQL statement does not modify the value returned by these functions.
2925
**
2926
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2927
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2928
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2929
**
2930
** Changes to a view that are intercepted by
2931
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2932
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2933
** DELETE statement run on a view is always zero. Only changes made to real
2934
** tables are counted.
2935
**
2936
** Things are more complicated if the sqlite3_changes() function is
2937
** executed while a trigger program is running. This may happen if the
2938
** program uses the [changes() SQL function], or if some other callback
2939
** function invokes sqlite3_changes() directly. Essentially:
2940
**
2941
** <ul>
2942
**   <li> ^(Before entering a trigger program the value returned by
2943
**        sqlite3_changes() function is saved. After the trigger program
2944
**        has finished, the original value is restored.)^
2945
**
2946
**   <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2947
**        statement sets the value returned by sqlite3_changes()
2948
**        upon completion as normal. Of course, this value will not include
2949
**        any changes performed by sub-triggers, as the sqlite3_changes()
2950
**        value will be saved and restored after each sub-trigger has run.)^
2951
** </ul>
2952
**
2953
** ^This means that if the changes() SQL function (or similar) is used
2954
** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2955
** returns the value as set when the calling statement began executing.
2956
** ^If it is used by the second or subsequent such statement within a trigger
2957
** program, the value returned reflects the number of rows modified by the
2958
** previous INSERT, UPDATE or DELETE statement within the same trigger.
2959
**
2960
** If a separate thread makes changes on the same database connection
2961
** while [sqlite3_changes()] is running then the value returned
2962
** is unpredictable and not meaningful.
2963
**
2964
** See also:
2965
** <ul>
2966
** <li> the [sqlite3_total_changes()] interface
2967
** <li> the [count_changes pragma]
2968
** <li> the [changes() SQL function]
2969
** <li> the [data_version pragma]
2970
** </ul>
2971
*/
2972
SQLITE_API int sqlite3_changes(sqlite3*);
2973
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
2974
2975
/*
2976
** CAPI3REF: Total Number Of Rows Modified
2977
** METHOD: sqlite3
2978
**
2979
** ^These functions return the total number of rows inserted, modified or
2980
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2981
** since the database connection was opened, including those executed as
2982
** part of trigger programs. The two functions are identical except for the
2983
** type of the return value and that if the number of rows modified by the
2984
** connection exceeds the maximum value supported by type "int", then
2985
** the return value of sqlite3_total_changes() is undefined. ^Executing
2986
** any other type of SQL statement does not affect the value returned by
2987
** sqlite3_total_changes().
2988
**
2989
** ^Changes made as part of [foreign key actions] are included in the
2990
** count, but those made as part of REPLACE constraint resolution are
2991
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2992
** are not counted.
2993
**
2994
** The [sqlite3_total_changes(D)] interface only reports the number
2995
** of rows that changed due to SQL statement run against database
2996
** connection D.  Any changes by other database connections are ignored.
2997
** To detect changes against a database file from other database
2998
** connections use the [PRAGMA data_version] command or the
2999
** [SQLITE_FCNTL_DATA_VERSION] [file control].
3000
**
3001
** If a separate thread makes changes on the same database connection
3002
** while [sqlite3_total_changes()] is running then the value
3003
** returned is unpredictable and not meaningful.
3004
**
3005
** See also:
3006
** <ul>
3007
** <li> the [sqlite3_changes()] interface
3008
** <li> the [count_changes pragma]
3009
** <li> the [changes() SQL function]
3010
** <li> the [data_version pragma]
3011
** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
3012
** </ul>
3013
*/
3014
SQLITE_API int sqlite3_total_changes(sqlite3*);
3015
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
3016
3017
/*
3018
** CAPI3REF: Interrupt A Long-Running Query
3019
** METHOD: sqlite3
3020
**
3021
** ^This function causes any pending database operation to abort and
3022
** return at its earliest opportunity. This routine is typically
3023
** called in response to a user action such as pressing "Cancel"
3024
** or Ctrl-C where the user wants a long query operation to halt
3025
** immediately.
3026
**
3027
** ^It is safe to call this routine from a thread different from the
3028
** thread that is currently running the database operation.  But it
3029
** is not safe to call this routine with a [database connection] that
3030
** is closed or might close before sqlite3_interrupt() returns.
3031
**
3032
** ^If an SQL operation is very nearly finished at the time when
3033
** sqlite3_interrupt() is called, then it might not have an opportunity
3034
** to be interrupted and might continue to completion.
3035
**
3036
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
3037
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
3038
** that is inside an explicit transaction, then the entire transaction
3039
** will be rolled back automatically.
3040
**
3041
** ^The sqlite3_interrupt(D) call is in effect until all currently running
3042
** SQL statements on [database connection] D complete.  ^Any new SQL statements
3043
** that are started after the sqlite3_interrupt() call and before the
3044
** running statement count reaches zero are interrupted as if they had been
3045
** running prior to the sqlite3_interrupt() call.  ^New SQL statements
3046
** that are started after the running statement count reaches zero are
3047
** not effected by the sqlite3_interrupt().
3048
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
3049
** SQL statements is a no-op and has no effect on SQL statements
3050
** that are started after the sqlite3_interrupt() call returns.
3051
**
3052
** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
3053
** or not an interrupt is currently in effect for [database connection] D.
3054
** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
3055
*/
3056
SQLITE_API void sqlite3_interrupt(sqlite3*);
3057
SQLITE_API int sqlite3_is_interrupted(sqlite3*);
3058
3059
/*
3060
** CAPI3REF: Determine If An SQL Statement Is Complete
3061
**
3062
** These routines are useful during command-line input to determine if the
3063
** currently entered text seems to form a complete SQL statement or
3064
** if additional input is needed before sending the text into
3065
** SQLite for parsing.  ^These routines return 1 if the input string
3066
** appears to be a complete SQL statement.  ^A statement is judged to be
3067
** complete if it ends with a semicolon token and is not a prefix of a
3068
** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
3069
** string literals or quoted identifier names or comments are not
3070
** independent tokens (they are part of the token in which they are
3071
** embedded) and thus do not count as a statement terminator.  ^Whitespace
3072
** and comments that follow the final semicolon are ignored.
3073
**
3074
** ^These routines return 0 if the statement is incomplete.  ^If a
3075
** memory allocation fails, then SQLITE_NOMEM is returned.
3076
**
3077
** ^These routines do not parse the SQL statements thus
3078
** will not detect syntactically incorrect SQL.
3079
**
3080
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
3081
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
3082
** automatically by sqlite3_complete16().  If that initialization fails,
3083
** then the return value from sqlite3_complete16() will be non-zero
3084
** regardless of whether or not the input SQL is complete.)^
3085
**
3086
** The input to [sqlite3_complete()] must be a zero-terminated
3087
** UTF-8 string.
3088
**
3089
** The input to [sqlite3_complete16()] must be a zero-terminated
3090
** UTF-16 string in native byte order.
3091
*/
3092
SQLITE_API int sqlite3_complete(const char *sql);
3093
SQLITE_API int sqlite3_complete16(const void *sql);
3094
3095
/*
3096
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
3097
** KEYWORDS: {busy-handler callback} {busy handler}
3098
** METHOD: sqlite3
3099
**
3100
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
3101
** that might be invoked with argument P whenever
3102
** an attempt is made to access a database table associated with
3103
** [database connection] D when another thread
3104
** or process has the table locked.
3105
** The sqlite3_busy_handler() interface is used to implement
3106
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
3107
**
3108
** ^If the busy callback is NULL, then [SQLITE_BUSY]
3109
** is returned immediately upon encountering the lock.  ^If the busy callback
3110
** is not NULL, then the callback might be invoked with two arguments.
3111
**
3112
** ^The first argument to the busy handler is a copy of the void* pointer which
3113
** is the third argument to sqlite3_busy_handler().  ^The second argument to
3114
** the busy handler callback is the number of times that the busy handler has
3115
** been invoked previously for the same locking event.  ^If the
3116
** busy callback returns 0, then no additional attempts are made to
3117
** access the database and [SQLITE_BUSY] is returned
3118
** to the application.
3119
** ^If the callback returns non-zero, then another attempt
3120
** is made to access the database and the cycle repeats.
3121
**
3122
** The presence of a busy handler does not guarantee that it will be invoked
3123
** when there is lock contention. ^If SQLite determines that invoking the busy
3124
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
3125
** to the application instead of invoking the
3126
** busy handler.
3127
** Consider a scenario where one process is holding a read lock that
3128
** it is trying to promote to a reserved lock and
3129
** a second process is holding a reserved lock that it is trying
3130
** to promote to an exclusive lock.  The first process cannot proceed
3131
** because it is blocked by the second and the second process cannot
3132
** proceed because it is blocked by the first.  If both processes
3133
** invoke the busy handlers, neither will make any progress.  Therefore,
3134
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
3135
** will induce the first process to release its read lock and allow
3136
** the second process to proceed.
3137
**
3138
** ^The default busy callback is NULL.
3139
**
3140
** ^(There can only be a single busy handler defined for each
3141
** [database connection].  Setting a new busy handler clears any
3142
** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
3143
** or evaluating [PRAGMA busy_timeout=N] will change the
3144
** busy handler and thus clear any previously set busy handler.
3145
**
3146
** The busy callback should not take any actions which modify the
3147
** database connection that invoked the busy handler.  In other words,
3148
** the busy handler is not reentrant.  Any such actions
3149
** result in undefined behavior.
3150
**
3151
** A busy handler must not close the database connection
3152
** or [prepared statement] that invoked the busy handler.
3153
*/
3154
SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
3155
3156
/*
3157
** CAPI3REF: Set A Busy Timeout
3158
** METHOD: sqlite3
3159
**
3160
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
3161
** for a specified amount of time when a table is locked.  ^The handler
3162
** will sleep multiple times until at least "ms" milliseconds of sleeping
3163
** have accumulated.  ^After at least "ms" milliseconds of sleeping,
3164
** the handler returns 0 which causes [sqlite3_step()] to return
3165
** [SQLITE_BUSY].
3166
**
3167
** ^Calling this routine with an argument less than or equal to zero
3168
** turns off all busy handlers.
3169
**
3170
** ^(There can only be a single busy handler for a particular
3171
** [database connection] at any given moment.  If another busy handler
3172
** was defined  (using [sqlite3_busy_handler()]) prior to calling
3173
** this routine, that other busy handler is cleared.)^
3174
**
3175
** See also:  [PRAGMA busy_timeout]
3176
*/
3177
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3178
3179
/*
3180
** CAPI3REF: Convenience Routines For Running Queries
3181
** METHOD: sqlite3
3182
**
3183
** This is a legacy interface that is preserved for backwards compatibility.
3184
** Use of this interface is not recommended.
3185
**
3186
** Definition: A <b>result table</b> is memory data structure created by the
3187
** [sqlite3_get_table()] interface.  A result table records the
3188
** complete query results from one or more queries.
3189
**
3190
** The table conceptually has a number of rows and columns.  But
3191
** these numbers are not part of the result table itself.  These
3192
** numbers are obtained separately.  Let N be the number of rows
3193
** and M be the number of columns.
3194
**
3195
** A result table is an array of pointers to zero-terminated UTF-8 strings.
3196
** There are (N+1)*M elements in the array.  The first M pointers point
3197
** to zero-terminated strings that  contain the names of the columns.
3198
** The remaining entries all point to query results.  NULL values result
3199
** in NULL pointers.  All other values are in their UTF-8 zero-terminated
3200
** string representation as returned by [sqlite3_column_text()].
3201
**
3202
** A result table might consist of one or more memory allocations.
3203
** It is not safe to pass a result table directly to [sqlite3_free()].
3204
** A result table should be deallocated using [sqlite3_free_table()].
3205
**
3206
** ^(As an example of the result table format, suppose a query result
3207
** is as follows:
3208
**
3209
** <blockquote><pre>
3210
**        Name        | Age
3211
**        -----------------------
3212
**        Alice       | 43
3213
**        Bob         | 28
3214
**        Cindy       | 21
3215
** </pre></blockquote>
3216
**
3217
** There are two columns (M==2) and three rows (N==3).  Thus the
3218
** result table has 8 entries.  Suppose the result table is stored
3219
** in an array named azResult.  Then azResult holds this content:
3220
**
3221
** <blockquote><pre>
3222
**        azResult&#91;0] = "Name";
3223
**        azResult&#91;1] = "Age";
3224
**        azResult&#91;2] = "Alice";
3225
**        azResult&#91;3] = "43";
3226
**        azResult&#91;4] = "Bob";
3227
**        azResult&#91;5] = "28";
3228
**        azResult&#91;6] = "Cindy";
3229
**        azResult&#91;7] = "21";
3230
** </pre></blockquote>)^
3231
**
3232
** ^The sqlite3_get_table() function evaluates one or more
3233
** semicolon-separated SQL statements in the zero-terminated UTF-8
3234
** string of its 2nd parameter and returns a result table to the
3235
** pointer given in its 3rd parameter.
3236
**
3237
** After the application has finished with the result from sqlite3_get_table(),
3238
** it must pass the result table pointer to sqlite3_free_table() in order to
3239
** release the memory that was malloced.  Because of the way the
3240
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
3241
** function must not try to call [sqlite3_free()] directly.  Only
3242
** [sqlite3_free_table()] is able to release the memory properly and safely.
3243
**
3244
** The sqlite3_get_table() interface is implemented as a wrapper around
3245
** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
3246
** to any internal data structures of SQLite.  It uses only the public
3247
** interface defined here.  As a consequence, errors that occur in the
3248
** wrapper layer outside of the internal [sqlite3_exec()] call are not
3249
** reflected in subsequent calls to [sqlite3_errcode()] or
3250
** [sqlite3_errmsg()].
3251
*/
3252
SQLITE_API int sqlite3_get_table(
3253
  sqlite3 *db,          /* An open database */
3254
  const char *zSql,     /* SQL to be evaluated */
3255
  char ***pazResult,    /* Results of the query */
3256
  int *pnRow,           /* Number of result rows written here */
3257
  int *pnColumn,        /* Number of result columns written here */
3258
  char **pzErrmsg       /* Error msg written here */
3259
);
3260
SQLITE_API void sqlite3_free_table(char **result);
3261
3262
/*
3263
** CAPI3REF: Formatted String Printing Functions
3264
**
3265
** These routines are work-alikes of the "printf()" family of functions
3266
** from the standard C library.
3267
** These routines understand most of the common formatting options from
3268
** the standard library printf()
3269
** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
3270
** See the [built-in printf()] documentation for details.
3271
**
3272
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
3273
** results into memory obtained from [sqlite3_malloc64()].
3274
** The strings returned by these two routines should be
3275
** released by [sqlite3_free()].  ^Both routines return a
3276
** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
3277
** memory to hold the resulting string.
3278
**
3279
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
3280
** the standard C library.  The result is written into the
3281
** buffer supplied as the second parameter whose size is given by
3282
** the first parameter. Note that the order of the
3283
** first two parameters is reversed from snprintf().)^  This is an
3284
** historical accident that cannot be fixed without breaking
3285
** backwards compatibility.  ^(Note also that sqlite3_snprintf()
3286
** returns a pointer to its buffer instead of the number of
3287
** characters actually written into the buffer.)^  We admit that
3288
** the number of characters written would be a more useful return
3289
** value but we cannot change the implementation of sqlite3_snprintf()
3290
** now without breaking compatibility.
3291
**
3292
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
3293
** guarantees that the buffer is always zero-terminated.  ^The first
3294
** parameter "n" is the total size of the buffer, including space for
3295
** the zero terminator.  So the longest string that can be completely
3296
** written will be n-1 characters.
3297
**
3298
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
3299
**
3300
** See also:  [built-in printf()], [printf() SQL function]
3301
*/
3302
SQLITE_API char *sqlite3_mprintf(const char*,...);
3303
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3304
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3305
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3306
3307
/*
3308
** CAPI3REF: Memory Allocation Subsystem
3309
**
3310
** The SQLite core uses these three routines for all of its own
3311
** internal memory allocation needs. "Core" in the previous sentence
3312
** does not include operating-system specific [VFS] implementation.  The
3313
** Windows VFS uses native malloc() and free() for some operations.
3314
**
3315
** ^The sqlite3_malloc() routine returns a pointer to a block
3316
** of memory at least N bytes in length, where N is the parameter.
3317
** ^If sqlite3_malloc() is unable to obtain sufficient free
3318
** memory, it returns a NULL pointer.  ^If the parameter N to
3319
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
3320
** a NULL pointer.
3321
**
3322
** ^The sqlite3_malloc64(N) routine works just like
3323
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
3324
** of a signed 32-bit integer.
3325
**
3326
** ^Calling sqlite3_free() with a pointer previously returned
3327
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3328
** that it might be reused.  ^The sqlite3_free() routine is
3329
** a no-op if is called with a NULL pointer.  Passing a NULL pointer
3330
** to sqlite3_free() is harmless.  After being freed, memory
3331
** should neither be read nor written.  Even reading previously freed
3332
** memory might result in a segmentation fault or other severe error.
3333
** Memory corruption, a segmentation fault, or other severe error
3334
** might result if sqlite3_free() is called with a non-NULL pointer that
3335
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
3336
**
3337
** ^The sqlite3_realloc(X,N) interface attempts to resize a
3338
** prior memory allocation X to be at least N bytes.
3339
** ^If the X parameter to sqlite3_realloc(X,N)
3340
** is a NULL pointer then its behavior is identical to calling
3341
** sqlite3_malloc(N).
3342
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3343
** negative then the behavior is exactly the same as calling
3344
** sqlite3_free(X).
3345
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3346
** of at least N bytes in size or NULL if insufficient memory is available.
3347
** ^If M is the size of the prior allocation, then min(N,M) bytes
3348
** of the prior allocation are copied into the beginning of buffer returned
3349
** by sqlite3_realloc(X,N) and the prior allocation is freed.
3350
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3351
** prior allocation is not freed.
3352
**
3353
** ^The sqlite3_realloc64(X,N) interfaces works the same as
3354
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3355
** of a 32-bit signed integer.
3356
**
3357
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3358
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
3359
** sqlite3_msize(X) returns the size of that memory allocation in bytes.
3360
** ^The value returned by sqlite3_msize(X) might be larger than the number
3361
** of bytes requested when X was allocated.  ^If X is a NULL pointer then
3362
** sqlite3_msize(X) returns zero.  If X points to something that is not
3363
** the beginning of memory allocation, or if it points to a formerly
3364
** valid memory allocation that has now been freed, then the behavior
3365
** of sqlite3_msize(X) is undefined and possibly harmful.
3366
**
3367
** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
3368
** sqlite3_malloc64(), and sqlite3_realloc64()
3369
** is always aligned to at least an 8 byte boundary, or to a
3370
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3371
** option is used.
3372
**
3373
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3374
** must be either NULL or else pointers obtained from a prior
3375
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3376
** not yet been released.
3377
**
3378
** The application must not read or write any part of
3379
** a block of memory after it has been released using
3380
** [sqlite3_free()] or [sqlite3_realloc()].
3381
*/
3382
SQLITE_API void *sqlite3_malloc(int);
3383
SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
3384
SQLITE_API void *sqlite3_realloc(void*, int);
3385
SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
3386
SQLITE_API void sqlite3_free(void*);
3387
SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
3388
3389
/*
3390
** CAPI3REF: Memory Allocator Statistics
3391
**
3392
** SQLite provides these two interfaces for reporting on the status
3393
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
3394
** routines, which form the built-in memory allocation subsystem.
3395
**
3396
** ^The [sqlite3_memory_used()] routine returns the number of bytes
3397
** of memory currently outstanding (malloced but not freed).
3398
** ^The [sqlite3_memory_highwater()] routine returns the maximum
3399
** value of [sqlite3_memory_used()] since the high-water mark
3400
** was last reset.  ^The values returned by [sqlite3_memory_used()] and
3401
** [sqlite3_memory_highwater()] include any overhead
3402
** added by SQLite in its implementation of [sqlite3_malloc()],
3403
** but not overhead added by the any underlying system library
3404
** routines that [sqlite3_malloc()] may call.
3405
**
3406
** ^The memory high-water mark is reset to the current value of
3407
** [sqlite3_memory_used()] if and only if the parameter to
3408
** [sqlite3_memory_highwater()] is true.  ^The value returned
3409
** by [sqlite3_memory_highwater(1)] is the high-water mark
3410
** prior to the reset.
3411
*/
3412
SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
3413
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
3414
3415
/*
3416
** CAPI3REF: Pseudo-Random Number Generator
3417
**
3418
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3419
** select random [ROWID | ROWIDs] when inserting new records into a table that
3420
** already uses the largest possible [ROWID].  The PRNG is also used for
3421
** the built-in random() and randomblob() SQL functions.  This interface allows
3422
** applications to access the same PRNG for other purposes.
3423
**
3424
** ^A call to this routine stores N bytes of randomness into buffer P.
3425
** ^The P parameter can be a NULL pointer.
3426
**
3427
** ^If this routine has not been previously called or if the previous
3428
** call had N less than one or a NULL pointer for P, then the PRNG is
3429
** seeded using randomness obtained from the xRandomness method of
3430
** the default [sqlite3_vfs] object.
3431
** ^If the previous call to this routine had an N of 1 or more and a
3432
** non-NULL P then the pseudo-randomness is generated
3433
** internally and without recourse to the [sqlite3_vfs] xRandomness
3434
** method.
3435
*/
3436
SQLITE_API void sqlite3_randomness(int N, void *P);
3437
3438
/*
3439
** CAPI3REF: Compile-Time Authorization Callbacks
3440
** METHOD: sqlite3
3441
** KEYWORDS: {authorizer callback}
3442
**
3443
** ^This routine registers an authorizer callback with a particular
3444
** [database connection], supplied in the first argument.
3445
** ^The authorizer callback is invoked as SQL statements are being compiled
3446
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
3447
** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
3448
** and [sqlite3_prepare16_v3()].  ^At various
3449
** points during the compilation process, as logic is being created
3450
** to perform various actions, the authorizer callback is invoked to
3451
** see if those actions are allowed.  ^The authorizer callback should
3452
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
3453
** specific action but allow the SQL statement to continue to be
3454
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
3455
** rejected with an error.  ^If the authorizer callback returns
3456
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
3457
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
3458
** the authorizer will fail with an error message.
3459
**
3460
** When the callback returns [SQLITE_OK], that means the operation
3461
** requested is ok.  ^When the callback returns [SQLITE_DENY], the
3462
** [sqlite3_prepare_v2()] or equivalent call that triggered the
3463
** authorizer will fail with an error message explaining that
3464
** access is denied.
3465
**
3466
** ^The first parameter to the authorizer callback is a copy of the third
3467
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3468
** to the callback is an integer [SQLITE_COPY | action code] that specifies
3469
** the particular action to be authorized. ^The third through sixth parameters
3470
** to the callback are either NULL pointers or zero-terminated strings
3471
** that contain additional details about the action to be authorized.
3472
** Applications must always be prepared to encounter a NULL pointer in any
3473
** of the third through the sixth parameters of the authorization callback.
3474
**
3475
** ^If the action code is [SQLITE_READ]
3476
** and the callback returns [SQLITE_IGNORE] then the
3477
** [prepared statement] statement is constructed to substitute
3478
** a NULL value in place of the table column that would have
3479
** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
3480
** return can be used to deny an untrusted user access to individual
3481
** columns of a table.
3482
** ^When a table is referenced by a [SELECT] but no column values are
3483
** extracted from that table (for example in a query like
3484
** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
3485
** is invoked once for that table with a column name that is an empty string.
3486
** ^If the action code is [SQLITE_DELETE] and the callback returns
3487
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
3488
** [truncate optimization] is disabled and all rows are deleted individually.
3489
**
3490
** An authorizer is used when [sqlite3_prepare | preparing]
3491
** SQL statements from an untrusted source, to ensure that the SQL statements
3492
** do not try to access data they are not allowed to see, or that they do not
3493
** try to execute malicious statements that damage the database.  For
3494
** example, an application may allow a user to enter arbitrary
3495
** SQL queries for evaluation by a database.  But the application does
3496
** not want the user to be able to make arbitrary changes to the
3497
** database.  An authorizer could then be put in place while the
3498
** user-entered SQL is being [sqlite3_prepare | prepared] that
3499
** disallows everything except [SELECT] statements.
3500
**
3501
** Applications that need to process SQL from untrusted sources
3502
** might also consider lowering resource limits using [sqlite3_limit()]
3503
** and limiting database size using the [max_page_count] [PRAGMA]
3504
** in addition to using an authorizer.
3505
**
3506
** ^(Only a single authorizer can be in place on a database connection
3507
** at a time.  Each call to sqlite3_set_authorizer overrides the
3508
** previous call.)^  ^Disable the authorizer by installing a NULL callback.
3509
** The authorizer is disabled by default.
3510
**
3511
** The authorizer callback must not do anything that will modify
3512
** the database connection that invoked the authorizer callback.
3513
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3514
** database connections for the meaning of "modify" in this paragraph.
3515
**
3516
** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3517
** statement might be re-prepared during [sqlite3_step()] due to a
3518
** schema change.  Hence, the application should ensure that the
3519
** correct authorizer callback remains in place during the [sqlite3_step()].
3520
**
3521
** ^Note that the authorizer callback is invoked only during
3522
** [sqlite3_prepare()] or its variants.  Authorization is not
3523
** performed during statement evaluation in [sqlite3_step()], unless
3524
** as stated in the previous paragraph, sqlite3_step() invokes
3525
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3526
*/
3527
SQLITE_API int sqlite3_set_authorizer(
3528
  sqlite3*,
3529
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3530
  void *pUserData
3531
);
3532
3533
/*
3534
** CAPI3REF: Authorizer Return Codes
3535
**
3536
** The [sqlite3_set_authorizer | authorizer callback function] must
3537
** return either [SQLITE_OK] or one of these two constants in order
3538
** to signal SQLite whether or not the action is permitted.  See the
3539
** [sqlite3_set_authorizer | authorizer documentation] for additional
3540
** information.
3541
**
3542
** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
3543
** returned from the [sqlite3_vtab_on_conflict()] interface.
3544
*/
3545
1.42M
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
3546
2.01M
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
3547
3548
/*
3549
** CAPI3REF: Authorizer Action Codes
3550
**
3551
** The [sqlite3_set_authorizer()] interface registers a callback function
3552
** that is invoked to authorize certain SQL statement actions.  The
3553
** second parameter to the callback is an integer code that specifies
3554
** what action is being authorized.  These are the integer action codes that
3555
** the authorizer callback may be passed.
3556
**
3557
** These action code values signify what kind of operation is to be
3558
** authorized.  The 3rd and 4th parameters to the authorization
3559
** callback function will be parameters or NULL depending on which of these
3560
** codes is used as the second parameter.  ^(The 5th parameter to the
3561
** authorizer callback is the name of the database ("main", "temp",
3562
** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
3563
** is the name of the inner-most trigger or view that is responsible for
3564
** the access attempt or NULL if this access attempt is directly from
3565
** top-level SQL code.
3566
*/
3567
/******************************************* 3rd ************ 4th ***********/
3568
92.7k
#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
3569
176k
#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
3570
4.47k
#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
3571
176k
#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
3572
686
#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
3573
176k
#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
3574
2.73k
#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
3575
176k
#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
3576
6.34k
#define SQLITE_DELETE                9   /* Table Name      NULL            */
3577
71
#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
3578
1.13k
#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
3579
47
#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
3580
45
#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
3581
73
#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
3582
0
#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
3583
115
#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
3584
0
#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
3585
357k
#define SQLITE_INSERT               18   /* Table Name      NULL            */
3586
69.7k
#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
3587
462k
#define SQLITE_READ                 20   /* Table Name      Column Name     */
3588
234k
#define SQLITE_SELECT               21   /* NULL            NULL            */
3589
14.7k
#define SQLITE_TRANSACTION          22   /* Operation       NULL            */
3590
207k
#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
3591
29.2k
#define SQLITE_ATTACH               24   /* Filename        NULL            */
3592
272
#define SQLITE_DETACH               25   /* Database Name   NULL            */
3593
568
#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
3594
7.27k
#define SQLITE_REINDEX              27   /* Index Name      NULL            */
3595
3.23k
#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
3596
76
#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
3597
1
#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
3598
113k
#define SQLITE_FUNCTION             31   /* NULL            Function Name   */
3599
2.88k
#define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
3600
#define SQLITE_COPY                  0   /* No longer used */
3601
426
#define SQLITE_RECURSIVE            33   /* NULL            NULL            */
3602
3603
/*
3604
** CAPI3REF: Tracing And Profiling Functions
3605
** METHOD: sqlite3
3606
**
3607
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3608
** instead of the routines described here.
3609
**
3610
** These routines register callback functions that can be used for
3611
** tracing and profiling the execution of SQL statements.
3612
**
3613
** ^The callback function registered by sqlite3_trace() is invoked at
3614
** various times when an SQL statement is being run by [sqlite3_step()].
3615
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
3616
** SQL statement text as the statement first begins executing.
3617
** ^(Additional sqlite3_trace() callbacks might occur
3618
** as each triggered subprogram is entered.  The callbacks for triggers
3619
** contain a UTF-8 SQL comment that identifies the trigger.)^
3620
**
3621
** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3622
** the length of [bound parameter] expansion in the output of sqlite3_trace().
3623
**
3624
** ^The callback function registered by sqlite3_profile() is invoked
3625
** as each SQL statement finishes.  ^The profile callback contains
3626
** the original statement text and an estimate of wall-clock time
3627
** of how long that statement took to run.  ^The profile callback
3628
** time is in units of nanoseconds, however the current implementation
3629
** is only capable of millisecond resolution so the six least significant
3630
** digits in the time are meaningless.  Future versions of SQLite
3631
** might provide greater resolution on the profiler callback.  Invoking
3632
** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
3633
** profile callback.
3634
*/
3635
SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
3636
   void(*xTrace)(void*,const char*), void*);
3637
SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3638
   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
3639
3640
/*
3641
** CAPI3REF: SQL Trace Event Codes
3642
** KEYWORDS: SQLITE_TRACE
3643
**
3644
** These constants identify classes of events that can be monitored
3645
** using the [sqlite3_trace_v2()] tracing logic.  The M argument
3646
** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
3647
** the following constants.  ^The first argument to the trace callback
3648
** is one of the following constants.
3649
**
3650
** New tracing constants may be added in future releases.
3651
**
3652
** ^A trace callback has four arguments: xCallback(T,C,P,X).
3653
** ^The T argument is one of the integer type codes above.
3654
** ^The C argument is a copy of the context pointer passed in as the
3655
** fourth argument to [sqlite3_trace_v2()].
3656
** The P and X arguments are pointers whose meanings depend on T.
3657
**
3658
** <dl>
3659
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
3660
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
3661
** first begins running and possibly at other times during the
3662
** execution of the prepared statement, such as at the start of each
3663
** trigger subprogram. ^The P argument is a pointer to the
3664
** [prepared statement]. ^The X argument is a pointer to a string which
3665
** is the unexpanded SQL text of the prepared statement or an SQL comment
3666
** that indicates the invocation of a trigger.  ^The callback can compute
3667
** the same text that would have been returned by the legacy [sqlite3_trace()]
3668
** interface by using the X argument when X begins with "--" and invoking
3669
** [sqlite3_expanded_sql(P)] otherwise.
3670
**
3671
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3672
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3673
** information as is provided by the [sqlite3_profile()] callback.
3674
** ^The P argument is a pointer to the [prepared statement] and the
3675
** X argument points to a 64-bit integer which is approximately
3676
** the number of nanoseconds that the prepared statement took to run.
3677
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3678
**
3679
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3680
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3681
** statement generates a single row of result.
3682
** ^The P argument is a pointer to the [prepared statement] and the
3683
** X argument is unused.
3684
**
3685
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
3686
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
3687
** connection closes.
3688
** ^The P argument is a pointer to the [database connection] object
3689
** and the X argument is unused.
3690
** </dl>
3691
*/
3692
407k
#define SQLITE_TRACE_STMT       0x01
3693
379k
#define SQLITE_TRACE_PROFILE    0x02
3694
290k
#define SQLITE_TRACE_ROW        0x04
3695
10.1k
#define SQLITE_TRACE_CLOSE      0x08
3696
3697
/*
3698
** CAPI3REF: SQL Trace Hook
3699
** METHOD: sqlite3
3700
**
3701
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
3702
** function X against [database connection] D, using property mask M
3703
** and context pointer P.  ^If the X callback is
3704
** NULL or if the M mask is zero, then tracing is disabled.  The
3705
** M argument should be the bitwise OR-ed combination of
3706
** zero or more [SQLITE_TRACE] constants.
3707
**
3708
** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3709
** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3710
** sqlite3_trace_v2(D,M,X,P) for the [database connection] D.  Each
3711
** database connection may have at most one trace callback.
3712
**
3713
** ^The X callback is invoked whenever any of the events identified by
3714
** mask M occur.  ^The integer return value from the callback is currently
3715
** ignored, though this may change in future releases.  Callback
3716
** implementations should return zero to ensure future compatibility.
3717
**
3718
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
3719
** ^The T argument is one of the [SQLITE_TRACE]
3720
** constants to indicate why the callback was invoked.
3721
** ^The C argument is a copy of the context pointer.
3722
** The P and X arguments are pointers whose meanings depend on T.
3723
**
3724
** The sqlite3_trace_v2() interface is intended to replace the legacy
3725
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
3726
** are deprecated.
3727
*/
3728
SQLITE_API int sqlite3_trace_v2(
3729
  sqlite3*,
3730
  unsigned uMask,
3731
  int(*xCallback)(unsigned,void*,void*,void*),
3732
  void *pCtx
3733
);
3734
3735
/*
3736
** CAPI3REF: Query Progress Callbacks
3737
** METHOD: sqlite3
3738
**
3739
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3740
** function X to be invoked periodically during long running calls to
3741
** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3742
** database connection D.  An example use for this
3743
** interface is to keep a GUI updated during a large query.
3744
**
3745
** ^The parameter P is passed through as the only parameter to the
3746
** callback function X.  ^The parameter N is the approximate number of
3747
** [virtual machine instructions] that are evaluated between successive
3748
** invocations of the callback X.  ^If N is less than one then the progress
3749
** handler is disabled.
3750
**
3751
** ^Only a single progress handler may be defined at one time per
3752
** [database connection]; setting a new progress handler cancels the
3753
** old one.  ^Setting parameter X to NULL disables the progress handler.
3754
** ^The progress handler is also disabled by setting N to a value less
3755
** than 1.
3756
**
3757
** ^If the progress callback returns non-zero, the operation is
3758
** interrupted.  This feature can be used to implement a
3759
** "Cancel" button on a GUI progress dialog box.
3760
**
3761
** The progress handler callback must not do anything that will modify
3762
** the database connection that invoked the progress handler.
3763
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3764
** database connections for the meaning of "modify" in this paragraph.
3765
**
3766
** The progress handler callback would originally only be invoked from the
3767
** bytecode engine.  It still might be invoked during [sqlite3_prepare()]
3768
** and similar because those routines might force a reparse of the schema
3769
** which involves running the bytecode engine.  However, beginning with
3770
** SQLite version 3.41.0, the progress handler callback might also be
3771
** invoked directly from [sqlite3_prepare()] while analyzing and generating
3772
** code for complex queries.
3773
*/
3774
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3775
3776
/*
3777
** CAPI3REF: Opening A New Database Connection
3778
** CONSTRUCTOR: sqlite3
3779
**
3780
** ^These routines open an SQLite database file as specified by the
3781
** filename argument. ^The filename argument is interpreted as UTF-8 for
3782
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3783
** order for sqlite3_open16(). ^(A [database connection] handle is usually
3784
** returned in *ppDb, even if an error occurs.  The only exception is that
3785
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3786
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3787
** object.)^ ^(If the database is opened (and/or created) successfully, then
3788
** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
3789
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3790
** an English language description of the error following a failure of any
3791
** of the sqlite3_open() routines.
3792
**
3793
** ^The default encoding will be UTF-8 for databases created using
3794
** sqlite3_open() or sqlite3_open_v2().  ^The default encoding for databases
3795
** created using sqlite3_open16() will be UTF-16 in the native byte order.
3796
**
3797
** Whether or not an error occurs when it is opened, resources
3798
** associated with the [database connection] handle should be released by
3799
** passing it to [sqlite3_close()] when it is no longer required.
3800
**
3801
** The sqlite3_open_v2() interface works like sqlite3_open()
3802
** except that it accepts two additional parameters for additional control
3803
** over the new database connection.  ^(The flags parameter to
3804
** sqlite3_open_v2() must include, at a minimum, one of the following
3805
** three flag combinations:)^
3806
**
3807
** <dl>
3808
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3809
** <dd>The database is opened in read-only mode.  If the database does
3810
** not already exist, an error is returned.</dd>)^
3811
**
3812
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3813
** <dd>The database is opened for reading and writing if possible, or
3814
** reading only if the file is write protected by the operating
3815
** system.  In either case the database must already exist, otherwise
3816
** an error is returned.  For historical reasons, if opening in
3817
** read-write mode fails due to OS-level permissions, an attempt is
3818
** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3819
** used to determine whether the database is actually
3820
** read-write.</dd>)^
3821
**
3822
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3823
** <dd>The database is opened for reading and writing, and is created if
3824
** it does not already exist. This is the behavior that is always used for
3825
** sqlite3_open() and sqlite3_open16().</dd>)^
3826
** </dl>
3827
**
3828
** In addition to the required flags, the following optional flags are
3829
** also supported:
3830
**
3831
** <dl>
3832
** ^(<dt>[SQLITE_OPEN_URI]</dt>
3833
** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3834
**
3835
** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3836
** <dd>The database will be opened as an in-memory database.  The database
3837
** is named by the "filename" argument for the purposes of cache-sharing,
3838
** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3839
** </dd>)^
3840
**
3841
** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3842
** <dd>The new database connection will use the "multi-thread"
3843
** [threading mode].)^  This means that separate threads are allowed
3844
** to use SQLite at the same time, as long as each thread is using
3845
** a different [database connection].
3846
**
3847
** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3848
** <dd>The new database connection will use the "serialized"
3849
** [threading mode].)^  This means the multiple threads can safely
3850
** attempt to use the same database connection at the same time.
3851
** (Mutexes will block any actual concurrency, but in this mode
3852
** there is no harm in trying.)
3853
**
3854
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3855
** <dd>The database is opened [shared cache] enabled, overriding
3856
** the default shared cache setting provided by
3857
** [sqlite3_enable_shared_cache()].)^
3858
** The [use of shared cache mode is discouraged] and hence shared cache
3859
** capabilities may be omitted from many builds of SQLite.  In such cases,
3860
** this option is a no-op.
3861
**
3862
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3863
** <dd>The database is opened [shared cache] disabled, overriding
3864
** the default shared cache setting provided by
3865
** [sqlite3_enable_shared_cache()].)^
3866
**
3867
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3868
** <dd>The database connection comes up in "extended result code mode".
3869
** In other words, the database behaves has if
3870
** [sqlite3_extended_result_codes(db,1)] where called on the database
3871
** connection as soon as the connection is created. In addition to setting
3872
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3873
** to return an extended result code.</dd>
3874
**
3875
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3876
** <dd>The database filename is not allowed to contain a symbolic link</dd>
3877
** </dl>)^
3878
**
3879
** If the 3rd parameter to sqlite3_open_v2() is not one of the
3880
** required combinations shown above optionally combined with other
3881
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3882
** then the behavior is undefined.  Historic versions of SQLite
3883
** have silently ignored surplus bits in the flags parameter to
3884
** sqlite3_open_v2(), however that behavior might not be carried through
3885
** into future versions of SQLite and so applications should not rely
3886
** upon it.  Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3887
** for sqlite3_open_v2().  The SQLITE_OPEN_EXCLUSIVE does *not* cause
3888
** the open to fail if the database already exists.  The SQLITE_OPEN_EXCLUSIVE
3889
** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3890
** by sqlite3_open_v2().
3891
**
3892
** ^The fourth parameter to sqlite3_open_v2() is the name of the
3893
** [sqlite3_vfs] object that defines the operating system interface that
3894
** the new database connection should use.  ^If the fourth parameter is
3895
** a NULL pointer then the default [sqlite3_vfs] object is used.
3896
**
3897
** ^If the filename is ":memory:", then a private, temporary in-memory database
3898
** is created for the connection.  ^This in-memory database will vanish when
3899
** the database connection is closed.  Future versions of SQLite might
3900
** make use of additional special filenames that begin with the ":" character.
3901
** It is recommended that when a database filename actually does begin with
3902
** a ":" character you should prefix the filename with a pathname such as
3903
** "./" to avoid ambiguity.
3904
**
3905
** ^If the filename is an empty string, then a private, temporary
3906
** on-disk database will be created.  ^This private database will be
3907
** automatically deleted as soon as the database connection is closed.
3908
**
3909
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3910
**
3911
** ^If [URI filename] interpretation is enabled, and the filename argument
3912
** begins with "file:", then the filename is interpreted as a URI. ^URI
3913
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3914
** set in the third argument to sqlite3_open_v2(), or if it has
3915
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3916
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3917
** URI filename interpretation is turned off
3918
** by default, but future releases of SQLite might enable URI filename
3919
** interpretation by default.  See "[URI filenames]" for additional
3920
** information.
3921
**
3922
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3923
** authority, then it must be either an empty string or the string
3924
** "localhost". ^If the authority is not an empty string or "localhost", an
3925
** error is returned to the caller. ^The fragment component of a URI, if
3926
** present, is ignored.
3927
**
3928
** ^SQLite uses the path component of the URI as the name of the disk file
3929
** which contains the database. ^If the path begins with a '/' character,
3930
** then it is interpreted as an absolute path. ^If the path does not begin
3931
** with a '/' (meaning that the authority section is omitted from the URI)
3932
** then the path is interpreted as a relative path.
3933
** ^(On windows, the first component of an absolute path
3934
** is a drive specification (e.g. "C:").)^
3935
**
3936
** [[core URI query parameters]]
3937
** The query component of a URI may contain parameters that are interpreted
3938
** either by SQLite itself, or by a [VFS | custom VFS implementation].
3939
** SQLite and its built-in [VFSes] interpret the
3940
** following query parameters:
3941
**
3942
** <ul>
3943
**   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3944
**     a VFS object that provides the operating system interface that should
3945
**     be used to access the database file on disk. ^If this option is set to
3946
**     an empty string the default VFS object is used. ^Specifying an unknown
3947
**     VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3948
**     present, then the VFS specified by the option takes precedence over
3949
**     the value passed as the fourth parameter to sqlite3_open_v2().
3950
**
3951
**   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3952
**     "rwc", or "memory". Attempting to set it to any other value is
3953
**     an error)^.
3954
**     ^If "ro" is specified, then the database is opened for read-only
3955
**     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3956
**     third argument to sqlite3_open_v2(). ^If the mode option is set to
3957
**     "rw", then the database is opened for read-write (but not create)
3958
**     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3959
**     been set. ^Value "rwc" is equivalent to setting both
3960
**     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
3961
**     set to "memory" then a pure [in-memory database] that never reads
3962
**     or writes from disk is used. ^It is an error to specify a value for
3963
**     the mode parameter that is less restrictive than that specified by
3964
**     the flags passed in the third parameter to sqlite3_open_v2().
3965
**
3966
**   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3967
**     "private". ^Setting it to "shared" is equivalent to setting the
3968
**     SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3969
**     sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3970
**     equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3971
**     ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3972
**     a URI filename, its value overrides any behavior requested by setting
3973
**     SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3974
**
3975
**  <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3976
**     [powersafe overwrite] property does or does not apply to the
3977
**     storage media on which the database file resides.
3978
**
3979
**  <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3980
**     which if set disables file locking in rollback journal modes.  This
3981
**     is useful for accessing a database on a filesystem that does not
3982
**     support locking.  Caution:  Database corruption might result if two
3983
**     or more processes write to the same database and any one of those
3984
**     processes uses nolock=1.
3985
**
3986
**  <li> <b>immutable</b>: ^The immutable parameter is a boolean query
3987
**     parameter that indicates that the database file is stored on
3988
**     read-only media.  ^When immutable is set, SQLite assumes that the
3989
**     database file cannot be changed, even by a process with higher
3990
**     privilege, and so the database is opened read-only and all locking
3991
**     and change detection is disabled.  Caution: Setting the immutable
3992
**     property on a database file that does in fact change can result
3993
**     in incorrect query results and/or [SQLITE_CORRUPT] errors.
3994
**     See also: [SQLITE_IOCAP_IMMUTABLE].
3995
**
3996
** </ul>
3997
**
3998
** ^Specifying an unknown parameter in the query component of a URI is not an
3999
** error.  Future versions of SQLite might understand additional query
4000
** parameters.  See "[query parameters with special meaning to SQLite]" for
4001
** additional information.
4002
**
4003
** [[URI filename examples]] <h3>URI filename examples</h3>
4004
**
4005
** <table border="1" align=center cellpadding=5>
4006
** <tr><th> URI filenames <th> Results
4007
** <tr><td> file:data.db <td>
4008
**          Open the file "data.db" in the current directory.
4009
** <tr><td> file:/home/fred/data.db<br>
4010
**          file:///home/fred/data.db <br>
4011
**          file://localhost/home/fred/data.db <br> <td>
4012
**          Open the database file "/home/fred/data.db".
4013
** <tr><td> file://darkstar/home/fred/data.db <td>
4014
**          An error. "darkstar" is not a recognized authority.
4015
** <tr><td style="white-space:nowrap">
4016
**          file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
4017
**     <td> Windows only: Open the file "data.db" on fred's desktop on drive
4018
**          C:. Note that the %20 escaping in this example is not strictly
4019
**          necessary - space characters can be used literally
4020
**          in URI filenames.
4021
** <tr><td> file:data.db?mode=ro&cache=private <td>
4022
**          Open file "data.db" in the current directory for read-only access.
4023
**          Regardless of whether or not shared-cache mode is enabled by
4024
**          default, use a private cache.
4025
** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
4026
**          Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
4027
**          that uses dot-files in place of posix advisory locking.
4028
** <tr><td> file:data.db?mode=readonly <td>
4029
**          An error. "readonly" is not a valid option for the "mode" parameter.
4030
**          Use "ro" instead:  "file:data.db?mode=ro".
4031
** </table>
4032
**
4033
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
4034
** query components of a URI. A hexadecimal escape sequence consists of a
4035
** percent sign - "%" - followed by exactly two hexadecimal digits
4036
** specifying an octet value. ^Before the path or query components of a
4037
** URI filename are interpreted, they are encoded using UTF-8 and all
4038
** hexadecimal escape sequences replaced by a single byte containing the
4039
** corresponding octet. If this process generates an invalid UTF-8 encoding,
4040
** the results are undefined.
4041
**
4042
** <b>Note to Windows users:</b>  The encoding used for the filename argument
4043
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
4044
** codepage is currently defined.  Filenames containing international
4045
** characters must be converted to UTF-8 prior to passing them into
4046
** sqlite3_open() or sqlite3_open_v2().
4047
**
4048
** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
4049
** prior to calling sqlite3_open() or sqlite3_open_v2().  Otherwise, various
4050
** features that require the use of temporary files may fail.
4051
**
4052
** See also: [sqlite3_temp_directory]
4053
*/
4054
SQLITE_API int sqlite3_open(
4055
  const char *filename,   /* Database filename (UTF-8) */
4056
  sqlite3 **ppDb          /* OUT: SQLite db handle */
4057
);
4058
SQLITE_API int sqlite3_open16(
4059
  const void *filename,   /* Database filename (UTF-16) */
4060
  sqlite3 **ppDb          /* OUT: SQLite db handle */
4061
);
4062
SQLITE_API int sqlite3_open_v2(
4063
  const char *filename,   /* Database filename (UTF-8) */
4064
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
4065
  int flags,              /* Flags */
4066
  const char *zVfs        /* Name of VFS module to use */
4067
);
4068
4069
/*
4070
** CAPI3REF: Obtain Values For URI Parameters
4071
**
4072
** These are utility routines, useful to [VFS|custom VFS implementations],
4073
** that check if a database file was a URI that contained a specific query
4074
** parameter, and if so obtains the value of that query parameter.
4075
**
4076
** The first parameter to these interfaces (hereafter referred to
4077
** as F) must be one of:
4078
** <ul>
4079
** <li> A database filename pointer created by the SQLite core and
4080
** passed into the xOpen() method of a VFS implementation, or
4081
** <li> A filename obtained from [sqlite3_db_filename()], or
4082
** <li> A new filename constructed using [sqlite3_create_filename()].
4083
** </ul>
4084
** If the F parameter is not one of the above, then the behavior is
4085
** undefined and probably undesirable.  Older versions of SQLite were
4086
** more tolerant of invalid F parameters than newer versions.
4087
**
4088
** If F is a suitable filename (as described in the previous paragraph)
4089
** and if P is the name of the query parameter, then
4090
** sqlite3_uri_parameter(F,P) returns the value of the P
4091
** parameter if it exists or a NULL pointer if P does not appear as a
4092
** query parameter on F.  If P is a query parameter of F and it
4093
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4094
** a pointer to an empty string.
4095
**
4096
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
4097
** parameter and returns true (1) or false (0) according to the value
4098
** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
4099
** value of query parameter P is one of "yes", "true", or "on" in any
4100
** case or if the value begins with a non-zero number.  The
4101
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4102
** query parameter P is one of "no", "false", or "off" in any case or
4103
** if the value begins with a numeric zero.  If P is not a query
4104
** parameter on F or if the value of P does not match any of the
4105
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4106
**
4107
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4108
** 64-bit signed integer and returns that integer, or D if P does not
4109
** exist.  If the value of P is something other than an integer, then
4110
** zero is returned.
4111
**
4112
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4113
** the value) of the N-th query parameter for filename F, or a NULL
4114
** pointer if N is less than zero or greater than the number of query
4115
** parameters minus 1.  The N value is zero-based so N should be 0 to obtain
4116
** the name of the first query parameter, 1 for the second parameter, and
4117
** so forth.
4118
**
4119
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4120
** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
4121
** is not a database file pathname pointer that the SQLite core passed
4122
** into the xOpen VFS method, then the behavior of this routine is undefined
4123
** and probably undesirable.
4124
**
4125
** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4126
** parameter can also be the name of a rollback journal file or WAL file
4127
** in addition to the main database file.  Prior to version 3.31.0, these
4128
** routines would only work if F was the name of the main database file.
4129
** When the F parameter is the name of the rollback journal or WAL file,
4130
** it has access to all the same query parameters as were found on the
4131
** main database file.
4132
**
4133
** See the [URI filename] documentation for additional information.
4134
*/
4135
SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
4136
SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
4137
SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
4138
SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
4139
4140
/*
4141
** CAPI3REF:  Translate filenames
4142
**
4143
** These routines are available to [VFS|custom VFS implementations] for
4144
** translating filenames between the main database file, the journal file,
4145
** and the WAL file.
4146
**
4147
** If F is the name of an sqlite database file, journal file, or WAL file
4148
** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
4149
** returns the name of the corresponding database file.
4150
**
4151
** If F is the name of an sqlite database file, journal file, or WAL file
4152
** passed by the SQLite core into the VFS, or if F is a database filename
4153
** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
4154
** returns the name of the corresponding rollback journal file.
4155
**
4156
** If F is the name of an sqlite database file, journal file, or WAL file
4157
** that was passed by the SQLite core into the VFS, or if F is a database
4158
** filename obtained from [sqlite3_db_filename()], then
4159
** sqlite3_filename_wal(F) returns the name of the corresponding
4160
** WAL file.
4161
**
4162
** In all of the above, if F is not the name of a database, journal or WAL
4163
** filename passed into the VFS from the SQLite core and F is not the
4164
** return value from [sqlite3_db_filename()], then the result is
4165
** undefined and is likely a memory access violation.
4166
*/
4167
SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
4168
SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
4169
SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
4170
4171
/*
4172
** CAPI3REF:  Database File Corresponding To A Journal
4173
**
4174
** ^If X is the name of a rollback or WAL-mode journal file that is
4175
** passed into the xOpen method of [sqlite3_vfs], then
4176
** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
4177
** object that represents the main database file.
4178
**
4179
** This routine is intended for use in custom [VFS] implementations
4180
** only.  It is not a general-purpose interface.
4181
** The argument sqlite3_file_object(X) must be a filename pointer that
4182
** has been passed into [sqlite3_vfs].xOpen method where the
4183
** flags parameter to xOpen contains one of the bits
4184
** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL].  Any other use
4185
** of this routine results in undefined and probably undesirable
4186
** behavior.
4187
*/
4188
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4189
4190
/*
4191
** CAPI3REF: Create and Destroy VFS Filenames
4192
**
4193
** These interfaces are provided for use by [VFS shim] implementations and
4194
** are not useful outside of that context.
4195
**
4196
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4197
** database filename D with corresponding journal file J and WAL file W and
4198
** with N URI parameters key/values pairs in the array P.  The result from
4199
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4200
** is safe to pass to routines like:
4201
** <ul>
4202
** <li> [sqlite3_uri_parameter()],
4203
** <li> [sqlite3_uri_boolean()],
4204
** <li> [sqlite3_uri_int64()],
4205
** <li> [sqlite3_uri_key()],
4206
** <li> [sqlite3_filename_database()],
4207
** <li> [sqlite3_filename_journal()], or
4208
** <li> [sqlite3_filename_wal()].
4209
** </ul>
4210
** If a memory allocation error occurs, sqlite3_create_filename() might
4211
** return a NULL pointer.  The memory obtained from sqlite3_create_filename(X)
4212
** must be released by a corresponding call to sqlite3_free_filename(Y).
4213
**
4214
** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
4215
** of 2*N pointers to strings.  Each pair of pointers in this array corresponds
4216
** to a key and value for a query parameter.  The P parameter may be a NULL
4217
** pointer if N is zero.  None of the 2*N pointers in the P array may be
4218
** NULL pointers and key pointers should not be empty strings.
4219
** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
4220
** be NULL pointers, though they can be empty strings.
4221
**
4222
** The sqlite3_free_filename(Y) routine releases a memory allocation
4223
** previously obtained from sqlite3_create_filename().  Invoking
4224
** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
4225
**
4226
** If the Y parameter to sqlite3_free_filename(Y) is anything other
4227
** than a NULL pointer or a pointer previously acquired from
4228
** sqlite3_create_filename(), then bad things such as heap
4229
** corruption or segfaults may occur. The value Y should not be
4230
** used again after sqlite3_free_filename(Y) has been called.  This means
4231
** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
4232
** then the corresponding [sqlite3_module.xClose() method should also be
4233
** invoked prior to calling sqlite3_free_filename(Y).
4234
*/
4235
SQLITE_API sqlite3_filename sqlite3_create_filename(
4236
  const char *zDatabase,
4237
  const char *zJournal,
4238
  const char *zWal,
4239
  int nParam,
4240
  const char **azParam
4241
);
4242
SQLITE_API void sqlite3_free_filename(sqlite3_filename);
4243
4244
/*
4245
** CAPI3REF: Error Codes And Messages
4246
** METHOD: sqlite3
4247
**
4248
** ^If the most recent sqlite3_* API call associated with
4249
** [database connection] D failed, then the sqlite3_errcode(D) interface
4250
** returns the numeric [result code] or [extended result code] for that
4251
** API call.
4252
** ^The sqlite3_extended_errcode()
4253
** interface is the same except that it always returns the
4254
** [extended result code] even when extended result codes are
4255
** disabled.
4256
**
4257
** The values returned by sqlite3_errcode() and/or
4258
** sqlite3_extended_errcode() might change with each API call.
4259
** Except, there are some interfaces that are guaranteed to never
4260
** change the value of the error code.  The error-code preserving
4261
** interfaces include the following:
4262
**
4263
** <ul>
4264
** <li> sqlite3_errcode()
4265
** <li> sqlite3_extended_errcode()
4266
** <li> sqlite3_errmsg()
4267
** <li> sqlite3_errmsg16()
4268
** <li> sqlite3_error_offset()
4269
** </ul>
4270
**
4271
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4272
** text that describes the error, as either UTF-8 or UTF-16 respectively,
4273
** or NULL if no error message is available.
4274
** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
4275
** ^(Memory to hold the error message string is managed internally.
4276
** The application does not need to worry about freeing the result.
4277
** However, the error string might be overwritten or deallocated by
4278
** subsequent calls to other SQLite interface functions.)^
4279
**
4280
** ^The sqlite3_errstr(E) interface returns the English-language text
4281
** that describes the [result code] E, as UTF-8, or NULL if E is not an
4282
** result code for which a text error message is available.
4283
** ^(Memory to hold the error message string is managed internally
4284
** and must not be freed by the application)^.
4285
**
4286
** ^If the most recent error references a specific token in the input
4287
** SQL, the sqlite3_error_offset() interface returns the byte offset
4288
** of the start of that token.  ^The byte offset returned by
4289
** sqlite3_error_offset() assumes that the input SQL is UTF8.
4290
** ^If the most recent error does not reference a specific token in the input
4291
** SQL, then the sqlite3_error_offset() function returns -1.
4292
**
4293
** When the serialized [threading mode] is in use, it might be the
4294
** case that a second error occurs on a separate thread in between
4295
** the time of the first error and the call to these interfaces.
4296
** When that happens, the second error will be reported since these
4297
** interfaces always report the most recent result.  To avoid
4298
** this, each thread can obtain exclusive use of the [database connection] D
4299
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
4300
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
4301
** all calls to the interfaces listed here are completed.
4302
**
4303
** If an interface fails with SQLITE_MISUSE, that means the interface
4304
** was invoked incorrectly by the application.  In that case, the
4305
** error code and message may or may not be set.
4306
*/
4307
SQLITE_API int sqlite3_errcode(sqlite3 *db);
4308
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
4309
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4310
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4311
SQLITE_API const char *sqlite3_errstr(int);
4312
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4313
4314
/*
4315
** CAPI3REF: Prepared Statement Object
4316
** KEYWORDS: {prepared statement} {prepared statements}
4317
**
4318
** An instance of this object represents a single SQL statement that
4319
** has been compiled into binary form and is ready to be evaluated.
4320
**
4321
** Think of each SQL statement as a separate computer program.  The
4322
** original SQL text is source code.  A prepared statement object
4323
** is the compiled object code.  All SQL must be converted into a
4324
** prepared statement before it can be run.
4325
**
4326
** The life-cycle of a prepared statement object usually goes like this:
4327
**
4328
** <ol>
4329
** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
4330
** <li> Bind values to [parameters] using the sqlite3_bind_*()
4331
**      interfaces.
4332
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
4333
** <li> Reset the prepared statement using [sqlite3_reset()] then go back
4334
**      to step 2.  Do this zero or more times.
4335
** <li> Destroy the object using [sqlite3_finalize()].
4336
** </ol>
4337
*/
4338
typedef struct sqlite3_stmt sqlite3_stmt;
4339
4340
/*
4341
** CAPI3REF: Run-time Limits
4342
** METHOD: sqlite3
4343
**
4344
** ^(This interface allows the size of various constructs to be limited
4345
** on a connection by connection basis.  The first parameter is the
4346
** [database connection] whose limit is to be set or queried.  The
4347
** second parameter is one of the [limit categories] that define a
4348
** class of constructs to be size limited.  The third parameter is the
4349
** new limit for that construct.)^
4350
**
4351
** ^If the new limit is a negative number, the limit is unchanged.
4352
** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
4353
** [limits | hard upper bound]
4354
** set at compile-time by a C preprocessor macro called
4355
** [limits | SQLITE_MAX_<i>NAME</i>].
4356
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
4357
** ^Attempts to increase a limit above its hard upper bound are
4358
** silently truncated to the hard upper bound.
4359
**
4360
** ^Regardless of whether or not the limit was changed, the
4361
** [sqlite3_limit()] interface returns the prior value of the limit.
4362
** ^Hence, to find the current value of a limit without changing it,
4363
** simply invoke this interface with the third parameter set to -1.
4364
**
4365
** Run-time limits are intended for use in applications that manage
4366
** both their own internal database and also databases that are controlled
4367
** by untrusted external sources.  An example application might be a
4368
** web browser that has its own databases for storing history and
4369
** separate databases controlled by JavaScript applications downloaded
4370
** off the Internet.  The internal databases can be given the
4371
** large, default limits.  Databases managed by external sources can
4372
** be given much smaller limits designed to prevent a denial of service
4373
** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
4374
** interface to further control untrusted SQL.  The size of the database
4375
** created by an untrusted script can be contained using the
4376
** [max_page_count] [PRAGMA].
4377
**
4378
** New run-time limit categories may be added in future releases.
4379
*/
4380
SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4381
4382
/*
4383
** CAPI3REF: Run-Time Limit Categories
4384
** KEYWORDS: {limit category} {*limit categories}
4385
**
4386
** These constants define various performance limits
4387
** that can be lowered at run-time using [sqlite3_limit()].
4388
** The synopsis of the meanings of the various limits is shown below.
4389
** Additional information is available at [limits | Limits in SQLite].
4390
**
4391
** <dl>
4392
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4393
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4394
**
4395
** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
4396
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
4397
**
4398
** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
4399
** <dd>The maximum number of columns in a table definition or in the
4400
** result set of a [SELECT] or the maximum number of columns in an index
4401
** or in an ORDER BY or GROUP BY clause.</dd>)^
4402
**
4403
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4404
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
4405
**
4406
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
4407
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
4408
**
4409
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
4410
** <dd>The maximum number of instructions in a virtual machine program
4411
** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
4412
** the equivalent tries to allocate space for more than this many opcodes
4413
** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
4414
**
4415
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
4416
** <dd>The maximum number of arguments on a function.</dd>)^
4417
**
4418
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
4419
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
4420
**
4421
** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
4422
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
4423
** <dd>The maximum length of the pattern argument to the [LIKE] or
4424
** [GLOB] operators.</dd>)^
4425
**
4426
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4427
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4428
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4429
**
4430
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4431
** <dd>The maximum depth of recursion for triggers.</dd>)^
4432
**
4433
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4434
** <dd>The maximum number of auxiliary worker threads that a single
4435
** [prepared statement] may start.</dd>)^
4436
** </dl>
4437
*/
4438
31.6M
#define SQLITE_LIMIT_LENGTH                    0
4439
628k
#define SQLITE_LIMIT_SQL_LENGTH                1
4440
1.02M
#define SQLITE_LIMIT_COLUMN                    2
4441
3.38M
#define SQLITE_LIMIT_EXPR_DEPTH                3
4442
678
#define SQLITE_LIMIT_COMPOUND_SELECT           4
4443
599k
#define SQLITE_LIMIT_VDBE_OP                   5
4444
107k
#define SQLITE_LIMIT_FUNCTION_ARG              6
4445
14.5k
#define SQLITE_LIMIT_ATTACHED                  7
4446
1.14M
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
4447
11.1k
#define SQLITE_LIMIT_VARIABLE_NUMBER           9
4448
7.92k
#define SQLITE_LIMIT_TRIGGER_DEPTH            10
4449
44.3k
#define SQLITE_LIMIT_WORKER_THREADS           11
4450
4451
/*
4452
** CAPI3REF: Prepare Flags
4453
**
4454
** These constants define various flags that can be passed into
4455
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4456
** [sqlite3_prepare16_v3()] interfaces.
4457
**
4458
** New flags may be added in future releases of SQLite.
4459
**
4460
** <dl>
4461
** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
4462
** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
4463
** that the prepared statement will be retained for a long time and
4464
** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
4465
** and [sqlite3_prepare16_v3()] assume that the prepared statement will
4466
** be used just once or at most a few times and then destroyed using
4467
** [sqlite3_finalize()] relatively soon. The current implementation acts
4468
** on this hint by avoiding the use of [lookaside memory] so as not to
4469
** deplete the limited store of lookaside memory. Future versions of
4470
** SQLite may act on this hint differently.
4471
**
4472
** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
4473
** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
4474
** to be required for any prepared statement that wanted to use the
4475
** [sqlite3_normalized_sql()] interface.  However, the
4476
** [sqlite3_normalized_sql()] interface is now available to all
4477
** prepared statements, regardless of whether or not they use this
4478
** flag.
4479
**
4480
** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
4481
** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4482
** to return an error (error code SQLITE_ERROR) if the statement uses
4483
** any virtual tables.
4484
** </dl>
4485
*/
4486
537k
#define SQLITE_PREPARE_PERSISTENT              0x01
4487
#define SQLITE_PREPARE_NORMALIZE               0x02
4488
2.85k
#define SQLITE_PREPARE_NO_VTAB                 0x04
4489
4490
/*
4491
** CAPI3REF: Compiling An SQL Statement
4492
** KEYWORDS: {SQL statement compiler}
4493
** METHOD: sqlite3
4494
** CONSTRUCTOR: sqlite3_stmt
4495
**
4496
** To execute an SQL statement, it must first be compiled into a byte-code
4497
** program using one of these routines.  Or, in other words, these routines
4498
** are constructors for the [prepared statement] object.
4499
**
4500
** The preferred routine to use is [sqlite3_prepare_v2()].  The
4501
** [sqlite3_prepare()] interface is legacy and should be avoided.
4502
** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4503
** for special purposes.
4504
**
4505
** The use of the UTF-8 interfaces is preferred, as SQLite currently
4506
** does all parsing using UTF-8.  The UTF-16 interfaces are provided
4507
** as a convenience.  The UTF-16 interfaces work by converting the
4508
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4509
**
4510
** The first argument, "db", is a [database connection] obtained from a
4511
** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
4512
** [sqlite3_open16()].  The database connection must not have been closed.
4513
**
4514
** The second argument, "zSql", is the statement to be compiled, encoded
4515
** as either UTF-8 or UTF-16.  The sqlite3_prepare(), sqlite3_prepare_v2(),
4516
** and sqlite3_prepare_v3()
4517
** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
4518
** and sqlite3_prepare16_v3() use UTF-16.
4519
**
4520
** ^If the nByte argument is negative, then zSql is read up to the
4521
** first zero terminator. ^If nByte is positive, then it is the
4522
** number of bytes read from zSql.  ^If nByte is zero, then no prepared
4523
** statement is generated.
4524
** If the caller knows that the supplied string is nul-terminated, then
4525
** there is a small performance advantage to passing an nByte parameter that
4526
** is the number of bytes in the input string <i>including</i>
4527
** the nul-terminator.
4528
**
4529
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4530
** past the end of the first SQL statement in zSql.  These routines only
4531
** compile the first statement in zSql, so *pzTail is left pointing to
4532
** what remains uncompiled.
4533
**
4534
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
4535
** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
4536
** to NULL.  ^If the input text contains no SQL (if the input is an empty
4537
** string or a comment) then *ppStmt is set to NULL.
4538
** The calling procedure is responsible for deleting the compiled
4539
** SQL statement using [sqlite3_finalize()] after it has finished with it.
4540
** ppStmt may not be NULL.
4541
**
4542
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
4543
** otherwise an [error code] is returned.
4544
**
4545
** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
4546
** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
4547
** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
4548
** are retained for backwards compatibility, but their use is discouraged.
4549
** ^In the "vX" interfaces, the prepared statement
4550
** that is returned (the [sqlite3_stmt] object) contains a copy of the
4551
** original SQL text. This causes the [sqlite3_step()] interface to
4552
** behave differently in three ways:
4553
**
4554
** <ol>
4555
** <li>
4556
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
4557
** always used to do, [sqlite3_step()] will automatically recompile the SQL
4558
** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
4559
** retries will occur before sqlite3_step() gives up and returns an error.
4560
** </li>
4561
**
4562
** <li>
4563
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
4564
** [error codes] or [extended error codes].  ^The legacy behavior was that
4565
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
4566
** and the application would have to make a second call to [sqlite3_reset()]
4567
** in order to find the underlying cause of the problem. With the "v2" prepare
4568
** interfaces, the underlying reason for the error is returned immediately.
4569
** </li>
4570
**
4571
** <li>
4572
** ^If the specific value bound to a [parameter | host parameter] in the
4573
** WHERE clause might influence the choice of query plan for a statement,
4574
** then the statement will be automatically recompiled, as if there had been
4575
** a schema change, on the first [sqlite3_step()] call following any change
4576
** to the [sqlite3_bind_text | bindings] of that [parameter].
4577
** ^The specific value of a WHERE-clause [parameter] might influence the
4578
** choice of query plan if the parameter is the left-hand side of a [LIKE]
4579
** or [GLOB] operator or if the parameter is compared to an indexed column
4580
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4581
** </li>
4582
** </ol>
4583
**
4584
** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
4585
** the extra prepFlags parameter, which is a bit array consisting of zero or
4586
** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags.  ^The
4587
** sqlite3_prepare_v2() interface works exactly the same as
4588
** sqlite3_prepare_v3() with a zero prepFlags parameter.
4589
*/
4590
SQLITE_API int sqlite3_prepare(
4591
  sqlite3 *db,            /* Database handle */
4592
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4593
  int nByte,              /* Maximum length of zSql in bytes. */
4594
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4595
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4596
);
4597
SQLITE_API int sqlite3_prepare_v2(
4598
  sqlite3 *db,            /* Database handle */
4599
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4600
  int nByte,              /* Maximum length of zSql in bytes. */
4601
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4602
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4603
);
4604
SQLITE_API int sqlite3_prepare_v3(
4605
  sqlite3 *db,            /* Database handle */
4606
  const char *zSql,       /* SQL statement, UTF-8 encoded */
4607
  int nByte,              /* Maximum length of zSql in bytes. */
4608
  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4609
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4610
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4611
);
4612
SQLITE_API int sqlite3_prepare16(
4613
  sqlite3 *db,            /* Database handle */
4614
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4615
  int nByte,              /* Maximum length of zSql in bytes. */
4616
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4617
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4618
);
4619
SQLITE_API int sqlite3_prepare16_v2(
4620
  sqlite3 *db,            /* Database handle */
4621
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4622
  int nByte,              /* Maximum length of zSql in bytes. */
4623
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4624
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4625
);
4626
SQLITE_API int sqlite3_prepare16_v3(
4627
  sqlite3 *db,            /* Database handle */
4628
  const void *zSql,       /* SQL statement, UTF-16 encoded */
4629
  int nByte,              /* Maximum length of zSql in bytes. */
4630
  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4631
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4632
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4633
);
4634
4635
/*
4636
** CAPI3REF: Retrieving Statement SQL
4637
** METHOD: sqlite3_stmt
4638
**
4639
** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
4640
** SQL text used to create [prepared statement] P if P was
4641
** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
4642
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4643
** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
4644
** string containing the SQL text of prepared statement P with
4645
** [bound parameters] expanded.
4646
** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
4647
** string containing the normalized SQL text of prepared statement P.  The
4648
** semantics used to normalize a SQL statement are unspecified and subject
4649
** to change.  At a minimum, literal values will be replaced with suitable
4650
** placeholders.
4651
**
4652
** ^(For example, if a prepared statement is created using the SQL
4653
** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
4654
** and parameter :xyz is unbound, then sqlite3_sql() will return
4655
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4656
** will return "SELECT 2345,NULL".)^
4657
**
4658
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4659
** is available to hold the result, or if the result would exceed the
4660
** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4661
**
4662
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4663
** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
4664
** option causes sqlite3_expanded_sql() to always return NULL.
4665
**
4666
** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
4667
** are managed by SQLite and are automatically freed when the prepared
4668
** statement is finalized.
4669
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
4670
** is obtained from [sqlite3_malloc()] and must be freed by the application
4671
** by passing it to [sqlite3_free()].
4672
**
4673
** ^The sqlite3_normalized_sql() interface is only available if
4674
** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
4675
*/
4676
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
4677
SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
4678
#ifdef SQLITE_ENABLE_NORMALIZE
4679
SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
4680
#endif
4681
4682
/*
4683
** CAPI3REF: Determine If An SQL Statement Writes The Database
4684
** METHOD: sqlite3_stmt
4685
**
4686
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
4687
** and only if the [prepared statement] X makes no direct changes to
4688
** the content of the database file.
4689
**
4690
** Note that [application-defined SQL functions] or
4691
** [virtual tables] might change the database indirectly as a side effect.
4692
** ^(For example, if an application defines a function "eval()" that
4693
** calls [sqlite3_exec()], then the following SQL statement would
4694
** change the database file through side-effects:
4695
**
4696
** <blockquote><pre>
4697
**    SELECT eval('DELETE FROM t1') FROM t2;
4698
** </pre></blockquote>
4699
**
4700
** But because the [SELECT] statement does not change the database file
4701
** directly, sqlite3_stmt_readonly() would still return true.)^
4702
**
4703
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
4704
** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
4705
** since the statements themselves do not actually modify the database but
4706
** rather they control the timing of when other statements modify the
4707
** database.  ^The [ATTACH] and [DETACH] statements also cause
4708
** sqlite3_stmt_readonly() to return true since, while those statements
4709
** change the configuration of a database connection, they do not make
4710
** changes to the content of the database files on disk.
4711
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4712
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4713
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4714
** sqlite3_stmt_readonly() returns false for those commands.
4715
**
4716
** ^This routine returns false if there is any possibility that the
4717
** statement might change the database file.  ^A false return does
4718
** not guarantee that the statement will change the database file.
4719
** ^For example, an UPDATE statement might have a WHERE clause that
4720
** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4721
** be false.  ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4722
** read-only no-op if the table already exists, but
4723
** sqlite3_stmt_readonly() still returns false for such a statement.
4724
**
4725
** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
4726
** statement, then sqlite3_stmt_readonly(X) returns the same value as
4727
** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
4728
*/
4729
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4730
4731
/*
4732
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4733
** METHOD: sqlite3_stmt
4734
**
4735
** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4736
** prepared statement S is an EXPLAIN statement, or 2 if the
4737
** statement S is an EXPLAIN QUERY PLAN.
4738
** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4739
** an ordinary statement or a NULL pointer.
4740
*/
4741
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4742
4743
/*
4744
** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement
4745
** METHOD: sqlite3_stmt
4746
**
4747
** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN
4748
** setting for [prepared statement] S.  If E is zero, then S becomes
4749
** a normal prepared statement.  If E is 1, then S behaves as if
4750
** its SQL text began with "[EXPLAIN]".  If E is 2, then S behaves as if
4751
** its SQL text began with "[EXPLAIN QUERY PLAN]".
4752
**
4753
** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.
4754
** SQLite tries to avoid a reprepare, but a reprepare might be necessary
4755
** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.
4756
**
4757
** Because of the potential need to reprepare, a call to
4758
** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be
4759
** reprepared because it was created using [sqlite3_prepare()] instead of
4760
** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and
4761
** hence has no saved SQL text with which to reprepare.
4762
**
4763
** Changing the explain setting for a prepared statement does not change
4764
** the original SQL text for the statement.  Hence, if the SQL text originally
4765
** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
4766
** is called to convert the statement into an ordinary statement, the EXPLAIN
4767
** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)
4768
** output, even though the statement now acts like a normal SQL statement.
4769
**
4770
** This routine returns SQLITE_OK if the explain mode is successfully
4771
** changed, or an error code if the explain mode could not be changed.
4772
** The explain mode cannot be changed while a statement is active.
4773
** Hence, it is good practice to call [sqlite3_reset(S)]
4774
** immediately prior to calling sqlite3_stmt_explain(S,E).
4775
*/
4776
SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);
4777
4778
/*
4779
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4780
** METHOD: sqlite3_stmt
4781
**
4782
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
4783
** [prepared statement] S has been stepped at least once using
4784
** [sqlite3_step(S)] but has neither run to completion (returned
4785
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
4786
** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
4787
** interface returns false if S is a NULL pointer.  If S is not a
4788
** NULL pointer and is not a pointer to a valid [prepared statement]
4789
** object, then the behavior is undefined and probably undesirable.
4790
**
4791
** This interface can be used in combination [sqlite3_next_stmt()]
4792
** to locate all prepared statements associated with a database
4793
** connection that are in need of being reset.  This can be used,
4794
** for example, in diagnostic routines to search for prepared
4795
** statements that are holding a transaction open.
4796
*/
4797
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
4798
4799
/*
4800
** CAPI3REF: Dynamically Typed Value Object
4801
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
4802
**
4803
** SQLite uses the sqlite3_value object to represent all values
4804
** that can be stored in a database table. SQLite uses dynamic typing
4805
** for the values it stores.  ^Values stored in sqlite3_value objects
4806
** can be integers, floating point values, strings, BLOBs, or NULL.
4807
**
4808
** An sqlite3_value object may be either "protected" or "unprotected".
4809
** Some interfaces require a protected sqlite3_value.  Other interfaces
4810
** will accept either a protected or an unprotected sqlite3_value.
4811
** Every interface that accepts sqlite3_value arguments specifies
4812
** whether or not it requires a protected sqlite3_value.  The
4813
** [sqlite3_value_dup()] interface can be used to construct a new
4814
** protected sqlite3_value from an unprotected sqlite3_value.
4815
**
4816
** The terms "protected" and "unprotected" refer to whether or not
4817
** a mutex is held.  An internal mutex is held for a protected
4818
** sqlite3_value object but no mutex is held for an unprotected
4819
** sqlite3_value object.  If SQLite is compiled to be single-threaded
4820
** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
4821
** or if SQLite is run in one of reduced mutex modes
4822
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
4823
** then there is no distinction between protected and unprotected
4824
** sqlite3_value objects and they can be used interchangeably.  However,
4825
** for maximum code portability it is recommended that applications
4826
** still make the distinction between protected and unprotected
4827
** sqlite3_value objects even when not strictly required.
4828
**
4829
** ^The sqlite3_value objects that are passed as parameters into the
4830
** implementation of [application-defined SQL functions] are protected.
4831
** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4832
** are protected.
4833
** ^The sqlite3_value object returned by
4834
** [sqlite3_column_value()] is unprotected.
4835
** Unprotected sqlite3_value objects may only be used as arguments
4836
** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4837
** [sqlite3_value_dup()].
4838
** The [sqlite3_value_blob | sqlite3_value_type()] family of
4839
** interfaces require protected sqlite3_value objects.
4840
*/
4841
typedef struct sqlite3_value sqlite3_value;
4842
4843
/*
4844
** CAPI3REF: SQL Function Context Object
4845
**
4846
** The context in which an SQL function executes is stored in an
4847
** sqlite3_context object.  ^A pointer to an sqlite3_context object
4848
** is always first parameter to [application-defined SQL functions].
4849
** The application-defined SQL function implementation will pass this
4850
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4851
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4852
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4853
** and/or [sqlite3_set_auxdata()].
4854
*/
4855
typedef struct sqlite3_context sqlite3_context;
4856
4857
/*
4858
** CAPI3REF: Binding Values To Prepared Statements
4859
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4860
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4861
** METHOD: sqlite3_stmt
4862
**
4863
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4864
** literals may be replaced by a [parameter] that matches one of following
4865
** templates:
4866
**
4867
** <ul>
4868
** <li>  ?
4869
** <li>  ?NNN
4870
** <li>  :VVV
4871
** <li>  @VVV
4872
** <li>  $VVV
4873
** </ul>
4874
**
4875
** In the templates above, NNN represents an integer literal,
4876
** and VVV represents an alphanumeric identifier.)^  ^The values of these
4877
** parameters (also called "host parameter names" or "SQL parameters")
4878
** can be set using the sqlite3_bind_*() routines defined here.
4879
**
4880
** ^The first argument to the sqlite3_bind_*() routines is always
4881
** a pointer to the [sqlite3_stmt] object returned from
4882
** [sqlite3_prepare_v2()] or its variants.
4883
**
4884
** ^The second argument is the index of the SQL parameter to be set.
4885
** ^The leftmost SQL parameter has an index of 1.  ^When the same named
4886
** SQL parameter is used more than once, second and subsequent
4887
** occurrences have the same index as the first occurrence.
4888
** ^The index for named parameters can be looked up using the
4889
** [sqlite3_bind_parameter_index()] API if desired.  ^The index
4890
** for "?NNN" parameters is the value of NNN.
4891
** ^The NNN value must be between 1 and the [sqlite3_limit()]
4892
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
4893
**
4894
** ^The third argument is the value to bind to the parameter.
4895
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4896
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4897
** is ignored and the end result is the same as sqlite3_bind_null().
4898
** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4899
** it should be a pointer to well-formed UTF8 text.
4900
** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4901
** it should be a pointer to well-formed UTF16 text.
4902
** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4903
** it should be a pointer to a well-formed unicode string that is
4904
** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4905
** otherwise.
4906
**
4907
** [[byte-order determination rules]] ^The byte-order of
4908
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4909
** found in first character, which is removed, or in the absence of a BOM
4910
** the byte order is the native byte order of the host
4911
** machine for sqlite3_bind_text16() or the byte order specified in
4912
** the 6th parameter for sqlite3_bind_text64().)^
4913
** ^If UTF16 input text contains invalid unicode
4914
** characters, then SQLite might change those invalid characters
4915
** into the unicode replacement character: U+FFFD.
4916
**
4917
** ^(In those routines that have a fourth argument, its value is the
4918
** number of bytes in the parameter.  To be clear: the value is the
4919
** number of <u>bytes</u> in the value, not the number of characters.)^
4920
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4921
** is negative, then the length of the string is
4922
** the number of bytes up to the first zero terminator.
4923
** If the fourth parameter to sqlite3_bind_blob() is negative, then
4924
** the behavior is undefined.
4925
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4926
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4927
** that parameter must be the byte offset
4928
** where the NUL terminator would occur assuming the string were NUL
4929
** terminated.  If any NUL characters occurs at byte offsets less than
4930
** the value of the fourth parameter then the resulting string value will
4931
** contain embedded NULs.  The result of expressions involving strings
4932
** with embedded NULs is undefined.
4933
**
4934
** ^The fifth argument to the BLOB and string binding interfaces controls
4935
** or indicates the lifetime of the object referenced by the third parameter.
4936
** These three options exist:
4937
** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4938
** with it may be passed. ^It is called to dispose of the BLOB or string even
4939
** if the call to the bind API fails, except the destructor is not called if
4940
** the third parameter is a NULL pointer or the fourth parameter is negative.
4941
** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4942
** the application remains responsible for disposing of the object. ^In this
4943
** case, the object and the provided pointer to it must remain valid until
4944
** either the prepared statement is finalized or the same SQL parameter is
4945
** bound to something else, whichever occurs sooner.
4946
** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4947
** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4948
** object and pointer to it must remain valid until then. ^SQLite will then
4949
** manage the lifetime of its private copy.
4950
**
4951
** ^The sixth argument to sqlite3_bind_text64() must be one of
4952
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4953
** to specify the encoding of the text in the third parameter.  If
4954
** the sixth argument to sqlite3_bind_text64() is not one of the
4955
** allowed values shown above, or if the text encoding is different
4956
** from the encoding specified by the sixth parameter, then the behavior
4957
** is undefined.
4958
**
4959
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
4960
** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
4961
** (just an integer to hold its size) while it is being processed.
4962
** Zeroblobs are intended to serve as placeholders for BLOBs whose
4963
** content is later written using
4964
** [sqlite3_blob_open | incremental BLOB I/O] routines.
4965
** ^A negative value for the zeroblob results in a zero-length BLOB.
4966
**
4967
** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
4968
** [prepared statement] S to have an SQL value of NULL, but to also be
4969
** associated with the pointer P of type T.  ^D is either a NULL pointer or
4970
** a pointer to a destructor function for P. ^SQLite will invoke the
4971
** destructor D with a single argument of P when it is finished using
4972
** P.  The T parameter should be a static string, preferably a string
4973
** literal. The sqlite3_bind_pointer() routine is part of the
4974
** [pointer passing interface] added for SQLite 3.20.0.
4975
**
4976
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4977
** for the [prepared statement] or with a prepared statement for which
4978
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4979
** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
4980
** routine is passed a [prepared statement] that has been finalized, the
4981
** result is undefined and probably harmful.
4982
**
4983
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
4984
** ^Unbound parameters are interpreted as NULL.
4985
**
4986
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
4987
** [error code] if anything goes wrong.
4988
** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
4989
** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
4990
** [SQLITE_MAX_LENGTH].
4991
** ^[SQLITE_RANGE] is returned if the parameter
4992
** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
4993
**
4994
** See also: [sqlite3_bind_parameter_count()],
4995
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
4996
*/
4997
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
4998
SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
4999
                        void(*)(void*));
5000
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
5001
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
5002
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
5003
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
5004
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
5005
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
5006
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
5007
                         void(*)(void*), unsigned char encoding);
5008
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
5009
SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
5010
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
5011
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
5012
5013
/*
5014
** CAPI3REF: Number Of SQL Parameters
5015
** METHOD: sqlite3_stmt
5016
**
5017
** ^This routine can be used to find the number of [SQL parameters]
5018
** in a [prepared statement].  SQL parameters are tokens of the
5019
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
5020
** placeholders for values that are [sqlite3_bind_blob | bound]
5021
** to the parameters at a later time.
5022
**
5023
** ^(This routine actually returns the index of the largest (rightmost)
5024
** parameter. For all forms except ?NNN, this will correspond to the
5025
** number of unique parameters.  If parameters of the ?NNN form are used,
5026
** there may be gaps in the list.)^
5027
**
5028
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5029
** [sqlite3_bind_parameter_name()], and
5030
** [sqlite3_bind_parameter_index()].
5031
*/
5032
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
5033
5034
/*
5035
** CAPI3REF: Name Of A Host Parameter
5036
** METHOD: sqlite3_stmt
5037
**
5038
** ^The sqlite3_bind_parameter_name(P,N) interface returns
5039
** the name of the N-th [SQL parameter] in the [prepared statement] P.
5040
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
5041
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
5042
** respectively.
5043
** In other words, the initial ":" or "$" or "@" or "?"
5044
** is included as part of the name.)^
5045
** ^Parameters of the form "?" without a following integer have no name
5046
** and are referred to as "nameless" or "anonymous parameters".
5047
**
5048
** ^The first host parameter has an index of 1, not 0.
5049
**
5050
** ^If the value N is out of range or if the N-th parameter is
5051
** nameless, then NULL is returned.  ^The returned string is
5052
** always in UTF-8 encoding even if the named parameter was
5053
** originally specified as UTF-16 in [sqlite3_prepare16()],
5054
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
5055
**
5056
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5057
** [sqlite3_bind_parameter_count()], and
5058
** [sqlite3_bind_parameter_index()].
5059
*/
5060
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
5061
5062
/*
5063
** CAPI3REF: Index Of A Parameter With A Given Name
5064
** METHOD: sqlite3_stmt
5065
**
5066
** ^Return the index of an SQL parameter given its name.  ^The
5067
** index value returned is suitable for use as the second
5068
** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
5069
** is returned if no matching parameter is found.  ^The parameter
5070
** name must be given in UTF-8 even if the original statement
5071
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
5072
** [sqlite3_prepare16_v3()].
5073
**
5074
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5075
** [sqlite3_bind_parameter_count()], and
5076
** [sqlite3_bind_parameter_name()].
5077
*/
5078
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
5079
5080
/*
5081
** CAPI3REF: Reset All Bindings On A Prepared Statement
5082
** METHOD: sqlite3_stmt
5083
**
5084
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
5085
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
5086
** ^Use this routine to reset all host parameters to NULL.
5087
*/
5088
SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
5089
5090
/*
5091
** CAPI3REF: Number Of Columns In A Result Set
5092
** METHOD: sqlite3_stmt
5093
**
5094
** ^Return the number of columns in the result set returned by the
5095
** [prepared statement]. ^If this routine returns 0, that means the
5096
** [prepared statement] returns no data (for example an [UPDATE]).
5097
** ^However, just because this routine returns a positive number does not
5098
** mean that one or more rows of data will be returned.  ^A SELECT statement
5099
** will always have a positive sqlite3_column_count() but depending on the
5100
** WHERE clause constraints and the table content, it might return no rows.
5101
**
5102
** See also: [sqlite3_data_count()]
5103
*/
5104
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
5105
5106
/*
5107
** CAPI3REF: Column Names In A Result Set
5108
** METHOD: sqlite3_stmt
5109
**
5110
** ^These routines return the name assigned to a particular column
5111
** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
5112
** interface returns a pointer to a zero-terminated UTF-8 string
5113
** and sqlite3_column_name16() returns a pointer to a zero-terminated
5114
** UTF-16 string.  ^The first parameter is the [prepared statement]
5115
** that implements the [SELECT] statement. ^The second parameter is the
5116
** column number.  ^The leftmost column is number 0.
5117
**
5118
** ^The returned string pointer is valid until either the [prepared statement]
5119
** is destroyed by [sqlite3_finalize()] or until the statement is automatically
5120
** reprepared by the first call to [sqlite3_step()] for a particular run
5121
** or until the next call to
5122
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
5123
**
5124
** ^If sqlite3_malloc() fails during the processing of either routine
5125
** (for example during a conversion from UTF-8 to UTF-16) then a
5126
** NULL pointer is returned.
5127
**
5128
** ^The name of a result column is the value of the "AS" clause for
5129
** that column, if there is an AS clause.  If there is no AS clause
5130
** then the name of the column is unspecified and may change from
5131
** one release of SQLite to the next.
5132
*/
5133
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
5134
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
5135
5136
/*
5137
** CAPI3REF: Source Of Data In A Query Result
5138
** METHOD: sqlite3_stmt
5139
**
5140
** ^These routines provide a means to determine the database, table, and
5141
** table column that is the origin of a particular result column in
5142
** [SELECT] statement.
5143
** ^The name of the database or table or column can be returned as
5144
** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
5145
** the database name, the _table_ routines return the table name, and
5146
** the origin_ routines return the column name.
5147
** ^The returned string is valid until the [prepared statement] is destroyed
5148
** using [sqlite3_finalize()] or until the statement is automatically
5149
** reprepared by the first call to [sqlite3_step()] for a particular run
5150
** or until the same information is requested
5151
** again in a different encoding.
5152
**
5153
** ^The names returned are the original un-aliased names of the
5154
** database, table, and column.
5155
**
5156
** ^The first argument to these interfaces is a [prepared statement].
5157
** ^These functions return information about the Nth result column returned by
5158
** the statement, where N is the second function argument.
5159
** ^The left-most column is column 0 for these routines.
5160
**
5161
** ^If the Nth column returned by the statement is an expression or
5162
** subquery and is not a column value, then all of these functions return
5163
** NULL.  ^These routines might also return NULL if a memory allocation error
5164
** occurs.  ^Otherwise, they return the name of the attached database, table,
5165
** or column that query result column was extracted from.
5166
**
5167
** ^As with all other SQLite APIs, those whose names end with "16" return
5168
** UTF-16 encoded strings and the other functions return UTF-8.
5169
**
5170
** ^These APIs are only available if the library was compiled with the
5171
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
5172
**
5173
** If two or more threads call one or more
5174
** [sqlite3_column_database_name | column metadata interfaces]
5175
** for the same [prepared statement] and result column
5176
** at the same time then the results are undefined.
5177
*/
5178
SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
5179
SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
5180
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
5181
SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
5182
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
5183
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);