Fossil SCM

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