Coverage Report

Created: 2024-10-08 18:15

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