Fossil SCM

fossil-scm / src / sqlite4.h
Blame History Raw 4445 lines
1
/*
2
** 2001 September 15
3
**
4
** The author disclaims copyright to this source code. In place of
5
** a legal notice, here is a blessing:
6
**
7
** May you do good and not evil.
8
** May you find forgiveness for yourself and forgive others.
9
** May you share freely, never taking more than you give.
10
**
11
*************************************************************************
12
** This header file defines the interface that the SQLite library
13
** presents to client programs. If a C-function, structure, datatype,
14
** or constant definition does not appear in this file, then it is
15
** not a published API of SQLite, is subject to change without
16
** notice, and should not be referenced by programs that use SQLite.
17
**
18
** Some of the definitions that are in this file are marked as
19
** "experimental". Experimental interfaces are normally new
20
** features recently added to SQLite. We do not anticipate changes
21
** to experimental interfaces but reserve the right to make minor changes
22
** if experience from use "in the wild" suggest such changes are prudent.
23
**
24
** The official C-language API documentation for SQLite is derived
25
** from comments in this file. This file is the authoritative source
26
** on how SQLite interfaces are suppose to operate.
27
**
28
** The name of this file under configuration management is "sqlite.h.in".
29
** The makefile makes some minor changes to this file (such as inserting
30
** the version number) and changes its name to "sqlite4.h" as
31
** part of the build process.
32
*/
33
#ifndef _SQLITE4_H_
34
#define _SQLITE4_H_
35
#include <stdarg.h> /* Needed for the definition of va_list */
36
37
/*
38
** Make sure we can call this stuff from C++.
39
*/
40
#ifdef __cplusplus
41
extern "C" {
42
#endif
43
44
45
/*
46
** Add the ability to override 'extern'
47
*/
48
#ifndef SQLITE4_EXTERN
49
# define SQLITE4_EXTERN extern
50
#endif
51
52
#ifndef SQLITE4_API
53
# define SQLITE4_API
54
#endif
55
56
57
/*
58
** These no-op macros are used in front of interfaces to mark those
59
** interfaces as either deprecated or experimental. New applications
60
** should not use deprecated interfaces - they are support for backwards
61
** compatibility only. Application writers should be aware that
62
** experimental interfaces are subject to change in point releases.
63
**
64
** These macros used to resolve to various kinds of compiler magic that
65
** would generate warning messages when they were used. But that
66
** compiler magic ended up generating such a flurry of bug reports
67
** that we have taken it all out and gone back to using simple
68
** noop macros.
69
*/
70
#define SQLITE4_DEPRECATED
71
#define SQLITE4_EXPERIMENTAL
72
73
/*
74
** Ensure these symbols were not defined by some previous header file.
75
*/
76
#ifdef SQLITE4_VERSION
77
# undef SQLITE4_VERSION
78
#endif
79
#ifdef SQLITE4_VERSION_NUMBER
80
# undef SQLITE4_VERSION_NUMBER
81
#endif
82
83
/*
84
** CAPIREF: Run-time Environment Object
85
**
86
** An instance of the following object defines the run-time environment
87
** for an SQLite4 database connection. This object defines the interface
88
** to appropriate mutex routines, memory allocation routines, a
89
** pseudo-random number generator, real-time clock, and the key-value
90
** backend stores.
91
*/
92
typedef struct sqlite4_env sqlite4_env;
93
94
/*
95
** CAPIREF: Find the default run-time environment
96
**
97
** Return a pointer to the default run-time environment.
98
*/
99
SQLITE4_API sqlite4_env *sqlite4_env_default(void);
100
101
/*
102
** CAPIREF: Size of an sqlite4_env object
103
**
104
** Return the number of bytes of memory needed to hold an sqlite4_env
105
** object. This number varies from one machine to another, and from
106
** one release of SQLite to another.
107
*/
108
SQLITE4_API int sqlite4_env_size(void);
109
110
/*
111
** CAPIREF: Configure a run-time environment
112
*/
113
SQLITE4_API int sqlite4_env_config(sqlite4_env*, int op, ...);
114
115
/*
116
** CAPIREF: Configuration options for sqlite4_env_config().
117
*/
118
#define SQLITE4_ENVCONFIG_INIT 1 /* size, template */
119
#define SQLITE4_ENVCONFIG_SINGLETHREAD 2 /* */
120
#define SQLITE4_ENVCONFIG_MULTITHREAD 3 /* */
121
#define SQLITE4_ENVCONFIG_SERIALIZED 4 /* */
122
#define SQLITE4_ENVCONFIG_MUTEX 5 /* sqlite4_mutex_methods* */
123
#define SQLITE4_ENVCONFIG_GETMUTEX 6 /* sqlite4_mutex_methods* */
124
#define SQLITE4_ENVCONFIG_MALLOC 7 /* sqlite4_mem_methods* */
125
#define SQLITE4_ENVCONFIG_GETMALLOC 8 /* sqlite4_mem_methods* */
126
#define SQLITE4_ENVCONFIG_MEMSTATUS 9 /* boolean */
127
#define SQLITE4_ENVCONFIG_LOOKASIDE 10 /* size, count */
128
#define SQLITE4_ENVCONFIG_LOG 11 /* xLog, pArg */
129
#define SQLITE4_ENVCONFIG_KVSTORE_PUSH 12 /* name, factory */
130
#define SQLITE4_ENVCONFIG_KVSTORE_POP 13 /* name */
131
#define SQLITE4_ENVCONFIG_KVSTORE_GET 14 /* name, *factor */
132
133
134
/*
135
** CAPIREF: Compile-Time Library Version Numbers
136
**
137
** ^(The [SQLITE4_VERSION] C preprocessor macro in the sqlite4.h header
138
** evaluates to a string literal that is the SQLite version in the
139
** format "X.Y.Z" where X is the major version number (always 3 for
140
** SQLite3) and Y is the minor version number and Z is the release number.)^
141
** ^(The [SQLITE4_VERSION_NUMBER] C preprocessor macro resolves to an integer
142
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
143
** numbers used in [SQLITE4_VERSION].)^
144
** The SQLITE4_VERSION_NUMBER for any given release of SQLite will also
145
** be larger than the release from which it is derived. Either Y will
146
** be held constant and Z will be incremented or else Y will be incremented
147
** and Z will be reset to zero.
148
**
149
** Since version 3.6.18, SQLite source code has been stored in the
150
** <a href="http://www.fossil-scm.org/">Fossil configuration management
151
** system</a>. ^The SQLITE4_SOURCE_ID macro evaluates to
152
** a string which identifies a particular check-in of SQLite
153
** within its configuration management system. ^The SQLITE4_SOURCE_ID
154
** string contains the date and time of the check-in (UTC) and an SHA1
155
** hash of the entire source tree.
156
**
157
** See also: [sqlite4_libversion()],
158
** [sqlite4_libversion_number()], [sqlite4_sourceid()],
159
** [sqlite_version()] and [sqlite_source_id()].
160
*/
161
#define SQLITE4_VERSION "4.0.0"
162
#define SQLITE4_VERSION_NUMBER 4000000
163
#define SQLITE4_SOURCE_ID "2012-06-29 15:58:49 2aa05e9008ff9e3630161995cdb256351cc45f9b"
164
165
/*
166
** CAPIREF: Run-Time Library Version Numbers
167
** KEYWORDS: sqlite4_version, sqlite4_sourceid
168
**
169
** These interfaces provide the same information as the [SQLITE4_VERSION],
170
** [SQLITE4_VERSION_NUMBER], and [SQLITE4_SOURCE_ID] C preprocessor macros
171
** but are associated with the library instead of the header file. ^(Cautious
172
** programmers might include assert() statements in their application to
173
** verify that values returned by these interfaces match the macros in
174
** the header, and thus insure that the application is
175
** compiled with matching library and header files.
176
**
177
** <blockquote><pre>
178
** assert( sqlite4_libversion_number()==SQLITE4_VERSION_NUMBER );
179
** assert( strcmp(sqlite4_sourceid(),SQLITE4_SOURCE_ID)==0 );
180
** assert( strcmp(sqlite4_libversion(),SQLITE4_VERSION)==0 );
181
** </pre></blockquote>)^
182
**
183
** ^The sqlite4_libversion() function returns a pointer to a string
184
** constant that contains the text of [SQLITE4_VERSION]. ^The
185
** sqlite4_libversion_number() function returns an integer equal to
186
** [SQLITE4_VERSION_NUMBER]. ^The sqlite4_sourceid() function returns
187
** a pointer to a string constant whose value is the same as the
188
** [SQLITE4_SOURCE_ID] C preprocessor macro.
189
**
190
** See also: [sqlite_version()] and [sqlite_source_id()].
191
*/
192
SQLITE4_API const char *sqlite4_libversion(void);
193
SQLITE4_API const char *sqlite4_sourceid(void);
194
SQLITE4_API int sqlite4_libversion_number(void);
195
196
/*
197
** CAPIREF: Run-Time Library Compilation Options Diagnostics
198
**
199
** ^The sqlite4_compileoption_used() function returns 0 or 1
200
** indicating whether the specified option was defined at
201
** compile time. ^The SQLITE4_ prefix may be omitted from the
202
** option name passed to sqlite4_compileoption_used().
203
**
204
** ^The sqlite4_compileoption_get() function allows iterating
205
** over the list of options that were defined at compile time by
206
** returning the N-th compile time option string. ^If N is out of range,
207
** sqlite4_compileoption_get() returns a NULL pointer. ^The SQLITE4_
208
** prefix is omitted from any strings returned by
209
** sqlite4_compileoption_get().
210
**
211
** ^Support for the diagnostic functions sqlite4_compileoption_used()
212
** and sqlite4_compileoption_get() may be omitted by specifying the
213
** [SQLITE4_OMIT_COMPILEOPTION_DIAGS] option at compile time.
214
**
215
** See also: SQL functions [sqlite_compileoption_used()] and
216
** [sqlite_compileoption_get()] and the [compile_options pragma].
217
*/
218
#ifndef SQLITE4_OMIT_COMPILEOPTION_DIAGS
219
SQLITE4_API int sqlite4_compileoption_used(const char *zOptName);
220
SQLITE4_API const char *sqlite4_compileoption_get(int N);
221
#endif
222
223
/*
224
** CAPIREF: Test To See If The Library Is Threadsafe
225
**
226
** ^The sqlite4_threadsafe(E) function returns zero if the [sqlite4_env]
227
** object is configured in such a way that it should only be used by a
228
** single thread at a time. In other words, this routine returns zero
229
** if the environment is configured as [SQLITE4_ENVCONFIG_SINGLETHREAD].
230
**
231
** ^The sqlite4_threadsafe(E) function returns one if multiple
232
** [database connection] objects associated with E can be used at the
233
** same time in different threads, so long as no single [database connection]
234
** object is used by two or more threads at the same time. This
235
** corresponds to [SQLITE4_ENVCONFIG_MULTITHREAD].
236
**
237
** ^The sqlite4_threadsafe(E) function returns two if the same
238
** [database connection] can be used at the same time from two or more
239
** separate threads. This setting corresponds to [SQLITE4_ENVCONFIG_SERIALIZED].
240
**
241
** Note that SQLite4 is always threadsafe in this sense: Two or more
242
** objects each associated with different [sqlite4_env] objects can
243
** always be used at the same time in separate threads.
244
*/
245
SQLITE4_API int sqlite4_threadsafe(sqlite4_env*);
246
247
/*
248
** CAPIREF: Database Connection Handle
249
** KEYWORDS: {database connection} {database connections}
250
**
251
** Each open SQLite database is represented by a pointer to an instance of
252
** the opaque structure named "sqlite4". It is useful to think of an sqlite4
253
** pointer as an object. The [sqlite4_open()]
254
** interface is its constructors, and [sqlite4_close()]
255
** is its destructor. There are many other interfaces (such as
256
** [sqlite4_prepare], [sqlite4_create_function()], and
257
** [sqlite4_busy_timeout()] to name but three) that are methods on an
258
** sqlite4 object.
259
*/
260
typedef struct sqlite4 sqlite4;
261
262
/*
263
** CAPIREF: 64-Bit Integer Types
264
** KEYWORDS: sqlite_int64 sqlite_uint64
265
**
266
** Because there is no cross-platform way to specify 64-bit integer types
267
** SQLite includes typedefs for 64-bit signed and unsigned integers.
268
**
269
** The sqlite4_int64 and sqlite4_uint64 are the preferred type definitions.
270
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
271
** compatibility only.
272
**
273
** ^The sqlite4_int64 and sqlite_int64 types can store integer values
274
** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
275
** sqlite4_uint64 and sqlite_uint64 types can store integer values
276
** between 0 and +18446744073709551615 inclusive.
277
*/
278
#ifdef SQLITE4_INT64_TYPE
279
typedef SQLITE4_INT64_TYPE sqlite_int64;
280
typedef unsigned SQLITE4_INT64_TYPE sqlite_uint64;
281
#elif defined(_MSC_VER) || defined(__BORLANDC__)
282
typedef __int64 sqlite_int64;
283
typedef unsigned __int64 sqlite_uint64;
284
#else
285
typedef long long int sqlite_int64;
286
typedef unsigned long long int sqlite_uint64;
287
#endif
288
typedef sqlite_int64 sqlite4_int64;
289
typedef sqlite_uint64 sqlite4_uint64;
290
291
/*
292
** CAPIREF: String length type
293
**
294
** A type for measuring the length of the string. Like size_t but
295
** does not require &lt;stddef.h&gt;
296
*/
297
typedef int sqlite4_size_t;
298
299
/*
300
** If compiling for a processor that lacks floating point support,
301
** substitute integer for floating-point.
302
*/
303
#ifdef SQLITE4_OMIT_FLOATING_POINT
304
# define double sqlite4_int64
305
#endif
306
307
/*
308
** CAPIREF: Closing A Database Connection
309
**
310
** ^The sqlite4_close() routine is the destructor for the [sqlite4] object.
311
** ^Calls to sqlite4_close() return SQLITE4_OK if the [sqlite4] object is
312
** successfully destroyed and all associated resources are deallocated.
313
**
314
** Applications must [sqlite4_finalize | finalize] all [prepared statements]
315
** and [sqlite4_blob_close | close] all [BLOB handles] associated with
316
** the [sqlite4] object prior to attempting to close the object. ^If
317
** sqlite4_close() is called on a [database connection] that still has
318
** outstanding [prepared statements] or [BLOB handles], then it returns
319
** SQLITE4_BUSY.
320
**
321
** ^If [sqlite4_close()] is invoked while a transaction is open,
322
** the transaction is automatically rolled back.
323
**
324
** The C parameter to [sqlite4_close(C)] must be either a NULL
325
** pointer or an [sqlite4] object pointer obtained
326
** from [sqlite4_open()] and not previously closed.
327
** ^Calling sqlite4_close() with a NULL pointer argument is a
328
** harmless no-op.
329
*/
330
SQLITE4_API int sqlite4_close(sqlite4 *);
331
332
/*
333
** The type for a callback function.
334
** This is legacy and deprecated. It is included for historical
335
** compatibility and is not documented.
336
*/
337
typedef int (*sqlite4_callback)(void*,int,char**, char**);
338
339
/*
340
** CAPIREF: One-Step Query Execution Interface
341
**
342
** The sqlite4_exec() interface is a convenience wrapper around
343
** [sqlite4_prepare()], [sqlite4_step()], and [sqlite4_finalize()],
344
** that allows an application to run multiple statements of SQL
345
** without having to use a lot of C code.
346
**
347
** ^The sqlite4_exec() interface runs zero or more UTF-8 encoded,
348
** semicolon-separate SQL statements passed into its 2nd argument,
349
** in the context of the [database connection] passed in as its 1st
350
** argument. ^If the callback function of the 3rd argument to
351
** sqlite4_exec() is not NULL, then it is invoked for each result row
352
** coming out of the evaluated SQL statements. ^The 4th argument to
353
** sqlite4_exec() is relayed through to the 1st argument of each
354
** callback invocation. ^If the callback pointer to sqlite4_exec()
355
** is NULL, then no callback is ever invoked and result rows are
356
** ignored.
357
**
358
** ^If an error occurs while evaluating the SQL statements passed into
359
** sqlite4_exec(), then execution of the current statement stops and
360
** subsequent statements are skipped. ^If the 5th parameter to sqlite4_exec()
361
** is not NULL then any error message is written into memory obtained
362
** from [sqlite4_malloc()] and passed back through the 5th parameter.
363
** To avoid memory leaks, the application should invoke [sqlite4_free()]
364
** on error message strings returned through the 5th parameter of
365
** of sqlite4_exec() after the error message string is no longer needed.
366
** ^If the 5th parameter to sqlite4_exec() is not NULL and no errors
367
** occur, then sqlite4_exec() sets the pointer in its 5th parameter to
368
** NULL before returning.
369
**
370
** ^If an sqlite4_exec() callback returns non-zero, the sqlite4_exec()
371
** routine returns SQLITE4_ABORT without invoking the callback again and
372
** without running any subsequent SQL statements.
373
**
374
** ^The 2nd argument to the sqlite4_exec() callback function is the
375
** number of columns in the result. ^The 3rd argument to the sqlite4_exec()
376
** callback is an array of pointers to strings obtained as if from
377
** [sqlite4_column_text()], one for each column. ^If an element of a
378
** result row is NULL then the corresponding string pointer for the
379
** sqlite4_exec() callback is a NULL pointer. ^The 4th argument to the
380
** sqlite4_exec() callback is an array of pointers to strings where each
381
** entry represents the name of corresponding result column as obtained
382
** from [sqlite4_column_name()].
383
**
384
** ^If the 2nd parameter to sqlite4_exec() is a NULL pointer, a pointer
385
** to an empty string, or a pointer that contains only whitespace and/or
386
** SQL comments, then no SQL statements are evaluated and the database
387
** is not changed.
388
**
389
** Restrictions:
390
**
391
** <ul>
392
** <li> The application must insure that the 1st parameter to sqlite4_exec()
393
** is a valid and open [database connection].
394
** <li> The application must not close [database connection] specified by
395
** the 1st parameter to sqlite4_exec() while sqlite4_exec() is running.
396
** <li> The application must not modify the SQL statement text passed into
397
** the 2nd parameter of sqlite4_exec() while sqlite4_exec() is running.
398
** </ul>
399
*/
400
SQLITE4_API int sqlite4_exec(
401
sqlite4*, /* An open database */
402
const char *sql, /* SQL to be evaluated */
403
int (*callback)(void*,int,char**,char**), /* Callback function */
404
void *, /* 1st argument to callback */
405
char **errmsg /* Error msg written here */
406
);
407
408
/*
409
** CAPIREF: Result Codes
410
** KEYWORDS: SQLITE4_OK {error code} {error codes}
411
** KEYWORDS: {result code} {result codes}
412
**
413
** Many SQLite functions return an integer result code from the set shown
414
** here in order to indicate success or failure.
415
**
416
** New error codes may be added in future versions of SQLite.
417
**
418
** See also: [SQLITE4_IOERR_READ | extended result codes],
419
** [sqlite4_vtab_on_conflict()] [SQLITE4_ROLLBACK | result codes].
420
*/
421
#define SQLITE4_OK 0 /* Successful result */
422
/* beginning-of-error-codes */
423
#define SQLITE4_ERROR 1 /* SQL error or missing database */
424
#define SQLITE4_INTERNAL 2 /* Internal logic error in SQLite */
425
#define SQLITE4_PERM 3 /* Access permission denied */
426
#define SQLITE4_ABORT 4 /* Callback routine requested an abort */
427
#define SQLITE4_BUSY 5 /* The database file is locked */
428
#define SQLITE4_LOCKED 6 /* A table in the database is locked */
429
#define SQLITE4_NOMEM 7 /* A malloc() failed */
430
#define SQLITE4_READONLY 8 /* Attempt to write a readonly database */
431
#define SQLITE4_INTERRUPT 9 /* Operation terminated by sqlite4_interrupt()*/
432
#define SQLITE4_IOERR 10 /* Some kind of disk I/O error occurred */
433
#define SQLITE4_CORRUPT 11 /* The database disk image is malformed */
434
#define SQLITE4_NOTFOUND 12 /* Unknown opcode in sqlite4_file_control() */
435
#define SQLITE4_FULL 13 /* Insertion failed because database is full */
436
#define SQLITE4_CANTOPEN 14 /* Unable to open the database file */
437
#define SQLITE4_PROTOCOL 15 /* Database lock protocol error */
438
#define SQLITE4_EMPTY 16 /* Database is empty */
439
#define SQLITE4_SCHEMA 17 /* The database schema changed */
440
#define SQLITE4_TOOBIG 18 /* String or BLOB exceeds size limit */
441
#define SQLITE4_CONSTRAINT 19 /* Abort due to constraint violation */
442
#define SQLITE4_MISMATCH 20 /* Data type mismatch */
443
#define SQLITE4_MISUSE 21 /* Library used incorrectly */
444
#define SQLITE4_NOLFS 22 /* Uses OS features not supported on host */
445
#define SQLITE4_AUTH 23 /* Authorization denied */
446
#define SQLITE4_FORMAT 24 /* Auxiliary database format error */
447
#define SQLITE4_RANGE 25 /* 2nd parameter to sqlite4_bind out of range */
448
#define SQLITE4_NOTADB 26 /* File opened that is not a database file */
449
#define SQLITE4_ROW 100 /* sqlite4_step() has another row ready */
450
#define SQLITE4_DONE 101 /* sqlite4_step() has finished executing */
451
#define SQLITE4_INEXACT 102 /* xSeek method of storage finds nearby ans */
452
/* end-of-error-codes */
453
454
/*
455
** CAPIREF: Extended Result Codes
456
** KEYWORDS: {extended error code} {extended error codes}
457
** KEYWORDS: {extended result code} {extended result codes}
458
**
459
** In its default configuration, SQLite API routines return one of 26 integer
460
** [SQLITE4_OK | result codes]. However, experience has shown that many of
461
** these result codes are too coarse-grained. They do not provide as
462
** much information about problems as programmers might like. In an effort to
463
** address this, newer versions of SQLite (version 3.3.8 and later) include
464
** support for additional result codes that provide more detailed information
465
** about errors. The extended result codes are enabled or disabled
466
** on a per database connection basis using the
467
** [sqlite4_extended_result_codes()] API.
468
**
469
** Some of the available extended result codes are listed here.
470
** One may expect the number of extended result codes will be expand
471
** over time. Software that uses extended result codes should expect
472
** to see new result codes in future releases of SQLite.
473
**
474
** The SQLITE4_OK result code will never be extended. It will always
475
** be exactly zero.
476
*/
477
#define SQLITE4_IOERR_READ (SQLITE4_IOERR | (1<<8))
478
#define SQLITE4_IOERR_SHORT_READ (SQLITE4_IOERR | (2<<8))
479
#define SQLITE4_IOERR_WRITE (SQLITE4_IOERR | (3<<8))
480
#define SQLITE4_IOERR_FSYNC (SQLITE4_IOERR | (4<<8))
481
#define SQLITE4_IOERR_DIR_FSYNC (SQLITE4_IOERR | (5<<8))
482
#define SQLITE4_IOERR_TRUNCATE (SQLITE4_IOERR | (6<<8))
483
#define SQLITE4_IOERR_FSTAT (SQLITE4_IOERR | (7<<8))
484
#define SQLITE4_IOERR_UNLOCK (SQLITE4_IOERR | (8<<8))
485
#define SQLITE4_IOERR_RDLOCK (SQLITE4_IOERR | (9<<8))
486
#define SQLITE4_IOERR_DELETE (SQLITE4_IOERR | (10<<8))
487
#define SQLITE4_IOERR_BLOCKED (SQLITE4_IOERR | (11<<8))
488
#define SQLITE4_IOERR_NOMEM (SQLITE4_IOERR | (12<<8))
489
#define SQLITE4_IOERR_ACCESS (SQLITE4_IOERR | (13<<8))
490
#define SQLITE4_IOERR_CHECKRESERVEDLOCK (SQLITE4_IOERR | (14<<8))
491
#define SQLITE4_IOERR_LOCK (SQLITE4_IOERR | (15<<8))
492
#define SQLITE4_IOERR_CLOSE (SQLITE4_IOERR | (16<<8))
493
#define SQLITE4_IOERR_DIR_CLOSE (SQLITE4_IOERR | (17<<8))
494
#define SQLITE4_IOERR_SHMOPEN (SQLITE4_IOERR | (18<<8))
495
#define SQLITE4_IOERR_SHMSIZE (SQLITE4_IOERR | (19<<8))
496
#define SQLITE4_IOERR_SHMLOCK (SQLITE4_IOERR | (20<<8))
497
#define SQLITE4_IOERR_SHMMAP (SQLITE4_IOERR | (21<<8))
498
#define SQLITE4_IOERR_SEEK (SQLITE4_IOERR | (22<<8))
499
#define SQLITE4_LOCKED_SHAREDCACHE (SQLITE4_LOCKED | (1<<8))
500
#define SQLITE4_BUSY_RECOVERY (SQLITE4_BUSY | (1<<8))
501
#define SQLITE4_CANTOPEN_NOTEMPDIR (SQLITE4_CANTOPEN | (1<<8))
502
#define SQLITE4_CORRUPT_VTAB (SQLITE4_CORRUPT | (1<<8))
503
#define SQLITE4_READONLY_RECOVERY (SQLITE4_READONLY | (1<<8))
504
#define SQLITE4_READONLY_CANTLOCK (SQLITE4_READONLY | (2<<8))
505
506
/*
507
** CAPIREF: Flags For File Open Operations
508
**
509
** These bit values are intended for use as options in the
510
** [sqlite4_open()] interface
511
*/
512
#define SQLITE4_OPEN_READONLY 0x00000001 /* Ok for sqlite4_open() */
513
#define SQLITE4_OPEN_READWRITE 0x00000002 /* Ok for sqlite4_open() */
514
#define SQLITE4_OPEN_CREATE 0x00000004 /* Ok for sqlite4_open() */
515
516
/* NB: The above must not overlap with the SQLITE4_KVOPEN_xxxxx flags
517
** defined below */
518
519
520
/*
521
** CAPIREF: Mutex Handle
522
**
523
** The mutex module within SQLite defines [sqlite4_mutex] to be an
524
** abstract type for a mutex object. The SQLite core never looks
525
** at the internal representation of an [sqlite4_mutex]. It only
526
** deals with pointers to the [sqlite4_mutex] object.
527
**
528
** Mutexes are created using [sqlite4_mutex_alloc()].
529
*/
530
typedef struct sqlite4_mutex sqlite4_mutex;
531
struct sqlite4_mutex {
532
struct sqlite4_mutex_methods *pMutexMethods;
533
/* Subclasses will typically add additional fields */
534
};
535
536
/*
537
** CAPIREF: Initialize The SQLite Library
538
**
539
** ^The sqlite4_initialize(A) routine initializes an sqlite4_env object A.
540
** ^The sqlite4_shutdown(A) routine
541
** deallocates any resources that were allocated by sqlite4_initialize(A).
542
**
543
** A call to sqlite4_initialize(A) is an "effective" call if it is
544
** the first time sqlite4_initialize(A) is invoked during the lifetime of
545
** A, or if it is the first time sqlite4_initialize(A) is invoked
546
** following a call to sqlite4_shutdown(A). ^(Only an effective call
547
** of sqlite4_initialize(A) does any initialization or A. All other calls
548
** are harmless no-ops.)^
549
**
550
** A call to sqlite4_shutdown(A) is an "effective" call if it is the first
551
** call to sqlite4_shutdown(A) since the last sqlite4_initialize(A). ^(Only
552
** an effective call to sqlite4_shutdown(A) does any deinitialization.
553
** All other valid calls to sqlite4_shutdown(A) are harmless no-ops.)^
554
**
555
** The sqlite4_initialize(A) interface is threadsafe, but sqlite4_shutdown(A)
556
** is not. The sqlite4_shutdown(A) interface must only be called from a
557
** single thread. All open [database connections] must be closed and all
558
** other SQLite resources must be deallocated prior to invoking
559
** sqlite4_shutdown(A).
560
**
561
** ^The sqlite4_initialize(A) routine returns [SQLITE4_OK] on success.
562
** ^If for some reason, sqlite4_initialize(A) is unable to initialize
563
** the sqlite4_env object A (perhaps it is unable to allocate a needed
564
** resource such as a mutex) it returns an [error code] other than [SQLITE4_OK].
565
**
566
** ^The sqlite4_initialize() routine is called internally by many other
567
** SQLite interfaces so that an application usually does not need to
568
** invoke sqlite4_initialize() directly. For example, [sqlite4_open()]
569
** calls sqlite4_initialize() so the SQLite library will be automatically
570
** initialized when [sqlite4_open()] is called if it has not be initialized
571
** already. ^However, if SQLite is compiled with the [SQLITE4_OMIT_AUTOINIT]
572
** compile-time option, then the automatic calls to sqlite4_initialize()
573
** are omitted and the application must call sqlite4_initialize() directly
574
** prior to using any other SQLite interface. For maximum portability,
575
** it is recommended that applications always invoke sqlite4_initialize()
576
** directly prior to using any other SQLite interface. Future releases
577
** of SQLite may require this. In other words, the behavior exhibited
578
** when SQLite is compiled with [SQLITE4_OMIT_AUTOINIT] might become the
579
** default behavior in some future release of SQLite.
580
*/
581
SQLITE4_API int sqlite4_initialize(sqlite4_env*);
582
SQLITE4_API int sqlite4_shutdown(sqlite4_env*);
583
584
/*
585
** CAPIREF: Configure database connections
586
**
587
** The sqlite4_db_config() interface is used to make configuration
588
** changes to a [database connection]. The interface is similar to
589
** [sqlite4_env_config()] except that the changes apply to a single
590
** [database connection] (specified in the first argument).
591
**
592
** The second argument to sqlite4_db_config(D,V,...) is the
593
** [SQLITE4_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
594
** that indicates what aspect of the [database connection] is being configured.
595
** Subsequent arguments vary depending on the configuration verb.
596
**
597
** ^Calls to sqlite4_db_config() return SQLITE4_OK if and only if
598
** the call is considered successful.
599
*/
600
SQLITE4_API int sqlite4_db_config(sqlite4*, int op, ...);
601
602
/*
603
** CAPIREF: Run-time environment of a database connection
604
**
605
** Return the sqlite4_env object to which the database connection
606
** belongs.
607
*/
608
SQLITE4_API sqlite4_env *sqlite4_db_env(sqlite4*);
609
610
/*
611
** CAPIREF: Memory Allocation Routines
612
**
613
** An instance of this object defines the interface between SQLite
614
** and low-level memory allocation routines.
615
**
616
** This object is used in only one place in the SQLite interface.
617
** A pointer to an instance of this object is the argument to
618
** [sqlite4_env_config()] when the configuration option is
619
** [SQLITE4_ENVCONFIG_MALLOC] or [SQLITE4_ENVCONFIG_GETMALLOC].
620
** By creating an instance of this object
621
** and passing it to [sqlite4_env_config]([SQLITE4_ENVCONFIG_MALLOC])
622
** during configuration, an application can specify an alternative
623
** memory allocation subsystem for SQLite to use for all of its
624
** dynamic memory needs.
625
**
626
** Note that SQLite comes with several [built-in memory allocators]
627
** that are perfectly adequate for the overwhelming majority of applications
628
** and that this object is only useful to a tiny minority of applications
629
** with specialized memory allocation requirements. This object is
630
** also used during testing of SQLite in order to specify an alternative
631
** memory allocator that simulates memory out-of-memory conditions in
632
** order to verify that SQLite recovers gracefully from such
633
** conditions.
634
**
635
** The xMalloc, xRealloc, and xFree methods must work like the
636
** malloc(), realloc() and free() functions from the standard C library.
637
** ^SQLite guarantees that the second argument to
638
** xRealloc is always a value returned by a prior call to xRoundup.
639
**
640
** xSize should return the allocated size of a memory allocation
641
** previously obtained from xMalloc or xRealloc. The allocated size
642
** is always at least as big as the requested size but may be larger.
643
**
644
** The xRoundup method returns what would be the allocated size of
645
** a memory allocation given a particular requested size. Most memory
646
** allocators round up memory allocations at least to the next multiple
647
** of 8. Some allocators round up to a larger multiple or to a power of 2.
648
** Every memory allocation request coming in through [sqlite4_malloc()]
649
** or [sqlite4_realloc()] first calls xRoundup. If xRoundup returns 0,
650
** that causes the corresponding memory allocation to fail.
651
**
652
** The xInit method initializes the memory allocator. (For example,
653
** it might allocate any require mutexes or initialize internal data
654
** structures. The xShutdown method is invoked (indirectly) by
655
** [sqlite4_shutdown()] and should deallocate any resources acquired
656
** by xInit. The pMemEnv pointer is used as the only parameter to
657
** xInit and xShutdown.
658
**
659
** SQLite holds the [SQLITE4_MUTEX_STATIC_MASTER] mutex when it invokes
660
** the xInit method, so the xInit method need not be threadsafe. The
661
** xShutdown method is only called from [sqlite4_shutdown()] so it does
662
** not need to be threadsafe either. For all other methods, SQLite
663
** holds the [SQLITE4_MUTEX_STATIC_MEM] mutex as long as the
664
** [SQLITE4_CONFIG_MEMSTATUS] configuration option is turned on (which
665
** it is by default) and so the methods are automatically serialized.
666
** However, if [SQLITE4_CONFIG_MEMSTATUS] is disabled, then the other
667
** methods must be threadsafe or else make their own arrangements for
668
** serialization.
669
**
670
** SQLite will never invoke xInit() more than once without an intervening
671
** call to xShutdown().
672
*/
673
typedef struct sqlite4_mem_methods sqlite4_mem_methods;
674
struct sqlite4_mem_methods {
675
void *(*xMalloc)(void*,sqlite4_size_t); /* Memory allocation function */
676
void (*xFree)(void*,void*); /* Free a prior allocation */
677
void *(*xRealloc)(void*,void*,int); /* Resize an allocation */
678
sqlite4_size_t (*xSize)(void*,void*); /* Return the size of an allocation */
679
int (*xInit)(void*); /* Initialize the memory allocator */
680
void (*xShutdown)(void*); /* Deinitialize the allocator */
681
void (*xBeginBenign)(void*); /* Enter a benign malloc region */
682
void (*xEndBenign)(void*); /* Leave a benign malloc region */
683
void *pMemEnv; /* 1st argument to all routines */
684
};
685
686
687
/*
688
** CAPIREF: Database Connection Configuration Options
689
**
690
** These constants are the available integer configuration options that
691
** can be passed as the second argument to the [sqlite4_db_config()] interface.
692
**
693
** New configuration options may be added in future releases of SQLite.
694
** Existing configuration options might be discontinued. Applications
695
** should check the return code from [sqlite4_db_config()] to make sure that
696
** the call worked. ^The [sqlite4_db_config()] interface will return a
697
** non-zero [error code] if a discontinued or unsupported configuration option
698
** is invoked.
699
**
700
** <dl>
701
** <dt>SQLITE4_DBCONFIG_LOOKASIDE</dt>
702
** <dd> ^This option takes three additional arguments that determine the
703
** [lookaside memory allocator] configuration for the [database connection].
704
** ^The first argument (the third parameter to [sqlite4_db_config()] is a
705
** pointer to a memory buffer to use for lookaside memory.
706
** ^The first argument after the SQLITE4_DBCONFIG_LOOKASIDE verb
707
** may be NULL in which case SQLite will allocate the
708
** lookaside buffer itself using [sqlite4_malloc()]. ^The second argument is the
709
** size of each lookaside buffer slot. ^The third argument is the number of
710
** slots. The size of the buffer in the first argument must be greater than
711
** or equal to the product of the second and third arguments. The buffer
712
** must be aligned to an 8-byte boundary. ^If the second argument to
713
** SQLITE4_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
714
** rounded down to the next smaller multiple of 8. ^(The lookaside memory
715
** configuration for a database connection can only be changed when that
716
** connection is not currently using lookaside memory, or in other words
717
** when the "current value" returned by
718
** [sqlite4_db_status](D,[SQLITE4_CONFIG_LOOKASIDE],...) is zero.
719
** Any attempt to change the lookaside memory configuration when lookaside
720
** memory is in use leaves the configuration unchanged and returns
721
** [SQLITE4_BUSY].)^</dd>
722
**
723
** <dt>SQLITE4_DBCONFIG_ENABLE_FKEY</dt>
724
** <dd> ^This option is used to enable or disable the enforcement of
725
** [foreign key constraints]. There should be two additional arguments.
726
** The first argument is an integer which is 0 to disable FK enforcement,
727
** positive to enable FK enforcement or negative to leave FK enforcement
728
** unchanged. The second parameter is a pointer to an integer into which
729
** is written 0 or 1 to indicate whether FK enforcement is off or on
730
** following this call. The second parameter may be a NULL pointer, in
731
** which case the FK enforcement setting is not reported back. </dd>
732
**
733
** <dt>SQLITE4_DBCONFIG_ENABLE_TRIGGER</dt>
734
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
735
** There should be two additional arguments.
736
** The first argument is an integer which is 0 to disable triggers,
737
** positive to enable triggers or negative to leave the setting unchanged.
738
** The second parameter is a pointer to an integer into which
739
** is written 0 or 1 to indicate whether triggers are disabled or enabled
740
** following this call. The second parameter may be a NULL pointer, in
741
** which case the trigger setting is not reported back. </dd>
742
**
743
** </dl>
744
*/
745
#define SQLITE4_DBCONFIG_LOOKASIDE 1001 /* void* int int */
746
#define SQLITE4_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
747
#define SQLITE4_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
748
749
750
/*
751
** CAPIREF: Last Insert Rowid
752
**
753
** ^Each entry in an SQLite table has a unique 64-bit signed
754
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
755
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
756
** names are not also used by explicitly declared columns. ^If
757
** the table has a column of type [INTEGER PRIMARY KEY] then that column
758
** is another alias for the rowid.
759
**
760
** ^This routine returns the [rowid] of the most recent
761
** successful [INSERT] into the database from the [database connection]
762
** in the first argument. ^As of SQLite version 3.7.7, this routines
763
** records the last insert rowid of both ordinary tables and [virtual tables].
764
** ^If no successful [INSERT]s
765
** have ever occurred on that database connection, zero is returned.
766
**
767
** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
768
** method, then this routine will return the [rowid] of the inserted
769
** row as long as the trigger or virtual table method is running.
770
** But once the trigger or virtual table method ends, the value returned
771
** by this routine reverts to what it was before the trigger or virtual
772
** table method began.)^
773
**
774
** ^An [INSERT] that fails due to a constraint violation is not a
775
** successful [INSERT] and does not change the value returned by this
776
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
777
** and INSERT OR ABORT make no changes to the return value of this
778
** routine when their insertion fails. ^(When INSERT OR REPLACE
779
** encounters a constraint violation, it does not fail. The
780
** INSERT continues to completion after deleting rows that caused
781
** the constraint problem so INSERT OR REPLACE will always change
782
** the return value of this interface.)^
783
**
784
** ^For the purposes of this routine, an [INSERT] is considered to
785
** be successful even if it is subsequently rolled back.
786
**
787
** This function is accessible to SQL statements via the
788
** [last_insert_rowid() SQL function].
789
**
790
** If a separate thread performs a new [INSERT] on the same
791
** database connection while the [sqlite4_last_insert_rowid()]
792
** function is running and thus changes the last insert [rowid],
793
** then the value returned by [sqlite4_last_insert_rowid()] is
794
** unpredictable and might not equal either the old or the new
795
** last insert [rowid].
796
*/
797
SQLITE4_API sqlite4_int64 sqlite4_last_insert_rowid(sqlite4*);
798
799
/*
800
** CAPIREF: Count The Number Of Rows Modified
801
**
802
** ^This function returns the number of database rows that were changed
803
** or inserted or deleted by the most recently completed SQL statement
804
** on the [database connection] specified by the first parameter.
805
** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
806
** or [DELETE] statement are counted. Auxiliary changes caused by
807
** triggers or [foreign key actions] are not counted.)^ Use the
808
** [sqlite4_total_changes()] function to find the total number of changes
809
** including changes caused by triggers and foreign key actions.
810
**
811
** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
812
** are not counted. Only real table changes are counted.
813
**
814
** ^(A "row change" is a change to a single row of a single table
815
** caused by an INSERT, DELETE, or UPDATE statement. Rows that
816
** are changed as side effects of [REPLACE] constraint resolution,
817
** rollback, ABORT processing, [DROP TABLE], or by any other
818
** mechanisms do not count as direct row changes.)^
819
**
820
** A "trigger context" is a scope of execution that begins and
821
** ends with the script of a [CREATE TRIGGER | trigger].
822
** Most SQL statements are
823
** evaluated outside of any trigger. This is the "top level"
824
** trigger context. If a trigger fires from the top level, a
825
** new trigger context is entered for the duration of that one
826
** trigger. Subtriggers create subcontexts for their duration.
827
**
828
** ^Calling [sqlite4_exec()] or [sqlite4_step()] recursively does
829
** not create a new trigger context.
830
**
831
** ^This function returns the number of direct row changes in the
832
** most recent INSERT, UPDATE, or DELETE statement within the same
833
** trigger context.
834
**
835
** ^Thus, when called from the top level, this function returns the
836
** number of changes in the most recent INSERT, UPDATE, or DELETE
837
** that also occurred at the top level. ^(Within the body of a trigger,
838
** the sqlite4_changes() interface can be called to find the number of
839
** changes in the most recently completed INSERT, UPDATE, or DELETE
840
** statement within the body of the same trigger.
841
** However, the number returned does not include changes
842
** caused by subtriggers since those have their own context.)^
843
**
844
** See also the [sqlite4_total_changes()] interface, the
845
** [count_changes pragma], and the [changes() SQL function].
846
**
847
** If a separate thread makes changes on the same database connection
848
** while [sqlite4_changes()] is running then the value returned
849
** is unpredictable and not meaningful.
850
*/
851
SQLITE4_API int sqlite4_changes(sqlite4*);
852
853
/*
854
** CAPIREF: Total Number Of Rows Modified
855
**
856
** ^This function returns the number of row changes caused by [INSERT],
857
** [UPDATE] or [DELETE] statements since the [database connection] was opened.
858
** ^(The count returned by sqlite4_total_changes() includes all changes
859
** from all [CREATE TRIGGER | trigger] contexts and changes made by
860
** [foreign key actions]. However,
861
** the count does not include changes used to implement [REPLACE] constraints,
862
** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
863
** count does not include rows of views that fire an [INSTEAD OF trigger],
864
** though if the INSTEAD OF trigger makes changes of its own, those changes
865
** are counted.)^
866
** ^The sqlite4_total_changes() function counts the changes as soon as
867
** the statement that makes them is completed (when the statement handle
868
** is passed to [sqlite4_reset()] or [sqlite4_finalize()]).
869
**
870
** See also the [sqlite4_changes()] interface, the
871
** [count_changes pragma], and the [total_changes() SQL function].
872
**
873
** If a separate thread makes changes on the same database connection
874
** while [sqlite4_total_changes()] is running then the value
875
** returned is unpredictable and not meaningful.
876
*/
877
SQLITE4_API int sqlite4_total_changes(sqlite4*);
878
879
/*
880
** CAPIREF: Interrupt A Long-Running Query
881
**
882
** ^This function causes any pending database operation to abort and
883
** return at its earliest opportunity. This routine is typically
884
** called in response to a user action such as pressing "Cancel"
885
** or Ctrl-C where the user wants a long query operation to halt
886
** immediately.
887
**
888
** ^It is safe to call this routine from a thread different from the
889
** thread that is currently running the database operation. But it
890
** is not safe to call this routine with a [database connection] that
891
** is closed or might close before sqlite4_interrupt() returns.
892
**
893
** ^If an SQL operation is very nearly finished at the time when
894
** sqlite4_interrupt() is called, then it might not have an opportunity
895
** to be interrupted and might continue to completion.
896
**
897
** ^An SQL operation that is interrupted will return [SQLITE4_INTERRUPT].
898
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
899
** that is inside an explicit transaction, then the entire transaction
900
** will be rolled back automatically.
901
**
902
** ^The sqlite4_interrupt(D) call is in effect until all currently running
903
** SQL statements on [database connection] D complete. ^Any new SQL statements
904
** that are started after the sqlite4_interrupt() call and before the
905
** running statements reaches zero are interrupted as if they had been
906
** running prior to the sqlite4_interrupt() call. ^New SQL statements
907
** that are started after the running statement count reaches zero are
908
** not effected by the sqlite4_interrupt().
909
** ^A call to sqlite4_interrupt(D) that occurs when there are no running
910
** SQL statements is a no-op and has no effect on SQL statements
911
** that are started after the sqlite4_interrupt() call returns.
912
**
913
** If the database connection closes while [sqlite4_interrupt()]
914
** is running then bad things will likely happen.
915
*/
916
SQLITE4_API void sqlite4_interrupt(sqlite4*);
917
918
/*
919
** CAPIREF: Determine If An SQL Statement Is Complete
920
**
921
** These routines are useful during command-line input to determine if the
922
** currently entered text seems to form a complete SQL statement or
923
** if additional input is needed before sending the text into
924
** SQLite for parsing. ^These routines return 1 if the input string
925
** appears to be a complete SQL statement. ^A statement is judged to be
926
** complete if it ends with a semicolon token and is not a prefix of a
927
** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
928
** string literals or quoted identifier names or comments are not
929
** independent tokens (they are part of the token in which they are
930
** embedded) and thus do not count as a statement terminator. ^Whitespace
931
** and comments that follow the final semicolon are ignored.
932
**
933
** ^These routines return 0 if the statement is incomplete. ^If a
934
** memory allocation fails, then SQLITE4_NOMEM is returned.
935
**
936
** ^These routines do not parse the SQL statements thus
937
** will not detect syntactically incorrect SQL.
938
**
939
** ^(If SQLite has not been initialized using [sqlite4_initialize()] prior
940
** to invoking sqlite4_complete16() then sqlite4_initialize() is invoked
941
** automatically by sqlite4_complete16(). If that initialization fails,
942
** then the return value from sqlite4_complete16() will be non-zero
943
** regardless of whether or not the input SQL is complete.)^
944
**
945
** The input to [sqlite4_complete()] must be a zero-terminated
946
** UTF-8 string.
947
**
948
** The input to [sqlite4_complete16()] must be a zero-terminated
949
** UTF-16 string in native byte order.
950
*/
951
SQLITE4_API int sqlite4_complete(const char *sql);
952
SQLITE4_API int sqlite4_complete16(const void *sql);
953
954
955
/*
956
** CAPIREF: Formatted String Printing Functions
957
**
958
** These routines are work-alikes of the "printf()" family of functions
959
** from the standard C library.
960
**
961
** ^The sqlite4_mprintf() and sqlite4_vmprintf() routines write their
962
** results into memory obtained from [sqlite4_malloc()].
963
** The strings returned by these two routines should be
964
** released by [sqlite4_free()]. ^Both routines return a
965
** NULL pointer if [sqlite4_malloc()] is unable to allocate enough
966
** memory to hold the resulting string.
967
**
968
** ^(The sqlite4_snprintf() routine is similar to "snprintf()" from
969
** the standard C library. The result is written into the
970
** buffer supplied as the first parameter whose size is given by
971
** the second parameter.)^ The return value from sqltie4_snprintf()
972
** is the number of bytes actually written into the buffer, not
973
** counting the zero terminator. The buffer is always zero-terminated
974
** as long as it it at least one byte in length.
975
**
976
** The sqlite4_snprintf() differs from the standard library snprintf()
977
** routine in two ways: (1) sqlite4_snprintf() returns the number of
978
** bytes actually written, not the number of bytes that would have been
979
** written if the buffer had been infinitely long. (2) If the buffer is
980
** at least one byte long, sqlite4_snprintf() always zero-terminates its
981
** result.
982
**
983
** ^As long as the buffer size is greater than zero, sqlite4_snprintf()
984
** guarantees that the buffer is always zero-terminated. ^The second
985
** parameter "n" is the total size of the buffer, including space for
986
** the zero terminator. So the longest string that can be completely
987
** written will be n-1 characters.
988
**
989
** ^The sqlite4_vsnprintf() routine is a varargs version of sqlite4_snprintf().
990
**
991
** These routines all implement some additional formatting
992
** options that are useful for constructing SQL statements.
993
** All of the usual printf() formatting options apply. In addition, there
994
** is are "%q", "%Q", and "%z" options.
995
**
996
** ^(The %q option works like %s in that it substitutes a nul-terminated
997
** string from the argument list. But %q also doubles every '\'' character.
998
** %q is designed for use inside a string literal.)^ By doubling each '\''
999
** character it escapes that character and allows it to be inserted into
1000
** the string.
1001
**
1002
** For example, assume the string variable zText contains text as follows:
1003
**
1004
** <blockquote><pre>
1005
** char *zText = "It's a happy day!";
1006
** </pre></blockquote>
1007
**
1008
** One can use this text in an SQL statement as follows:
1009
**
1010
** <blockquote><pre>
1011
** char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES('%q')", zText);
1012
** sqlite4_exec(db, zSQL, 0, 0, 0);
1013
** sqlite4_free(zSQL);
1014
** </pre></blockquote>
1015
**
1016
** Because the %q format string is used, the '\'' character in zText
1017
** is escaped and the SQL generated is as follows:
1018
**
1019
** <blockquote><pre>
1020
** INSERT INTO table1 VALUES('It''s a happy day!')
1021
** </pre></blockquote>
1022
**
1023
** This is correct. Had we used %s instead of %q, the generated SQL
1024
** would have looked like this:
1025
**
1026
** <blockquote><pre>
1027
** INSERT INTO table1 VALUES('It's a happy day!');
1028
** </pre></blockquote>
1029
**
1030
** This second example is an SQL syntax error. As a general rule you should
1031
** always use %q instead of %s when inserting text into a string literal.
1032
**
1033
** ^(The %Q option works like %q except it also adds single quotes around
1034
** the outside of the total string. Additionally, if the parameter in the
1035
** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
1036
** single quotes).)^ So, for example, one could say:
1037
**
1038
** <blockquote><pre>
1039
** char *zSQL = sqlite4_mprintf("INSERT INTO table VALUES(%Q)", zText);
1040
** sqlite4_exec(db, zSQL, 0, 0, 0);
1041
** sqlite4_free(zSQL);
1042
** </pre></blockquote>
1043
**
1044
** The code above will render a correct SQL statement in the zSQL
1045
** variable even if the zText variable is a NULL pointer.
1046
**
1047
** ^(The "%z" formatting option works like "%s" but with the
1048
** addition that after the string has been read and copied into
1049
** the result, [sqlite4_free()] is called on the input string.)^
1050
*/
1051
SQLITE4_API char *sqlite4_mprintf(sqlite4_env*, const char*,...);
1052
SQLITE4_API char *sqlite4_vmprintf(sqlite4_env*, const char*, va_list);
1053
SQLITE4_API sqlite4_size_t sqlite4_snprintf(char*,sqlite4_size_t,const char*, ...);
1054
SQLITE4_API sqlite4_size_t sqlite4_vsnprintf(char*,sqlite4_size_t,const char*, va_list);
1055
1056
/*
1057
** CAPIREF: Memory Allocation Subsystem
1058
**
1059
** The SQLite core uses these three routines for all of its own
1060
** internal memory allocation needs.
1061
**
1062
** ^The sqlite4_malloc() routine returns a pointer to a block
1063
** of memory at least N bytes in length, where N is the parameter.
1064
** ^If sqlite4_malloc() is unable to obtain sufficient free
1065
** memory, it returns a NULL pointer. ^If the parameter N to
1066
** sqlite4_malloc() is zero or negative then sqlite4_malloc() returns
1067
** a NULL pointer.
1068
**
1069
** ^Calling sqlite4_free() with a pointer previously returned
1070
** by sqlite4_malloc() or sqlite4_realloc() releases that memory so
1071
** that it might be reused. ^The sqlite4_free() routine is
1072
** a no-op if is called with a NULL pointer. Passing a NULL pointer
1073
** to sqlite4_free() is harmless. After being freed, memory
1074
** should neither be read nor written. Even reading previously freed
1075
** memory might result in a segmentation fault or other severe error.
1076
** Memory corruption, a segmentation fault, or other severe error
1077
** might result if sqlite4_free() is called with a non-NULL pointer that
1078
** was not obtained from sqlite4_malloc() or sqlite4_realloc().
1079
**
1080
** ^(The sqlite4_realloc() interface attempts to resize a
1081
** prior memory allocation to be at least N bytes, where N is the
1082
** second parameter. The memory allocation to be resized is the first
1083
** parameter.)^ ^ If the first parameter to sqlite4_realloc()
1084
** is a NULL pointer then its behavior is identical to calling
1085
** sqlite4_malloc(N) where N is the second parameter to sqlite4_realloc().
1086
** ^If the second parameter to sqlite4_realloc() is zero or
1087
** negative then the behavior is exactly the same as calling
1088
** sqlite4_free(P) where P is the first parameter to sqlite4_realloc().
1089
** ^sqlite4_realloc() returns a pointer to a memory allocation
1090
** of at least N bytes in size or NULL if sufficient memory is unavailable.
1091
** ^If M is the size of the prior allocation, then min(N,M) bytes
1092
** of the prior allocation are copied into the beginning of buffer returned
1093
** by sqlite4_realloc() and the prior allocation is freed.
1094
** ^If sqlite4_realloc() returns NULL, then the prior allocation
1095
** is not freed.
1096
**
1097
** ^The memory returned by sqlite4_malloc() and sqlite4_realloc()
1098
** is always aligned to at least an 8 byte boundary, or to a
1099
** 4 byte boundary if the [SQLITE4_4_BYTE_ALIGNED_MALLOC] compile-time
1100
** option is used.
1101
**
1102
** The pointer arguments to [sqlite4_free()] and [sqlite4_realloc()]
1103
** must be either NULL or else pointers obtained from a prior
1104
** invocation of [sqlite4_malloc()] or [sqlite4_realloc()] that have
1105
** not yet been released.
1106
**
1107
** The application must not read or write any part of
1108
** a block of memory after it has been released using
1109
** [sqlite4_free()] or [sqlite4_realloc()].
1110
*/
1111
SQLITE4_API void *sqlite4_malloc(sqlite4_env*, sqlite4_size_t);
1112
SQLITE4_API void *sqlite4_realloc(sqlite4_env*, void*, sqlite4_size_t);
1113
SQLITE4_API void sqlite4_free(sqlite4_env*, void*);
1114
1115
/*
1116
** CAPIREF: Memory Allocator Statistics
1117
**
1118
** SQLite provides these two interfaces for reporting on the status
1119
** of the [sqlite4_malloc()], [sqlite4_free()], and [sqlite4_realloc()]
1120
** routines, which form the built-in memory allocation subsystem.
1121
**
1122
** ^The [sqlite4_memory_used(E)] routine returns the number of bytes
1123
** of memory currently outstanding (malloced but not freed) for
1124
** sqlite4_env environment E.
1125
** ^The [sqlite4_memory_highwater(E)] routine returns the maximum
1126
** value of [sqlite4_memory_used(E)] since the high-water mark
1127
** was last reset. ^The values returned by [sqlite4_memory_used()] and
1128
** [sqlite4_memory_highwater()] include any overhead
1129
** added by SQLite in its implementation of [sqlite4_malloc()],
1130
** but not overhead added by the any underlying system library
1131
** routines that [sqlite4_malloc()] may call.
1132
**
1133
** ^The memory high-water mark is reset to the current value of
1134
** [sqlite4_memory_used(E)] if and only if the R parameter to
1135
** [sqlite4_memory_highwater(E,R)] is true. ^The value returned
1136
** by [sqlite4_memory_highwater(E,1)] is the high-water mark
1137
** prior to the reset.
1138
*/
1139
SQLITE4_API sqlite4_uint64 sqlite4_memory_used(sqlite4_env*);
1140
SQLITE4_API sqlite4_uint64 sqlite4_memory_highwater(sqlite4_env*, int resetFlag);
1141
1142
/*
1143
** CAPIREF: Pseudo-Random Number Generator
1144
**
1145
** ^A call to this routine stores N bytes of pseudo-randomness into buffer P.
1146
*/
1147
SQLITE4_API void sqlite4_randomness(sqlite4_env*, int N, void *P);
1148
1149
/*
1150
** CAPIREF: Compile-Time Authorization Callbacks
1151
**
1152
** ^This routine registers an authorizer callback with a particular
1153
** [database connection], supplied in the first argument.
1154
** ^The authorizer callback is invoked as SQL statements are being compiled
1155
** by [sqlite4_prepare()] or its variants [sqlite4_prepare()],
1156
** [sqlite4_prepare16()] and [sqlite4_prepare16_v2()]. ^At various
1157
** points during the compilation process, as logic is being created
1158
** to perform various actions, the authorizer callback is invoked to
1159
** see if those actions are allowed. ^The authorizer callback should
1160
** return [SQLITE4_OK] to allow the action, [SQLITE4_IGNORE] to disallow the
1161
** specific action but allow the SQL statement to continue to be
1162
** compiled, or [SQLITE4_DENY] to cause the entire SQL statement to be
1163
** rejected with an error. ^If the authorizer callback returns
1164
** any value other than [SQLITE4_IGNORE], [SQLITE4_OK], or [SQLITE4_DENY]
1165
** then the [sqlite4_prepare()] or equivalent call that triggered
1166
** the authorizer will fail with an error message.
1167
**
1168
** When the callback returns [SQLITE4_OK], that means the operation
1169
** requested is ok. ^When the callback returns [SQLITE4_DENY], the
1170
** [sqlite4_prepare()] or equivalent call that triggered the
1171
** authorizer will fail with an error message explaining that
1172
** access is denied.
1173
**
1174
** ^The first parameter to the authorizer callback is a copy of the third
1175
** parameter to the sqlite4_set_authorizer() interface. ^The second parameter
1176
** to the callback is an integer [SQLITE4_COPY | action code] that specifies
1177
** the particular action to be authorized. ^The third through sixth parameters
1178
** to the callback are zero-terminated strings that contain additional
1179
** details about the action to be authorized.
1180
**
1181
** ^If the action code is [SQLITE4_READ]
1182
** and the callback returns [SQLITE4_IGNORE] then the
1183
** [prepared statement] statement is constructed to substitute
1184
** a NULL value in place of the table column that would have
1185
** been read if [SQLITE4_OK] had been returned. The [SQLITE4_IGNORE]
1186
** return can be used to deny an untrusted user access to individual
1187
** columns of a table.
1188
** ^If the action code is [SQLITE4_DELETE] and the callback returns
1189
** [SQLITE4_IGNORE] then the [DELETE] operation proceeds but the
1190
** [truncate optimization] is disabled and all rows are deleted individually.
1191
**
1192
** An authorizer is used when [sqlite4_prepare | preparing]
1193
** SQL statements from an untrusted source, to ensure that the SQL statements
1194
** do not try to access data they are not allowed to see, or that they do not
1195
** try to execute malicious statements that damage the database. For
1196
** example, an application may allow a user to enter arbitrary
1197
** SQL queries for evaluation by a database. But the application does
1198
** not want the user to be able to make arbitrary changes to the
1199
** database. An authorizer could then be put in place while the
1200
** user-entered SQL is being [sqlite4_prepare | prepared] that
1201
** disallows everything except [SELECT] statements.
1202
**
1203
** Applications that need to process SQL from untrusted sources
1204
** might also consider lowering resource limits using [sqlite4_limit()]
1205
** and limiting database size using the [max_page_count] [PRAGMA]
1206
** in addition to using an authorizer.
1207
**
1208
** ^(Only a single authorizer can be in place on a database connection
1209
** at a time. Each call to sqlite4_set_authorizer overrides the
1210
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
1211
** The authorizer is disabled by default.
1212
**
1213
** The authorizer callback must not do anything that will modify
1214
** the database connection that invoked the authorizer callback.
1215
** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their
1216
** database connections for the meaning of "modify" in this paragraph.
1217
**
1218
** ^When [sqlite4_prepare()] is used to prepare a statement, the
1219
** statement might be re-prepared during [sqlite4_step()] due to a
1220
** schema change. Hence, the application should ensure that the
1221
** correct authorizer callback remains in place during the [sqlite4_step()].
1222
**
1223
** ^Note that the authorizer callback is invoked only during
1224
** [sqlite4_prepare()] or its variants. Authorization is not
1225
** performed during statement evaluation in [sqlite4_step()], unless
1226
** as stated in the previous paragraph, sqlite4_step() invokes
1227
** sqlite4_prepare() to reprepare a statement after a schema change.
1228
*/
1229
SQLITE4_API int sqlite4_set_authorizer(
1230
sqlite4*,
1231
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
1232
void *pUserData
1233
);
1234
1235
/*
1236
** CAPIREF: Authorizer Return Codes
1237
**
1238
** The [sqlite4_set_authorizer | authorizer callback function] must
1239
** return either [SQLITE4_OK] or one of these two constants in order
1240
** to signal SQLite whether or not the action is permitted. See the
1241
** [sqlite4_set_authorizer | authorizer documentation] for additional
1242
** information.
1243
**
1244
** Note that SQLITE4_IGNORE is also used as a [SQLITE4_ROLLBACK | return code]
1245
** from the [sqlite4_vtab_on_conflict()] interface.
1246
*/
1247
#define SQLITE4_DENY 1 /* Abort the SQL statement with an error */
1248
#define SQLITE4_IGNORE 2 /* Don't allow access, but don't generate an error */
1249
1250
/*
1251
** CAPIREF: Authorizer Action Codes
1252
**
1253
** The [sqlite4_set_authorizer()] interface registers a callback function
1254
** that is invoked to authorize certain SQL statement actions. The
1255
** second parameter to the callback is an integer code that specifies
1256
** what action is being authorized. These are the integer action codes that
1257
** the authorizer callback may be passed.
1258
**
1259
** These action code values signify what kind of operation is to be
1260
** authorized. The 3rd and 4th parameters to the authorization
1261
** callback function will be parameters or NULL depending on which of these
1262
** codes is used as the second parameter. ^(The 5th parameter to the
1263
** authorizer callback is the name of the database ("main", "temp",
1264
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
1265
** is the name of the inner-most trigger or view that is responsible for
1266
** the access attempt or NULL if this access attempt is directly from
1267
** top-level SQL code.
1268
*/
1269
/******************************************* 3rd ************ 4th ***********/
1270
#define SQLITE4_CREATE_INDEX 1 /* Index Name Table Name */
1271
#define SQLITE4_CREATE_TABLE 2 /* Table Name NULL */
1272
#define SQLITE4_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
1273
#define SQLITE4_CREATE_TEMP_TABLE 4 /* Table Name NULL */
1274
#define SQLITE4_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
1275
#define SQLITE4_CREATE_TEMP_VIEW 6 /* View Name NULL */
1276
#define SQLITE4_CREATE_TRIGGER 7 /* Trigger Name Table Name */
1277
#define SQLITE4_CREATE_VIEW 8 /* View Name NULL */
1278
#define SQLITE4_DELETE 9 /* Table Name NULL */
1279
#define SQLITE4_DROP_INDEX 10 /* Index Name Table Name */
1280
#define SQLITE4_DROP_TABLE 11 /* Table Name NULL */
1281
#define SQLITE4_DROP_TEMP_INDEX 12 /* Index Name Table Name */
1282
#define SQLITE4_DROP_TEMP_TABLE 13 /* Table Name NULL */
1283
#define SQLITE4_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
1284
#define SQLITE4_DROP_TEMP_VIEW 15 /* View Name NULL */
1285
#define SQLITE4_DROP_TRIGGER 16 /* Trigger Name Table Name */
1286
#define SQLITE4_DROP_VIEW 17 /* View Name NULL */
1287
#define SQLITE4_INSERT 18 /* Table Name NULL */
1288
#define SQLITE4_PRAGMA 19 /* Pragma Name 1st arg or NULL */
1289
#define SQLITE4_READ 20 /* Table Name Column Name */
1290
#define SQLITE4_SELECT 21 /* NULL NULL */
1291
#define SQLITE4_TRANSACTION 22 /* Operation NULL */
1292
#define SQLITE4_UPDATE 23 /* Table Name Column Name */
1293
#define SQLITE4_ATTACH 24 /* Filename NULL */
1294
#define SQLITE4_DETACH 25 /* Database Name NULL */
1295
#define SQLITE4_ALTER_TABLE 26 /* Database Name Table Name */
1296
#define SQLITE4_REINDEX 27 /* Index Name NULL */
1297
#define SQLITE4_ANALYZE 28 /* Table Name NULL */
1298
#define SQLITE4_CREATE_VTABLE 29 /* Table Name Module Name */
1299
#define SQLITE4_DROP_VTABLE 30 /* Table Name Module Name */
1300
#define SQLITE4_FUNCTION 31 /* NULL Function Name */
1301
#define SQLITE4_SAVEPOINT 32 /* Operation Savepoint Name */
1302
#define SQLITE4_COPY 0 /* No longer used */
1303
1304
/*
1305
** CAPIREF: Tracing And Profiling Functions
1306
**
1307
** These routines register callback functions that can be used for
1308
** tracing and profiling the execution of SQL statements.
1309
**
1310
** ^The callback function registered by sqlite4_trace() is invoked at
1311
** various times when an SQL statement is being run by [sqlite4_step()].
1312
** ^The sqlite4_trace() callback is invoked with a UTF-8 rendering of the
1313
** SQL statement text as the statement first begins executing.
1314
** ^(Additional sqlite4_trace() callbacks might occur
1315
** as each triggered subprogram is entered. The callbacks for triggers
1316
** contain a UTF-8 SQL comment that identifies the trigger.)^
1317
**
1318
** ^The callback function registered by sqlite4_profile() is invoked
1319
** as each SQL statement finishes. ^The profile callback contains
1320
** the original statement text and an estimate of wall-clock time
1321
** of how long that statement took to run. ^The profile callback
1322
** time is in units of nanoseconds, however the current implementation
1323
** is only capable of millisecond resolution so the six least significant
1324
** digits in the time are meaningless. Future versions of SQLite
1325
** might provide greater resolution on the profiler callback. The
1326
** sqlite4_profile() function is considered experimental and is
1327
** subject to change in future versions of SQLite.
1328
*/
1329
SQLITE4_API void *sqlite4_trace(sqlite4*, void(*xTrace)(void*,const char*), void*);
1330
SQLITE4_API SQLITE4_EXPERIMENTAL void *sqlite4_profile(sqlite4*,
1331
void(*xProfile)(void*,const char*,sqlite4_uint64), void*);
1332
1333
/*
1334
** CAPIREF: Query Progress Callbacks
1335
**
1336
** ^The sqlite4_progress_handler(D,N,X,P) interface causes the callback
1337
** function X to be invoked periodically during long running calls to
1338
** [sqlite4_exec()] and [sqlite4_step()] for
1339
** database connection D. An example use for this
1340
** interface is to keep a GUI updated during a large query.
1341
**
1342
** ^The parameter P is passed through as the only parameter to the
1343
** callback function X. ^The parameter N is the number of
1344
** [virtual machine instructions] that are evaluated between successive
1345
** invocations of the callback X.
1346
**
1347
** ^Only a single progress handler may be defined at one time per
1348
** [database connection]; setting a new progress handler cancels the
1349
** old one. ^Setting parameter X to NULL disables the progress handler.
1350
** ^The progress handler is also disabled by setting N to a value less
1351
** than 1.
1352
**
1353
** ^If the progress callback returns non-zero, the operation is
1354
** interrupted. This feature can be used to implement a
1355
** "Cancel" button on a GUI progress dialog box.
1356
**
1357
** The progress handler callback must not do anything that will modify
1358
** the database connection that invoked the progress handler.
1359
** Note that [sqlite4_prepare()] and [sqlite4_step()] both modify their
1360
** database connections for the meaning of "modify" in this paragraph.
1361
**
1362
*/
1363
SQLITE4_API void sqlite4_progress_handler(sqlite4*, int, int(*)(void*), void*);
1364
1365
/*
1366
** CAPIREF: Opening A New Database Connection
1367
**
1368
** ^These routines open an SQLite4 database file as specified by the
1369
** URI argument.
1370
** ^(A [database connection] handle is usually
1371
** returned in *ppDb, even if an error occurs. The only exception is that
1372
** if SQLite is unable to allocate memory to hold the [sqlite4] object,
1373
** a NULL will be written into *ppDb instead of a pointer to the [sqlite4]
1374
** object.)^ ^(If the database is opened (and/or created) successfully, then
1375
** [SQLITE4_OK] is returned. Otherwise an [error code] is returned.)^ ^The
1376
** [sqlite4_errmsg()] routine can be used to obtain
1377
** an English language description of the error following a failure of any
1378
** of the sqlite4_open() routines.
1379
**
1380
** Whether or not an error occurs when it is opened, resources
1381
** associated with the [database connection] handle should be released by
1382
** passing it to [sqlite4_close()] when it is no longer required.
1383
**
1384
*/
1385
SQLITE4_API int sqlite4_open(
1386
sqlite4_env *pEnv, /* Run-time environment. NULL means use the default */
1387
const char *filename, /* Database filename (UTF-8) */
1388
sqlite4 **ppDb, /* OUT: SQLite db handle */
1389
... /* Optional parameters. Zero terminates options */
1390
);
1391
1392
/*
1393
** CAPIREF: Obtain Values For URI Parameters
1394
**
1395
** These are utility routines, useful to VFS implementations, that check
1396
** to see if a database file was a URI that contained a specific query
1397
** parameter, and if so obtains the value of that query parameter.
1398
**
1399
** If F is the database filename pointer passed into the xOpen() method of
1400
** a VFS implementation when the flags parameter to xOpen() has one or
1401
** more of the [SQLITE4_OPEN_URI] or [SQLITE4_OPEN_MAIN_DB] bits set and
1402
** P is the name of the query parameter, then
1403
** sqlite4_uri_parameter(F,P) returns the value of the P
1404
** parameter if it exists or a NULL pointer if P does not appear as a
1405
** query parameter on F. If P is a query parameter of F
1406
** has no explicit value, then sqlite4_uri_parameter(F,P) returns
1407
** a pointer to an empty string.
1408
**
1409
** The sqlite4_uri_boolean(F,P,B) routine assumes that P is a boolean
1410
** parameter and returns true (1) or false (0) according to the value
1411
** of P. The value of P is true if it is "yes" or "true" or "on" or
1412
** a non-zero number and is false otherwise. If P is not a query parameter
1413
** on F then sqlite4_uri_boolean(F,P,B) returns (B!=0).
1414
**
1415
** The sqlite4_uri_int64(F,P,D) routine converts the value of P into a
1416
** 64-bit signed integer and returns that integer, or D if P does not
1417
** exist. If the value of P is something other than an integer, then
1418
** zero is returned.
1419
**
1420
** If F is a NULL pointer, then sqlite4_uri_parameter(F,P) returns NULL and
1421
** sqlite4_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
1422
** is not a database file pathname pointer that SQLite passed into the xOpen
1423
** VFS method, then the behavior of this routine is undefined and probably
1424
** undesirable.
1425
*/
1426
SQLITE4_API const char *sqlite4_uri_parameter(const char *zFilename, const char *zParam);
1427
SQLITE4_API int sqlite4_uri_boolean(const char *zFile, const char *zParam, int bDefault);
1428
SQLITE4_API sqlite4_int64 sqlite4_uri_int64(const char*, const char*, sqlite4_int64);
1429
1430
1431
/*
1432
** CAPIREF: Error Codes And Messages
1433
**
1434
** ^The sqlite4_errcode() interface returns the numeric
1435
** [extended result code] for the most recent failed sqlite4_* API call
1436
** associated with a [database connection]. If a prior API call failed
1437
** but the most recent API call succeeded, the return value from
1438
** sqlite4_errcode() is undefined.
1439
**
1440
** ^The sqlite4_errmsg() and sqlite4_errmsg16() return English-language
1441
** text that describes the error, as either UTF-8 or UTF-16 respectively.
1442
** ^(Memory to hold the error message string is managed internally.
1443
** The application does not need to worry about freeing the result.
1444
** However, the error string might be overwritten or deallocated by
1445
** subsequent calls to other SQLite interface functions.)^
1446
**
1447
** When the serialized [threading mode] is in use, it might be the
1448
** case that a second error occurs on a separate thread in between
1449
** the time of the first error and the call to these interfaces.
1450
** When that happens, the second error will be reported since these
1451
** interfaces always report the most recent result. To avoid
1452
** this, each thread can obtain exclusive use of the [database connection] D
1453
** by invoking [sqlite4_mutex_enter]([sqlite4_db_mutex](D)) before beginning
1454
** to use D and invoking [sqlite4_mutex_leave]([sqlite4_db_mutex](D)) after
1455
** all calls to the interfaces listed here are completed.
1456
**
1457
** If an interface fails with SQLITE4_MISUSE, that means the interface
1458
** was invoked incorrectly by the application. In that case, the
1459
** error code and message may or may not be set.
1460
*/
1461
SQLITE4_API int sqlite4_errcode(sqlite4 *db);
1462
SQLITE4_API const char *sqlite4_errmsg(sqlite4*);
1463
SQLITE4_API const void *sqlite4_errmsg16(sqlite4*);
1464
1465
/*
1466
** CAPIREF: SQL Statement Object
1467
** KEYWORDS: {prepared statement} {prepared statements}
1468
**
1469
** An instance of this object represents a single SQL statement.
1470
** This object is variously known as a "prepared statement" or a
1471
** "compiled SQL statement" or simply as a "statement".
1472
**
1473
** The life of a statement object goes something like this:
1474
**
1475
** <ol>
1476
** <li> Create the object using [sqlite4_prepare()] or a related
1477
** function.
1478
** <li> Bind values to [host parameters] using the sqlite4_bind_*()
1479
** interfaces.
1480
** <li> Run the SQL by calling [sqlite4_step()] one or more times.
1481
** <li> Reset the statement using [sqlite4_reset()] then go back
1482
** to step 2. Do this zero or more times.
1483
** <li> Destroy the object using [sqlite4_finalize()].
1484
** </ol>
1485
**
1486
** Refer to documentation on individual methods above for additional
1487
** information.
1488
*/
1489
typedef struct sqlite4_stmt sqlite4_stmt;
1490
1491
/*
1492
** CAPIREF: Run-time Limits
1493
**
1494
** ^(This interface allows the size of various constructs to be limited
1495
** on a connection by connection basis. The first parameter is the
1496
** [database connection] whose limit is to be set or queried. The
1497
** second parameter is one of the [limit categories] that define a
1498
** class of constructs to be size limited. The third parameter is the
1499
** new limit for that construct.)^
1500
**
1501
** ^If the new limit is a negative number, the limit is unchanged.
1502
** ^(For each limit category SQLITE4_LIMIT_<i>NAME</i> there is a
1503
** [limits | hard upper bound]
1504
** set at compile-time by a C preprocessor macro called
1505
** [limits | SQLITE4_MAX_<i>NAME</i>].
1506
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
1507
** ^Attempts to increase a limit above its hard upper bound are
1508
** silently truncated to the hard upper bound.
1509
**
1510
** ^Regardless of whether or not the limit was changed, the
1511
** [sqlite4_limit()] interface returns the prior value of the limit.
1512
** ^Hence, to find the current value of a limit without changing it,
1513
** simply invoke this interface with the third parameter set to -1.
1514
**
1515
** Run-time limits are intended for use in applications that manage
1516
** both their own internal database and also databases that are controlled
1517
** by untrusted external sources. An example application might be a
1518
** web browser that has its own databases for storing history and
1519
** separate databases controlled by JavaScript applications downloaded
1520
** off the Internet. The internal databases can be given the
1521
** large, default limits. Databases managed by external sources can
1522
** be given much smaller limits designed to prevent a denial of service
1523
** attack. Developers might also want to use the [sqlite4_set_authorizer()]
1524
** interface to further control untrusted SQL. The size of the database
1525
** created by an untrusted script can be contained using the
1526
** [max_page_count] [PRAGMA].
1527
**
1528
** New run-time limit categories may be added in future releases.
1529
*/
1530
SQLITE4_API int sqlite4_limit(sqlite4*, int id, int newVal);
1531
1532
/*
1533
** CAPIREF: Run-Time Limit Categories
1534
** KEYWORDS: {limit category} {*limit categories}
1535
**
1536
** These constants define various performance limits
1537
** that can be lowered at run-time using [sqlite4_limit()].
1538
** The synopsis of the meanings of the various limits is shown below.
1539
** Additional information is available at [limits | Limits in SQLite].
1540
**
1541
** <dl>
1542
** [[SQLITE4_LIMIT_LENGTH]] ^(<dt>SQLITE4_LIMIT_LENGTH</dt>
1543
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
1544
**
1545
** [[SQLITE4_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE4_LIMIT_SQL_LENGTH</dt>
1546
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
1547
**
1548
** [[SQLITE4_LIMIT_COLUMN]] ^(<dt>SQLITE4_LIMIT_COLUMN</dt>
1549
** <dd>The maximum number of columns in a table definition or in the
1550
** result set of a [SELECT] or the maximum number of columns in an index
1551
** or in an ORDER BY or GROUP BY clause.</dd>)^
1552
**
1553
** [[SQLITE4_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE4_LIMIT_EXPR_DEPTH</dt>
1554
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
1555
**
1556
** [[SQLITE4_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE4_LIMIT_COMPOUND_SELECT</dt>
1557
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
1558
**
1559
** [[SQLITE4_LIMIT_VDBE_OP]] ^(<dt>SQLITE4_LIMIT_VDBE_OP</dt>
1560
** <dd>The maximum number of instructions in a virtual machine program
1561
** used to implement an SQL statement. This limit is not currently
1562
** enforced, though that might be added in some future release of
1563
** SQLite.</dd>)^
1564
**
1565
** [[SQLITE4_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE4_LIMIT_FUNCTION_ARG</dt>
1566
** <dd>The maximum number of arguments on a function.</dd>)^
1567
**
1568
** [[SQLITE4_LIMIT_ATTACHED]] ^(<dt>SQLITE4_LIMIT_ATTACHED</dt>
1569
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
1570
**
1571
** [[SQLITE4_LIMIT_LIKE_PATTERN_LENGTH]]
1572
** ^(<dt>SQLITE4_LIMIT_LIKE_PATTERN_LENGTH</dt>
1573
** <dd>The maximum length of the pattern argument to the [LIKE] or
1574
** [GLOB] operators.</dd>)^
1575
**
1576
** [[SQLITE4_LIMIT_VARIABLE_NUMBER]]
1577
** ^(<dt>SQLITE4_LIMIT_VARIABLE_NUMBER</dt>
1578
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
1579
**
1580
** [[SQLITE4_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE4_LIMIT_TRIGGER_DEPTH</dt>
1581
** <dd>The maximum depth of recursion for triggers.</dd>)^
1582
** </dl>
1583
*/
1584
#define SQLITE4_LIMIT_LENGTH 0
1585
#define SQLITE4_LIMIT_SQL_LENGTH 1
1586
#define SQLITE4_LIMIT_COLUMN 2
1587
#define SQLITE4_LIMIT_EXPR_DEPTH 3
1588
#define SQLITE4_LIMIT_COMPOUND_SELECT 4
1589
#define SQLITE4_LIMIT_VDBE_OP 5
1590
#define SQLITE4_LIMIT_FUNCTION_ARG 6
1591
#define SQLITE4_LIMIT_ATTACHED 7
1592
#define SQLITE4_LIMIT_LIKE_PATTERN_LENGTH 8
1593
#define SQLITE4_LIMIT_VARIABLE_NUMBER 9
1594
#define SQLITE4_LIMIT_TRIGGER_DEPTH 10
1595
1596
/*
1597
** CAPIREF: Compiling An SQL Statement
1598
** KEYWORDS: {SQL statement compiler}
1599
**
1600
** To execute an SQL query, it must first be compiled into a byte-code
1601
** program using one of these routines.
1602
**
1603
** The first argument, "db", is a [database connection] obtained from a
1604
** prior successful call to [sqlite4_open()].
1605
** The database connection must not have been closed.
1606
**
1607
** The second argument, "zSql", is the statement to be compiled, encoded
1608
** as either UTF-8 or UTF-16. The sqlite4_prepare()
1609
** interface uses UTF-8, and sqlite4_prepare16()
1610
** uses UTF-16.
1611
**
1612
** ^If the nByte argument is less than zero, then zSql is read up to the
1613
** first zero terminator. ^If nByte is non-negative, then it is the maximum
1614
** number of bytes read from zSql. ^When nByte is non-negative, the
1615
** zSql string ends at either the first '\000' or '\u0000' character or
1616
** the nByte-th byte, whichever comes first. If the caller knows
1617
** that the supplied string is nul-terminated, then there is a small
1618
** performance advantage to be gained by passing an nByte parameter that
1619
** is equal to the number of bytes in the input string <i>including</i>
1620
** the nul-terminator bytes as this saves SQLite from having to
1621
** make a copy of the input string.
1622
**
1623
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
1624
** past the end of the first SQL statement in zSql. These routines only
1625
** compile the first statement in zSql, so *pzTail is left pointing to
1626
** what remains uncompiled.
1627
**
1628
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
1629
** executed using [sqlite4_step()]. ^If there is an error, *ppStmt is set
1630
** to NULL. ^If the input text contains no SQL (if the input is an empty
1631
** string or a comment) then *ppStmt is set to NULL.
1632
** The calling procedure is responsible for deleting the compiled
1633
** SQL statement using [sqlite4_finalize()] after it has finished with it.
1634
** ppStmt may not be NULL.
1635
**
1636
** ^On success, the sqlite4_prepare() family of routines return [SQLITE4_OK];
1637
** otherwise an [error code] is returned.
1638
*/
1639
SQLITE4_API int sqlite4_prepare(
1640
sqlite4 *db, /* Database handle */
1641
const char *zSql, /* SQL statement, UTF-8 encoded */
1642
int nByte, /* Maximum length of zSql in bytes. */
1643
sqlite4_stmt **ppStmt, /* OUT: Statement handle */
1644
const char **pzTail /* OUT: Pointer to unused portion of zSql */
1645
);
1646
1647
/*
1648
** CAPIREF: Retrieving Statement SQL
1649
**
1650
** ^This interface can be used to retrieve a saved copy of the original
1651
** SQL text used to create a [prepared statement] if that statement was
1652
** compiled using either [sqlite4_prepare()] or [sqlite4_prepare16_v2()].
1653
*/
1654
SQLITE4_API const char *sqlite4_sql(sqlite4_stmt *pStmt);
1655
1656
/*
1657
** CAPIREF: Determine If An SQL Statement Writes The Database
1658
**
1659
** ^The sqlite4_stmt_readonly(X) interface returns true (non-zero) if
1660
** and only if the [prepared statement] X makes no direct changes to
1661
** the content of the database file.
1662
**
1663
** Note that [application-defined SQL functions] or
1664
** [virtual tables] might change the database indirectly as a side effect.
1665
** ^(For example, if an application defines a function "eval()" that
1666
** calls [sqlite4_exec()], then the following SQL statement would
1667
** change the database file through side-effects:
1668
**
1669
** <blockquote><pre>
1670
** SELECT eval('DELETE FROM t1') FROM t2;
1671
** </pre></blockquote>
1672
**
1673
** But because the [SELECT] statement does not change the database file
1674
** directly, sqlite4_stmt_readonly() would still return true.)^
1675
**
1676
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
1677
** [SAVEPOINT], and [RELEASE] cause sqlite4_stmt_readonly() to return true,
1678
** since the statements themselves do not actually modify the database but
1679
** rather they control the timing of when other statements modify the
1680
** database. ^The [ATTACH] and [DETACH] statements also cause
1681
** sqlite4_stmt_readonly() to return true since, while those statements
1682
** change the configuration of a database connection, they do not make
1683
** changes to the content of the database files on disk.
1684
*/
1685
SQLITE4_API int sqlite4_stmt_readonly(sqlite4_stmt *pStmt);
1686
1687
/*
1688
** CAPIREF: Determine If A Prepared Statement Has Been Reset
1689
**
1690
** ^The sqlite4_stmt_busy(S) interface returns true (non-zero) if the
1691
** [prepared statement] S has been stepped at least once using
1692
** [sqlite4_step(S)] but has not run to completion and/or has not
1693
** been reset using [sqlite4_reset(S)]. ^The sqlite4_stmt_busy(S)
1694
** interface returns false if S is a NULL pointer. If S is not a
1695
** NULL pointer and is not a pointer to a valid [prepared statement]
1696
** object, then the behavior is undefined and probably undesirable.
1697
**
1698
** This interface can be used in combination [sqlite4_next_stmt()]
1699
** to locate all prepared statements associated with a database
1700
** connection that are in need of being reset. This can be used,
1701
** for example, in diagnostic routines to search for prepared
1702
** statements that are holding a transaction open.
1703
*/
1704
SQLITE4_API int sqlite4_stmt_busy(sqlite4_stmt*);
1705
1706
/*
1707
** CAPIREF: Dynamically Typed Value Object
1708
** KEYWORDS: {protected sqlite4_value} {unprotected sqlite4_value}
1709
**
1710
** SQLite uses the sqlite4_value object to represent all values
1711
** that can be stored in a database table. SQLite uses dynamic typing
1712
** for the values it stores. ^Values stored in sqlite4_value objects
1713
** can be integers, floating point values, strings, BLOBs, or NULL.
1714
**
1715
** An sqlite4_value object may be either "protected" or "unprotected".
1716
** Some interfaces require a protected sqlite4_value. Other interfaces
1717
** will accept either a protected or an unprotected sqlite4_value.
1718
** Every interface that accepts sqlite4_value arguments specifies
1719
** whether or not it requires a protected sqlite4_value.
1720
**
1721
** The terms "protected" and "unprotected" refer to whether or not
1722
** a mutex is held. An internal mutex is held for a protected
1723
** sqlite4_value object but no mutex is held for an unprotected
1724
** sqlite4_value object. If SQLite is compiled to be single-threaded
1725
** (with [SQLITE4_THREADSAFE=0] and with [sqlite4_threadsafe()] returning 0)
1726
** or if SQLite is run in one of reduced mutex modes
1727
** [SQLITE4_CONFIG_SINGLETHREAD] or [SQLITE4_CONFIG_MULTITHREAD]
1728
** then there is no distinction between protected and unprotected
1729
** sqlite4_value objects and they can be used interchangeably. However,
1730
** for maximum code portability it is recommended that applications
1731
** still make the distinction between protected and unprotected
1732
** sqlite4_value objects even when not strictly required.
1733
**
1734
** ^The sqlite4_value objects that are passed as parameters into the
1735
** implementation of [application-defined SQL functions] are protected.
1736
** ^The sqlite4_value object returned by
1737
** [sqlite4_column_value()] is unprotected.
1738
** Unprotected sqlite4_value objects may only be used with
1739
** [sqlite4_result_value()] and [sqlite4_bind_value()].
1740
** The [sqlite4_value_blob | sqlite4_value_type()] family of
1741
** interfaces require protected sqlite4_value objects.
1742
*/
1743
typedef struct Mem sqlite4_value;
1744
1745
/*
1746
** CAPIREF: SQL Function Context Object
1747
**
1748
** The context in which an SQL function executes is stored in an
1749
** sqlite4_context object. ^A pointer to an sqlite4_context object
1750
** is always first parameter to [application-defined SQL functions].
1751
** The application-defined SQL function implementation will pass this
1752
** pointer through into calls to [sqlite4_result_int | sqlite4_result()],
1753
** [sqlite4_aggregate_context()], [sqlite4_user_data()],
1754
** [sqlite4_context_db_handle()], [sqlite4_get_auxdata()],
1755
** and/or [sqlite4_set_auxdata()].
1756
*/
1757
typedef struct sqlite4_context sqlite4_context;
1758
1759
/*
1760
** CAPIREF: Binding Values To Prepared Statements
1761
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
1762
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
1763
**
1764
** ^(In the SQL statement text input to [sqlite4_prepare()] and its variants,
1765
** literals may be replaced by a [parameter] that matches one of following
1766
** templates:
1767
**
1768
** <ul>
1769
** <li> ?
1770
** <li> ?NNN
1771
** <li> :VVV
1772
** <li> @VVV
1773
** <li> $VVV
1774
** </ul>
1775
**
1776
** In the templates above, NNN represents an integer literal,
1777
** and VVV represents an alphanumeric identifier.)^ ^The values of these
1778
** parameters (also called "host parameter names" or "SQL parameters")
1779
** can be set using the sqlite4_bind_*() routines defined here.
1780
**
1781
** ^The first argument to the sqlite4_bind_*() routines is always
1782
** a pointer to the [sqlite4_stmt] object returned from
1783
** [sqlite4_prepare()] or its variants.
1784
**
1785
** ^The second argument is the index of the SQL parameter to be set.
1786
** ^The leftmost SQL parameter has an index of 1. ^When the same named
1787
** SQL parameter is used more than once, second and subsequent
1788
** occurrences have the same index as the first occurrence.
1789
** ^The index for named parameters can be looked up using the
1790
** [sqlite4_bind_parameter_index()] API if desired. ^The index
1791
** for "?NNN" parameters is the value of NNN.
1792
** ^The NNN value must be between 1 and the [sqlite4_limit()]
1793
** parameter [SQLITE4_LIMIT_VARIABLE_NUMBER] (default value: 999).
1794
**
1795
** ^The third argument is the value to bind to the parameter.
1796
**
1797
** ^(In those routines that have a fourth argument, its value is the
1798
** number of bytes in the parameter. To be clear: the value is the
1799
** number of <u>bytes</u> in the value, not the number of characters.)^
1800
** ^If the fourth parameter is negative, the length of the string is
1801
** the number of bytes up to the first zero terminator.
1802
** If a non-negative fourth parameter is provided to sqlite4_bind_text()
1803
** or sqlite4_bind_text16() then that parameter must be the byte offset
1804
** where the NUL terminator would occur assuming the string were NUL
1805
** terminated. If any NUL characters occur at byte offsets less than
1806
** the value of the fourth parameter then the resulting string value will
1807
** contain embedded NULs. The result of expressions involving strings
1808
** with embedded NULs is undefined.
1809
**
1810
** ^The fifth argument to sqlite4_bind_blob(), sqlite4_bind_text(), and
1811
** sqlite4_bind_text16() is a destructor used to dispose of the BLOB or
1812
** string after SQLite has finished with it. ^The destructor is called
1813
** to dispose of the BLOB or string even if the call to sqlite4_bind_blob(),
1814
** sqlite4_bind_text(), or sqlite4_bind_text16() fails.
1815
** ^If the fifth argument is
1816
** the special value [SQLITE4_STATIC], then SQLite assumes that the
1817
** information is in static, unmanaged space and does not need to be freed.
1818
** ^If the fifth argument has the value [SQLITE4_TRANSIENT], then
1819
** SQLite makes its own private copy of the data immediately, before
1820
** the sqlite4_bind_*() routine returns.
1821
**
1822
** ^The sqlite4_bind_zeroblob() routine binds a BLOB of length N that
1823
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
1824
** (just an integer to hold its size) while it is being processed.
1825
** Zeroblobs are intended to serve as placeholders for BLOBs whose
1826
** content is later written using
1827
** [sqlite4_blob_open | incremental BLOB I/O] routines.
1828
** ^A negative value for the zeroblob results in a zero-length BLOB.
1829
**
1830
** ^If any of the sqlite4_bind_*() routines are called with a NULL pointer
1831
** for the [prepared statement] or with a prepared statement for which
1832
** [sqlite4_step()] has been called more recently than [sqlite4_reset()],
1833
** then the call will return [SQLITE4_MISUSE]. If any sqlite4_bind_()
1834
** routine is passed a [prepared statement] that has been finalized, the
1835
** result is undefined and probably harmful.
1836
**
1837
** ^Bindings are not cleared by the [sqlite4_reset()] routine.
1838
** ^Unbound parameters are interpreted as NULL.
1839
**
1840
** ^The sqlite4_bind_* routines return [SQLITE4_OK] on success or an
1841
** [error code] if anything goes wrong.
1842
** ^[SQLITE4_RANGE] is returned if the parameter
1843
** index is out of range. ^[SQLITE4_NOMEM] is returned if malloc() fails.
1844
**
1845
** See also: [sqlite4_bind_parameter_count()],
1846
** [sqlite4_bind_parameter_name()], and [sqlite4_bind_parameter_index()].
1847
*/
1848
SQLITE4_API int sqlite4_bind_blob(sqlite4_stmt*, int, const void*, int n, void(*)(void*));
1849
SQLITE4_API int sqlite4_bind_double(sqlite4_stmt*, int, double);
1850
SQLITE4_API int sqlite4_bind_int(sqlite4_stmt*, int, int);
1851
SQLITE4_API int sqlite4_bind_int64(sqlite4_stmt*, int, sqlite4_int64);
1852
SQLITE4_API int sqlite4_bind_null(sqlite4_stmt*, int);
1853
SQLITE4_API int sqlite4_bind_text(sqlite4_stmt*, int, const char*, int n, void(*)(void*));
1854
SQLITE4_API int sqlite4_bind_text16(sqlite4_stmt*, int, const void*, int, void(*)(void*));
1855
SQLITE4_API int sqlite4_bind_value(sqlite4_stmt*, int, const sqlite4_value*);
1856
SQLITE4_API int sqlite4_bind_zeroblob(sqlite4_stmt*, int, int n);
1857
1858
/*
1859
** CAPIREF: Number Of SQL Parameters
1860
**
1861
** ^This routine can be used to find the number of [SQL parameters]
1862
** in a [prepared statement]. SQL parameters are tokens of the
1863
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
1864
** placeholders for values that are [sqlite4_bind_blob | bound]
1865
** to the parameters at a later time.
1866
**
1867
** ^(This routine actually returns the index of the largest (rightmost)
1868
** parameter. For all forms except ?NNN, this will correspond to the
1869
** number of unique parameters. If parameters of the ?NNN form are used,
1870
** there may be gaps in the list.)^
1871
**
1872
** See also: [sqlite4_bind_blob|sqlite4_bind()],
1873
** [sqlite4_bind_parameter_name()], and
1874
** [sqlite4_bind_parameter_index()].
1875
*/
1876
SQLITE4_API int sqlite4_bind_parameter_count(sqlite4_stmt*);
1877
1878
/*
1879
** CAPIREF: Name Of A Host Parameter
1880
**
1881
** ^The sqlite4_bind_parameter_name(P,N) interface returns
1882
** the name of the N-th [SQL parameter] in the [prepared statement] P.
1883
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
1884
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
1885
** respectively.
1886
** In other words, the initial ":" or "$" or "@" or "?"
1887
** is included as part of the name.)^
1888
** ^Parameters of the form "?" without a following integer have no name
1889
** and are referred to as "nameless" or "anonymous parameters".
1890
**
1891
** ^The first host parameter has an index of 1, not 0.
1892
**
1893
** ^If the value N is out of range or if the N-th parameter is
1894
** nameless, then NULL is returned. ^The returned string is
1895
** always in UTF-8 encoding even if the named parameter was
1896
** originally specified as UTF-16 in [sqlite4_prepare16()] or
1897
** [sqlite4_prepare16_v2()].
1898
**
1899
** See also: [sqlite4_bind_blob|sqlite4_bind()],
1900
** [sqlite4_bind_parameter_count()], and
1901
** [sqlite4_bind_parameter_index()].
1902
*/
1903
SQLITE4_API const char *sqlite4_bind_parameter_name(sqlite4_stmt*, int);
1904
1905
/*
1906
** CAPIREF: Index Of A Parameter With A Given Name
1907
**
1908
** ^Return the index of an SQL parameter given its name. ^The
1909
** index value returned is suitable for use as the second
1910
** parameter to [sqlite4_bind_blob|sqlite4_bind()]. ^A zero
1911
** is returned if no matching parameter is found. ^The parameter
1912
** name must be given in UTF-8 even if the original statement
1913
** was prepared from UTF-16 text using [sqlite4_prepare16_v2()].
1914
**
1915
** See also: [sqlite4_bind_blob|sqlite4_bind()],
1916
** [sqlite4_bind_parameter_count()], and
1917
** [sqlite4_bind_parameter_index()].
1918
*/
1919
SQLITE4_API int sqlite4_bind_parameter_index(sqlite4_stmt*, const char *zName);
1920
1921
/*
1922
** CAPIREF: Reset All Bindings On A Prepared Statement
1923
**
1924
** ^Contrary to the intuition of many, [sqlite4_reset()] does not reset
1925
** the [sqlite4_bind_blob | bindings] on a [prepared statement].
1926
** ^Use this routine to reset all host parameters to NULL.
1927
*/
1928
SQLITE4_API int sqlite4_clear_bindings(sqlite4_stmt*);
1929
1930
/*
1931
** CAPIREF: Number Of Columns In A Result Set
1932
**
1933
** ^Return the number of columns in the result set returned by the
1934
** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
1935
** statement that does not return data (for example an [UPDATE]).
1936
**
1937
** See also: [sqlite4_data_count()]
1938
*/
1939
SQLITE4_API int sqlite4_column_count(sqlite4_stmt *pStmt);
1940
1941
/*
1942
** CAPIREF: Column Names In A Result Set
1943
**
1944
** ^These routines return the name assigned to a particular column
1945
** in the result set of a [SELECT] statement. ^The sqlite4_column_name()
1946
** interface returns a pointer to a zero-terminated UTF-8 string
1947
** and sqlite4_column_name16() returns a pointer to a zero-terminated
1948
** UTF-16 string. ^The first parameter is the [prepared statement]
1949
** that implements the [SELECT] statement. ^The second parameter is the
1950
** column number. ^The leftmost column is number 0.
1951
**
1952
** ^The returned string pointer is valid until either the [prepared statement]
1953
** is destroyed by [sqlite4_finalize()] or until the statement is automatically
1954
** reprepared by the first call to [sqlite4_step()] for a particular run
1955
** or until the next call to
1956
** sqlite4_column_name() or sqlite4_column_name16() on the same column.
1957
**
1958
** ^If sqlite4_malloc() fails during the processing of either routine
1959
** (for example during a conversion from UTF-8 to UTF-16) then a
1960
** NULL pointer is returned.
1961
**
1962
** ^The name of a result column is the value of the "AS" clause for
1963
** that column, if there is an AS clause. If there is no AS clause
1964
** then the name of the column is unspecified and may change from
1965
** one release of SQLite to the next.
1966
*/
1967
SQLITE4_API const char *sqlite4_column_name(sqlite4_stmt*, int N);
1968
SQLITE4_API const void *sqlite4_column_name16(sqlite4_stmt*, int N);
1969
1970
/*
1971
** CAPIREF: Source Of Data In A Query Result
1972
**
1973
** ^These routines provide a means to determine the database, table, and
1974
** table column that is the origin of a particular result column in
1975
** [SELECT] statement.
1976
** ^The name of the database or table or column can be returned as
1977
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
1978
** the database name, the _table_ routines return the table name, and
1979
** the origin_ routines return the column name.
1980
** ^The returned string is valid until the [prepared statement] is destroyed
1981
** using [sqlite4_finalize()] or until the statement is automatically
1982
** reprepared by the first call to [sqlite4_step()] for a particular run
1983
** or until the same information is requested
1984
** again in a different encoding.
1985
**
1986
** ^The names returned are the original un-aliased names of the
1987
** database, table, and column.
1988
**
1989
** ^The first argument to these interfaces is a [prepared statement].
1990
** ^These functions return information about the Nth result column returned by
1991
** the statement, where N is the second function argument.
1992
** ^The left-most column is column 0 for these routines.
1993
**
1994
** ^If the Nth column returned by the statement is an expression or
1995
** subquery and is not a column value, then all of these functions return
1996
** NULL. ^These routine might also return NULL if a memory allocation error
1997
** occurs. ^Otherwise, they return the name of the attached database, table,
1998
** or column that query result column was extracted from.
1999
**
2000
** ^As with all other SQLite APIs, those whose names end with "16" return
2001
** UTF-16 encoded strings and the other functions return UTF-8.
2002
**
2003
** ^These APIs are only available if the library was compiled with the
2004
** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
2005
**
2006
** If two or more threads call one or more of these routines against the same
2007
** prepared statement and column at the same time then the results are
2008
** undefined.
2009
**
2010
** If two or more threads call one or more
2011
** [sqlite4_column_database_name | column metadata interfaces]
2012
** for the same [prepared statement] and result column
2013
** at the same time then the results are undefined.
2014
*/
2015
SQLITE4_API const char *sqlite4_column_database_name(sqlite4_stmt*,int);
2016
SQLITE4_API const void *sqlite4_column_database_name16(sqlite4_stmt*,int);
2017
SQLITE4_API const char *sqlite4_column_table_name(sqlite4_stmt*,int);
2018
SQLITE4_API const void *sqlite4_column_table_name16(sqlite4_stmt*,int);
2019
SQLITE4_API const char *sqlite4_column_origin_name(sqlite4_stmt*,int);
2020
SQLITE4_API const void *sqlite4_column_origin_name16(sqlite4_stmt*,int);
2021
2022
/*
2023
** CAPIREF: Declared Datatype Of A Query Result
2024
**
2025
** ^(The first parameter is a [prepared statement].
2026
** If this statement is a [SELECT] statement and the Nth column of the
2027
** returned result set of that [SELECT] is a table column (not an
2028
** expression or subquery) then the declared type of the table
2029
** column is returned.)^ ^If the Nth column of the result set is an
2030
** expression or subquery, then a NULL pointer is returned.
2031
** ^The returned string is always UTF-8 encoded.
2032
**
2033
** ^(For example, given the database schema:
2034
**
2035
** CREATE TABLE t1(c1 VARIANT);
2036
**
2037
** and the following statement to be compiled:
2038
**
2039
** SELECT c1 + 1, c1 FROM t1;
2040
**
2041
** this routine would return the string "VARIANT" for the second result
2042
** column (i==1), and a NULL pointer for the first result column (i==0).)^
2043
**
2044
** ^SQLite uses dynamic run-time typing. ^So just because a column
2045
** is declared to contain a particular type does not mean that the
2046
** data stored in that column is of the declared type. SQLite is
2047
** strongly typed, but the typing is dynamic not static. ^Type
2048
** is associated with individual values, not with the containers
2049
** used to hold those values.
2050
*/
2051
SQLITE4_API const char *sqlite4_column_decltype(sqlite4_stmt*,int);
2052
SQLITE4_API const void *sqlite4_column_decltype16(sqlite4_stmt*,int);
2053
2054
/*
2055
** CAPIREF: Evaluate An SQL Statement
2056
**
2057
** After a [prepared statement] has been prepared using [sqlite4_prepare()],
2058
** this function must be called one or more times to evaluate the statement.
2059
**
2060
** ^This routine can return any of the other [result codes] or
2061
** [extended result codes].
2062
**
2063
** ^[SQLITE4_BUSY] means that the database engine was unable to acquire the
2064
** database locks it needs to do its job. ^If the statement is a [COMMIT]
2065
** or occurs outside of an explicit transaction, then you can retry the
2066
** statement. If the statement is not a [COMMIT] and occurs within an
2067
** explicit transaction then you should rollback the transaction before
2068
** continuing.
2069
**
2070
** ^[SQLITE4_DONE] means that the statement has finished executing
2071
** successfully. sqlite4_step() should not be called again on this virtual
2072
** machine without first calling [sqlite4_reset()] to reset the virtual
2073
** machine back to its initial state.
2074
**
2075
** ^If the SQL statement being executed returns any data, then [SQLITE4_ROW]
2076
** is returned each time a new row of data is ready for processing by the
2077
** caller. The values may be accessed using the [column access functions].
2078
** sqlite4_step() is called again to retrieve the next row of data.
2079
**
2080
** ^[SQLITE4_ERROR] means that a run-time error (such as a constraint
2081
** violation) has occurred. sqlite4_step() should not be called again on
2082
** the VM. More information may be found by calling [sqlite4_errmsg()].
2083
**
2084
** [SQLITE4_MISUSE] means that the this routine was called inappropriately.
2085
** Perhaps it was called on a [prepared statement] that has
2086
** already been [sqlite4_finalize | finalized] or on one that had
2087
** previously returned [SQLITE4_ERROR] or [SQLITE4_DONE]. Or it could
2088
** be the case that the same database connection is being used by two or
2089
** more threads at the same moment in time.
2090
*/
2091
SQLITE4_API int sqlite4_step(sqlite4_stmt*);
2092
2093
/*
2094
** CAPIREF: Number of columns in a result set
2095
**
2096
** ^The sqlite4_data_count(P) interface returns the number of columns in the
2097
** current row of the result set of [prepared statement] P.
2098
** ^If prepared statement P does not have results ready to return
2099
** (via calls to the [sqlite4_column_int | sqlite4_column_*()] of
2100
** interfaces) then sqlite4_data_count(P) returns 0.
2101
** ^The sqlite4_data_count(P) routine also returns 0 if P is a NULL pointer.
2102
** ^The sqlite4_data_count(P) routine returns 0 if the previous call to
2103
** [sqlite4_step](P) returned [SQLITE4_DONE]. ^The sqlite4_data_count(P)
2104
** will return non-zero if previous call to [sqlite4_step](P) returned
2105
** [SQLITE4_ROW], except in the case of the [PRAGMA incremental_vacuum]
2106
** where it always returns zero since each step of that multi-step
2107
** pragma returns 0 columns of data.
2108
**
2109
** See also: [sqlite4_column_count()]
2110
*/
2111
SQLITE4_API int sqlite4_data_count(sqlite4_stmt *pStmt);
2112
2113
/*
2114
** CAPIREF: Fundamental Datatypes
2115
** KEYWORDS: SQLITE4_TEXT
2116
**
2117
** ^(Every value in SQLite has one of five fundamental datatypes:
2118
**
2119
** <ul>
2120
** <li> 64-bit signed integer
2121
** <li> 64-bit IEEE floating point number
2122
** <li> string
2123
** <li> BLOB
2124
** <li> NULL
2125
** </ul>)^
2126
**
2127
** These constants are codes for each of those types.
2128
*/
2129
#define SQLITE4_INTEGER 1
2130
#define SQLITE4_FLOAT 2
2131
#define SQLITE4_TEXT 3
2132
#define SQLITE4_BLOB 4
2133
#define SQLITE4_NULL 5
2134
2135
/*
2136
** CAPIREF: Result Values From A Query
2137
** KEYWORDS: {column access functions}
2138
**
2139
** These routines form the "result set" interface.
2140
**
2141
** ^These routines return information about a single column of the current
2142
** result row of a query. ^In every case the first argument is a pointer
2143
** to the [prepared statement] that is being evaluated (the [sqlite4_stmt*]
2144
** that was returned from [sqlite4_prepare()].
2145
** and the second argument is the index of the column for which information
2146
** should be returned. ^The leftmost column of the result set has the index 0.
2147
** ^The number of columns in the result can be determined using
2148
** [sqlite4_column_count()].
2149
**
2150
** If the SQL statement does not currently point to a valid row, or if the
2151
** column index is out of range, the result is undefined.
2152
** These routines may only be called when the most recent call to
2153
** [sqlite4_step()] has returned [SQLITE4_ROW] and neither
2154
** [sqlite4_reset()] nor [sqlite4_finalize()] have been called subsequently.
2155
** If any of these routines are called after [sqlite4_reset()] or
2156
** [sqlite4_finalize()] or after [sqlite4_step()] has returned
2157
** something other than [SQLITE4_ROW], the results are undefined.
2158
** If [sqlite4_step()] or [sqlite4_reset()] or [sqlite4_finalize()]
2159
** are called from a different thread while any of these routines
2160
** are pending, then the results are undefined.
2161
**
2162
** ^The sqlite4_column_type() routine returns the
2163
** [SQLITE4_INTEGER | datatype code] for the initial data type
2164
** of the result column. ^The returned value is one of [SQLITE4_INTEGER],
2165
** [SQLITE4_FLOAT], [SQLITE4_TEXT], [SQLITE4_BLOB], or [SQLITE4_NULL]. The value
2166
** returned by sqlite4_column_type() is only meaningful if no type
2167
** conversions have occurred as described below. After a type conversion,
2168
** the value returned by sqlite4_column_type() is undefined. Future
2169
** versions of SQLite may change the behavior of sqlite4_column_type()
2170
** following a type conversion.
2171
**
2172
** ^If the result is a BLOB or UTF-8 string then the sqlite4_column_bytes()
2173
** routine returns the number of bytes in that BLOB or string.
2174
** ^If the result is a UTF-16 string, then sqlite4_column_bytes() converts
2175
** the string to UTF-8 and then returns the number of bytes.
2176
** ^If the result is a numeric value then sqlite4_column_bytes() uses
2177
** [sqlite4_snprintf()] to convert that value to a UTF-8 string and returns
2178
** the number of bytes in that string.
2179
** ^If the result is NULL, then sqlite4_column_bytes() returns zero.
2180
**
2181
** ^If the result is a BLOB or UTF-16 string then the sqlite4_column_bytes16()
2182
** routine returns the number of bytes in that BLOB or string.
2183
** ^If the result is a UTF-8 string, then sqlite4_column_bytes16() converts
2184
** the string to UTF-16 and then returns the number of bytes.
2185
** ^If the result is a numeric value then sqlite4_column_bytes16() uses
2186
** [sqlite4_snprintf()] to convert that value to a UTF-16 string and returns
2187
** the number of bytes in that string.
2188
** ^If the result is NULL, then sqlite4_column_bytes16() returns zero.
2189
**
2190
** ^The values returned by [sqlite4_column_bytes()] and
2191
** [sqlite4_column_bytes16()] do not include the zero terminators at the end
2192
** of the string. ^For clarity: the values returned by
2193
** [sqlite4_column_bytes()] and [sqlite4_column_bytes16()] are the number of
2194
** bytes in the string, not the number of characters.
2195
**
2196
** ^Strings returned by sqlite4_column_text() and sqlite4_column_text16(),
2197
** even empty strings, are always zero-terminated. ^The return
2198
** value from sqlite4_column_blob() for a zero-length BLOB is a NULL pointer.
2199
**
2200
** ^The object returned by [sqlite4_column_value()] is an
2201
** [unprotected sqlite4_value] object. An unprotected sqlite4_value object
2202
** may only be used with [sqlite4_bind_value()] and [sqlite4_result_value()].
2203
** If the [unprotected sqlite4_value] object returned by
2204
** [sqlite4_column_value()] is used in any other way, including calls
2205
** to routines like [sqlite4_value_int()], [sqlite4_value_text()],
2206
** or [sqlite4_value_bytes()], then the behavior is undefined.
2207
**
2208
** These routines attempt to convert the value where appropriate. ^For
2209
** example, if the internal representation is FLOAT and a text result
2210
** is requested, [sqlite4_snprintf()] is used internally to perform the
2211
** conversion automatically. ^(The following table details the conversions
2212
** that are applied:
2213
**
2214
** <blockquote>
2215
** <table border="1">
2216
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
2217
**
2218
** <tr><td> NULL <td> INTEGER <td> Result is 0
2219
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
2220
** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
2221
** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
2222
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
2223
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
2224
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
2225
** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
2226
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
2227
** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
2228
** <tr><td> TEXT <td> INTEGER <td> Use atoi()
2229
** <tr><td> TEXT <td> FLOAT <td> Use atof()
2230
** <tr><td> TEXT <td> BLOB <td> No change
2231
** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
2232
** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
2233
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
2234
** </table>
2235
** </blockquote>)^
2236
**
2237
** The table above makes reference to standard C library functions atoi()
2238
** and atof(). SQLite does not really use these functions. It has its
2239
** own equivalent internal routines. The atoi() and atof() names are
2240
** used in the table for brevity and because they are familiar to most
2241
** C programmers.
2242
**
2243
** Note that when type conversions occur, pointers returned by prior
2244
** calls to sqlite4_column_blob(), sqlite4_column_text(), and/or
2245
** sqlite4_column_text16() may be invalidated.
2246
** Type conversions and pointer invalidations might occur
2247
** in the following cases:
2248
**
2249
** <ul>
2250
** <li> The initial content is a BLOB and sqlite4_column_text() or
2251
** sqlite4_column_text16() is called. A zero-terminator might
2252
** need to be added to the string.</li>
2253
** <li> The initial content is UTF-8 text and sqlite4_column_bytes16() or
2254
** sqlite4_column_text16() is called. The content must be converted
2255
** to UTF-16.</li>
2256
** <li> The initial content is UTF-16 text and sqlite4_column_bytes() or
2257
** sqlite4_column_text() is called. The content must be converted
2258
** to UTF-8.</li>
2259
** </ul>
2260
**
2261
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
2262
** not invalidate a prior pointer, though of course the content of the buffer
2263
** that the prior pointer references will have been modified. Other kinds
2264
** of conversion are done in place when it is possible, but sometimes they
2265
** are not possible and in those cases prior pointers are invalidated.
2266
**
2267
** The safest and easiest to remember policy is to invoke these routines
2268
** in one of the following ways:
2269
**
2270
** <ul>
2271
** <li>sqlite4_column_text() followed by sqlite4_column_bytes()</li>
2272
** <li>sqlite4_column_blob() followed by sqlite4_column_bytes()</li>
2273
** <li>sqlite4_column_text16() followed by sqlite4_column_bytes16()</li>
2274
** </ul>
2275
**
2276
** In other words, you should call sqlite4_column_text(),
2277
** sqlite4_column_blob(), or sqlite4_column_text16() first to force the result
2278
** into the desired format, then invoke sqlite4_column_bytes() or
2279
** sqlite4_column_bytes16() to find the size of the result. Do not mix calls
2280
** to sqlite4_column_text() or sqlite4_column_blob() with calls to
2281
** sqlite4_column_bytes16(), and do not mix calls to sqlite4_column_text16()
2282
** with calls to sqlite4_column_bytes().
2283
**
2284
** ^The pointers returned are valid until a type conversion occurs as
2285
** described above, or until [sqlite4_step()] or [sqlite4_reset()] or
2286
** [sqlite4_finalize()] is called. ^The memory space used to hold strings
2287
** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
2288
** [sqlite4_column_blob()], [sqlite4_column_text()], etc. into
2289
** [sqlite4_free()].
2290
**
2291
** ^(If a memory allocation error occurs during the evaluation of any
2292
** of these routines, a default value is returned. The default value
2293
** is either the integer 0, the floating point number 0.0, or a NULL
2294
** pointer. Subsequent calls to [sqlite4_errcode()] will return
2295
** [SQLITE4_NOMEM].)^
2296
*/
2297
SQLITE4_API const void *sqlite4_column_blob(sqlite4_stmt*, int iCol);
2298
SQLITE4_API int sqlite4_column_bytes(sqlite4_stmt*, int iCol);
2299
SQLITE4_API int sqlite4_column_bytes16(sqlite4_stmt*, int iCol);
2300
SQLITE4_API double sqlite4_column_double(sqlite4_stmt*, int iCol);
2301
SQLITE4_API int sqlite4_column_int(sqlite4_stmt*, int iCol);
2302
SQLITE4_API sqlite4_int64 sqlite4_column_int64(sqlite4_stmt*, int iCol);
2303
SQLITE4_API const unsigned char *sqlite4_column_text(sqlite4_stmt*, int iCol);
2304
SQLITE4_API const void *sqlite4_column_text16(sqlite4_stmt*, int iCol);
2305
SQLITE4_API int sqlite4_column_type(sqlite4_stmt*, int iCol);
2306
SQLITE4_API sqlite4_value *sqlite4_column_value(sqlite4_stmt*, int iCol);
2307
2308
/*
2309
** CAPIREF: Destroy A Prepared Statement Object
2310
**
2311
** ^The sqlite4_finalize() function is called to delete a [prepared statement].
2312
** ^If the most recent evaluation of the statement encountered no errors
2313
** or if the statement is never been evaluated, then sqlite4_finalize() returns
2314
** SQLITE4_OK. ^If the most recent evaluation of statement S failed, then
2315
** sqlite4_finalize(S) returns the appropriate [error code] or
2316
** [extended error code].
2317
**
2318
** ^The sqlite4_finalize(S) routine can be called at any point during
2319
** the life cycle of [prepared statement] S:
2320
** before statement S is ever evaluated, after
2321
** one or more calls to [sqlite4_reset()], or after any call
2322
** to [sqlite4_step()] regardless of whether or not the statement has
2323
** completed execution.
2324
**
2325
** ^Invoking sqlite4_finalize() on a NULL pointer is a harmless no-op.
2326
**
2327
** The application must finalize every [prepared statement] in order to avoid
2328
** resource leaks. It is a grievous error for the application to try to use
2329
** a prepared statement after it has been finalized. Any use of a prepared
2330
** statement after it has been finalized can result in undefined and
2331
** undesirable behavior such as segfaults and heap corruption.
2332
*/
2333
SQLITE4_API int sqlite4_finalize(sqlite4_stmt *pStmt);
2334
2335
/*
2336
** CAPIREF: Reset A Prepared Statement Object
2337
**
2338
** The sqlite4_reset() function is called to reset a [prepared statement]
2339
** object back to its initial state, ready to be re-executed.
2340
** ^Any SQL statement variables that had values bound to them using
2341
** the [sqlite4_bind_blob | sqlite4_bind_*() API] retain their values.
2342
** Use [sqlite4_clear_bindings()] to reset the bindings.
2343
**
2344
** ^The [sqlite4_reset(S)] interface resets the [prepared statement] S
2345
** back to the beginning of its program.
2346
**
2347
** ^If the most recent call to [sqlite4_step(S)] for the
2348
** [prepared statement] S returned [SQLITE4_ROW] or [SQLITE4_DONE],
2349
** or if [sqlite4_step(S)] has never before been called on S,
2350
** then [sqlite4_reset(S)] returns [SQLITE4_OK].
2351
**
2352
** ^If the most recent call to [sqlite4_step(S)] for the
2353
** [prepared statement] S indicated an error, then
2354
** [sqlite4_reset(S)] returns an appropriate [error code].
2355
**
2356
** ^The [sqlite4_reset(S)] interface does not change the values
2357
** of any [sqlite4_bind_blob|bindings] on the [prepared statement] S.
2358
*/
2359
SQLITE4_API int sqlite4_reset(sqlite4_stmt *pStmt);
2360
2361
/*
2362
** CAPIREF: Create Or Redefine SQL Functions
2363
** KEYWORDS: {function creation routines}
2364
** KEYWORDS: {application-defined SQL function}
2365
** KEYWORDS: {application-defined SQL functions}
2366
**
2367
** ^These functions (collectively known as "function creation routines")
2368
** are used to add SQL functions or aggregates or to redefine the behavior
2369
** of existing SQL functions or aggregates. The only differences between
2370
** these routines are the text encoding expected for
2371
** the second parameter (the name of the function being created)
2372
** and the presence or absence of a destructor callback for
2373
** the application data pointer.
2374
**
2375
** ^The first parameter is the [database connection] to which the SQL
2376
** function is to be added. ^If an application uses more than one database
2377
** connection then application-defined SQL functions must be added
2378
** to each database connection separately.
2379
**
2380
** ^The second parameter is the name of the SQL function to be created or
2381
** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
2382
** representation, exclusive of the zero-terminator. ^Note that the name
2383
** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
2384
** ^Any attempt to create a function with a longer name
2385
** will result in [SQLITE4_MISUSE] being returned.
2386
**
2387
** ^The third parameter (nArg)
2388
** is the number of arguments that the SQL function or
2389
** aggregate takes. ^If this parameter is -1, then the SQL function or
2390
** aggregate may take any number of arguments between 0 and the limit
2391
** set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]). If the third
2392
** parameter is less than -1 or greater than 127 then the behavior is
2393
** undefined.
2394
**
2395
** ^The fourth parameter, eTextRep, specifies what
2396
** [SQLITE4_UTF8 | text encoding] this SQL function prefers for
2397
** its parameters. Every SQL function implementation must be able to work
2398
** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
2399
** more efficient with one encoding than another. ^An application may
2400
** invoke sqlite4_create_function() or sqlite4_create_function16() multiple
2401
** times with the same function but with different values of eTextRep.
2402
** ^When multiple implementations of the same function are available, SQLite
2403
** will pick the one that involves the least amount of data conversion.
2404
** If there is only a single implementation which does not care what text
2405
** encoding is used, then the fourth argument should be [SQLITE4_ANY].
2406
**
2407
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
2408
** function can gain access to this pointer using [sqlite4_user_data()].)^
2409
**
2410
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
2411
** pointers to C-language functions that implement the SQL function or
2412
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
2413
** callback only; NULL pointers must be passed as the xStep and xFinal
2414
** parameters. ^An aggregate SQL function requires an implementation of xStep
2415
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
2416
** SQL function or aggregate, pass NULL pointers for all three function
2417
** callbacks.
2418
**
2419
** ^(If the ninth parameter to sqlite4_create_function_v2() is not NULL,
2420
** then it is destructor for the application data pointer.
2421
** The destructor is invoked when the function is deleted, either by being
2422
** overloaded or when the database connection closes.)^
2423
** ^The destructor is also invoked if the call to
2424
** sqlite4_create_function_v2() fails.
2425
** ^When the destructor callback of the tenth parameter is invoked, it
2426
** is passed a single argument which is a copy of the application data
2427
** pointer which was the fifth parameter to sqlite4_create_function_v2().
2428
**
2429
** ^It is permitted to register multiple implementations of the same
2430
** functions with the same name but with either differing numbers of
2431
** arguments or differing preferred text encodings. ^SQLite will use
2432
** the implementation that most closely matches the way in which the
2433
** SQL function is used. ^A function implementation with a non-negative
2434
** nArg parameter is a better match than a function implementation with
2435
** a negative nArg. ^A function where the preferred text encoding
2436
** matches the database encoding is a better
2437
** match than a function where the encoding is different.
2438
** ^A function where the encoding difference is between UTF16le and UTF16be
2439
** is a closer match than a function where the encoding difference is
2440
** between UTF8 and UTF16.
2441
**
2442
** ^Built-in functions may be overloaded by new application-defined functions.
2443
**
2444
** ^An application-defined function is permitted to call other
2445
** SQLite interfaces. However, such calls must not
2446
** close the database connection nor finalize or reset the prepared
2447
** statement in which the function is running.
2448
*/
2449
SQLITE4_API int sqlite4_create_function(
2450
sqlite4 *db,
2451
const char *zFunctionName,
2452
int nArg,
2453
int eTextRep,
2454
void *pApp,
2455
void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
2456
void (*xStep)(sqlite4_context*,int,sqlite4_value**),
2457
void (*xFinal)(sqlite4_context*)
2458
);
2459
SQLITE4_API int sqlite4_create_function16(
2460
sqlite4 *db,
2461
const void *zFunctionName,
2462
int nArg,
2463
int eTextRep,
2464
void *pApp,
2465
void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
2466
void (*xStep)(sqlite4_context*,int,sqlite4_value**),
2467
void (*xFinal)(sqlite4_context*)
2468
);
2469
SQLITE4_API int sqlite4_create_function_v2(
2470
sqlite4 *db,
2471
const char *zFunctionName,
2472
int nArg,
2473
int eTextRep,
2474
void *pApp,
2475
void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
2476
void (*xStep)(sqlite4_context*,int,sqlite4_value**),
2477
void (*xFinal)(sqlite4_context*),
2478
void(*xDestroy)(void*)
2479
);
2480
2481
/*
2482
** CAPIREF: Text Encodings
2483
**
2484
** These constant define integer codes that represent the various
2485
** text encodings supported by SQLite.
2486
*/
2487
#define SQLITE4_UTF8 1
2488
#define SQLITE4_UTF16LE 2
2489
#define SQLITE4_UTF16BE 3
2490
#define SQLITE4_UTF16 4 /* Use native byte order */
2491
#define SQLITE4_ANY 5 /* sqlite4_create_function only */
2492
#define SQLITE4_UTF16_ALIGNED 8 /* sqlite4_create_collation only */
2493
2494
/*
2495
** CAPIREF: Deprecated Functions
2496
** DEPRECATED
2497
**
2498
** These functions are [deprecated]. In order to maintain
2499
** backwards compatibility with older code, these functions continue
2500
** to be supported. However, new applications should avoid
2501
** the use of these functions. To help encourage people to avoid
2502
** using these functions, we are not going to tell you what they do.
2503
*/
2504
#ifndef SQLITE4_OMIT_DEPRECATED
2505
SQLITE4_API SQLITE4_DEPRECATED int sqlite4_aggregate_count(sqlite4_context*);
2506
SQLITE4_API SQLITE4_DEPRECATED int sqlite4_expired(sqlite4_stmt*);
2507
SQLITE4_API SQLITE4_DEPRECATED int sqlite4_transfer_bindings(sqlite4_stmt*, sqlite4_stmt*);
2508
SQLITE4_API SQLITE4_DEPRECATED int sqlite4_global_recover(void);
2509
#endif
2510
2511
/*
2512
** CAPIREF: Obtaining SQL Function Parameter Values
2513
**
2514
** The C-language implementation of SQL functions and aggregates uses
2515
** this set of interface routines to access the parameter values on
2516
** the function or aggregate.
2517
**
2518
** The xFunc (for scalar functions) or xStep (for aggregates) parameters
2519
** to [sqlite4_create_function()] and [sqlite4_create_function16()]
2520
** define callbacks that implement the SQL functions and aggregates.
2521
** The 3rd parameter to these callbacks is an array of pointers to
2522
** [protected sqlite4_value] objects. There is one [sqlite4_value] object for
2523
** each parameter to the SQL function. These routines are used to
2524
** extract values from the [sqlite4_value] objects.
2525
**
2526
** These routines work only with [protected sqlite4_value] objects.
2527
** Any attempt to use these routines on an [unprotected sqlite4_value]
2528
** object results in undefined behavior.
2529
**
2530
** ^These routines work just like the corresponding [column access functions]
2531
** except that these routines take a single [protected sqlite4_value] object
2532
** pointer instead of a [sqlite4_stmt*] pointer and an integer column number.
2533
**
2534
** ^The sqlite4_value_text16() interface extracts a UTF-16 string
2535
** in the native byte-order of the host machine. ^The
2536
** sqlite4_value_text16be() and sqlite4_value_text16le() interfaces
2537
** extract UTF-16 strings as big-endian and little-endian respectively.
2538
**
2539
** ^(The sqlite4_value_numeric_type() interface attempts to apply
2540
** numeric affinity to the value. This means that an attempt is
2541
** made to convert the value to an integer or floating point. If
2542
** such a conversion is possible without loss of information (in other
2543
** words, if the value is a string that looks like a number)
2544
** then the conversion is performed. Otherwise no conversion occurs.
2545
** The [SQLITE4_INTEGER | datatype] after conversion is returned.)^
2546
**
2547
** Please pay particular attention to the fact that the pointer returned
2548
** from [sqlite4_value_blob()], [sqlite4_value_text()], or
2549
** [sqlite4_value_text16()] can be invalidated by a subsequent call to
2550
** [sqlite4_value_bytes()], [sqlite4_value_bytes16()], [sqlite4_value_text()],
2551
** or [sqlite4_value_text16()].
2552
**
2553
** These routines must be called from the same thread as
2554
** the SQL function that supplied the [sqlite4_value*] parameters.
2555
*/
2556
SQLITE4_API const void *sqlite4_value_blob(sqlite4_value*);
2557
SQLITE4_API int sqlite4_value_bytes(sqlite4_value*);
2558
SQLITE4_API int sqlite4_value_bytes16(sqlite4_value*);
2559
SQLITE4_API double sqlite4_value_double(sqlite4_value*);
2560
SQLITE4_API int sqlite4_value_int(sqlite4_value*);
2561
SQLITE4_API sqlite4_int64 sqlite4_value_int64(sqlite4_value*);
2562
SQLITE4_API const unsigned char *sqlite4_value_text(sqlite4_value*);
2563
SQLITE4_API const void *sqlite4_value_text16(sqlite4_value*);
2564
SQLITE4_API const void *sqlite4_value_text16le(sqlite4_value*);
2565
SQLITE4_API const void *sqlite4_value_text16be(sqlite4_value*);
2566
SQLITE4_API int sqlite4_value_type(sqlite4_value*);
2567
SQLITE4_API int sqlite4_value_numeric_type(sqlite4_value*);
2568
2569
/*
2570
** CAPIREF: Obtain Aggregate Function Context
2571
**
2572
** Implementations of aggregate SQL functions use this
2573
** routine to allocate memory for storing their state.
2574
**
2575
** ^The first time the sqlite4_aggregate_context(C,N) routine is called
2576
** for a particular aggregate function, SQLite
2577
** allocates N of memory, zeroes out that memory, and returns a pointer
2578
** to the new memory. ^On second and subsequent calls to
2579
** sqlite4_aggregate_context() for the same aggregate function instance,
2580
** the same buffer is returned. Sqlite3_aggregate_context() is normally
2581
** called once for each invocation of the xStep callback and then one
2582
** last time when the xFinal callback is invoked. ^(When no rows match
2583
** an aggregate query, the xStep() callback of the aggregate function
2584
** implementation is never called and xFinal() is called exactly once.
2585
** In those cases, sqlite4_aggregate_context() might be called for the
2586
** first time from within xFinal().)^
2587
**
2588
** ^The sqlite4_aggregate_context(C,N) routine returns a NULL pointer if N is
2589
** less than or equal to zero or if a memory allocate error occurs.
2590
**
2591
** ^(The amount of space allocated by sqlite4_aggregate_context(C,N) is
2592
** determined by the N parameter on first successful call. Changing the
2593
** value of N in subsequent call to sqlite4_aggregate_context() within
2594
** the same aggregate function instance will not resize the memory
2595
** allocation.)^
2596
**
2597
** ^SQLite automatically frees the memory allocated by
2598
** sqlite4_aggregate_context() when the aggregate query concludes.
2599
**
2600
** The first parameter must be a copy of the
2601
** [sqlite4_context | SQL function context] that is the first parameter
2602
** to the xStep or xFinal callback routine that implements the aggregate
2603
** function.
2604
**
2605
** This routine must be called from the same thread in which
2606
** the aggregate SQL function is running.
2607
*/
2608
SQLITE4_API void *sqlite4_aggregate_context(sqlite4_context*, int nBytes);
2609
2610
/*
2611
** CAPIREF: User Data For Functions
2612
**
2613
** ^The sqlite4_user_data() interface returns a copy of
2614
** the pointer that was the pUserData parameter (the 5th parameter)
2615
** of the [sqlite4_create_function()]
2616
** and [sqlite4_create_function16()] routines that originally
2617
** registered the application defined function.
2618
**
2619
** This routine must be called from the same thread in which
2620
** the application-defined function is running.
2621
*/
2622
SQLITE4_API void *sqlite4_user_data(sqlite4_context*);
2623
2624
/*
2625
** CAPIREF: Database Connection For Functions
2626
**
2627
** ^The sqlite4_context_db_handle() interface returns a copy of
2628
** the pointer to the [database connection] (the 1st parameter)
2629
** of the [sqlite4_create_function()]
2630
** and [sqlite4_create_function16()] routines that originally
2631
** registered the application defined function.
2632
*/
2633
SQLITE4_API sqlite4 *sqlite4_context_db_handle(sqlite4_context*);
2634
SQLITE4_API sqlite4_env *sqlite4_context_env(sqlite4_context*);
2635
2636
/*
2637
** CAPIREF: Function Auxiliary Data
2638
**
2639
** The following two functions may be used by scalar SQL functions to
2640
** associate metadata with argument values. If the same value is passed to
2641
** multiple invocations of the same SQL function during query execution, under
2642
** some circumstances the associated metadata may be preserved. This may
2643
** be used, for example, to add a regular-expression matching scalar
2644
** function. The compiled version of the regular expression is stored as
2645
** metadata associated with the SQL value passed as the regular expression
2646
** pattern. The compiled regular expression can be reused on multiple
2647
** invocations of the same function so that the original pattern string
2648
** does not need to be recompiled on each invocation.
2649
**
2650
** ^The sqlite4_get_auxdata() interface returns a pointer to the metadata
2651
** associated by the sqlite4_set_auxdata() function with the Nth argument
2652
** value to the application-defined function. ^If no metadata has been ever
2653
** been set for the Nth argument of the function, or if the corresponding
2654
** function parameter has changed since the meta-data was set,
2655
** then sqlite4_get_auxdata() returns a NULL pointer.
2656
**
2657
** ^The sqlite4_set_auxdata() interface saves the metadata
2658
** pointed to by its 3rd parameter as the metadata for the N-th
2659
** argument of the application-defined function. Subsequent
2660
** calls to sqlite4_get_auxdata() might return this data, if it has
2661
** not been destroyed.
2662
** ^If it is not NULL, SQLite will invoke the destructor
2663
** function given by the 4th parameter to sqlite4_set_auxdata() on
2664
** the metadata when the corresponding function parameter changes
2665
** or when the SQL statement completes, whichever comes first.
2666
**
2667
** SQLite is free to call the destructor and drop metadata on any
2668
** parameter of any function at any time. ^The only guarantee is that
2669
** the destructor will be called before the metadata is dropped.
2670
**
2671
** ^(In practice, metadata is preserved between function calls for
2672
** expressions that are constant at compile time. This includes literal
2673
** values and [parameters].)^
2674
**
2675
** These routines must be called from the same thread in which
2676
** the SQL function is running.
2677
*/
2678
SQLITE4_API void *sqlite4_get_auxdata(sqlite4_context*, int N);
2679
SQLITE4_API void sqlite4_set_auxdata(sqlite4_context*, int N, void*, void (*)(void*));
2680
2681
2682
/*
2683
** CAPIREF: Constants Defining Special Destructor Behavior
2684
**
2685
** These are special values for the destructor that is passed in as the
2686
** final argument to routines like [sqlite4_result_blob()]. ^If the destructor
2687
** argument is SQLITE4_STATIC, it means that the content pointer is constant
2688
** and will never change. It does not need to be destroyed. ^The
2689
** SQLITE4_TRANSIENT value means that the content will likely change in
2690
** the near future and that SQLite should make its own private copy of
2691
** the content before returning.
2692
**
2693
** The typedef is necessary to work around problems in certain
2694
** C++ compilers. See ticket #2191.
2695
*/
2696
typedef void (*sqlite4_destructor_type)(void*);
2697
SQLITE4_API void sqlite4_dynamic(void*);
2698
#define SQLITE4_STATIC ((sqlite4_destructor_type)0)
2699
#define SQLITE4_TRANSIENT ((sqlite4_destructor_type)-1)
2700
#define SQLITE4_DYNAMIC (sqlite4_dynamic)
2701
2702
2703
/*
2704
** CAPIREF: Setting The Result Of An SQL Function
2705
**
2706
** These routines are used by the xFunc or xFinal callbacks that
2707
** implement SQL functions and aggregates. See
2708
** [sqlite4_create_function()] and [sqlite4_create_function16()]
2709
** for additional information.
2710
**
2711
** These functions work very much like the [parameter binding] family of
2712
** functions used to bind values to host parameters in prepared statements.
2713
** Refer to the [SQL parameter] documentation for additional information.
2714
**
2715
** ^The sqlite4_result_blob() interface sets the result from
2716
** an application-defined function to be the BLOB whose content is pointed
2717
** to by the second parameter and which is N bytes long where N is the
2718
** third parameter.
2719
**
2720
** ^The sqlite4_result_zeroblob() interfaces set the result of
2721
** the application-defined function to be a BLOB containing all zero
2722
** bytes and N bytes in size, where N is the value of the 2nd parameter.
2723
**
2724
** ^The sqlite4_result_double() interface sets the result from
2725
** an application-defined function to be a floating point value specified
2726
** by its 2nd argument.
2727
**
2728
** ^The sqlite4_result_error() and sqlite4_result_error16() functions
2729
** cause the implemented SQL function to throw an exception.
2730
** ^SQLite uses the string pointed to by the
2731
** 2nd parameter of sqlite4_result_error() or sqlite4_result_error16()
2732
** as the text of an error message. ^SQLite interprets the error
2733
** message string from sqlite4_result_error() as UTF-8. ^SQLite
2734
** interprets the string from sqlite4_result_error16() as UTF-16 in native
2735
** byte order. ^If the third parameter to sqlite4_result_error()
2736
** or sqlite4_result_error16() is negative then SQLite takes as the error
2737
** message all text up through the first zero character.
2738
** ^If the third parameter to sqlite4_result_error() or
2739
** sqlite4_result_error16() is non-negative then SQLite takes that many
2740
** bytes (not characters) from the 2nd parameter as the error message.
2741
** ^The sqlite4_result_error() and sqlite4_result_error16()
2742
** routines make a private copy of the error message text before
2743
** they return. Hence, the calling function can deallocate or
2744
** modify the text after they return without harm.
2745
** ^The sqlite4_result_error_code() function changes the error code
2746
** returned by SQLite as a result of an error in a function. ^By default,
2747
** the error code is SQLITE4_ERROR. ^A subsequent call to sqlite4_result_error()
2748
** or sqlite4_result_error16() resets the error code to SQLITE4_ERROR.
2749
**
2750
** ^The sqlite4_result_toobig() interface causes SQLite to throw an error
2751
** indicating that a string or BLOB is too long to represent.
2752
**
2753
** ^The sqlite4_result_nomem() interface causes SQLite to throw an error
2754
** indicating that a memory allocation failed.
2755
**
2756
** ^The sqlite4_result_int() interface sets the return value
2757
** of the application-defined function to be the 32-bit signed integer
2758
** value given in the 2nd argument.
2759
** ^The sqlite4_result_int64() interface sets the return value
2760
** of the application-defined function to be the 64-bit signed integer
2761
** value given in the 2nd argument.
2762
**
2763
** ^The sqlite4_result_null() interface sets the return value
2764
** of the application-defined function to be NULL.
2765
**
2766
** ^The sqlite4_result_text(), sqlite4_result_text16(),
2767
** sqlite4_result_text16le(), and sqlite4_result_text16be() interfaces
2768
** set the return value of the application-defined function to be
2769
** a text string which is represented as UTF-8, UTF-16 native byte order,
2770
** UTF-16 little endian, or UTF-16 big endian, respectively.
2771
** ^SQLite takes the text result from the application from
2772
** the 2nd parameter of the sqlite4_result_text* interfaces.
2773
** ^If the 3rd parameter to the sqlite4_result_text* interfaces
2774
** is negative, then SQLite takes result text from the 2nd parameter
2775
** through the first zero character.
2776
** ^If the 3rd parameter to the sqlite4_result_text* interfaces
2777
** is non-negative, then as many bytes (not characters) of the text
2778
** pointed to by the 2nd parameter are taken as the application-defined
2779
** function result. If the 3rd parameter is non-negative, then it
2780
** must be the byte offset into the string where the NUL terminator would
2781
** appear if the string where NUL terminated. If any NUL characters occur
2782
** in the string at a byte offset that is less than the value of the 3rd
2783
** parameter, then the resulting string will contain embedded NULs and the
2784
** result of expressions operating on strings with embedded NULs is undefined.
2785
** ^If the 4th parameter to the sqlite4_result_text* interfaces
2786
** or sqlite4_result_blob is a non-NULL pointer, then SQLite calls that
2787
** function as the destructor on the text or BLOB result when it has
2788
** finished using that result.
2789
** ^If the 4th parameter to the sqlite4_result_text* interfaces or to
2790
** sqlite4_result_blob is the special constant SQLITE4_STATIC, then SQLite
2791
** assumes that the text or BLOB result is in constant space and does not
2792
** copy the content of the parameter nor call a destructor on the content
2793
** when it has finished using that result.
2794
** ^If the 4th parameter to the sqlite4_result_text* interfaces
2795
** or sqlite4_result_blob is the special constant SQLITE4_TRANSIENT
2796
** then SQLite makes a copy of the result into space obtained from
2797
** from [sqlite4_malloc()] before it returns.
2798
**
2799
** ^The sqlite4_result_value() interface sets the result of
2800
** the application-defined function to be a copy the
2801
** [unprotected sqlite4_value] object specified by the 2nd parameter. ^The
2802
** sqlite4_result_value() interface makes a copy of the [sqlite4_value]
2803
** so that the [sqlite4_value] specified in the parameter may change or
2804
** be deallocated after sqlite4_result_value() returns without harm.
2805
** ^A [protected sqlite4_value] object may always be used where an
2806
** [unprotected sqlite4_value] object is required, so either
2807
** kind of [sqlite4_value] object can be used with this interface.
2808
**
2809
** If these routines are called from within the different thread
2810
** than the one containing the application-defined function that received
2811
** the [sqlite4_context] pointer, the results are undefined.
2812
*/
2813
SQLITE4_API void sqlite4_result_blob(sqlite4_context*, const void*, int, void(*)(void*));
2814
SQLITE4_API void sqlite4_result_double(sqlite4_context*, double);
2815
SQLITE4_API void sqlite4_result_error(sqlite4_context*, const char*, int);
2816
SQLITE4_API void sqlite4_result_error16(sqlite4_context*, const void*, int);
2817
SQLITE4_API void sqlite4_result_error_toobig(sqlite4_context*);
2818
SQLITE4_API void sqlite4_result_error_nomem(sqlite4_context*);
2819
SQLITE4_API void sqlite4_result_error_code(sqlite4_context*, int);
2820
SQLITE4_API void sqlite4_result_int(sqlite4_context*, int);
2821
SQLITE4_API void sqlite4_result_int64(sqlite4_context*, sqlite4_int64);
2822
SQLITE4_API void sqlite4_result_null(sqlite4_context*);
2823
SQLITE4_API void sqlite4_result_text(sqlite4_context*, const char*, int, void(*)(void*));
2824
SQLITE4_API void sqlite4_result_text16(sqlite4_context*, const void*, int, void(*)(void*));
2825
SQLITE4_API void sqlite4_result_text16le(sqlite4_context*, const void*, int,void(*)(void*));
2826
SQLITE4_API void sqlite4_result_text16be(sqlite4_context*, const void*, int,void(*)(void*));
2827
SQLITE4_API void sqlite4_result_value(sqlite4_context*, sqlite4_value*);
2828
SQLITE4_API void sqlite4_result_zeroblob(sqlite4_context*, int n);
2829
2830
/*
2831
** CAPIREF: Define New Collating Sequences
2832
**
2833
** ^This function adds, removes, or modifies a [collation] associated
2834
** with the [database connection] specified as the first argument.
2835
**
2836
** ^The name of the collation is a UTF-8 string.
2837
** ^Collation names that compare equal according to [sqlite4_strnicmp()] are
2838
** considered to be the same name.
2839
**
2840
** ^(The third argument (eTextRep) must be one of the constants:
2841
** <ul>
2842
** <li> [SQLITE4_UTF8],
2843
** <li> [SQLITE4_UTF16LE],
2844
** <li> [SQLITE4_UTF16BE],
2845
** <li> [SQLITE4_UTF16], or
2846
** <li> [SQLITE4_UTF16_ALIGNED].
2847
** </ul>)^
2848
** ^The eTextRep argument determines the encoding of strings passed
2849
** to the collating function callback, xCallback.
2850
** ^The [SQLITE4_UTF16] and [SQLITE4_UTF16_ALIGNED] values for eTextRep
2851
** force strings to be UTF16 with native byte order.
2852
** ^The [SQLITE4_UTF16_ALIGNED] value for eTextRep forces strings to begin
2853
** on an even byte address.
2854
**
2855
** ^The fourth argument, pArg, is an application data pointer that is passed
2856
** through as the first argument to the collating function callback.
2857
**
2858
** ^The fifth argument, xCallback, is a pointer to the comparision function.
2859
** ^The sixth argument, xMakeKey, is a pointer to a function that generates
2860
** a sort key.
2861
** ^Multiple functions can be registered using the same name but
2862
** with different eTextRep parameters and SQLite will use whichever
2863
** function requires the least amount of data transformation.
2864
** ^If the xCallback argument is NULL then the collating function is
2865
** deleted. ^When all collating functions having the same name are deleted,
2866
** that collation is no longer usable.
2867
**
2868
** ^The collating function callback is invoked with a copy of the pArg
2869
** application data pointer and with two strings in the encoding specified
2870
** by the eTextRep argument. The collating function must return an
2871
** integer that is negative, zero, or positive
2872
** if the first string is less than, equal to, or greater than the second,
2873
** respectively. A collating function must always return the same answer
2874
** given the same inputs. If two or more collating functions are registered
2875
** to the same collation name (using different eTextRep values) then all
2876
** must give an equivalent answer when invoked with equivalent strings.
2877
** The collating function must obey the following properties for all
2878
** strings A, B, and C:
2879
**
2880
** <ol>
2881
** <li> If A==B then B==A.
2882
** <li> If A==B and B==C then A==C.
2883
** <li> If A&lt;B THEN B&gt;A.
2884
** <li> If A&lt;B and B&lt;C then A&lt;C.
2885
** </ol>
2886
**
2887
** If a collating function fails any of the above constraints and that
2888
** collating function is registered and used, then the behavior of SQLite
2889
** is undefined.
2890
**
2891
** ^Collating functions are deleted when they are overridden by later
2892
** calls to the collation creation functions or when the
2893
** [database connection] is closed using [sqlite4_close()].
2894
**
2895
** ^The xDestroy callback is <u>not</u> called if the
2896
** sqlite4_create_collation() function fails. Applications that invoke
2897
** sqlite4_create_collation() with a non-NULL xDestroy argument should
2898
** check the return code and dispose of the application data pointer
2899
** themselves rather than expecting SQLite to deal with it for them.
2900
** This is different from every other SQLite interface. The inconsistency
2901
** is unfortunate but cannot be changed without breaking backwards
2902
** compatibility.
2903
**
2904
** See also: [sqlite4_collation_needed()] and [sqlite4_collation_needed16()].
2905
*/
2906
SQLITE4_API int sqlite4_create_collation(
2907
sqlite4*,
2908
const char *zName,
2909
int eTextRep,
2910
void *pArg,
2911
int(*xCompare)(void*,int,const void*,int,const void*),
2912
int(*xMakeKey)(void*,int,const void*,int,void*),
2913
void(*xDestroy)(void*)
2914
);
2915
2916
/*
2917
** CAPIREF: Collation Needed Callbacks
2918
**
2919
** ^To avoid having to register all collation sequences before a database
2920
** can be used, a single callback function may be registered with the
2921
** [database connection] to be invoked whenever an undefined collation
2922
** sequence is required.
2923
**
2924
** ^If the function is registered using the sqlite4_collation_needed() API,
2925
** then it is passed the names of undefined collation sequences as strings
2926
** encoded in UTF-8. ^If sqlite4_collation_needed16() is used,
2927
** the names are passed as UTF-16 in machine native byte order.
2928
** ^A call to either function replaces the existing collation-needed callback.
2929
**
2930
** ^(When the callback is invoked, the first argument passed is a copy
2931
** of the second argument to sqlite4_collation_needed() or
2932
** sqlite4_collation_needed16(). The second argument is the database
2933
** connection. The third argument is one of [SQLITE4_UTF8], [SQLITE4_UTF16BE],
2934
** or [SQLITE4_UTF16LE], indicating the most desirable form of the collation
2935
** sequence function required. The fourth parameter is the name of the
2936
** required collation sequence.)^
2937
**
2938
** The callback function should register the desired collation using
2939
** [sqlite4_create_collation()], [sqlite4_create_collation16()], or
2940
** [sqlite4_create_collation_v2()].
2941
*/
2942
SQLITE4_API int sqlite4_collation_needed(
2943
sqlite4*,
2944
void*,
2945
void(*)(void*,sqlite4*,int eTextRep,const char*)
2946
);
2947
SQLITE4_API int sqlite4_collation_needed16(
2948
sqlite4*,
2949
void*,
2950
void(*)(void*,sqlite4*,int eTextRep,const void*)
2951
);
2952
2953
/*
2954
** CAPIREF: Suspend Execution For A Short Time
2955
**
2956
** The sqlite4_sleep() function causes the current thread to suspend execution
2957
** for at least a number of milliseconds specified in its parameter.
2958
**
2959
** If the operating system does not support sleep requests with
2960
** millisecond time resolution, then the time will be rounded up to
2961
** the nearest second. The number of milliseconds of sleep actually
2962
** requested from the operating system is returned.
2963
**
2964
** ^SQLite implements this interface by calling the xSleep()
2965
** method of the default [sqlite4_vfs] object. If the xSleep() method
2966
** of the default VFS is not implemented correctly, or not implemented at
2967
** all, then the behavior of sqlite4_sleep() may deviate from the description
2968
** in the previous paragraphs.
2969
*/
2970
SQLITE4_API int sqlite4_sleep(int);
2971
2972
/*
2973
** CAPIREF: Test For Auto-Commit Mode
2974
** KEYWORDS: {autocommit mode}
2975
**
2976
** ^The sqlite4_get_autocommit() interface returns non-zero or
2977
** zero if the given database connection is or is not in autocommit mode,
2978
** respectively. ^Autocommit mode is on by default.
2979
** ^Autocommit mode is disabled by a [BEGIN] statement.
2980
** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
2981
**
2982
** If certain kinds of errors occur on a statement within a multi-statement
2983
** transaction (errors including [SQLITE4_FULL], [SQLITE4_IOERR],
2984
** [SQLITE4_NOMEM], [SQLITE4_BUSY], and [SQLITE4_INTERRUPT]) then the
2985
** transaction might be rolled back automatically. The only way to
2986
** find out whether SQLite automatically rolled back the transaction after
2987
** an error is to use this function.
2988
**
2989
** If another thread changes the autocommit status of the database
2990
** connection while this routine is running, then the return value
2991
** is undefined.
2992
*/
2993
SQLITE4_API int sqlite4_get_autocommit(sqlite4*);
2994
2995
/*
2996
** CAPIREF: Find The Database Handle Of A Prepared Statement
2997
**
2998
** ^The sqlite4_db_handle interface returns the [database connection] handle
2999
** to which a [prepared statement] belongs. ^The [database connection]
3000
** returned by sqlite4_db_handle is the same [database connection]
3001
** that was the first argument
3002
** to the [sqlite4_prepare()] call (or its variants) that was used to
3003
** create the statement in the first place.
3004
*/
3005
SQLITE4_API sqlite4 *sqlite4_db_handle(sqlite4_stmt*);
3006
3007
/*
3008
** CAPIREF: Return The Filename For A Database Connection
3009
**
3010
** ^The sqlite4_db_filename(D,N) interface returns a pointer to a filename
3011
** associated with database N of connection D. ^The main database file
3012
** has the name "main". If there is no attached database N on the database
3013
** connection D, or if database N is a temporary or in-memory database, then
3014
** a NULL pointer is returned.
3015
**
3016
** ^The filename returned by this function is the output of the
3017
** xFullPathname method of the [VFS]. ^In other words, the filename
3018
** will be an absolute pathname, even if the filename used
3019
** to open the database originally was a URI or relative pathname.
3020
*/
3021
SQLITE4_API const char *sqlite4_db_filename(sqlite4 *db, const char *zDbName);
3022
3023
/*
3024
** CAPIREF: Find the next prepared statement
3025
**
3026
** ^This interface returns a pointer to the next [prepared statement] after
3027
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
3028
** then this interface returns a pointer to the first prepared statement
3029
** associated with the database connection pDb. ^If no prepared statement
3030
** satisfies the conditions of this routine, it returns NULL.
3031
**
3032
** The [database connection] pointer D in a call to
3033
** [sqlite4_next_stmt(D,S)] must refer to an open database
3034
** connection and in particular must not be a NULL pointer.
3035
*/
3036
SQLITE4_API sqlite4_stmt *sqlite4_next_stmt(sqlite4 *pDb, sqlite4_stmt *pStmt);
3037
3038
/*
3039
** CAPIREF: Free Memory Used By A Database Connection
3040
**
3041
** ^The sqlite4_db_release_memory(D) interface attempts to free as much heap
3042
** memory as possible from database connection D.
3043
*/
3044
SQLITE4_API int sqlite4_db_release_memory(sqlite4*);
3045
3046
/*
3047
** CAPIREF: Extract Metadata About A Column Of A Table
3048
**
3049
** ^This routine returns metadata about a specific column of a specific
3050
** database table accessible using the [database connection] handle
3051
** passed as the first function argument.
3052
**
3053
** ^The column is identified by the second, third and fourth parameters to
3054
** this function. ^The second parameter is either the name of the database
3055
** (i.e. "main", "temp", or an attached database) containing the specified
3056
** table or NULL. ^If it is NULL, then all attached databases are searched
3057
** for the table using the same algorithm used by the database engine to
3058
** resolve unqualified table references.
3059
**
3060
** ^The third and fourth parameters to this function are the table and column
3061
** name of the desired column, respectively. Neither of these parameters
3062
** may be NULL.
3063
**
3064
** ^Metadata is returned by writing to the memory locations passed as the 5th
3065
** and subsequent parameters to this function. ^Any of these arguments may be
3066
** NULL, in which case the corresponding element of metadata is omitted.
3067
**
3068
** ^(<blockquote>
3069
** <table border="1">
3070
** <tr><th> Parameter <th> Output<br>Type <th> Description
3071
**
3072
** <tr><td> 5th <td> const char* <td> Data type
3073
** <tr><td> 6th <td> const char* <td> Name of default collation sequence
3074
** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
3075
** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
3076
** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
3077
** </table>
3078
** </blockquote>)^
3079
**
3080
** ^The memory pointed to by the character pointers returned for the
3081
** declaration type and collation sequence is valid only until the next
3082
** call to any SQLite API function.
3083
**
3084
** ^If the specified table is actually a view, an [error code] is returned.
3085
**
3086
** ^If the specified column is "rowid", "oid" or "_rowid_" and an
3087
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
3088
** parameters are set for the explicitly declared column. ^(If there is no
3089
** explicitly declared [INTEGER PRIMARY KEY] column, then the output
3090
** parameters are set as follows:
3091
**
3092
** <pre>
3093
** data type: "INTEGER"
3094
** collation sequence: "BINARY"
3095
** not null: 0
3096
** primary key: 1
3097
** auto increment: 0
3098
** </pre>)^
3099
**
3100
** ^(This function may load one or more schemas from database files. If an
3101
** error occurs during this process, or if the requested table or column
3102
** cannot be found, an [error code] is returned and an error message left
3103
** in the [database connection] (to be retrieved using sqlite4_errmsg()).)^
3104
**
3105
** ^This API is only available if the library was compiled with the
3106
** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
3107
*/
3108
SQLITE4_API int sqlite4_table_column_metadata(
3109
sqlite4 *db, /* Connection handle */
3110
const char *zDbName, /* Database name or NULL */
3111
const char *zTableName, /* Table name */
3112
const char *zColumnName, /* Column name */
3113
char const **pzDataType, /* OUTPUT: Declared data type */
3114
char const **pzCollSeq, /* OUTPUT: Collation sequence name */
3115
int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
3116
int *pPrimaryKey, /* OUTPUT: True if column part of PK */
3117
int *pAutoinc /* OUTPUT: True if column is auto-increment */
3118
);
3119
3120
/*
3121
** CAPIREF: Load An Extension
3122
**
3123
** ^This interface loads an SQLite extension library from the named file.
3124
**
3125
** ^The sqlite4_load_extension() interface attempts to load an
3126
** SQLite extension library contained in the file zFile.
3127
**
3128
** ^The entry point is zProc.
3129
** ^zProc may be 0, in which case the name of the entry point
3130
** defaults to "sqlite4_extension_init".
3131
** ^The sqlite4_load_extension() interface returns
3132
** [SQLITE4_OK] on success and [SQLITE4_ERROR] if something goes wrong.
3133
** ^If an error occurs and pzErrMsg is not 0, then the
3134
** [sqlite4_load_extension()] interface shall attempt to
3135
** fill *pzErrMsg with error message text stored in memory
3136
** obtained from [sqlite4_malloc()]. The calling function
3137
** should free this memory by calling [sqlite4_free()].
3138
**
3139
** ^Extension loading must be enabled using
3140
** [sqlite4_enable_load_extension()] prior to calling this API,
3141
** otherwise an error will be returned.
3142
**
3143
** See also the [load_extension() SQL function].
3144
*/
3145
SQLITE4_API int sqlite4_load_extension(
3146
sqlite4 *db, /* Load the extension into this database connection */
3147
const char *zFile, /* Name of the shared library containing extension */
3148
const char *zProc, /* Entry point. Derived from zFile if 0 */
3149
char **pzErrMsg /* Put error message here if not 0 */
3150
);
3151
3152
/*
3153
** CAPIREF: Enable Or Disable Extension Loading
3154
**
3155
** ^So as not to open security holes in older applications that are
3156
** unprepared to deal with extension loading, and as a means of disabling
3157
** extension loading while evaluating user-entered SQL, the following API
3158
** is provided to turn the [sqlite4_load_extension()] mechanism on and off.
3159
**
3160
** ^Extension loading is off by default. See ticket #1863.
3161
** ^Call the sqlite4_enable_load_extension() routine with onoff==1
3162
** to turn extension loading on and call it with onoff==0 to turn
3163
** it back off again.
3164
*/
3165
SQLITE4_API int sqlite4_enable_load_extension(sqlite4 *db, int onoff);
3166
3167
/*
3168
** The interface to the virtual-table mechanism is currently considered
3169
** to be experimental. The interface might change in incompatible ways.
3170
** If this is a problem for you, do not use the interface at this time.
3171
**
3172
** When the virtual-table mechanism stabilizes, we will declare the
3173
** interface fixed, support it indefinitely, and remove this comment.
3174
*/
3175
3176
/*
3177
** Structures used by the virtual table interface
3178
*/
3179
typedef struct sqlite4_vtab sqlite4_vtab;
3180
typedef struct sqlite4_index_info sqlite4_index_info;
3181
typedef struct sqlite4_vtab_cursor sqlite4_vtab_cursor;
3182
typedef struct sqlite4_module sqlite4_module;
3183
3184
/*
3185
** CAPIREF: Virtual Table Object
3186
** KEYWORDS: sqlite4_module {virtual table module}
3187
**
3188
** This structure, sometimes called a "virtual table module",
3189
** defines the implementation of a [virtual tables].
3190
** This structure consists mostly of methods for the module.
3191
**
3192
** ^A virtual table module is created by filling in a persistent
3193
** instance of this structure and passing a pointer to that instance
3194
** to [sqlite4_create_module()] or [sqlite4_create_module_v2()].
3195
** ^The registration remains valid until it is replaced by a different
3196
** module or until the [database connection] closes. The content
3197
** of this structure must not change while it is registered with
3198
** any database connection.
3199
*/
3200
struct sqlite4_module {
3201
int iVersion;
3202
int (*xCreate)(sqlite4*, void *pAux,
3203
int argc, const char *const*argv,
3204
sqlite4_vtab **ppVTab, char**);
3205
int (*xConnect)(sqlite4*, void *pAux,
3206
int argc, const char *const*argv,
3207
sqlite4_vtab **ppVTab, char**);
3208
int (*xBestIndex)(sqlite4_vtab *pVTab, sqlite4_index_info*);
3209
int (*xDisconnect)(sqlite4_vtab *pVTab);
3210
int (*xDestroy)(sqlite4_vtab *pVTab);
3211
int (*xOpen)(sqlite4_vtab *pVTab, sqlite4_vtab_cursor **ppCursor);
3212
int (*xClose)(sqlite4_vtab_cursor*);
3213
int (*xFilter)(sqlite4_vtab_cursor*, int idxNum, const char *idxStr,
3214
int argc, sqlite4_value **argv);
3215
int (*xNext)(sqlite4_vtab_cursor*);
3216
int (*xEof)(sqlite4_vtab_cursor*);
3217
int (*xColumn)(sqlite4_vtab_cursor*, sqlite4_context*, int);
3218
int (*xRowid)(sqlite4_vtab_cursor*, sqlite4_int64 *pRowid);
3219
int (*xUpdate)(sqlite4_vtab *, int, sqlite4_value **, sqlite4_int64 *);
3220
int (*xBegin)(sqlite4_vtab *pVTab);
3221
int (*xSync)(sqlite4_vtab *pVTab);
3222
int (*xCommit)(sqlite4_vtab *pVTab);
3223
int (*xRollback)(sqlite4_vtab *pVTab);
3224
int (*xFindFunction)(sqlite4_vtab *pVtab, int nArg, const char *zName,
3225
void (**pxFunc)(sqlite4_context*,int,sqlite4_value**),
3226
void **ppArg);
3227
int (*xRename)(sqlite4_vtab *pVtab, const char *zNew);
3228
/* The methods above are in version 1 of the sqlite_module object. Those
3229
** below are for version 2 and greater. */
3230
int (*xSavepoint)(sqlite4_vtab *pVTab, int);
3231
int (*xRelease)(sqlite4_vtab *pVTab, int);
3232
int (*xRollbackTo)(sqlite4_vtab *pVTab, int);
3233
};
3234
3235
/*
3236
** CAPIREF: Virtual Table Indexing Information
3237
** KEYWORDS: sqlite4_index_info
3238
**
3239
** The sqlite4_index_info structure and its substructures is used as part
3240
** of the [virtual table] interface to
3241
** pass information into and receive the reply from the [xBestIndex]
3242
** method of a [virtual table module]. The fields under **Inputs** are the
3243
** inputs to xBestIndex and are read-only. xBestIndex inserts its
3244
** results into the **Outputs** fields.
3245
**
3246
** ^(The aConstraint[] array records WHERE clause constraints of the form:
3247
**
3248
** <blockquote>column OP expr</blockquote>
3249
**
3250
** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^ ^(The particular operator is
3251
** stored in aConstraint[].op using one of the
3252
** [SQLITE4_INDEX_CONSTRAINT_EQ | SQLITE4_INDEX_CONSTRAINT_ values].)^
3253
** ^(The index of the column is stored in
3254
** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
3255
** expr on the right-hand side can be evaluated (and thus the constraint
3256
** is usable) and false if it cannot.)^
3257
**
3258
** ^The optimizer automatically inverts terms of the form "expr OP column"
3259
** and makes other simplifications to the WHERE clause in an attempt to
3260
** get as many WHERE clause terms into the form shown above as possible.
3261
** ^The aConstraint[] array only reports WHERE clause terms that are
3262
** relevant to the particular virtual table being queried.
3263
**
3264
** ^Information about the ORDER BY clause is stored in aOrderBy[].
3265
** ^Each term of aOrderBy records a column of the ORDER BY clause.
3266
**
3267
** The [xBestIndex] method must fill aConstraintUsage[] with information
3268
** about what parameters to pass to xFilter. ^If argvIndex>0 then
3269
** the right-hand side of the corresponding aConstraint[] is evaluated
3270
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
3271
** is true, then the constraint is assumed to be fully handled by the
3272
** virtual table and is not checked again by SQLite.)^
3273
**
3274
** ^The idxNum and idxPtr values are recorded and passed into the
3275
** [xFilter] method.
3276
** ^[sqlite4_free()] is used to free idxPtr if and only if
3277
** needToFreeIdxPtr is true.
3278
**
3279
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
3280
** the correct order to satisfy the ORDER BY clause so that no separate
3281
** sorting step is required.
3282
**
3283
** ^The estimatedCost value is an estimate of the cost of doing the
3284
** particular lookup. A full scan of a table with N entries should have
3285
** a cost of N. A binary search of a table of N entries should have a
3286
** cost of approximately log(N).
3287
*/
3288
struct sqlite4_index_info {
3289
/* Inputs */
3290
int nConstraint; /* Number of entries in aConstraint */
3291
struct sqlite4_index_constraint {
3292
int iColumn; /* Column on left-hand side of constraint */
3293
unsigned char op; /* Constraint operator */
3294
unsigned char usable; /* True if this constraint is usable */
3295
int iTermOffset; /* Used internally - xBestIndex should ignore */
3296
} *aConstraint; /* Table of WHERE clause constraints */
3297
int nOrderBy; /* Number of terms in the ORDER BY clause */
3298
struct sqlite4_index_orderby {
3299
int iColumn; /* Column number */
3300
unsigned char desc; /* True for DESC. False for ASC. */
3301
} *aOrderBy; /* The ORDER BY clause */
3302
/* Outputs */
3303
struct sqlite4_index_constraint_usage {
3304
int argvIndex; /* if >0, constraint is part of argv to xFilter */
3305
unsigned char omit; /* Do not code a test for this constraint */
3306
} *aConstraintUsage;
3307
int idxNum; /* Number used to identify the index */
3308
char *idxStr; /* String, possibly obtained from sqlite4_malloc */
3309
int needToFreeIdxStr; /* Free idxStr using sqlite4_free() if true */
3310
int orderByConsumed; /* True if output is already ordered */
3311
double estimatedCost; /* Estimated cost of using this index */
3312
};
3313
3314
/*
3315
** CAPIREF: Virtual Table Constraint Operator Codes
3316
**
3317
** These macros defined the allowed values for the
3318
** [sqlite4_index_info].aConstraint[].op field. Each value represents
3319
** an operator that is part of a constraint term in the wHERE clause of
3320
** a query that uses a [virtual table].
3321
*/
3322
#define SQLITE4_INDEX_CONSTRAINT_EQ 2
3323
#define SQLITE4_INDEX_CONSTRAINT_GT 4
3324
#define SQLITE4_INDEX_CONSTRAINT_LE 8
3325
#define SQLITE4_INDEX_CONSTRAINT_LT 16
3326
#define SQLITE4_INDEX_CONSTRAINT_GE 32
3327
#define SQLITE4_INDEX_CONSTRAINT_MATCH 64
3328
3329
/*
3330
** CAPIREF: Register A Virtual Table Implementation
3331
**
3332
** ^These routines are used to register a new [virtual table module] name.
3333
** ^Module names must be registered before
3334
** creating a new [virtual table] using the module and before using a
3335
** preexisting [virtual table] for the module.
3336
**
3337
** ^The module name is registered on the [database connection] specified
3338
** by the first parameter. ^The name of the module is given by the
3339
** second parameter. ^The third parameter is a pointer to
3340
** the implementation of the [virtual table module]. ^The fourth
3341
** parameter is an arbitrary client data pointer that is passed through
3342
** into the [xCreate] and [xConnect] methods of the virtual table module
3343
** when a new virtual table is be being created or reinitialized.
3344
**
3345
** ^The sqlite4_create_module_v2() interface has a fifth parameter which
3346
** is a pointer to a destructor for the pClientData. ^SQLite will
3347
** invoke the destructor function (if it is not NULL) when SQLite
3348
** no longer needs the pClientData pointer. ^The destructor will also
3349
** be invoked if the call to sqlite4_create_module_v2() fails.
3350
** ^The sqlite4_create_module()
3351
** interface is equivalent to sqlite4_create_module_v2() with a NULL
3352
** destructor.
3353
*/
3354
SQLITE4_API int sqlite4_create_module(
3355
sqlite4 *db, /* SQLite connection to register module with */
3356
const char *zName, /* Name of the module */
3357
const sqlite4_module *p, /* Methods for the module */
3358
void *pClientData /* Client data for xCreate/xConnect */
3359
);
3360
SQLITE4_API int sqlite4_create_module_v2(
3361
sqlite4 *db, /* SQLite connection to register module with */
3362
const char *zName, /* Name of the module */
3363
const sqlite4_module *p, /* Methods for the module */
3364
void *pClientData, /* Client data for xCreate/xConnect */
3365
void(*xDestroy)(void*) /* Module destructor function */
3366
);
3367
3368
/*
3369
** CAPIREF: Virtual Table Instance Object
3370
** KEYWORDS: sqlite4_vtab
3371
**
3372
** Every [virtual table module] implementation uses a subclass
3373
** of this object to describe a particular instance
3374
** of the [virtual table]. Each subclass will
3375
** be tailored to the specific needs of the module implementation.
3376
** The purpose of this superclass is to define certain fields that are
3377
** common to all module implementations.
3378
**
3379
** ^Virtual tables methods can set an error message by assigning a
3380
** string obtained from [sqlite4_mprintf()] to zErrMsg. The method should
3381
** take care that any prior string is freed by a call to [sqlite4_free()]
3382
** prior to assigning a new string to zErrMsg. ^After the error message
3383
** is delivered up to the client application, the string will be automatically
3384
** freed by sqlite4_free() and the zErrMsg field will be zeroed.
3385
*/
3386
struct sqlite4_vtab {
3387
const sqlite4_module *pModule; /* The module for this virtual table */
3388
int nRef; /* NO LONGER USED */
3389
char *zErrMsg; /* Error message from sqlite4_mprintf() */
3390
/* Virtual table implementations will typically add additional fields */
3391
};
3392
3393
/*
3394
** CAPIREF: Virtual Table Cursor Object
3395
** KEYWORDS: sqlite4_vtab_cursor {virtual table cursor}
3396
**
3397
** Every [virtual table module] implementation uses a subclass of the
3398
** following structure to describe cursors that point into the
3399
** [virtual table] and are used
3400
** to loop through the virtual table. Cursors are created using the
3401
** [sqlite4_module.xOpen | xOpen] method of the module and are destroyed
3402
** by the [sqlite4_module.xClose | xClose] method. Cursors are used
3403
** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
3404
** of the module. Each module implementation will define
3405
** the content of a cursor structure to suit its own needs.
3406
**
3407
** This superclass exists in order to define fields of the cursor that
3408
** are common to all implementations.
3409
*/
3410
struct sqlite4_vtab_cursor {
3411
sqlite4_vtab *pVtab; /* Virtual table of this cursor */
3412
/* Virtual table implementations will typically add additional fields */
3413
};
3414
3415
/*
3416
** CAPIREF: Declare The Schema Of A Virtual Table
3417
**
3418
** ^The [xCreate] and [xConnect] methods of a
3419
** [virtual table module] call this interface
3420
** to declare the format (the names and datatypes of the columns) of
3421
** the virtual tables they implement.
3422
*/
3423
SQLITE4_API int sqlite4_declare_vtab(sqlite4*, const char *zSQL);
3424
3425
/*
3426
** CAPIREF: Overload A Function For A Virtual Table
3427
**
3428
** ^(Virtual tables can provide alternative implementations of functions
3429
** using the [xFindFunction] method of the [virtual table module].
3430
** But global versions of those functions
3431
** must exist in order to be overloaded.)^
3432
**
3433
** ^(This API makes sure a global version of a function with a particular
3434
** name and number of parameters exists. If no such function exists
3435
** before this API is called, a new function is created.)^ ^The implementation
3436
** of the new function always causes an exception to be thrown. So
3437
** the new function is not good for anything by itself. Its only
3438
** purpose is to be a placeholder function that can be overloaded
3439
** by a [virtual table].
3440
*/
3441
SQLITE4_API int sqlite4_overload_function(sqlite4*, const char *zFuncName, int nArg);
3442
3443
/*
3444
** CAPIREF: Mutexes
3445
**
3446
** The SQLite core uses these routines for thread
3447
** synchronization. Though they are intended for internal
3448
** use by SQLite, code that links against SQLite is
3449
** permitted to use any of these routines.
3450
**
3451
** The SQLite source code contains multiple implementations
3452
** of these mutex routines. An appropriate implementation
3453
** is selected automatically at compile-time. ^(The following
3454
** implementations are available in the SQLite core:
3455
**
3456
** <ul>
3457
** <li> SQLITE4_MUTEX_PTHREADS
3458
** <li> SQLITE4_MUTEX_W32
3459
** <li> SQLITE4_MUTEX_NOOP
3460
** </ul>)^
3461
**
3462
** ^The SQLITE4_MUTEX_NOOP implementation is a set of routines
3463
** that does no real locking and is appropriate for use in
3464
** a single-threaded application. ^The SQLITE4_MUTEX_PTHREADS
3465
** and SQLITE4_MUTEX_W32 implementations
3466
** are appropriate for use on Unix and Windows.
3467
**
3468
** ^(If SQLite is compiled with the SQLITE4_MUTEX_APPDEF preprocessor
3469
** macro defined (with "-DSQLITE4_MUTEX_APPDEF=1"), then no mutex
3470
** implementation is included with the library. In this case the
3471
** application must supply a custom mutex implementation using the
3472
** [SQLITE4_CONFIG_MUTEX] option of the sqlite4_env_config() function
3473
** before calling sqlite4_initialize() or any other public sqlite4_
3474
** function that calls sqlite4_initialize().)^
3475
**
3476
** ^The sqlite4_mutex_alloc() routine allocates a new
3477
** mutex and returns a pointer to it. ^If it returns NULL
3478
** that means that a mutex could not be allocated. ^SQLite
3479
** will unwind its stack and return an error. ^(The argument
3480
** to sqlite4_mutex_alloc() is one of these integer constants:
3481
**
3482
** <ul>
3483
** <li> SQLITE4_MUTEX_FAST
3484
** <li> SQLITE4_MUTEX_RECURSIVE
3485
** </ul>)^
3486
**
3487
** ^The new mutex is recursive when SQLITE4_MUTEX_RECURSIVE
3488
** is used but not necessarily so when SQLITE4_MUTEX_FAST is used.
3489
** The mutex implementation does not need to make a distinction
3490
** between SQLITE4_MUTEX_RECURSIVE and SQLITE4_MUTEX_FAST if it does
3491
** not want to. ^SQLite will only request a recursive mutex in
3492
** cases where it really needs one. ^If a faster non-recursive mutex
3493
** implementation is available on the host platform, the mutex subsystem
3494
** might return such a mutex in response to SQLITE4_MUTEX_FAST.
3495
**
3496
** ^The sqlite4_mutex_free() routine deallocates a previously
3497
** allocated mutex.
3498
**
3499
** ^The sqlite4_mutex_enter() and sqlite4_mutex_try() routines attempt
3500
** to enter a mutex. ^If another thread is already within the mutex,
3501
** sqlite4_mutex_enter() will block and sqlite4_mutex_try() will return
3502
** SQLITE4_BUSY. ^The sqlite4_mutex_try() interface returns [SQLITE4_OK]
3503
** upon successful entry. ^(Mutexes created using
3504
** SQLITE4_MUTEX_RECURSIVE can be entered multiple times by the same thread.
3505
** In such cases the,
3506
** mutex must be exited an equal number of times before another thread
3507
** can enter.)^ ^(If the same thread tries to enter any other
3508
** kind of mutex more than once, the behavior is undefined.
3509
** SQLite will never exhibit
3510
** such behavior in its own use of mutexes.)^
3511
**
3512
** ^(Some systems (for example, Windows 95) do not support the operation
3513
** implemented by sqlite4_mutex_try(). On those systems, sqlite4_mutex_try()
3514
** will always return SQLITE4_BUSY. The SQLite core only ever uses
3515
** sqlite4_mutex_try() as an optimization so this is acceptable behavior.)^
3516
**
3517
** ^The sqlite4_mutex_leave() routine exits a mutex that was
3518
** previously entered by the same thread. ^(The behavior
3519
** is undefined if the mutex is not currently entered by the
3520
** calling thread or is not currently allocated. SQLite will
3521
** never do either.)^
3522
**
3523
** ^If the argument to sqlite4_mutex_enter(), sqlite4_mutex_try(), or
3524
** sqlite4_mutex_leave() is a NULL pointer, then all three routines
3525
** behave as no-ops.
3526
**
3527
** See also: [sqlite4_mutex_held()] and [sqlite4_mutex_notheld()].
3528
*/
3529
SQLITE4_API sqlite4_mutex *sqlite4_mutex_alloc(sqlite4_env*, int);
3530
SQLITE4_API void sqlite4_mutex_free(sqlite4_mutex*);
3531
SQLITE4_API void sqlite4_mutex_enter(sqlite4_mutex*);
3532
SQLITE4_API int sqlite4_mutex_try(sqlite4_mutex*);
3533
SQLITE4_API void sqlite4_mutex_leave(sqlite4_mutex*);
3534
3535
/*
3536
** CAPIREF: Mutex Methods Object
3537
**
3538
** An instance of this structure defines the low-level routines
3539
** used to allocate and use mutexes.
3540
**
3541
** Usually, the default mutex implementations provided by SQLite are
3542
** sufficient, however the user has the option of substituting a custom
3543
** implementation for specialized deployments or systems for which SQLite
3544
** does not provide a suitable implementation. In this case, the user
3545
** creates and populates an instance of this structure to pass
3546
** to sqlite4_env_config() along with the [SQLITE4_CONFIG_MUTEX] option.
3547
** Additionally, an instance of this structure can be used as an
3548
** output variable when querying the system for the current mutex
3549
** implementation, using the [SQLITE4_CONFIG_GETMUTEX] option.
3550
**
3551
** ^The xMutexInit method defined by this structure is invoked as
3552
** part of system initialization by the sqlite4_initialize() function.
3553
** ^The xMutexInit routine is called by SQLite exactly once for each
3554
** effective call to [sqlite4_initialize()].
3555
**
3556
** ^The xMutexEnd method defined by this structure is invoked as
3557
** part of system shutdown by the sqlite4_shutdown() function. The
3558
** implementation of this method is expected to release all outstanding
3559
** resources obtained by the mutex methods implementation, especially
3560
** those obtained by the xMutexInit method. ^The xMutexEnd()
3561
** interface is invoked exactly once for each call to [sqlite4_shutdown()].
3562
**
3563
** ^(The remaining seven methods defined by this structure (xMutexAlloc,
3564
** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
3565
** xMutexNotheld) implement the following interfaces (respectively):
3566
**
3567
** <ul>
3568
** <li> [sqlite4_mutex_alloc()] </li>
3569
** <li> [sqlite4_mutex_free()] </li>
3570
** <li> [sqlite4_mutex_enter()] </li>
3571
** <li> [sqlite4_mutex_try()] </li>
3572
** <li> [sqlite4_mutex_leave()] </li>
3573
** <li> [sqlite4_mutex_held()] </li>
3574
** <li> [sqlite4_mutex_notheld()] </li>
3575
** </ul>)^
3576
**
3577
** The only difference is that the public sqlite4_XXX functions enumerated
3578
** above silently ignore any invocations that pass a NULL pointer instead
3579
** of a valid mutex handle. The implementations of the methods defined
3580
** by this structure are not required to handle this case, the results
3581
** of passing a NULL pointer instead of a valid mutex handle are undefined
3582
** (i.e. it is acceptable to provide an implementation that segfaults if
3583
** it is passed a NULL pointer).
3584
**
3585
** The xMutexInit() method must be threadsafe. ^It must be harmless to
3586
** invoke xMutexInit() multiple times within the same process and without
3587
** intervening calls to xMutexEnd(). Second and subsequent calls to
3588
** xMutexInit() must be no-ops.
3589
**
3590
** ^xMutexInit() must not use SQLite memory allocation ([sqlite4_malloc()]
3591
** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
3592
** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
3593
** memory allocation for a fast or recursive mutex.
3594
**
3595
** ^SQLite will invoke the xMutexEnd() method when [sqlite4_shutdown()] is
3596
** called, but only if the prior call to xMutexInit returned SQLITE4_OK.
3597
** If xMutexInit fails in any way, it is expected to clean up after itself
3598
** prior to returning.
3599
*/
3600
typedef struct sqlite4_mutex_methods sqlite4_mutex_methods;
3601
struct sqlite4_mutex_methods {
3602
int (*xMutexInit)(void*);
3603
int (*xMutexEnd)(void*);
3604
sqlite4_mutex *(*xMutexAlloc)(void*,int);
3605
void (*xMutexFree)(sqlite4_mutex *);
3606
void (*xMutexEnter)(sqlite4_mutex *);
3607
int (*xMutexTry)(sqlite4_mutex *);
3608
void (*xMutexLeave)(sqlite4_mutex *);
3609
int (*xMutexHeld)(sqlite4_mutex *);
3610
int (*xMutexNotheld)(sqlite4_mutex *);
3611
void *pMutexEnv;
3612
};
3613
3614
/*
3615
** CAPIREF: Mutex Verification Routines
3616
**
3617
** The sqlite4_mutex_held() and sqlite4_mutex_notheld() routines
3618
** are intended for use inside assert() statements. ^The SQLite core
3619
** never uses these routines except inside an assert() and applications
3620
** are advised to follow the lead of the core. ^The SQLite core only
3621
** provides implementations for these routines when it is compiled
3622
** with the SQLITE4_DEBUG flag. ^External mutex implementations
3623
** are only required to provide these routines if SQLITE4_DEBUG is
3624
** defined and if NDEBUG is not defined.
3625
**
3626
** ^These routines should return true if the mutex in their argument
3627
** is held or not held, respectively, by the calling thread.
3628
**
3629
** ^The implementation is not required to provide versions of these
3630
** routines that actually work. If the implementation does not provide working
3631
** versions of these routines, it should at least provide stubs that always
3632
** return true so that one does not get spurious assertion failures.
3633
**
3634
** ^If the argument to sqlite4_mutex_held() is a NULL pointer then
3635
** the routine should return 1. This seems counter-intuitive since
3636
** clearly the mutex cannot be held if it does not exist. But
3637
** the reason the mutex does not exist is because the build is not
3638
** using mutexes. And we do not want the assert() containing the
3639
** call to sqlite4_mutex_held() to fail, so a non-zero return is
3640
** the appropriate thing to do. ^The sqlite4_mutex_notheld()
3641
** interface should also return 1 when given a NULL pointer.
3642
*/
3643
#ifndef NDEBUG
3644
SQLITE4_API int sqlite4_mutex_held(sqlite4_mutex*);
3645
SQLITE4_API int sqlite4_mutex_notheld(sqlite4_mutex*);
3646
#endif
3647
3648
/*
3649
** CAPIREF: Mutex Types
3650
**
3651
** The [sqlite4_mutex_alloc()] interface takes a single argument
3652
** which is one of these integer constants.
3653
**
3654
** The set of static mutexes may change from one SQLite release to the
3655
** next. Applications that override the built-in mutex logic must be
3656
** prepared to accommodate additional static mutexes.
3657
*/
3658
#define SQLITE4_MUTEX_FAST 0
3659
#define SQLITE4_MUTEX_RECURSIVE 1
3660
3661
/*
3662
** CAPIREF: Retrieve the mutex for a database connection
3663
**
3664
** ^This interface returns a pointer the [sqlite4_mutex] object that
3665
** serializes access to the [database connection] given in the argument
3666
** when the [threading mode] is Serialized.
3667
** ^If the [threading mode] is Single-thread or Multi-thread then this
3668
** routine returns a NULL pointer.
3669
*/
3670
SQLITE4_API sqlite4_mutex *sqlite4_db_mutex(sqlite4*);
3671
3672
/*
3673
** CAPIREF: Low-Level Control Of Database Backends
3674
**
3675
** ^The [sqlite4_kvstore_control()] interface makes a direct call to the
3676
** xControl method of the key-value store associated with the particular
3677
** database identified by the second argument. ^The name of the database
3678
** is "main" for the main database or "temp" for the TEMP database, or the
3679
** name that appears after the AS keyword for databases that were added
3680
** using the [ATTACH] SQL command. ^A NULL pointer can be used in place
3681
** of "main" to refer to the main database file.
3682
**
3683
** ^The third and fourth parameters to this routine are passed directly
3684
** through to the second and third parameters of the
3685
** sqlite4_kv_methods.xControl method. ^The return value of the xControl
3686
** call becomes the return value of this routine.
3687
**
3688
** ^If the second parameter (zDbName) does not match the name of any
3689
** open database file, then SQLITE4_ERROR is returned. ^This error
3690
** code is not remembered and will not be recalled by [sqlite4_errcode()]
3691
** or [sqlite4_errmsg()]. The underlying xControl method might also return
3692
** SQLITE4_ERROR. There is no way to distinguish between an incorrect zDbName
3693
** and an SQLITE4_ERROR return from the underlying xControl method.
3694
*/
3695
SQLITE4_API int sqlite4_kvstore_control(sqlite4*, const char *zDbName, int op, void*);
3696
3697
/*
3698
** <dl>
3699
** <dt>SQLITE4_KVCTRL_LSM_HANDLE</dt><dd>
3700
**
3701
** <dt>SQLITE4_KVCTRL_SYNCHRONOUS</dt><dd>
3702
** This op is used to configure or query the synchronous level of the
3703
** database backend (either OFF, NORMAL or FULL). The fourth parameter passed
3704
** to kvstore_control should be of type (int *). Call the value that the
3705
** parameter points to N. If N is initially 0, 1 or 2, then the database
3706
** backend should attempt to change the synchronous level to OFF, NORMAL
3707
** or FULL, respectively. Regardless of its initial value, N is set to
3708
** the current (possibly updated) synchronous level before returning (
3709
** 0, 1 or 2).
3710
*/
3711
#define SQLITE4_KVCTRL_LSM_HANDLE 1
3712
#define SQLITE4_KVCTRL_SYNCHRONOUS 2
3713
#define SQLITE4_KVCTRL_LSM_FLUSH 3
3714
#define SQLITE4_KVCTRL_LSM_MERGE 4
3715
#define SQLITE4_KVCTRL_LSM_CHECKPOINT 5
3716
3717
/*
3718
** CAPIREF: Testing Interface
3719
**
3720
** ^The sqlite4_test_control() interface is used to read out internal
3721
** state of SQLite and to inject faults into SQLite for testing
3722
** purposes. ^The first parameter is an operation code that determines
3723
** the number, meaning, and operation of all subsequent parameters.
3724
**
3725
** This interface is not for use by applications. It exists solely
3726
** for verifying the correct operation of the SQLite library. Depending
3727
** on how the SQLite library is compiled, this interface might not exist.
3728
**
3729
** The details of the operation codes, their meanings, the parameters
3730
** they take, and what they do are all subject to change without notice.
3731
** Unlike most of the SQLite API, this function is not guaranteed to
3732
** operate consistently from one release to the next.
3733
*/
3734
SQLITE4_API int sqlite4_test_control(int op, ...);
3735
3736
/*
3737
** CAPIREF: Testing Interface Operation Codes
3738
**
3739
** These constants are the valid operation code parameters used
3740
** as the first argument to [sqlite4_test_control()].
3741
**
3742
** These parameters and their meanings are subject to change
3743
** without notice. These values are for testing purposes only.
3744
** Applications should not use any of these parameters or the
3745
** [sqlite4_test_control()] interface.
3746
*/
3747
#define SQLITE4_TESTCTRL_FIRST 1
3748
#define SQLITE4_TESTCTRL_FAULT_INSTALL 2
3749
#define SQLITE4_TESTCTRL_ASSERT 3
3750
#define SQLITE4_TESTCTRL_ALWAYS 4
3751
#define SQLITE4_TESTCTRL_RESERVE 5
3752
#define SQLITE4_TESTCTRL_OPTIMIZATIONS 6
3753
#define SQLITE4_TESTCTRL_ISKEYWORD 7
3754
#define SQLITE4_TESTCTRL_LOCALTIME_FAULT 8
3755
#define SQLITE4_TESTCTRL_EXPLAIN_STMT 9
3756
#define SQLITE4_TESTCTRL_LAST 9
3757
3758
/*
3759
** CAPIREF: SQLite Runtime Status
3760
**
3761
** ^This interface is used to retrieve runtime status information
3762
** about the performance of SQLite, and optionally to reset various
3763
** highwater marks. ^The first argument is an integer code for
3764
** the specific parameter to measure. ^(Recognized integer codes
3765
** are of the form [status parameters | SQLITE4_STATUS_...].)^
3766
** ^The current value of the parameter is returned into *pCurrent.
3767
** ^The highest recorded value is returned in *pHighwater. ^If the
3768
** resetFlag is true, then the highest record value is reset after
3769
** *pHighwater is written. ^(Some parameters do not record the highest
3770
** value. For those parameters
3771
** nothing is written into *pHighwater and the resetFlag is ignored.)^
3772
** ^(Other parameters record only the highwater mark and not the current
3773
** value. For these latter parameters nothing is written into *pCurrent.)^
3774
**
3775
** ^The sqlite4_status() routine returns SQLITE4_OK on success and a
3776
** non-zero [error code] on failure.
3777
**
3778
** This routine is threadsafe but is not atomic. This routine can be
3779
** called while other threads are running the same or different SQLite
3780
** interfaces. However the values returned in *pCurrent and
3781
** *pHighwater reflect the status of SQLite at different points in time
3782
** and it is possible that another thread might change the parameter
3783
** in between the times when *pCurrent and *pHighwater are written.
3784
**
3785
** See also: [sqlite4_db_status()]
3786
*/
3787
SQLITE4_API int sqlite4_env_status(
3788
sqlite4_env *pEnv,
3789
int op,
3790
sqlite4_uint64 *pCurrent,
3791
sqlite4_uint64 *pHighwater,
3792
int resetFlag
3793
);
3794
3795
3796
/*
3797
** CAPIREF: Status Parameters
3798
** KEYWORDS: {status parameters}
3799
**
3800
** These integer constants designate various run-time status parameters
3801
** that can be returned by [sqlite4_status()].
3802
**
3803
** <dl>
3804
** [[SQLITE4_STATUS_MEMORY_USED]] ^(<dt>SQLITE4_STATUS_MEMORY_USED</dt>
3805
** <dd>This parameter is the current amount of memory checked out
3806
** using [sqlite4_malloc()], either directly or indirectly. The
3807
** figure includes calls made to [sqlite4_malloc()] by the application
3808
** and internal memory usage by the SQLite library. Scratch memory
3809
** controlled by [SQLITE4_CONFIG_SCRATCH] and auxiliary page-cache
3810
** memory controlled by [SQLITE4_CONFIG_PAGECACHE] is not included in
3811
** this parameter. The amount returned is the sum of the allocation
3812
** sizes as reported by the xSize method in [sqlite4_mem_methods].</dd>)^
3813
**
3814
** [[SQLITE4_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE4_STATUS_MALLOC_SIZE</dt>
3815
** <dd>This parameter records the largest memory allocation request
3816
** handed to [sqlite4_malloc()] or [sqlite4_realloc()] (or their
3817
** internal equivalents). Only the value returned in the
3818
** *pHighwater parameter to [sqlite4_status()] is of interest.
3819
** The value written into the *pCurrent parameter is undefined.</dd>)^
3820
**
3821
** [[SQLITE4_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE4_STATUS_MALLOC_COUNT</dt>
3822
** <dd>This parameter records the number of separate memory allocations
3823
** currently checked out.</dd>)^
3824
**
3825
** [[SQLITE4_STATUS_PARSER_STACK]] ^(<dt>SQLITE4_STATUS_PARSER_STACK</dt>
3826
** <dd>This parameter records the deepest parser stack. It is only
3827
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
3828
** </dl>
3829
**
3830
** New status parameters may be added from time to time.
3831
*/
3832
#define SQLITE4_ENVSTATUS_MEMORY_USED 0
3833
#define SQLITE4_ENVSTATUS_MALLOC_SIZE 1
3834
#define SQLITE4_ENVSTATUS_MALLOC_COUNT 2
3835
#define SQLITE4_ENVSTATUS_PARSER_STACK 3
3836
3837
/*
3838
** CAPIREF: Database Connection Status
3839
**
3840
** ^This interface is used to retrieve runtime status information
3841
** about a single [database connection]. ^The first argument is the
3842
** database connection object to be interrogated. ^The second argument
3843
** is an integer constant, taken from the set of
3844
** [SQLITE4_DBSTATUS options], that
3845
** determines the parameter to interrogate. The set of
3846
** [SQLITE4_DBSTATUS options] is likely
3847
** to grow in future releases of SQLite.
3848
**
3849
** ^The current value of the requested parameter is written into *pCur
3850
** and the highest instantaneous value is written into *pHiwtr. ^If
3851
** the resetFlg is true, then the highest instantaneous value is
3852
** reset back down to the current value.
3853
**
3854
** ^The sqlite4_db_status() routine returns SQLITE4_OK on success and a
3855
** non-zero [error code] on failure.
3856
**
3857
** See also: [sqlite4_status()] and [sqlite4_stmt_status()].
3858
*/
3859
SQLITE4_API int sqlite4_db_status(sqlite4*, int op, int *pCur, int *pHiwtr, int resetFlg);
3860
3861
/*
3862
** CAPIREF: Status Parameters for database connections
3863
** KEYWORDS: {SQLITE4_DBSTATUS options}
3864
**
3865
** These constants are the available integer "verbs" that can be passed as
3866
** the second argument to the [sqlite4_db_status()] interface.
3867
**
3868
** New verbs may be added in future releases of SQLite. Existing verbs
3869
** might be discontinued. Applications should check the return code from
3870
** [sqlite4_db_status()] to make sure that the call worked.
3871
** The [sqlite4_db_status()] interface will return a non-zero error code
3872
** if a discontinued or unsupported verb is invoked.
3873
**
3874
** <dl>
3875
** [[SQLITE4_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_USED</dt>
3876
** <dd>This parameter returns the number of lookaside memory slots currently
3877
** checked out.</dd>)^
3878
**
3879
** [[SQLITE4_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_HIT</dt>
3880
** <dd>This parameter returns the number malloc attempts that were
3881
** satisfied using lookaside memory. Only the high-water value is meaningful;
3882
** the current value is always zero.)^
3883
**
3884
** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE]]
3885
** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
3886
** <dd>This parameter returns the number malloc attempts that might have
3887
** been satisfied using lookaside memory but failed due to the amount of
3888
** memory requested being larger than the lookaside slot size.
3889
** Only the high-water value is meaningful;
3890
** the current value is always zero.)^
3891
**
3892
** [[SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL]]
3893
** ^(<dt>SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
3894
** <dd>This parameter returns the number malloc attempts that might have
3895
** been satisfied using lookaside memory but failed due to all lookaside
3896
** memory already being in use.
3897
** Only the high-water value is meaningful;
3898
** the current value is always zero.)^
3899
**
3900
** [[SQLITE4_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE4_DBSTATUS_CACHE_USED</dt>
3901
** <dd>This parameter returns the approximate number of of bytes of heap
3902
** memory used by all pager caches associated with the database connection.)^
3903
** ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_USED is always 0.
3904
**
3905
** [[SQLITE4_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE4_DBSTATUS_SCHEMA_USED</dt>
3906
** <dd>This parameter returns the approximate number of of bytes of heap
3907
** memory used to store the schema for all databases associated
3908
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
3909
** ^The full amount of memory used by the schemas is reported, even if the
3910
** schema memory is shared with other database connections due to
3911
** [shared cache mode] being enabled.
3912
** ^The highwater mark associated with SQLITE4_DBSTATUS_SCHEMA_USED is always 0.
3913
**
3914
** [[SQLITE4_DBSTATUS_STMT_USED]] ^(<dt>SQLITE4_DBSTATUS_STMT_USED</dt>
3915
** <dd>This parameter returns the approximate number of of bytes of heap
3916
** and lookaside memory used by all prepared statements associated with
3917
** the database connection.)^
3918
** ^The highwater mark associated with SQLITE4_DBSTATUS_STMT_USED is always 0.
3919
** </dd>
3920
**
3921
** [[SQLITE4_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE4_DBSTATUS_CACHE_HIT</dt>
3922
** <dd>This parameter returns the number of pager cache hits that have
3923
** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_HIT
3924
** is always 0.
3925
** </dd>
3926
**
3927
** [[SQLITE4_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE4_DBSTATUS_CACHE_MISS</dt>
3928
** <dd>This parameter returns the number of pager cache misses that have
3929
** occurred.)^ ^The highwater mark associated with SQLITE4_DBSTATUS_CACHE_MISS
3930
** is always 0.
3931
** </dd>
3932
** </dl>
3933
*/
3934
#define SQLITE4_DBSTATUS_LOOKASIDE_USED 0
3935
#define SQLITE4_DBSTATUS_CACHE_USED 1
3936
#define SQLITE4_DBSTATUS_SCHEMA_USED 2
3937
#define SQLITE4_DBSTATUS_STMT_USED 3
3938
#define SQLITE4_DBSTATUS_LOOKASIDE_HIT 4
3939
#define SQLITE4_DBSTATUS_LOOKASIDE_MISS_SIZE 5
3940
#define SQLITE4_DBSTATUS_LOOKASIDE_MISS_FULL 6
3941
#define SQLITE4_DBSTATUS_CACHE_HIT 7
3942
#define SQLITE4_DBSTATUS_CACHE_MISS 8
3943
#define SQLITE4_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
3944
3945
3946
/*
3947
** CAPIREF: Prepared Statement Status
3948
**
3949
** ^(Each prepared statement maintains various
3950
** [SQLITE4_STMTSTATUS counters] that measure the number
3951
** of times it has performed specific operations.)^ These counters can
3952
** be used to monitor the performance characteristics of the prepared
3953
** statements. For example, if the number of table steps greatly exceeds
3954
** the number of table searches or result rows, that would tend to indicate
3955
** that the prepared statement is using a full table scan rather than
3956
** an index.
3957
**
3958
** ^(This interface is used to retrieve and reset counter values from
3959
** a [prepared statement]. The first argument is the prepared statement
3960
** object to be interrogated. The second argument
3961
** is an integer code for a specific [SQLITE4_STMTSTATUS counter]
3962
** to be interrogated.)^
3963
** ^The current value of the requested counter is returned.
3964
** ^If the resetFlg is true, then the counter is reset to zero after this
3965
** interface call returns.
3966
**
3967
** See also: [sqlite4_status()] and [sqlite4_db_status()].
3968
*/
3969
SQLITE4_API int sqlite4_stmt_status(sqlite4_stmt*, int op,int resetFlg);
3970
3971
/*
3972
** CAPIREF: Status Parameters for prepared statements
3973
** KEYWORDS: {SQLITE4_STMTSTATUS counter} {SQLITE4_STMTSTATUS counters}
3974
**
3975
** These preprocessor macros define integer codes that name counter
3976
** values associated with the [sqlite4_stmt_status()] interface.
3977
** The meanings of the various counters are as follows:
3978
**
3979
** <dl>
3980
** [[SQLITE4_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE4_STMTSTATUS_FULLSCAN_STEP</dt>
3981
** <dd>^This is the number of times that SQLite has stepped forward in
3982
** a table as part of a full table scan. Large numbers for this counter
3983
** may indicate opportunities for performance improvement through
3984
** careful use of indices.</dd>
3985
**
3986
** [[SQLITE4_STMTSTATUS_SORT]] <dt>SQLITE4_STMTSTATUS_SORT</dt>
3987
** <dd>^This is the number of sort operations that have occurred.
3988
** A non-zero value in this counter may indicate an opportunity to
3989
** improvement performance through careful use of indices.</dd>
3990
**
3991
** [[SQLITE4_STMTSTATUS_AUTOINDEX]] <dt>SQLITE4_STMTSTATUS_AUTOINDEX</dt>
3992
** <dd>^This is the number of rows inserted into transient indices that
3993
** were created automatically in order to help joins run faster.
3994
** A non-zero value in this counter may indicate an opportunity to
3995
** improvement performance by adding permanent indices that do not
3996
** need to be reinitialized each time the statement is run.</dd>
3997
** </dl>
3998
*/
3999
#define SQLITE4_STMTSTATUS_FULLSCAN_STEP 1
4000
#define SQLITE4_STMTSTATUS_SORT 2
4001
#define SQLITE4_STMTSTATUS_AUTOINDEX 3
4002
4003
4004
/*
4005
** CAPIREF: Unlock Notification
4006
**
4007
** ^When running in shared-cache mode, a database operation may fail with
4008
** an [SQLITE4_LOCKED] error if the required locks on the shared-cache or
4009
** individual tables within the shared-cache cannot be obtained. See
4010
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
4011
** ^This API may be used to register a callback that SQLite will invoke
4012
** when the connection currently holding the required lock relinquishes it.
4013
** ^This API is only available if the library was compiled with the
4014
** [SQLITE4_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
4015
**
4016
** See Also: [Using the SQLite Unlock Notification Feature].
4017
**
4018
** ^Shared-cache locks are released when a database connection concludes
4019
** its current transaction, either by committing it or rolling it back.
4020
**
4021
** ^When a connection (known as the blocked connection) fails to obtain a
4022
** shared-cache lock and SQLITE4_LOCKED is returned to the caller, the
4023
** identity of the database connection (the blocking connection) that
4024
** has locked the required resource is stored internally. ^After an
4025
** application receives an SQLITE4_LOCKED error, it may call the
4026
** sqlite4_unlock_notify() method with the blocked connection handle as
4027
** the first argument to register for a callback that will be invoked
4028
** when the blocking connections current transaction is concluded. ^The
4029
** callback is invoked from within the [sqlite4_step] or [sqlite4_close]
4030
** call that concludes the blocking connections transaction.
4031
**
4032
** ^(If sqlite4_unlock_notify() is called in a multi-threaded application,
4033
** there is a chance that the blocking connection will have already
4034
** concluded its transaction by the time sqlite4_unlock_notify() is invoked.
4035
** If this happens, then the specified callback is invoked immediately,
4036
** from within the call to sqlite4_unlock_notify().)^
4037
**
4038
** ^If the blocked connection is attempting to obtain a write-lock on a
4039
** shared-cache table, and more than one other connection currently holds
4040
** a read-lock on the same table, then SQLite arbitrarily selects one of
4041
** the other connections to use as the blocking connection.
4042
**
4043
** ^(There may be at most one unlock-notify callback registered by a
4044
** blocked connection. If sqlite4_unlock_notify() is called when the
4045
** blocked connection already has a registered unlock-notify callback,
4046
** then the new callback replaces the old.)^ ^If sqlite4_unlock_notify() is
4047
** called with a NULL pointer as its second argument, then any existing
4048
** unlock-notify callback is canceled. ^The blocked connections
4049
** unlock-notify callback may also be canceled by closing the blocked
4050
** connection using [sqlite4_close()].
4051
**
4052
** The unlock-notify callback is not reentrant. If an application invokes
4053
** any sqlite4_xxx API functions from within an unlock-notify callback, a
4054
** crash or deadlock may be the result.
4055
**
4056
** ^Unless deadlock is detected (see below), sqlite4_unlock_notify() always
4057
** returns SQLITE4_OK.
4058
**
4059
** <b>Callback Invocation Details</b>
4060
**
4061
** When an unlock-notify callback is registered, the application provides a
4062
** single void* pointer that is passed to the callback when it is invoked.
4063
** However, the signature of the callback function allows SQLite to pass
4064
** it an array of void* context pointers. The first argument passed to
4065
** an unlock-notify callback is a pointer to an array of void* pointers,
4066
** and the second is the number of entries in the array.
4067
**
4068
** When a blocking connections transaction is concluded, there may be
4069
** more than one blocked connection that has registered for an unlock-notify
4070
** callback. ^If two or more such blocked connections have specified the
4071
** same callback function, then instead of invoking the callback function
4072
** multiple times, it is invoked once with the set of void* context pointers
4073
** specified by the blocked connections bundled together into an array.
4074
** This gives the application an opportunity to prioritize any actions
4075
** related to the set of unblocked database connections.
4076
**
4077
** <b>Deadlock Detection</b>
4078
**
4079
** Assuming that after registering for an unlock-notify callback a
4080
** database waits for the callback to be issued before taking any further
4081
** action (a reasonable assumption), then using this API may cause the
4082
** application to deadlock. For example, if connection X is waiting for
4083
** connection Y's transaction to be concluded, and similarly connection
4084
** Y is waiting on connection X's transaction, then neither connection
4085
** will proceed and the system may remain deadlocked indefinitely.
4086
**
4087
** To avoid this scenario, the sqlite4_unlock_notify() performs deadlock
4088
** detection. ^If a given call to sqlite4_unlock_notify() would put the
4089
** system in a deadlocked state, then SQLITE4_LOCKED is returned and no
4090
** unlock-notify callback is registered. The system is said to be in
4091
** a deadlocked state if connection A has registered for an unlock-notify
4092
** callback on the conclusion of connection B's transaction, and connection
4093
** B has itself registered for an unlock-notify callback when connection
4094
** A's transaction is concluded. ^Indirect deadlock is also detected, so
4095
** the system is also considered to be deadlocked if connection B has
4096
** registered for an unlock-notify callback on the conclusion of connection
4097
** C's transaction, where connection C is waiting on connection A. ^Any
4098
** number of levels of indirection are allowed.
4099
**
4100
** <b>The "DROP TABLE" Exception</b>
4101
**
4102
** When a call to [sqlite4_step()] returns SQLITE4_LOCKED, it is almost
4103
** always appropriate to call sqlite4_unlock_notify(). There is however,
4104
** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
4105
** SQLite checks if there are any currently executing SELECT statements
4106
** that belong to the same connection. If there are, SQLITE4_LOCKED is
4107
** returned. In this case there is no "blocking connection", so invoking
4108
** sqlite4_unlock_notify() results in the unlock-notify callback being
4109
** invoked immediately. If the application then re-attempts the "DROP TABLE"
4110
** or "DROP INDEX" query, an infinite loop might be the result.
4111
**
4112
** One way around this problem is to check the extended error code returned
4113
** by an sqlite4_step() call. ^(If there is a blocking connection, then the
4114
** extended error code is set to SQLITE4_LOCKED_SHAREDCACHE. Otherwise, in
4115
** the special "DROP TABLE/INDEX" case, the extended error code is just
4116
** SQLITE4_LOCKED.)^
4117
*/
4118
SQLITE4_API int sqlite4_unlock_notify(
4119
sqlite4 *pBlocked, /* Waiting connection */
4120
void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
4121
void *pNotifyArg /* Argument to pass to xNotify */
4122
);
4123
4124
4125
/*
4126
** CAPIREF: String Comparison
4127
**
4128
** ^The [sqlite4_strnicmp()] API allows applications and extensions to
4129
** compare the contents of two buffers containing UTF-8 strings in a
4130
** case-independent fashion, using the same definition of case independence
4131
** that SQLite uses internally when comparing identifiers.
4132
*/
4133
SQLITE4_API int sqlite4_strnicmp(const char *, const char *, int);
4134
4135
/*
4136
** CAPIREF: Error Logging Interface
4137
**
4138
** ^The [sqlite4_log()] interface writes a message into the error log
4139
** established by the [SQLITE4_CONFIG_LOG] option to [sqlite4_env_config()].
4140
** ^If logging is enabled, the zFormat string and subsequent arguments are
4141
** used with [sqlite4_snprintf()] to generate the final output string.
4142
**
4143
** The sqlite4_log() interface is intended for use by extensions such as
4144
** virtual tables, collating functions, and SQL functions. While there is
4145
** nothing to prevent an application from calling sqlite4_log(), doing so
4146
** is considered bad form.
4147
**
4148
** The zFormat string must not be NULL.
4149
**
4150
** To avoid deadlocks and other threading problems, the sqlite4_log() routine
4151
** will not use dynamically allocated memory. The log message is stored in
4152
** a fixed-length buffer on the stack. If the log message is longer than
4153
** a few hundred characters, it will be truncated to the length of the
4154
** buffer.
4155
*/
4156
SQLITE4_API void sqlite4_log(sqlite4_env*, int iErrCode, const char *zFormat, ...);
4157
4158
/*
4159
** CAPIREF: Virtual Table Interface Configuration
4160
**
4161
** This function may be called by either the [xConnect] or [xCreate] method
4162
** of a [virtual table] implementation to configure
4163
** various facets of the virtual table interface.
4164
**
4165
** If this interface is invoked outside the context of an xConnect or
4166
** xCreate virtual table method then the behavior is undefined.
4167
**
4168
** At present, there is only one option that may be configured using
4169
** this function. (See [SQLITE4_VTAB_CONSTRAINT_SUPPORT].) Further options
4170
** may be added in the future.
4171
*/
4172
SQLITE4_API int sqlite4_vtab_config(sqlite4*, int op, ...);
4173
4174
/*
4175
** CAPIREF: Virtual Table Configuration Options
4176
**
4177
** These macros define the various options to the
4178
** [sqlite4_vtab_config()] interface that [virtual table] implementations
4179
** can use to customize and optimize their behavior.
4180
**
4181
** <dl>
4182
** <dt>SQLITE4_VTAB_CONSTRAINT_SUPPORT
4183
** <dd>Calls of the form
4184
** [sqlite4_vtab_config](db,SQLITE4_VTAB_CONSTRAINT_SUPPORT,X) are supported,
4185
** where X is an integer. If X is zero, then the [virtual table] whose
4186
** [xCreate] or [xConnect] method invoked [sqlite4_vtab_config()] does not
4187
** support constraints. In this configuration (which is the default) if
4188
** a call to the [xUpdate] method returns [SQLITE4_CONSTRAINT], then the entire
4189
** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
4190
** specified as part of the users SQL statement, regardless of the actual
4191
** ON CONFLICT mode specified.
4192
**
4193
** If X is non-zero, then the virtual table implementation guarantees
4194
** that if [xUpdate] returns [SQLITE4_CONSTRAINT], it will do so before
4195
** any modifications to internal or persistent data structures have been made.
4196
** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
4197
** is able to roll back a statement or database transaction, and abandon
4198
** or continue processing the current SQL statement as appropriate.
4199
** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
4200
** [SQLITE4_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
4201
** had been ABORT.
4202
**
4203
** Virtual table implementations that are required to handle OR REPLACE
4204
** must do so within the [xUpdate] method. If a call to the
4205
** [sqlite4_vtab_on_conflict()] function indicates that the current ON
4206
** CONFLICT policy is REPLACE, the virtual table implementation should
4207
** silently replace the appropriate rows within the xUpdate callback and
4208
** return SQLITE4_OK. Or, if this is not possible, it may return
4209
** SQLITE4_CONSTRAINT, in which case SQLite falls back to OR ABORT
4210
** constraint handling.
4211
** </dl>
4212
*/
4213
#define SQLITE4_VTAB_CONSTRAINT_SUPPORT 1
4214
4215
/*
4216
** CAPIREF: Determine The Virtual Table Conflict Policy
4217
**
4218
** This function may only be called from within a call to the [xUpdate] method
4219
** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
4220
** value returned is one of [SQLITE4_ROLLBACK], [SQLITE4_IGNORE], [SQLITE4_FAIL],
4221
** [SQLITE4_ABORT], or [SQLITE4_REPLACE], according to the [ON CONFLICT] mode
4222
** of the SQL statement that triggered the call to the [xUpdate] method of the
4223
** [virtual table].
4224
*/
4225
SQLITE4_API int sqlite4_vtab_on_conflict(sqlite4 *);
4226
4227
/*
4228
** CAPIREF: Conflict resolution modes
4229
**
4230
** These constants are returned by [sqlite4_vtab_on_conflict()] to
4231
** inform a [virtual table] implementation what the [ON CONFLICT] mode
4232
** is for the SQL statement being evaluated.
4233
**
4234
** Note that the [SQLITE4_IGNORE] constant is also used as a potential
4235
** return value from the [sqlite4_set_authorizer()] callback and that
4236
** [SQLITE4_ABORT] is also a [result code].
4237
*/
4238
#define SQLITE4_ROLLBACK 1
4239
/* #define SQLITE4_IGNORE 2 // Also used by sqlite4_authorizer() callback */
4240
#define SQLITE4_FAIL 3
4241
/* #define SQLITE4_ABORT 4 // Also an error code */
4242
#define SQLITE4_REPLACE 5
4243
4244
4245
/*
4246
** CAPI4REF: Length of a key-value storage key or data field
4247
**
4248
** The length of the key or data for a key-value storage entry is
4249
** stored in a variable of this type.
4250
*/
4251
typedef int sqlite4_kvsize;
4252
4253
/*
4254
** CAPI4REF: Key-Value Storage Engine Object
4255
**
4256
** An instance of a subclass of the following object defines a
4257
** connection to a storage engine.
4258
*/
4259
typedef struct sqlite4_kvstore sqlite4_kvstore;
4260
struct sqlite4_kvstore {
4261
const struct sqlite4_kv_methods *pStoreVfunc; /* Methods */
4262
sqlite4_env *pEnv; /* Runtime environment for kvstore */
4263
int iTransLevel; /* Current transaction level */
4264
unsigned kvId; /* Unique ID used for tracing */
4265
unsigned fTrace; /* True to enable tracing */
4266
char zKVName[12]; /* Used for debugging */
4267
/* Subclasses will typically append additional fields */
4268
};
4269
4270
/*
4271
** CAPI4REF: Key-Value Storage Engine Cursor Object
4272
**
4273
** An instance of a subclass of the following object defines a cursor
4274
** used to scan through a key-value storage engine.
4275
*/
4276
typedef struct sqlite4_kvcursor sqlite4_kvcursor;
4277
struct sqlite4_kvcursor {
4278
sqlite4_kvstore *pStore; /* The owner of this cursor */
4279
const struct sqlite4_kv_methods *pStoreVfunc; /* Methods */
4280
sqlite4_env *pEnv; /* Runtime environment */
4281
int iTransLevel; /* Current transaction level */
4282
unsigned curId; /* Unique ID for tracing */
4283
unsigned fTrace; /* True to enable tracing */
4284
/* Subclasses will typically add additional fields */
4285
};
4286
4287
/*
4288
** CAPI4REF: Key-value storage engine virtual method table
4289
**
4290
** A Key-Value storage engine is defined by an instance of the following
4291
** object.
4292
*/
4293
struct sqlite4_kv_methods {
4294
int iVersion;
4295
int szSelf;
4296
int (*xReplace)(
4297
sqlite4_kvstore*,
4298
const unsigned char *pKey, sqlite4_kvsize nKey,
4299
const unsigned char *pData, sqlite4_kvsize nData);
4300
int (*xOpenCursor)(sqlite4_kvstore*, sqlite4_kvcursor**);
4301
int (*xSeek)(sqlite4_kvcursor*,
4302
const unsigned char *pKey, sqlite4_kvsize nKey, int dir);
4303
int (*xNext)(sqlite4_kvcursor*);
4304
int (*xPrev)(sqlite4_kvcursor*);
4305
int (*xDelete)(sqlite4_kvcursor*);
4306
int (*xKey)(sqlite4_kvcursor*,
4307
const unsigned char **ppKey, sqlite4_kvsize *pnKey);
4308
int (*xData)(sqlite4_kvcursor*, sqlite4_kvsize ofst, sqlite4_kvsize n,
4309
const unsigned char **ppData, sqlite4_kvsize *pnData);
4310
int (*xReset)(sqlite4_kvcursor*);
4311
int (*xCloseCursor)(sqlite4_kvcursor*);
4312
int (*xBegin)(sqlite4_kvstore*, int);
4313
int (*xCommitPhaseOne)(sqlite4_kvstore*, int);
4314
int (*xCommitPhaseTwo)(sqlite4_kvstore*, int);
4315
int (*xRollback)(sqlite4_kvstore*, int);
4316
int (*xRevert)(sqlite4_kvstore*, int);
4317
int (*xClose)(sqlite4_kvstore*);
4318
int (*xControl)(sqlite4_kvstore*, int, void*);
4319
};
4320
typedef struct sqlite4_kv_methods sqlite4_kv_methods;
4321
4322
/*
4323
** CAPI4REF: Key-value storage engine open flags
4324
**
4325
** Allowed values to the flags parameter of an sqlite4_kvstore object
4326
** factory.
4327
**
4328
** The flags parameter to the sqlite4_kvstore factory (the fourth parameter)
4329
** is an OR-ed combination of these values and the
4330
** [SQLITE4_OPEN_READONLY | SQLITE4_OPEN_xxxxx] flags that appear as
4331
** arguments to [sqlite4_open()].
4332
*/
4333
#define SQLITE4_KVOPEN_TEMPORARY 0x00010000 /* A temporary database */
4334
#define SQLITE4_KVOPEN_NO_TRANSACTIONS 0x00020000 /* No transactions needed */
4335
4336
4337
/*
4338
** CAPI4REF: Representation Of Numbers
4339
**
4340
** Every number in SQLite is represented in memory by an instance of
4341
** the following object.
4342
*/
4343
typedef struct sqlite4_num sqlite4_num;
4344
struct sqlite4_num {
4345
unsigned char sign; /* Sign of the overall value */
4346
unsigned char approx; /* True if the value is approximate */
4347
unsigned short e; /* The exponent. */
4348
sqlite4_uint64 m; /* The significant */
4349
};
4350
4351
/*
4352
** CAPI4REF: Operations On SQLite Number Objects
4353
*/
4354
SQLITE4_API sqlite4_num sqlite4_num_add(sqlite4_num, sqlite4_num);
4355
SQLITE4_API sqlite4_num sqlite4_num_sub(sqlite4_num, sqlite4_num);
4356
SQLITE4_API sqlite4_num sqlite4_num_mul(sqlite4_num, sqlite4_num);
4357
SQLITE4_API sqlite4_num sqlite4_num_div(sqlite4_num, sqlite4_num);
4358
SQLITE4_API int sqlite4_num_isinf(sqlite4_num);
4359
SQLITE4_API int sqlite4_num_isnan(sqlite4_num);
4360
SQLITE4_API sqlite4_num sqlite4_num_round(sqlite4_num, int iDigit);
4361
SQLITE4_API int sqlite4_num_compare(sqlite4_num, sqlite4_num);
4362
SQLITE4_API sqlite4_num sqlite4_num_from_text(const char*, int n, unsigned flags);
4363
SQLITE4_API sqlite4_num sqlite4_num_from_int64(sqlite4_int64);
4364
SQLITE4_API sqlite4_num sqlite4_num_from_double(double);
4365
SQLITE4_API int sqlite4_num_to_int32(sqlite4_num, int*);
4366
SQLITE4_API int sqlite4_num_to_int64(sqlite4_num, sqlite4_int64*);
4367
SQLITE4_API double sqlite4_num_to_double(sqlite4_num);
4368
SQLITE4_API int sqlite4_num_to_text(sqlite4_num, char*);
4369
4370
/*
4371
** CAPI4REF: Flags For Text-To-Numeric Conversion
4372
*/
4373
#define SQLITE4_PREFIX_ONLY 0x10
4374
#define SQLITE4_IGNORE_WHITESPACE 0x20
4375
4376
/*
4377
** Undo the hack that converts floating point types to integer for
4378
** builds on processors without floating point support.
4379
*/
4380
#ifdef SQLITE4_OMIT_FLOATING_POINT
4381
# undef double
4382
#endif
4383
4384
#ifdef __cplusplus
4385
} /* End of the 'extern "C"' block */
4386
#endif
4387
#endif
4388
4389
/*
4390
** 2010 August 30
4391
**
4392
** The author disclaims copyright to this source code. In place of
4393
** a legal notice, here is a blessing:
4394
**
4395
** May you do good and not evil.
4396
** May you find forgiveness for yourself and forgive others.
4397
** May you share freely, never taking more than you give.
4398
**
4399
*************************************************************************
4400
*/
4401
4402
#ifndef _SQLITE3RTREE_H_
4403
#define _SQLITE3RTREE_H_
4404
4405
4406
#ifdef __cplusplus
4407
extern "C" {
4408
#endif
4409
4410
typedef struct sqlite4_rtree_geometry sqlite4_rtree_geometry;
4411
4412
/*
4413
** Register a geometry callback named zGeom that can be used as part of an
4414
** R-Tree geometry query as follows:
4415
**
4416
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
4417
*/
4418
SQLITE4_API int sqlite4_rtree_geometry_callback(
4419
sqlite4 *db,
4420
const char *zGeom,
4421
int (*xGeom)(sqlite4_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
4422
void *pContext
4423
);
4424
4425
4426
/*
4427
** A pointer to a structure of the following type is passed as the first
4428
** argument to callbacks registered using rtree_geometry_callback().
4429
*/
4430
struct sqlite4_rtree_geometry {
4431
void *pContext; /* Copy of pContext passed to s_r_g_c() */
4432
int nParam; /* Size of array aParam[] */
4433
double *aParam; /* Parameters passed to SQL geom function */
4434
void *pUser; /* Callback implementation user data */
4435
void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
4436
};
4437
4438
4439
#ifdef __cplusplus
4440
} /* end of the 'extern "C"' block */
4441
#endif
4442
4443
#endif /* ifndef _SQLITE3RTREE_H_ */
4444
4445

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button