src/sqlite3.h
author Dirk Zimmermann <dz@pep.security>
Thu, 11 Apr 2019 10:46:46 +0200
branchIOS-1482
changeset 3505 3fe4b41696d3
parent 3192 8797e99f7ab2
permissions -rw-r--r--
IOS-1482 close branch
vb@130
     1
/*
dz@3192
     2
** 2001-09-15
vb@130
     3
**
vb@130
     4
** The author disclaims copyright to this source code.  In place of
vb@130
     5
** a legal notice, here is a blessing:
vb@130
     6
**
vb@130
     7
**    May you do good and not evil.
vb@130
     8
**    May you find forgiveness for yourself and forgive others.
vb@130
     9
**    May you share freely, never taking more than you give.
vb@130
    10
**
vb@130
    11
*************************************************************************
vb@130
    12
** This header file defines the interface that the SQLite library
vb@130
    13
** presents to client programs.  If a C-function, structure, datatype,
vb@130
    14
** or constant definition does not appear in this file, then it is
vb@130
    15
** not a published API of SQLite, is subject to change without
vb@130
    16
** notice, and should not be referenced by programs that use SQLite.
vb@130
    17
**
vb@130
    18
** Some of the definitions that are in this file are marked as
vb@130
    19
** "experimental".  Experimental interfaces are normally new
vb@130
    20
** features recently added to SQLite.  We do not anticipate changes
vb@130
    21
** to experimental interfaces but reserve the right to make minor changes
vb@130
    22
** if experience from use "in the wild" suggest such changes are prudent.
vb@130
    23
**
vb@130
    24
** The official C-language API documentation for SQLite is derived
vb@130
    25
** from comments in this file.  This file is the authoritative source
Edouard@491
    26
** on how SQLite interfaces are supposed to operate.
vb@130
    27
**
vb@130
    28
** The name of this file under configuration management is "sqlite.h.in".
vb@130
    29
** The makefile makes some minor changes to this file (such as inserting
vb@130
    30
** the version number) and changes its name to "sqlite3.h" as
vb@130
    31
** part of the build process.
vb@130
    32
*/
edouard@1912
    33
#ifndef SQLITE3_H
edouard@1912
    34
#define SQLITE3_H
vb@130
    35
#include <stdarg.h>     /* Needed for the definition of va_list */
vb@130
    36
vb@130
    37
/*
vb@130
    38
** Make sure we can call this stuff from C++.
vb@130
    39
*/
vb@130
    40
#ifdef __cplusplus
vb@130
    41
extern "C" {
vb@130
    42
#endif
vb@130
    43
vb@130
    44
vb@130
    45
/*
Edouard@491
    46
** Provide the ability to override linkage features of the interface.
vb@130
    47
*/
vb@130
    48
#ifndef SQLITE_EXTERN
vb@130
    49
# define SQLITE_EXTERN extern
vb@130
    50
#endif
vb@130
    51
#ifndef SQLITE_API
vb@130
    52
# define SQLITE_API
vb@130
    53
#endif
Edouard@491
    54
#ifndef SQLITE_CDECL
Edouard@491
    55
# define SQLITE_CDECL
Edouard@491
    56
#endif
edouard@1912
    57
#ifndef SQLITE_APICALL
edouard@1912
    58
# define SQLITE_APICALL
edouard@1912
    59
#endif
Edouard@491
    60
#ifndef SQLITE_STDCALL
edouard@1912
    61
# define SQLITE_STDCALL SQLITE_APICALL
edouard@1912
    62
#endif
edouard@1912
    63
#ifndef SQLITE_CALLBACK
edouard@1912
    64
# define SQLITE_CALLBACK
edouard@1912
    65
#endif
edouard@1912
    66
#ifndef SQLITE_SYSAPI
edouard@1912
    67
# define SQLITE_SYSAPI
Edouard@491
    68
#endif
vb@130
    69
vb@130
    70
/*
vb@130
    71
** These no-op macros are used in front of interfaces to mark those
vb@130
    72
** interfaces as either deprecated or experimental.  New applications
Edouard@491
    73
** should not use deprecated interfaces - they are supported for backwards
vb@130
    74
** compatibility only.  Application writers should be aware that
vb@130
    75
** experimental interfaces are subject to change in point releases.
vb@130
    76
**
vb@130
    77
** These macros used to resolve to various kinds of compiler magic that
vb@130
    78
** would generate warning messages when they were used.  But that
vb@130
    79
** compiler magic ended up generating such a flurry of bug reports
vb@130
    80
** that we have taken it all out and gone back to using simple
vb@130
    81
** noop macros.
vb@130
    82
*/
vb@130
    83
#define SQLITE_DEPRECATED
vb@130
    84
#define SQLITE_EXPERIMENTAL
vb@130
    85
vb@130
    86
/*
vb@130
    87
** Ensure these symbols were not defined by some previous header file.
vb@130
    88
*/
vb@130
    89
#ifdef SQLITE_VERSION
vb@130
    90
# undef SQLITE_VERSION
vb@130
    91
#endif
vb@130
    92
#ifdef SQLITE_VERSION_NUMBER
vb@130
    93
# undef SQLITE_VERSION_NUMBER
vb@130
    94
#endif
vb@130
    95
vb@130
    96
/*
vb@130
    97
** CAPI3REF: Compile-Time Library Version Numbers
vb@130
    98
**
vb@130
    99
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
vb@130
   100
** evaluates to a string literal that is the SQLite version in the
vb@130
   101
** format "X.Y.Z" where X is the major version number (always 3 for
vb@130
   102
** SQLite3) and Y is the minor version number and Z is the release number.)^
vb@130
   103
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
vb@130
   104
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
vb@130
   105
** numbers used in [SQLITE_VERSION].)^
vb@130
   106
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
vb@130
   107
** be larger than the release from which it is derived.  Either Y will
vb@130
   108
** be held constant and Z will be incremented or else Y will be incremented
vb@130
   109
** and Z will be reset to zero.
vb@130
   110
**
edouard@1912
   111
** Since [version 3.6.18] ([dateof:3.6.18]), 
edouard@1912
   112
** SQLite source code has been stored in the
vb@130
   113
** <a href="http://www.fossil-scm.org/">Fossil configuration management
vb@130
   114
** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
vb@130
   115
** a string which identifies a particular check-in of SQLite
vb@130
   116
** within its configuration management system.  ^The SQLITE_SOURCE_ID
edouard@1912
   117
** string contains the date and time of the check-in (UTC) and a SHA1
dz@3192
   118
** or SHA3-256 hash of the entire source tree.  If the source code has
dz@3192
   119
** been edited in any way since it was last checked in, then the last
dz@3192
   120
** four hexadecimal digits of the hash may be modified.
vb@130
   121
**
vb@130
   122
** See also: [sqlite3_libversion()],
vb@130
   123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
vb@130
   124
** [sqlite_version()] and [sqlite_source_id()].
vb@130
   125
*/
dz@3192
   126
#define SQLITE_VERSION        "3.26.0"
dz@3192
   127
#define SQLITE_VERSION_NUMBER 3026000
dz@3192
   128
#define SQLITE_SOURCE_ID      "2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600fb58238b4f9"
vb@130
   129
vb@130
   130
/*
vb@130
   131
** CAPI3REF: Run-Time Library Version Numbers
edouard@1912
   132
** KEYWORDS: sqlite3_version sqlite3_sourceid
vb@130
   133
**
vb@130
   134
** These interfaces provide the same information as the [SQLITE_VERSION],
vb@130
   135
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
vb@130
   136
** but are associated with the library instead of the header file.  ^(Cautious
vb@130
   137
** programmers might include assert() statements in their application to
vb@130
   138
** verify that values returned by these interfaces match the macros in
Edouard@491
   139
** the header, and thus ensure that the application is
vb@130
   140
** compiled with matching library and header files.
vb@130
   141
**
vb@130
   142
** <blockquote><pre>
vb@130
   143
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
dz@3192
   144
** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
vb@130
   145
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
vb@130
   146
** </pre></blockquote>)^
vb@130
   147
**
vb@130
   148
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
vb@130
   149
** macro.  ^The sqlite3_libversion() function returns a pointer to the
vb@130
   150
** to the sqlite3_version[] string constant.  The sqlite3_libversion()
vb@130
   151
** function is provided for use in DLLs since DLL users usually do not have
vb@130
   152
** direct access to string constants within the DLL.  ^The
vb@130
   153
** sqlite3_libversion_number() function returns an integer equal to
dz@3192
   154
** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns 
vb@130
   155
** a pointer to a string constant whose value is the same as the 
dz@3192
   156
** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
dz@3192
   157
** using an edited copy of [the amalgamation], then the last four characters
dz@3192
   158
** of the hash might be different from [SQLITE_SOURCE_ID].)^
vb@130
   159
**
vb@130
   160
** See also: [sqlite_version()] and [sqlite_source_id()].
vb@130
   161
*/
vb@130
   162
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
edouard@1912
   163
SQLITE_API const char *sqlite3_libversion(void);
edouard@1912
   164
SQLITE_API const char *sqlite3_sourceid(void);
edouard@1912
   165
SQLITE_API int sqlite3_libversion_number(void);
vb@130
   166
vb@130
   167
/*
vb@130
   168
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
vb@130
   169
**
vb@130
   170
** ^The sqlite3_compileoption_used() function returns 0 or 1 
vb@130
   171
** indicating whether the specified option was defined at 
vb@130
   172
** compile time.  ^The SQLITE_ prefix may be omitted from the 
vb@130
   173
** option name passed to sqlite3_compileoption_used().  
vb@130
   174
**
vb@130
   175
** ^The sqlite3_compileoption_get() function allows iterating
vb@130
   176
** over the list of options that were defined at compile time by
vb@130
   177
** returning the N-th compile time option string.  ^If N is out of range,
vb@130
   178
** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_ 
vb@130
   179
** prefix is omitted from any strings returned by 
vb@130
   180
** sqlite3_compileoption_get().
vb@130
   181
**
vb@130
   182
** ^Support for the diagnostic functions sqlite3_compileoption_used()
vb@130
   183
** and sqlite3_compileoption_get() may be omitted by specifying the 
vb@130
   184
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
vb@130
   185
**
vb@130
   186
** See also: SQL functions [sqlite_compileoption_used()] and
vb@130
   187
** [sqlite_compileoption_get()] and the [compile_options pragma].
vb@130
   188
*/
vb@130
   189
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
edouard@1912
   190
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
edouard@1912
   191
SQLITE_API const char *sqlite3_compileoption_get(int N);
vb@130
   192
#endif
vb@130
   193
vb@130
   194
/*
vb@130
   195
** CAPI3REF: Test To See If The Library Is Threadsafe
vb@130
   196
**
vb@130
   197
** ^The sqlite3_threadsafe() function returns zero if and only if
vb@130
   198
** SQLite was compiled with mutexing code omitted due to the
vb@130
   199
** [SQLITE_THREADSAFE] compile-time option being set to 0.
vb@130
   200
**
vb@130
   201
** SQLite can be compiled with or without mutexes.  When
vb@130
   202
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
vb@130
   203
** are enabled and SQLite is threadsafe.  When the
vb@130
   204
** [SQLITE_THREADSAFE] macro is 0, 
vb@130
   205
** the mutexes are omitted.  Without the mutexes, it is not safe
vb@130
   206
** to use SQLite concurrently from more than one thread.
vb@130
   207
**
vb@130
   208
** Enabling mutexes incurs a measurable performance penalty.
vb@130
   209
** So if speed is of utmost importance, it makes sense to disable
vb@130
   210
** the mutexes.  But for maximum safety, mutexes should be enabled.
vb@130
   211
** ^The default behavior is for mutexes to be enabled.
vb@130
   212
**
vb@130
   213
** This interface can be used by an application to make sure that the
vb@130
   214
** version of SQLite that it is linking against was compiled with
vb@130
   215
** the desired setting of the [SQLITE_THREADSAFE] macro.
vb@130
   216
**
vb@130
   217
** This interface only reports on the compile-time mutex setting
vb@130
   218
** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
vb@130
   219
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
vb@130
   220
** can be fully or partially disabled using a call to [sqlite3_config()]
vb@130
   221
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
Edouard@491
   222
** or [SQLITE_CONFIG_SERIALIZED].  ^(The return value of the
vb@130
   223
** sqlite3_threadsafe() function shows only the compile-time setting of
vb@130
   224
** thread safety, not any run-time changes to that setting made by
vb@130
   225
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
vb@130
   226
** is unchanged by calls to sqlite3_config().)^
vb@130
   227
**
vb@130
   228
** See the [threading mode] documentation for additional information.
vb@130
   229
*/
edouard@1912
   230
SQLITE_API int sqlite3_threadsafe(void);
vb@130
   231
vb@130
   232
/*
vb@130
   233
** CAPI3REF: Database Connection Handle
vb@130
   234
** KEYWORDS: {database connection} {database connections}
vb@130
   235
**
vb@130
   236
** Each open SQLite database is represented by a pointer to an instance of
vb@130
   237
** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
vb@130
   238
** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
vb@130
   239
** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
vb@130
   240
** and [sqlite3_close_v2()] are its destructors.  There are many other
vb@130
   241
** interfaces (such as
vb@130
   242
** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
vb@130
   243
** [sqlite3_busy_timeout()] to name but three) that are methods on an
vb@130
   244
** sqlite3 object.
vb@130
   245
*/
vb@130
   246
typedef struct sqlite3 sqlite3;
vb@130
   247
vb@130
   248
/*
vb@130
   249
** CAPI3REF: 64-Bit Integer Types
vb@130
   250
** KEYWORDS: sqlite_int64 sqlite_uint64
vb@130
   251
**
vb@130
   252
** Because there is no cross-platform way to specify 64-bit integer types
vb@130
   253
** SQLite includes typedefs for 64-bit signed and unsigned integers.
vb@130
   254
**
vb@130
   255
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
vb@130
   256
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
vb@130
   257
** compatibility only.
vb@130
   258
**
vb@130
   259
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
vb@130
   260
** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
vb@130
   261
** sqlite3_uint64 and sqlite_uint64 types can store integer values 
vb@130
   262
** between 0 and +18446744073709551615 inclusive.
vb@130
   263
*/
vb@130
   264
#ifdef SQLITE_INT64_TYPE
vb@130
   265
  typedef SQLITE_INT64_TYPE sqlite_int64;
edouard@1912
   266
# ifdef SQLITE_UINT64_TYPE
edouard@1912
   267
    typedef SQLITE_UINT64_TYPE sqlite_uint64;
edouard@1912
   268
# else  
edouard@1912
   269
    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
edouard@1912
   270
# endif
vb@130
   271
#elif defined(_MSC_VER) || defined(__BORLANDC__)
vb@130
   272
  typedef __int64 sqlite_int64;
vb@130
   273
  typedef unsigned __int64 sqlite_uint64;
vb@130
   274
#else
vb@130
   275
  typedef long long int sqlite_int64;
vb@130
   276
  typedef unsigned long long int sqlite_uint64;
vb@130
   277
#endif
vb@130
   278
typedef sqlite_int64 sqlite3_int64;
vb@130
   279
typedef sqlite_uint64 sqlite3_uint64;
vb@130
   280
vb@130
   281
/*
vb@130
   282
** If compiling for a processor that lacks floating point support,
vb@130
   283
** substitute integer for floating-point.
vb@130
   284
*/
vb@130
   285
#ifdef SQLITE_OMIT_FLOATING_POINT
vb@130
   286
# define double sqlite3_int64
vb@130
   287
#endif
vb@130
   288
vb@130
   289
/*
vb@130
   290
** CAPI3REF: Closing A Database Connection
Edouard@491
   291
** DESTRUCTOR: sqlite3
vb@130
   292
**
vb@130
   293
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
vb@130
   294
** for the [sqlite3] object.
vb@130
   295
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
vb@130
   296
** the [sqlite3] object is successfully destroyed and all associated
vb@130
   297
** resources are deallocated.
vb@130
   298
**
vb@130
   299
** ^If the database connection is associated with unfinalized prepared
vb@130
   300
** statements or unfinished sqlite3_backup objects then sqlite3_close()
vb@130
   301
** will leave the database connection open and return [SQLITE_BUSY].
vb@130
   302
** ^If sqlite3_close_v2() is called with unfinalized prepared statements
vb@130
   303
** and/or unfinished sqlite3_backups, then the database connection becomes
vb@130
   304
** an unusable "zombie" which will automatically be deallocated when the
vb@130
   305
** last prepared statement is finalized or the last sqlite3_backup is
vb@130
   306
** finished.  The sqlite3_close_v2() interface is intended for use with
vb@130
   307
** host languages that are garbage collected, and where the order in which
vb@130
   308
** destructors are called is arbitrary.
vb@130
   309
**
vb@130
   310
** Applications should [sqlite3_finalize | finalize] all [prepared statements],
vb@130
   311
** [sqlite3_blob_close | close] all [BLOB handles], and 
vb@130
   312
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
vb@130
   313
** with the [sqlite3] object prior to attempting to close the object.  ^If
vb@130
   314
** sqlite3_close_v2() is called on a [database connection] that still has
vb@130
   315
** outstanding [prepared statements], [BLOB handles], and/or
vb@130
   316
** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
vb@130
   317
** of resources is deferred until all [prepared statements], [BLOB handles],
vb@130
   318
** and [sqlite3_backup] objects are also destroyed.
vb@130
   319
**
vb@130
   320
** ^If an [sqlite3] object is destroyed while a transaction is open,
vb@130
   321
** the transaction is automatically rolled back.
vb@130
   322
**
vb@130
   323
** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
vb@130
   324
** must be either a NULL
vb@130
   325
** pointer or an [sqlite3] object pointer obtained
vb@130
   326
** from [sqlite3_open()], [sqlite3_open16()], or
vb@130
   327
** [sqlite3_open_v2()], and not previously closed.
vb@130
   328
** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
vb@130
   329
** argument is a harmless no-op.
vb@130
   330
*/
edouard@1912
   331
SQLITE_API int sqlite3_close(sqlite3*);
edouard@1912
   332
SQLITE_API int sqlite3_close_v2(sqlite3*);
vb@130
   333
vb@130
   334
/*
vb@130
   335
** The type for a callback function.
vb@130
   336
** This is legacy and deprecated.  It is included for historical
vb@130
   337
** compatibility and is not documented.
vb@130
   338
*/
vb@130
   339
typedef int (*sqlite3_callback)(void*,int,char**, char**);
vb@130
   340
vb@130
   341
/*
vb@130
   342
** CAPI3REF: One-Step Query Execution Interface
Edouard@491
   343
** METHOD: sqlite3
vb@130
   344
**
vb@130
   345
** The sqlite3_exec() interface is a convenience wrapper around
vb@130
   346
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
vb@130
   347
** that allows an application to run multiple statements of SQL
vb@130
   348
** without having to use a lot of C code. 
vb@130
   349
**
vb@130
   350
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
vb@130
   351
** semicolon-separate SQL statements passed into its 2nd argument,
vb@130
   352
** in the context of the [database connection] passed in as its 1st
vb@130
   353
** argument.  ^If the callback function of the 3rd argument to
vb@130
   354
** sqlite3_exec() is not NULL, then it is invoked for each result row
vb@130
   355
** coming out of the evaluated SQL statements.  ^The 4th argument to
vb@130
   356
** sqlite3_exec() is relayed through to the 1st argument of each
vb@130
   357
** callback invocation.  ^If the callback pointer to sqlite3_exec()
vb@130
   358
** is NULL, then no callback is ever invoked and result rows are
vb@130
   359
** ignored.
vb@130
   360
**
vb@130
   361
** ^If an error occurs while evaluating the SQL statements passed into
vb@130
   362
** sqlite3_exec(), then execution of the current statement stops and
vb@130
   363
** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
vb@130
   364
** is not NULL then any error message is written into memory obtained
vb@130
   365
** from [sqlite3_malloc()] and passed back through the 5th parameter.
vb@130
   366
** To avoid memory leaks, the application should invoke [sqlite3_free()]
vb@130
   367
** on error message strings returned through the 5th parameter of
Edouard@491
   368
** sqlite3_exec() after the error message string is no longer needed.
vb@130
   369
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
vb@130
   370
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
vb@130
   371
** NULL before returning.
vb@130
   372
**
vb@130
   373
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
vb@130
   374
** routine returns SQLITE_ABORT without invoking the callback again and
vb@130
   375
** without running any subsequent SQL statements.
vb@130
   376
**
vb@130
   377
** ^The 2nd argument to the sqlite3_exec() callback function is the
vb@130
   378
** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
vb@130
   379
** callback is an array of pointers to strings obtained as if from
vb@130
   380
** [sqlite3_column_text()], one for each column.  ^If an element of a
vb@130
   381
** result row is NULL then the corresponding string pointer for the
vb@130
   382
** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
vb@130
   383
** sqlite3_exec() callback is an array of pointers to strings where each
vb@130
   384
** entry represents the name of corresponding result column as obtained
vb@130
   385
** from [sqlite3_column_name()].
vb@130
   386
**
vb@130
   387
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
vb@130
   388
** to an empty string, or a pointer that contains only whitespace and/or 
vb@130
   389
** SQL comments, then no SQL statements are evaluated and the database
vb@130
   390
** is not changed.
vb@130
   391
**
vb@130
   392
** Restrictions:
vb@130
   393
**
vb@130
   394
** <ul>
Edouard@491
   395
** <li> The application must ensure that the 1st parameter to sqlite3_exec()
vb@130
   396
**      is a valid and open [database connection].
vb@130
   397
** <li> The application must not close the [database connection] specified by
vb@130
   398
**      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
vb@130
   399
** <li> The application must not modify the SQL statement text passed into
vb@130
   400
**      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
vb@130
   401
** </ul>
vb@130
   402
*/
edouard@1912
   403
SQLITE_API int sqlite3_exec(
vb@130
   404
  sqlite3*,                                  /* An open database */
vb@130
   405
  const char *sql,                           /* SQL to be evaluated */
vb@130
   406
  int (*callback)(void*,int,char**,char**),  /* Callback function */
vb@130
   407
  void *,                                    /* 1st argument to callback */
vb@130
   408
  char **errmsg                              /* Error msg written here */
vb@130
   409
);
vb@130
   410
vb@130
   411
/*
vb@130
   412
** CAPI3REF: Result Codes
vb@130
   413
** KEYWORDS: {result code definitions}
vb@130
   414
**
vb@130
   415
** Many SQLite functions return an integer result code from the set shown
vb@130
   416
** here in order to indicate success or failure.
vb@130
   417
**
vb@130
   418
** New error codes may be added in future versions of SQLite.
vb@130
   419
**
vb@130
   420
** See also: [extended result code definitions]
vb@130
   421
*/
vb@130
   422
#define SQLITE_OK           0   /* Successful result */
vb@130
   423
/* beginning-of-error-codes */
dz@3192
   424
#define SQLITE_ERROR        1   /* Generic error */
vb@130
   425
#define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
vb@130
   426
#define SQLITE_PERM         3   /* Access permission denied */
vb@130
   427
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
vb@130
   428
#define SQLITE_BUSY         5   /* The database file is locked */
vb@130
   429
#define SQLITE_LOCKED       6   /* A table in the database is locked */
vb@130
   430
#define SQLITE_NOMEM        7   /* A malloc() failed */
vb@130
   431
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
vb@130
   432
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
vb@130
   433
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
vb@130
   434
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
vb@130
   435
#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
vb@130
   436
#define SQLITE_FULL        13   /* Insertion failed because database is full */
vb@130
   437
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
vb@130
   438
#define SQLITE_PROTOCOL    15   /* Database lock protocol error */
dz@3192
   439
#define SQLITE_EMPTY       16   /* Internal use only */
vb@130
   440
#define SQLITE_SCHEMA      17   /* The database schema changed */
vb@130
   441
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
vb@130
   442
#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
vb@130
   443
#define SQLITE_MISMATCH    20   /* Data type mismatch */
vb@130
   444
#define SQLITE_MISUSE      21   /* Library used incorrectly */
vb@130
   445
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
vb@130
   446
#define SQLITE_AUTH        23   /* Authorization denied */
dz@3192
   447
#define SQLITE_FORMAT      24   /* Not used */
vb@130
   448
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
vb@130
   449
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
vb@130
   450
#define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
vb@130
   451
#define SQLITE_WARNING     28   /* Warnings from sqlite3_log() */
vb@130
   452
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
vb@130
   453
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
vb@130
   454
/* end-of-error-codes */
vb@130
   455
vb@130
   456
/*
vb@130
   457
** CAPI3REF: Extended Result Codes
vb@130
   458
** KEYWORDS: {extended result code definitions}
vb@130
   459
**
vb@130
   460
** In its default configuration, SQLite API routines return one of 30 integer
vb@130
   461
** [result codes].  However, experience has shown that many of
vb@130
   462
** these result codes are too coarse-grained.  They do not provide as
vb@130
   463
** much information about problems as programmers might like.  In an effort to
edouard@1912
   464
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
edouard@1912
   465
** and later) include
vb@130
   466
** support for additional result codes that provide more detailed information
vb@130
   467
** about errors. These [extended result codes] are enabled or disabled
vb@130
   468
** on a per database connection basis using the
vb@130
   469
** [sqlite3_extended_result_codes()] API.  Or, the extended code for
vb@130
   470
** the most recent error can be obtained using
vb@130
   471
** [sqlite3_extended_errcode()].
vb@130
   472
*/
dz@3192
   473
#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
dz@3192
   474
#define SQLITE_ERROR_RETRY             (SQLITE_ERROR | (2<<8))
dz@3192
   475
#define SQLITE_ERROR_SNAPSHOT          (SQLITE_ERROR | (3<<8))
vb@130
   476
#define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
vb@130
   477
#define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
vb@130
   478
#define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
vb@130
   479
#define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
vb@130
   480
#define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
vb@130
   481
#define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
vb@130
   482
#define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
vb@130
   483
#define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
vb@130
   484
#define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
vb@130
   485
#define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
vb@130
   486
#define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
vb@130
   487
#define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
vb@130
   488
#define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
vb@130
   489
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
vb@130
   490
#define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
vb@130
   491
#define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
vb@130
   492
#define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
vb@130
   493
#define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
vb@130
   494
#define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
vb@130
   495
#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
vb@130
   496
#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
vb@130
   497
#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
vb@130
   498
#define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
vb@130
   499
#define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
vb@130
   500
#define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
vb@130
   501
#define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
Edouard@491
   502
#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
Edouard@491
   503
#define SQLITE_IOERR_AUTH              (SQLITE_IOERR | (28<<8))
dz@3192
   504
#define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
dz@3192
   505
#define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
dz@3192
   506
#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
vb@130
   507
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
dz@3192
   508
#define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
vb@130
   509
#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
vb@130
   510
#define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
vb@130
   511
#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
vb@130
   512
#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
vb@130
   513
#define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
vb@130
   514
#define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
dz@3192
   515
#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
vb@130
   516
#define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
dz@3192
   517
#define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
vb@130
   518
#define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
vb@130
   519
#define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
vb@130
   520
#define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
vb@130
   521
#define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
dz@3192
   522
#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
dz@3192
   523
#define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
vb@130
   524
#define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
vb@130
   525
#define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
vb@130
   526
#define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
vb@130
   527
#define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
vb@130
   528
#define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
vb@130
   529
#define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
vb@130
   530
#define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
vb@130
   531
#define SQLITE_CONSTRAINT_TRIGGER      (SQLITE_CONSTRAINT | (7<<8))
vb@130
   532
#define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
vb@130
   533
#define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
vb@130
   534
#define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
vb@130
   535
#define SQLITE_NOTICE_RECOVER_WAL      (SQLITE_NOTICE | (1<<8))
vb@130
   536
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
vb@130
   537
#define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
Edouard@491
   538
#define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
edouard@1912
   539
#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
vb@130
   540
vb@130
   541
/*
vb@130
   542
** CAPI3REF: Flags For File Open Operations
vb@130
   543
**
vb@130
   544
** These bit values are intended for use in the
vb@130
   545
** 3rd parameter to the [sqlite3_open_v2()] interface and
vb@130
   546
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
vb@130
   547
*/
vb@130
   548
#define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
vb@130
   549
#define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
vb@130
   550
#define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
vb@130
   551
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
vb@130
   552
#define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
vb@130
   553
#define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
vb@130
   554
#define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
vb@130
   555
#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
vb@130
   556
#define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
vb@130
   557
#define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
vb@130
   558
#define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
vb@130
   559
#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
vb@130
   560
#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
vb@130
   561
#define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
vb@130
   562
#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
vb@130
   563
#define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
vb@130
   564
#define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
vb@130
   565
#define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
vb@130
   566
#define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
vb@130
   567
#define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
vb@130
   568
vb@130
   569
/* Reserved:                         0x00F00000 */
vb@130
   570
vb@130
   571
/*
vb@130
   572
** CAPI3REF: Device Characteristics
vb@130
   573
**
vb@130
   574
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
vb@130
   575
** object returns an integer which is a vector of these
vb@130
   576
** bit values expressing I/O characteristics of the mass storage
vb@130
   577
** device that holds the file that the [sqlite3_io_methods]
vb@130
   578
** refers to.
vb@130
   579
**
vb@130
   580
** The SQLITE_IOCAP_ATOMIC property means that all writes of
vb@130
   581
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
vb@130
   582
** mean that writes of blocks that are nnn bytes in size and
vb@130
   583
** are aligned to an address which is an integer multiple of
vb@130
   584
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
vb@130
   585
** that when data is appended to a file, the data is appended
vb@130
   586
** first then the size of the file is extended, never the other
vb@130
   587
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
vb@130
   588
** information is written to disk in the same order as calls
vb@130
   589
** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
vb@130
   590
** after reboot following a crash or power loss, the only bytes in a
vb@130
   591
** file that were written at the application level might have changed
vb@130
   592
** and that adjacent bytes, even bytes within the same sector are
vb@130
   593
** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
edouard@1912
   594
** flag indicates that a file cannot be deleted when open.  The
vb@130
   595
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
vb@130
   596
** read-only media and cannot be changed even by processes with
vb@130
   597
** elevated privileges.
dz@3192
   598
**
dz@3192
   599
** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
dz@3192
   600
** filesystem supports doing multiple write operations atomically when those
dz@3192
   601
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
dz@3192
   602
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
vb@130
   603
*/
vb@130
   604
#define SQLITE_IOCAP_ATOMIC                 0x00000001
vb@130
   605
#define SQLITE_IOCAP_ATOMIC512              0x00000002
vb@130
   606
#define SQLITE_IOCAP_ATOMIC1K               0x00000004
vb@130
   607
#define SQLITE_IOCAP_ATOMIC2K               0x00000008
vb@130
   608
#define SQLITE_IOCAP_ATOMIC4K               0x00000010
vb@130
   609
#define SQLITE_IOCAP_ATOMIC8K               0x00000020
vb@130
   610
#define SQLITE_IOCAP_ATOMIC16K              0x00000040
vb@130
   611
#define SQLITE_IOCAP_ATOMIC32K              0x00000080
vb@130
   612
#define SQLITE_IOCAP_ATOMIC64K              0x00000100
vb@130
   613
#define SQLITE_IOCAP_SAFE_APPEND            0x00000200
vb@130
   614
#define SQLITE_IOCAP_SEQUENTIAL             0x00000400
vb@130
   615
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
vb@130
   616
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
vb@130
   617
#define SQLITE_IOCAP_IMMUTABLE              0x00002000
dz@3192
   618
#define SQLITE_IOCAP_BATCH_ATOMIC           0x00004000
vb@130
   619
vb@130
   620
/*
vb@130
   621
** CAPI3REF: File Locking Levels
vb@130
   622
**
vb@130
   623
** SQLite uses one of these integer values as the second
vb@130
   624
** argument to calls it makes to the xLock() and xUnlock() methods
vb@130
   625
** of an [sqlite3_io_methods] object.
vb@130
   626
*/
vb@130
   627
#define SQLITE_LOCK_NONE          0
vb@130
   628
#define SQLITE_LOCK_SHARED        1
vb@130
   629
#define SQLITE_LOCK_RESERVED      2
vb@130
   630
#define SQLITE_LOCK_PENDING       3
vb@130
   631
#define SQLITE_LOCK_EXCLUSIVE     4
vb@130
   632
vb@130
   633
/*
vb@130
   634
** CAPI3REF: Synchronization Type Flags
vb@130
   635
**
vb@130
   636
** When SQLite invokes the xSync() method of an
vb@130
   637
** [sqlite3_io_methods] object it uses a combination of
vb@130
   638
** these integer values as the second argument.
vb@130
   639
**
vb@130
   640
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
vb@130
   641
** sync operation only needs to flush data to mass storage.  Inode
vb@130
   642
** information need not be flushed. If the lower four bits of the flag
vb@130
   643
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
vb@130
   644
** If the lower four bits equal SQLITE_SYNC_FULL, that means
vb@130
   645
** to use Mac OS X style fullsync instead of fsync().
vb@130
   646
**
vb@130
   647
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
vb@130
   648
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
vb@130
   649
** settings.  The [synchronous pragma] determines when calls to the
vb@130
   650
** xSync VFS method occur and applies uniformly across all platforms.
vb@130
   651
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
vb@130
   652
** energetic or rigorous or forceful the sync operations are and
vb@130
   653
** only make a difference on Mac OSX for the default SQLite code.
vb@130
   654
** (Third-party VFS implementations might also make the distinction
vb@130
   655
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
vb@130
   656
** operating systems natively supported by SQLite, only Mac OSX
vb@130
   657
** cares about the difference.)
vb@130
   658
*/
vb@130
   659
#define SQLITE_SYNC_NORMAL        0x00002
vb@130
   660
#define SQLITE_SYNC_FULL          0x00003
vb@130
   661
#define SQLITE_SYNC_DATAONLY      0x00010
vb@130
   662
vb@130
   663
/*
vb@130
   664
** CAPI3REF: OS Interface Open File Handle
vb@130
   665
**
vb@130
   666
** An [sqlite3_file] object represents an open file in the 
vb@130
   667
** [sqlite3_vfs | OS interface layer].  Individual OS interface
vb@130
   668
** implementations will
vb@130
   669
** want to subclass this object by appending additional fields
vb@130
   670
** for their own use.  The pMethods entry is a pointer to an
vb@130
   671
** [sqlite3_io_methods] object that defines methods for performing
vb@130
   672
** I/O operations on the open file.
vb@130
   673
*/
vb@130
   674
typedef struct sqlite3_file sqlite3_file;
vb@130
   675
struct sqlite3_file {
vb@130
   676
  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
vb@130
   677
};
vb@130
   678
vb@130
   679
/*
vb@130
   680
** CAPI3REF: OS Interface File Virtual Methods Object
vb@130
   681
**
vb@130
   682
** Every file opened by the [sqlite3_vfs.xOpen] method populates an
vb@130
   683
** [sqlite3_file] object (or, more commonly, a subclass of the
vb@130
   684
** [sqlite3_file] object) with a pointer to an instance of this object.
vb@130
   685
** This object defines the methods used to perform various operations
vb@130
   686
** against the open file represented by the [sqlite3_file] object.
vb@130
   687
**
vb@130
   688
** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 
vb@130
   689
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
vb@130
   690
** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
vb@130
   691
** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
vb@130
   692
** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
vb@130
   693
** to NULL.
vb@130
   694
**
vb@130
   695
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
vb@130
   696
** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
vb@130
   697
** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
vb@130
   698
** flag may be ORed in to indicate that only the data of the file
vb@130
   699
** and not its inode needs to be synced.
vb@130
   700
**
vb@130
   701
** The integer values to xLock() and xUnlock() are one of
vb@130
   702
** <ul>
vb@130
   703
** <li> [SQLITE_LOCK_NONE],
vb@130
   704
** <li> [SQLITE_LOCK_SHARED],
vb@130
   705
** <li> [SQLITE_LOCK_RESERVED],
vb@130
   706
** <li> [SQLITE_LOCK_PENDING], or
vb@130
   707
** <li> [SQLITE_LOCK_EXCLUSIVE].
vb@130
   708
** </ul>
vb@130
   709
** xLock() increases the lock. xUnlock() decreases the lock.
vb@130
   710
** The xCheckReservedLock() method checks whether any database connection,
vb@130
   711
** either in this process or in some other process, is holding a RESERVED,
vb@130
   712
** PENDING, or EXCLUSIVE lock on the file.  It returns true
vb@130
   713
** if such a lock exists and false otherwise.
vb@130
   714
**
vb@130
   715
** The xFileControl() method is a generic interface that allows custom
vb@130
   716
** VFS implementations to directly control an open file using the
vb@130
   717
** [sqlite3_file_control()] interface.  The second "op" argument is an
vb@130
   718
** integer opcode.  The third argument is a generic pointer intended to
vb@130
   719
** point to a structure that may contain arguments or space in which to
vb@130
   720
** write return values.  Potential uses for xFileControl() might be
vb@130
   721
** functions to enable blocking locks with timeouts, to change the
vb@130
   722
** locking strategy (for example to use dot-file locks), to inquire
vb@130
   723
** about the status of a lock, or to break stale locks.  The SQLite
vb@130
   724
** core reserves all opcodes less than 100 for its own use.
vb@130
   725
** A [file control opcodes | list of opcodes] less than 100 is available.
vb@130
   726
** Applications that define a custom xFileControl method should use opcodes
vb@130
   727
** greater than 100 to avoid conflicts.  VFS implementations should
vb@130
   728
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
vb@130
   729
** recognize.
vb@130
   730
**
vb@130
   731
** The xSectorSize() method returns the sector size of the
vb@130
   732
** device that underlies the file.  The sector size is the
vb@130
   733
** minimum write that can be performed without disturbing
vb@130
   734
** other bytes in the file.  The xDeviceCharacteristics()
vb@130
   735
** method returns a bit vector describing behaviors of the
vb@130
   736
** underlying device:
vb@130
   737
**
vb@130
   738
** <ul>
vb@130
   739
** <li> [SQLITE_IOCAP_ATOMIC]
vb@130
   740
** <li> [SQLITE_IOCAP_ATOMIC512]
vb@130
   741
** <li> [SQLITE_IOCAP_ATOMIC1K]
vb@130
   742
** <li> [SQLITE_IOCAP_ATOMIC2K]
vb@130
   743
** <li> [SQLITE_IOCAP_ATOMIC4K]
vb@130
   744
** <li> [SQLITE_IOCAP_ATOMIC8K]
vb@130
   745
** <li> [SQLITE_IOCAP_ATOMIC16K]
vb@130
   746
** <li> [SQLITE_IOCAP_ATOMIC32K]
vb@130
   747
** <li> [SQLITE_IOCAP_ATOMIC64K]
vb@130
   748
** <li> [SQLITE_IOCAP_SAFE_APPEND]
vb@130
   749
** <li> [SQLITE_IOCAP_SEQUENTIAL]
edouard@1912
   750
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
edouard@1912
   751
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
edouard@1912
   752
** <li> [SQLITE_IOCAP_IMMUTABLE]
dz@3192
   753
** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
vb@130
   754
** </ul>
vb@130
   755
**
vb@130
   756
** The SQLITE_IOCAP_ATOMIC property means that all writes of
vb@130
   757
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
vb@130
   758
** mean that writes of blocks that are nnn bytes in size and
vb@130
   759
** are aligned to an address which is an integer multiple of
vb@130
   760
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
vb@130
   761
** that when data is appended to a file, the data is appended
vb@130
   762
** first then the size of the file is extended, never the other
vb@130
   763
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
vb@130
   764
** information is written to disk in the same order as calls
vb@130
   765
** to xWrite().
vb@130
   766
**
vb@130
   767
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
vb@130
   768
** in the unread portions of the buffer with zeros.  A VFS that
vb@130
   769
** fails to zero-fill short reads might seem to work.  However,
vb@130
   770
** failure to zero-fill short reads will eventually lead to
vb@130
   771
** database corruption.
vb@130
   772
*/
vb@130
   773
typedef struct sqlite3_io_methods sqlite3_io_methods;
vb@130
   774
struct sqlite3_io_methods {
vb@130
   775
  int iVersion;
vb@130
   776
  int (*xClose)(sqlite3_file*);
vb@130
   777
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
vb@130
   778
  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
vb@130
   779
  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
vb@130
   780
  int (*xSync)(sqlite3_file*, int flags);
vb@130
   781
  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
vb@130
   782
  int (*xLock)(sqlite3_file*, int);
vb@130
   783
  int (*xUnlock)(sqlite3_file*, int);
vb@130
   784
  int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
vb@130
   785
  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
vb@130
   786
  int (*xSectorSize)(sqlite3_file*);
vb@130
   787
  int (*xDeviceCharacteristics)(sqlite3_file*);
vb@130
   788
  /* Methods above are valid for version 1 */
vb@130
   789
  int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
vb@130
   790
  int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
vb@130
   791
  void (*xShmBarrier)(sqlite3_file*);
vb@130
   792
  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
vb@130
   793
  /* Methods above are valid for version 2 */
vb@130
   794
  int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
vb@130
   795
  int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
vb@130
   796
  /* Methods above are valid for version 3 */
vb@130
   797
  /* Additional methods may be added in future releases */
vb@130
   798
};
vb@130
   799
vb@130
   800
/*
vb@130
   801
** CAPI3REF: Standard File Control Opcodes
vb@130
   802
** KEYWORDS: {file control opcodes} {file control opcode}
vb@130
   803
**
vb@130
   804
** These integer constants are opcodes for the xFileControl method
vb@130
   805
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
vb@130
   806
** interface.
vb@130
   807
**
Edouard@491
   808
** <ul>
Edouard@491
   809
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
vb@130
   810
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
vb@130
   811
** opcode causes the xFileControl method to write the current state of
vb@130
   812
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
vb@130
   813
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
vb@130
   814
** into an integer that the pArg argument points to. This capability
Edouard@491
   815
** is used during testing and is only available when the SQLITE_TEST
Edouard@491
   816
** compile-time option is used.
Edouard@491
   817
**
vb@130
   818
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
vb@130
   819
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
vb@130
   820
** layer a hint of how large the database file will grow to be during the
vb@130
   821
** current transaction.  This hint is not guaranteed to be accurate but it
vb@130
   822
** is often close.  The underlying VFS might choose to preallocate database
vb@130
   823
** file space based on this hint in order to help writes to the database
vb@130
   824
** file run faster.
vb@130
   825
**
vb@130
   826
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
vb@130
   827
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
vb@130
   828
** extends and truncates the database file in chunks of a size specified
vb@130
   829
** by the user. The fourth argument to [sqlite3_file_control()] should 
vb@130
   830
** point to an integer (type int) containing the new chunk-size to use
vb@130
   831
** for the nominated database. Allocating database file space in large
vb@130
   832
** chunks (say 1MB at a time), may reduce file-system fragmentation and
vb@130
   833
** improve performance on some systems.
vb@130
   834
**
vb@130
   835
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
vb@130
   836
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
vb@130
   837
** to the [sqlite3_file] object associated with a particular database
Edouard@491
   838
** connection.  See also [SQLITE_FCNTL_JOURNAL_POINTER].
Edouard@491
   839
**
Edouard@491
   840
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
Edouard@491
   841
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
Edouard@491
   842
** to the [sqlite3_file] object associated with the journal file (either
Edouard@491
   843
** the [rollback journal] or the [write-ahead log]) for a particular database
Edouard@491
   844
** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
vb@130
   845
**
vb@130
   846
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
vb@130
   847
** No longer in use.
vb@130
   848
**
vb@130
   849
** <li>[[SQLITE_FCNTL_SYNC]]
vb@130
   850
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
vb@130
   851
** sent to the VFS immediately before the xSync method is invoked on a
vb@130
   852
** database file descriptor. Or, if the xSync method is not invoked 
vb@130
   853
** because the user has configured SQLite with 
vb@130
   854
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place 
vb@130
   855
** of the xSync method. In most cases, the pointer argument passed with
vb@130
   856
** this file-control is NULL. However, if the database file is being synced
vb@130
   857
** as part of a multi-database commit, the argument points to a nul-terminated
vb@130
   858
** string containing the transactions master-journal file name. VFSes that 
vb@130
   859
** do not need this signal should silently ignore this opcode. Applications 
vb@130
   860
** should not call [sqlite3_file_control()] with this opcode as doing so may 
vb@130
   861
** disrupt the operation of the specialized VFSes that do require it.  
vb@130
   862
**
vb@130
   863
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
vb@130
   864
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
vb@130
   865
** and sent to the VFS after a transaction has been committed immediately
vb@130
   866
** but before the database is unlocked. VFSes that do not need this signal
vb@130
   867
** should silently ignore this opcode. Applications should not call
vb@130
   868
** [sqlite3_file_control()] with this opcode as doing so may disrupt the 
vb@130
   869
** operation of the specialized VFSes that do require it.  
vb@130
   870
**
vb@130
   871
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
vb@130
   872
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
vb@130
   873
** retry counts and intervals for certain disk I/O operations for the
vb@130
   874
** windows [VFS] in order to provide robustness in the presence of
vb@130
   875
** anti-virus programs.  By default, the windows VFS will retry file read,
vb@130
   876
** file write, and file delete operations up to 10 times, with a delay
vb@130
   877
** of 25 milliseconds before the first retry and with the delay increasing
vb@130
   878
** by an additional 25 milliseconds with each subsequent retry.  This
vb@130
   879
** opcode allows these two values (10 retries and 25 milliseconds of delay)
vb@130
   880
** to be adjusted.  The values are changed for all database connections
vb@130
   881
** within the same process.  The argument is a pointer to an array of two
edouard@1912
   882
** integers where the first integer is the new retry count and the second
vb@130
   883
** integer is the delay.  If either integer is negative, then the setting
vb@130
   884
** is not changed but instead the prior value of that setting is written
vb@130
   885
** into the array entry, allowing the current retry settings to be
vb@130
   886
** interrogated.  The zDbName parameter is ignored.
vb@130
   887
**
vb@130
   888
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
vb@130
   889
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
vb@130
   890
** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
dz@3192
   891
** write ahead log ([WAL file]) and shared memory
dz@3192
   892
** files used for transaction control
vb@130
   893
** are automatically deleted when the latest connection to the database
vb@130
   894
** closes.  Setting persistent WAL mode causes those files to persist after
vb@130
   895
** close.  Persisting the files is useful when other processes that do not
vb@130
   896
** have write permission on the directory containing the database file want
vb@130
   897
** to read the database file, as the WAL and shared memory files must exist
vb@130
   898
** in order for the database to be readable.  The fourth parameter to
vb@130
   899
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
vb@130
   900
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
vb@130
   901
** WAL mode.  If the integer is -1, then it is overwritten with the current
vb@130
   902
** WAL persistence setting.
vb@130
   903
**
vb@130
   904
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
vb@130
   905
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
vb@130
   906
** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
vb@130
   907
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
vb@130
   908
** xDeviceCharacteristics methods. The fourth parameter to
vb@130
   909
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
vb@130
   910
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
vb@130
   911
** mode.  If the integer is -1, then it is overwritten with the current
vb@130
   912
** zero-damage mode setting.
vb@130
   913
**
vb@130
   914
** <li>[[SQLITE_FCNTL_OVERWRITE]]
vb@130
   915
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
vb@130
   916
** a write transaction to indicate that, unless it is rolled back for some
vb@130
   917
** reason, the entire database file will be overwritten by the current 
vb@130
   918
** transaction. This is used by VACUUM operations.
vb@130
   919
**
vb@130
   920
** <li>[[SQLITE_FCNTL_VFSNAME]]
vb@130
   921
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
vb@130
   922
** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
vb@130
   923
** final bottom-level VFS are written into memory obtained from 
vb@130
   924
** [sqlite3_malloc()] and the result is stored in the char* variable
vb@130
   925
** that the fourth parameter of [sqlite3_file_control()] points to.
vb@130
   926
** The caller is responsible for freeing the memory when done.  As with
vb@130
   927
** all file-control actions, there is no guarantee that this will actually
vb@130
   928
** do anything.  Callers should initialize the char* variable to a NULL
vb@130
   929
** pointer in case this file-control is not implemented.  This file-control
vb@130
   930
** is intended for diagnostic use only.
vb@130
   931
**
Edouard@491
   932
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
Edouard@491
   933
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
Edouard@491
   934
** [VFSes] currently in use.  ^(The argument X in
Edouard@491
   935
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
Edouard@491
   936
** of type "[sqlite3_vfs] **".  This opcodes will set *X
Edouard@491
   937
** to a pointer to the top-level VFS.)^
Edouard@491
   938
** ^When there are multiple VFS shims in the stack, this opcode finds the
Edouard@491
   939
** upper-most shim only.
Edouard@491
   940
**
vb@130
   941
** <li>[[SQLITE_FCNTL_PRAGMA]]
vb@130
   942
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 
vb@130
   943
** file control is sent to the open [sqlite3_file] object corresponding
vb@130
   944
** to the database file to which the pragma statement refers. ^The argument
vb@130
   945
** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
vb@130
   946
** pointers to strings (char**) in which the second element of the array
vb@130
   947
** is the name of the pragma and the third element is the argument to the
vb@130
   948
** pragma or NULL if the pragma has no argument.  ^The handler for an
vb@130
   949
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
vb@130
   950
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
vb@130
   951
** or the equivalent and that string will become the result of the pragma or
vb@130
   952
** the error message if the pragma fails. ^If the
vb@130
   953
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 
vb@130
   954
** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
vb@130
   955
** file control returns [SQLITE_OK], then the parser assumes that the
vb@130
   956
** VFS has handled the PRAGMA itself and the parser generates a no-op
Edouard@491
   957
** prepared statement if result string is NULL, or that returns a copy
Edouard@491
   958
** of the result string if the string is non-NULL.
Edouard@491
   959
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
vb@130
   960
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
vb@130
   961
** that the VFS encountered an error while handling the [PRAGMA] and the
vb@130
   962
** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
vb@130
   963
** file control occurs at the beginning of pragma statement analysis and so
vb@130
   964
** it is able to override built-in [PRAGMA] statements.
vb@130
   965
**
vb@130
   966
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
vb@130
   967
** ^The [SQLITE_FCNTL_BUSYHANDLER]
vb@130
   968
** file-control may be invoked by SQLite on the database file handle
vb@130
   969
** shortly after it is opened in order to provide a custom VFS with access
vb@130
   970
** to the connections busy-handler callback. The argument is of type (void **)
vb@130
   971
** - an array of two (void *) values. The first (void *) actually points
vb@130
   972
** to a function of type (int (*)(void *)). In order to invoke the connections
vb@130
   973
** busy-handler, this function should be invoked with the second (void *) in
vb@130
   974
** the array as the only argument. If it returns non-zero, then the operation
vb@130
   975
** should be retried. If it returns zero, the custom VFS should abandon the
vb@130
   976
** current operation.
vb@130
   977
**
vb@130
   978
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
vb@130
   979
** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
vb@130
   980
** to have SQLite generate a
vb@130
   981
** temporary filename using the same algorithm that is followed to generate
vb@130
   982
** temporary filenames for TEMP tables and other internal uses.  The
vb@130
   983
** argument should be a char** which will be filled with the filename
vb@130
   984
** written into memory obtained from [sqlite3_malloc()].  The caller should
vb@130
   985
** invoke [sqlite3_free()] on the result to avoid a memory leak.
vb@130
   986
**
vb@130
   987
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
vb@130
   988
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
vb@130
   989
** maximum number of bytes that will be used for memory-mapped I/O.
vb@130
   990
** The argument is a pointer to a value of type sqlite3_int64 that
vb@130
   991
** is an advisory maximum number of bytes in the file to memory map.  The
vb@130
   992
** pointer is overwritten with the old value.  The limit is not changed if
vb@130
   993
** the value originally pointed to is negative, and so the current limit 
vb@130
   994
** can be queried by passing in a pointer to a negative number.  This
vb@130
   995
** file-control is used internally to implement [PRAGMA mmap_size].
vb@130
   996
**
vb@130
   997
** <li>[[SQLITE_FCNTL_TRACE]]
vb@130
   998
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
vb@130
   999
** to the VFS about what the higher layers of the SQLite stack are doing.
vb@130
  1000
** This file control is used by some VFS activity tracing [shims].
vb@130
  1001
** The argument is a zero-terminated string.  Higher layers in the
vb@130
  1002
** SQLite stack may generate instances of this file control if
vb@130
  1003
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
vb@130
  1004
**
vb@130
  1005
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
vb@130
  1006
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
vb@130
  1007
** pointer to an integer and it writes a boolean into that integer depending
vb@130
  1008
** on whether or not the file has been renamed, moved, or deleted since it
vb@130
  1009
** was first opened.
vb@130
  1010
**
edouard@1912
  1011
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
edouard@1912
  1012
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
edouard@1912
  1013
** underlying native file handle associated with a file handle.  This file
edouard@1912
  1014
** control interprets its argument as a pointer to a native file handle and
edouard@1912
  1015
** writes the resulting value there.
edouard@1912
  1016
**
vb@130
  1017
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
vb@130
  1018
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
vb@130
  1019
** opcode causes the xFileControl method to swap the file handle with the one
vb@130
  1020
** pointed to by the pArg argument.  This capability is used during testing
vb@130
  1021
** and only needs to be supported when SQLITE_TEST is defined.
vb@130
  1022
**
Edouard@491
  1023
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
Edouard@491
  1024
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
Edouard@491
  1025
** be advantageous to block on the next WAL lock if the lock is not immediately
Edouard@491
  1026
** available.  The WAL subsystem issues this signal during rare
Edouard@491
  1027
** circumstances in order to fix a problem with priority inversion.
Edouard@491
  1028
** Applications should <em>not</em> use this file-control.
Edouard@491
  1029
**
Edouard@491
  1030
** <li>[[SQLITE_FCNTL_ZIPVFS]]
Edouard@491
  1031
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
Edouard@491
  1032
** VFS should return SQLITE_NOTFOUND for this opcode.
Edouard@491
  1033
**
Edouard@491
  1034
** <li>[[SQLITE_FCNTL_RBU]]
Edouard@491
  1035
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
Edouard@491
  1036
** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
Edouard@491
  1037
** this opcode.  
dz@3192
  1038
**
dz@3192
  1039
** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
dz@3192
  1040
** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
dz@3192
  1041
** the file descriptor is placed in "batch write mode", which
dz@3192
  1042
** means all subsequent write operations will be deferred and done
dz@3192
  1043
** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
dz@3192
  1044
** that do not support batch atomic writes will return SQLITE_NOTFOUND.
dz@3192
  1045
** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
dz@3192
  1046
** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
dz@3192
  1047
** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
dz@3192
  1048
** no VFS interface calls on the same [sqlite3_file] file descriptor
dz@3192
  1049
** except for calls to the xWrite method and the xFileControl method
dz@3192
  1050
** with [SQLITE_FCNTL_SIZE_HINT].
dz@3192
  1051
**
dz@3192
  1052
** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
dz@3192
  1053
** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
dz@3192
  1054
** operations since the previous successful call to 
dz@3192
  1055
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
dz@3192
  1056
** This file control returns [SQLITE_OK] if and only if the writes were
dz@3192
  1057
** all performed successfully and have been committed to persistent storage.
dz@3192
  1058
** ^Regardless of whether or not it is successful, this file control takes
dz@3192
  1059
** the file descriptor out of batch write mode so that all subsequent
dz@3192
  1060
** write operations are independent.
dz@3192
  1061
** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
dz@3192
  1062
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
dz@3192
  1063
**
dz@3192
  1064
** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
dz@3192
  1065
** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
dz@3192
  1066
** operations since the previous successful call to 
dz@3192
  1067
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
dz@3192
  1068
** ^This file control takes the file descriptor out of batch write mode
dz@3192
  1069
** so that all subsequent write operations are independent.
dz@3192
  1070
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
dz@3192
  1071
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
dz@3192
  1072
**
dz@3192
  1073
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
dz@3192
  1074
** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
dz@3192
  1075
** a file lock using the xLock or xShmLock methods of the VFS to wait
dz@3192
  1076
** for up to M milliseconds before failing, where M is the single 
dz@3192
  1077
** unsigned integer parameter.
dz@3192
  1078
**
dz@3192
  1079
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
dz@3192
  1080
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
dz@3192
  1081
** a database file.  The argument is a pointer to a 32-bit unsigned integer.
dz@3192
  1082
** The "data version" for the pager is written into the pointer.  The
dz@3192
  1083
** "data version" changes whenever any change occurs to the corresponding
dz@3192
  1084
** database file, either through SQL statements on the same database
dz@3192
  1085
** connection or through transactions committed by separate database
dz@3192
  1086
** connections possibly in other processes. The [sqlite3_total_changes()]
dz@3192
  1087
** interface can be used to find if any database on the connection has changed,
dz@3192
  1088
** but that interface responds to changes on TEMP as well as MAIN and does
dz@3192
  1089
** not provide a mechanism to detect changes to MAIN only.  Also, the
dz@3192
  1090
** [sqlite3_total_changes()] interface responds to internal changes only and
dz@3192
  1091
** omits changes made by other database connections.  The
dz@3192
  1092
** [PRAGMA data_version] command provide a mechanism to detect changes to
dz@3192
  1093
** a single attached database that occur due to other database connections,
dz@3192
  1094
** but omits changes implemented by the database connection on which it is
dz@3192
  1095
** called.  This file control is the only mechanism to detect changes that
dz@3192
  1096
** happen either internally or externally and that are associated with
dz@3192
  1097
** a particular attached database.
vb@130
  1098
** </ul>
vb@130
  1099
*/
vb@130
  1100
#define SQLITE_FCNTL_LOCKSTATE               1
Edouard@491
  1101
#define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
Edouard@491
  1102
#define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
Edouard@491
  1103
#define SQLITE_FCNTL_LAST_ERRNO              4
vb@130
  1104
#define SQLITE_FCNTL_SIZE_HINT               5
vb@130
  1105
#define SQLITE_FCNTL_CHUNK_SIZE              6
vb@130
  1106
#define SQLITE_FCNTL_FILE_POINTER            7
vb@130
  1107
#define SQLITE_FCNTL_SYNC_OMITTED            8
vb@130
  1108
#define SQLITE_FCNTL_WIN32_AV_RETRY          9
vb@130
  1109
#define SQLITE_FCNTL_PERSIST_WAL            10
vb@130
  1110
#define SQLITE_FCNTL_OVERWRITE              11
vb@130
  1111
#define SQLITE_FCNTL_VFSNAME                12
vb@130
  1112
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
vb@130
  1113
#define SQLITE_FCNTL_PRAGMA                 14
vb@130
  1114
#define SQLITE_FCNTL_BUSYHANDLER            15
vb@130
  1115
#define SQLITE_FCNTL_TEMPFILENAME           16
vb@130
  1116
#define SQLITE_FCNTL_MMAP_SIZE              18
vb@130
  1117
#define SQLITE_FCNTL_TRACE                  19
vb@130
  1118
#define SQLITE_FCNTL_HAS_MOVED              20
vb@130
  1119
#define SQLITE_FCNTL_SYNC                   21
vb@130
  1120
#define SQLITE_FCNTL_COMMIT_PHASETWO        22
vb@130
  1121
#define SQLITE_FCNTL_WIN32_SET_HANDLE       23
Edouard@491
  1122
#define SQLITE_FCNTL_WAL_BLOCK              24
Edouard@491
  1123
#define SQLITE_FCNTL_ZIPVFS                 25
Edouard@491
  1124
#define SQLITE_FCNTL_RBU                    26
Edouard@491
  1125
#define SQLITE_FCNTL_VFS_POINTER            27
Edouard@491
  1126
#define SQLITE_FCNTL_JOURNAL_POINTER        28
edouard@1912
  1127
#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
edouard@1912
  1128
#define SQLITE_FCNTL_PDB                    30
dz@3192
  1129
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
dz@3192
  1130
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
dz@3192
  1131
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
dz@3192
  1132
#define SQLITE_FCNTL_LOCK_TIMEOUT           34
dz@3192
  1133
#define SQLITE_FCNTL_DATA_VERSION           35
Edouard@491
  1134
Edouard@491
  1135
/* deprecated names */
Edouard@491
  1136
#define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
Edouard@491
  1137
#define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
Edouard@491
  1138
#define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
Edouard@491
  1139
vb@130
  1140
vb@130
  1141
/*
vb@130
  1142
** CAPI3REF: Mutex Handle
vb@130
  1143
**
vb@130
  1144
** The mutex module within SQLite defines [sqlite3_mutex] to be an
vb@130
  1145
** abstract type for a mutex object.  The SQLite core never looks
vb@130
  1146
** at the internal representation of an [sqlite3_mutex].  It only
vb@130
  1147
** deals with pointers to the [sqlite3_mutex] object.
vb@130
  1148
**
vb@130
  1149
** Mutexes are created using [sqlite3_mutex_alloc()].
vb@130
  1150
*/
vb@130
  1151
typedef struct sqlite3_mutex sqlite3_mutex;
vb@130
  1152
vb@130
  1153
/*
edouard@1912
  1154
** CAPI3REF: Loadable Extension Thunk
edouard@1912
  1155
**
edouard@1912
  1156
** A pointer to the opaque sqlite3_api_routines structure is passed as
edouard@1912
  1157
** the third parameter to entry points of [loadable extensions].  This
edouard@1912
  1158
** structure must be typedefed in order to work around compiler warnings
edouard@1912
  1159
** on some platforms.
edouard@1912
  1160
*/
edouard@1912
  1161
typedef struct sqlite3_api_routines sqlite3_api_routines;
edouard@1912
  1162
edouard@1912
  1163
/*
vb@130
  1164
** CAPI3REF: OS Interface Object
vb@130
  1165
**
vb@130
  1166
** An instance of the sqlite3_vfs object defines the interface between
vb@130
  1167
** the SQLite core and the underlying operating system.  The "vfs"
vb@130
  1168
** in the name of the object stands for "virtual file system".  See
vb@130
  1169
** the [VFS | VFS documentation] for further information.
vb@130
  1170
**
dz@3192
  1171
** The VFS interface is sometimes extended by adding new methods onto
dz@3192
  1172
** the end.  Each time such an extension occurs, the iVersion field
dz@3192
  1173
** is incremented.  The iVersion value started out as 1 in
dz@3192
  1174
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
dz@3192
  1175
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
dz@3192
  1176
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
dz@3192
  1177
** may be appended to the sqlite3_vfs object and the iVersion value
dz@3192
  1178
** may increase again in future versions of SQLite.
dz@3192
  1179
** Note that the structure
dz@3192
  1180
** of the sqlite3_vfs object changes in the transition from
dz@3192
  1181
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
dz@3192
  1182
** and yet the iVersion field was not modified.
vb@130
  1183
**
vb@130
  1184
** The szOsFile field is the size of the subclassed [sqlite3_file]
vb@130
  1185
** structure used by this VFS.  mxPathname is the maximum length of
vb@130
  1186
** a pathname in this VFS.
vb@130
  1187
**
vb@130
  1188
** Registered sqlite3_vfs objects are kept on a linked list formed by
vb@130
  1189
** the pNext pointer.  The [sqlite3_vfs_register()]
vb@130
  1190
** and [sqlite3_vfs_unregister()] interfaces manage this list
vb@130
  1191
** in a thread-safe way.  The [sqlite3_vfs_find()] interface
vb@130
  1192
** searches the list.  Neither the application code nor the VFS
vb@130
  1193
** implementation should use the pNext pointer.
vb@130
  1194
**
vb@130
  1195
** The pNext field is the only field in the sqlite3_vfs
vb@130
  1196
** structure that SQLite will ever modify.  SQLite will only access
vb@130
  1197
** or modify this field while holding a particular static mutex.
vb@130
  1198
** The application should never modify anything within the sqlite3_vfs
vb@130
  1199
** object once the object has been registered.
vb@130
  1200
**
vb@130
  1201
** The zName field holds the name of the VFS module.  The name must
vb@130
  1202
** be unique across all VFS modules.
vb@130
  1203
**
vb@130
  1204
** [[sqlite3_vfs.xOpen]]
vb@130
  1205
** ^SQLite guarantees that the zFilename parameter to xOpen
vb@130
  1206
** is either a NULL pointer or string obtained
vb@130
  1207
** from xFullPathname() with an optional suffix added.
vb@130
  1208
** ^If a suffix is added to the zFilename parameter, it will
vb@130
  1209
** consist of a single "-" character followed by no more than
vb@130
  1210
** 11 alphanumeric and/or "-" characters.
vb@130
  1211
** ^SQLite further guarantees that
vb@130
  1212
** the string will be valid and unchanged until xClose() is
vb@130
  1213
** called. Because of the previous sentence,
vb@130
  1214
** the [sqlite3_file] can safely store a pointer to the
vb@130
  1215
** filename if it needs to remember the filename for some reason.
vb@130
  1216
** If the zFilename parameter to xOpen is a NULL pointer then xOpen
vb@130
  1217
** must invent its own temporary name for the file.  ^Whenever the 
vb@130
  1218
** xFilename parameter is NULL it will also be the case that the
vb@130
  1219
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
vb@130
  1220
**
vb@130
  1221
** The flags argument to xOpen() includes all bits set in
vb@130
  1222
** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
vb@130
  1223
** or [sqlite3_open16()] is used, then flags includes at least
vb@130
  1224
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 
vb@130
  1225
** If xOpen() opens a file read-only then it sets *pOutFlags to
vb@130
  1226
** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
vb@130
  1227
**
vb@130
  1228
** ^(SQLite will also add one of the following flags to the xOpen()
vb@130
  1229
** call, depending on the object being opened:
vb@130
  1230
**
vb@130
  1231
** <ul>
vb@130
  1232
** <li>  [SQLITE_OPEN_MAIN_DB]
vb@130
  1233
** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
vb@130
  1234
** <li>  [SQLITE_OPEN_TEMP_DB]
vb@130
  1235
** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
vb@130
  1236
** <li>  [SQLITE_OPEN_TRANSIENT_DB]
vb@130
  1237
** <li>  [SQLITE_OPEN_SUBJOURNAL]
vb@130
  1238
** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
vb@130
  1239
** <li>  [SQLITE_OPEN_WAL]
vb@130
  1240
** </ul>)^
vb@130
  1241
**
vb@130
  1242
** The file I/O implementation can use the object type flags to
vb@130
  1243
** change the way it deals with files.  For example, an application
vb@130
  1244
** that does not care about crash recovery or rollback might make
vb@130
  1245
** the open of a journal file a no-op.  Writes to this journal would
vb@130
  1246
** also be no-ops, and any attempt to read the journal would return
vb@130
  1247
** SQLITE_IOERR.  Or the implementation might recognize that a database
vb@130
  1248
** file will be doing page-aligned sector reads and writes in a random
vb@130
  1249
** order and set up its I/O subsystem accordingly.
vb@130
  1250
**
vb@130
  1251
** SQLite might also add one of the following flags to the xOpen method:
vb@130
  1252
**
vb@130
  1253
** <ul>
vb@130
  1254
** <li> [SQLITE_OPEN_DELETEONCLOSE]
vb@130
  1255
** <li> [SQLITE_OPEN_EXCLUSIVE]
vb@130
  1256
** </ul>
vb@130
  1257
**
vb@130
  1258
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
vb@130
  1259
** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
vb@130
  1260
** will be set for TEMP databases and their journals, transient
vb@130
  1261
** databases, and subjournals.
vb@130
  1262
**
vb@130
  1263
** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
vb@130
  1264
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
vb@130
  1265
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
vb@130
  1266
** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 
vb@130
  1267
** SQLITE_OPEN_CREATE, is used to indicate that file should always
vb@130
  1268
** be created, and that it is an error if it already exists.
vb@130
  1269
** It is <i>not</i> used to indicate the file should be opened 
vb@130
  1270
** for exclusive access.
vb@130
  1271
**
vb@130
  1272
** ^At least szOsFile bytes of memory are allocated by SQLite
vb@130
  1273
** to hold the  [sqlite3_file] structure passed as the third
vb@130
  1274
** argument to xOpen.  The xOpen method does not have to
vb@130
  1275
** allocate the structure; it should just fill it in.  Note that
vb@130
  1276
** the xOpen method must set the sqlite3_file.pMethods to either
vb@130
  1277
** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
vb@130
  1278
** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
vb@130
  1279
** element will be valid after xOpen returns regardless of the success
vb@130
  1280
** or failure of the xOpen call.
vb@130
  1281
**
vb@130
  1282
** [[sqlite3_vfs.xAccess]]
vb@130
  1283
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
vb@130
  1284
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
vb@130
  1285
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
vb@130
  1286
** to test whether a file is at least readable.   The file can be a
vb@130
  1287
** directory.
vb@130
  1288
**
vb@130
  1289
** ^SQLite will always allocate at least mxPathname+1 bytes for the
vb@130
  1290
** output buffer xFullPathname.  The exact size of the output buffer
vb@130
  1291
** is also passed as a parameter to both  methods. If the output buffer
vb@130
  1292
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
vb@130
  1293
** handled as a fatal error by SQLite, vfs implementations should endeavor
vb@130
  1294
** to prevent this by setting mxPathname to a sufficiently large value.
vb@130
  1295
**
vb@130
  1296
** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
vb@130
  1297
** interfaces are not strictly a part of the filesystem, but they are
vb@130
  1298
** included in the VFS structure for completeness.
vb@130
  1299
** The xRandomness() function attempts to return nBytes bytes
vb@130
  1300
** of good-quality randomness into zOut.  The return value is
vb@130
  1301
** the actual number of bytes of randomness obtained.
vb@130
  1302
** The xSleep() method causes the calling thread to sleep for at
vb@130
  1303
** least the number of microseconds given.  ^The xCurrentTime()
vb@130
  1304
** method returns a Julian Day Number for the current date and time as
vb@130
  1305
** a floating point value.
vb@130
  1306
** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
vb@130
  1307
** Day Number multiplied by 86400000 (the number of milliseconds in 
vb@130
  1308
** a 24-hour day).  
vb@130
  1309
** ^SQLite will use the xCurrentTimeInt64() method to get the current
vb@130
  1310
** date and time if that method is available (if iVersion is 2 or 
vb@130
  1311
** greater and the function pointer is not NULL) and will fall back
vb@130
  1312
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
vb@130
  1313
**
vb@130
  1314
** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
vb@130
  1315
** are not used by the SQLite core.  These optional interfaces are provided
vb@130
  1316
** by some VFSes to facilitate testing of the VFS code. By overriding 
vb@130
  1317
** system calls with functions under its control, a test program can
vb@130
  1318
** simulate faults and error conditions that would otherwise be difficult
vb@130
  1319
** or impossible to induce.  The set of system calls that can be overridden
vb@130
  1320
** varies from one VFS to another, and from one version of the same VFS to the
vb@130
  1321
** next.  Applications that use these interfaces must be prepared for any
vb@130
  1322
** or all of these interfaces to be NULL or for their behavior to change
vb@130
  1323
** from one release to the next.  Applications must not attempt to access
vb@130
  1324
** any of these methods if the iVersion of the VFS is less than 3.
vb@130
  1325
*/
vb@130
  1326
typedef struct sqlite3_vfs sqlite3_vfs;
vb@130
  1327
typedef void (*sqlite3_syscall_ptr)(void);
vb@130
  1328
struct sqlite3_vfs {
vb@130
  1329
  int iVersion;            /* Structure version number (currently 3) */
vb@130
  1330
  int szOsFile;            /* Size of subclassed sqlite3_file */
vb@130
  1331
  int mxPathname;          /* Maximum file pathname length */
vb@130
  1332
  sqlite3_vfs *pNext;      /* Next registered VFS */
vb@130
  1333
  const char *zName;       /* Name of this virtual file system */
vb@130
  1334
  void *pAppData;          /* Pointer to application-specific data */
vb@130
  1335
  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
vb@130
  1336
               int flags, int *pOutFlags);
vb@130
  1337
  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
vb@130
  1338
  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
vb@130
  1339
  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
vb@130
  1340
  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
vb@130
  1341
  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
vb@130
  1342
  void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
vb@130
  1343
  void (*xDlClose)(sqlite3_vfs*, void*);
vb@130
  1344
  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
vb@130
  1345
  int (*xSleep)(sqlite3_vfs*, int microseconds);
vb@130
  1346
  int (*xCurrentTime)(sqlite3_vfs*, double*);
vb@130
  1347
  int (*xGetLastError)(sqlite3_vfs*, int, char *);
vb@130
  1348
  /*
vb@130
  1349
  ** The methods above are in version 1 of the sqlite_vfs object
vb@130
  1350
  ** definition.  Those that follow are added in version 2 or later
vb@130
  1351
  */
vb@130
  1352
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
vb@130
  1353
  /*
vb@130
  1354
  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
vb@130
  1355
  ** Those below are for version 3 and greater.
vb@130
  1356
  */
vb@130
  1357
  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
vb@130
  1358
  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
vb@130
  1359
  const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
vb@130
  1360
  /*
vb@130
  1361
  ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
vb@716
  1362
  ** New fields may be appended in future versions.  The iVersion
vb@130
  1363
  ** value will increment whenever this happens. 
vb@130
  1364
  */
vb@130
  1365
};
vb@130
  1366
vb@130
  1367
/*
vb@130
  1368
** CAPI3REF: Flags for the xAccess VFS method
vb@130
  1369
**
vb@130
  1370
** These integer constants can be used as the third parameter to
vb@130
  1371
** the xAccess method of an [sqlite3_vfs] object.  They determine
vb@130
  1372
** what kind of permissions the xAccess method is looking for.
vb@130
  1373
** With SQLITE_ACCESS_EXISTS, the xAccess method
vb@130
  1374
** simply checks whether the file exists.
vb@130
  1375
** With SQLITE_ACCESS_READWRITE, the xAccess method
vb@130
  1376
** checks whether the named directory is both readable and writable
vb@130
  1377
** (in other words, if files can be added, removed, and renamed within
vb@130
  1378
** the directory).
vb@130
  1379
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
vb@130
  1380
** [temp_store_directory pragma], though this could change in a future
vb@130
  1381
** release of SQLite.
vb@130
  1382
** With SQLITE_ACCESS_READ, the xAccess method
vb@130
  1383
** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
vb@130
  1384
** currently unused, though it might be used in a future release of
vb@130
  1385
** SQLite.
vb@130
  1386
*/
vb@130
  1387
#define SQLITE_ACCESS_EXISTS    0
vb@130
  1388
#define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
vb@130
  1389
#define SQLITE_ACCESS_READ      2   /* Unused */
vb@130
  1390
vb@130
  1391
/*
vb@130
  1392
** CAPI3REF: Flags for the xShmLock VFS method
vb@130
  1393
**
vb@130
  1394
** These integer constants define the various locking operations
vb@130
  1395
** allowed by the xShmLock method of [sqlite3_io_methods].  The
vb@130
  1396
** following are the only legal combinations of flags to the
vb@130
  1397
** xShmLock method:
vb@130
  1398
**
vb@130
  1399
** <ul>
vb@130
  1400
** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
vb@130
  1401
** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
vb@130
  1402
** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
vb@130
  1403
** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
vb@130
  1404
** </ul>
vb@130
  1405
**
vb@130
  1406
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
Edouard@491
  1407
** was given on the corresponding lock.  
vb@130
  1408
**
vb@130
  1409
** The xShmLock method can transition between unlocked and SHARED or
vb@130
  1410
** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
vb@130
  1411
** and EXCLUSIVE.
vb@130
  1412
*/
vb@130
  1413
#define SQLITE_SHM_UNLOCK       1
vb@130
  1414
#define SQLITE_SHM_LOCK         2
vb@130
  1415
#define SQLITE_SHM_SHARED       4
vb@130
  1416
#define SQLITE_SHM_EXCLUSIVE    8
vb@130
  1417
vb@130
  1418
/*
vb@130
  1419
** CAPI3REF: Maximum xShmLock index
vb@130
  1420
**
vb@130
  1421
** The xShmLock method on [sqlite3_io_methods] may use values
vb@130
  1422
** between 0 and this upper bound as its "offset" argument.
vb@130
  1423
** The SQLite core will never attempt to acquire or release a
vb@130
  1424
** lock outside of this range
vb@130
  1425
*/
vb@130
  1426
#define SQLITE_SHM_NLOCK        8
vb@130
  1427
vb@130
  1428
vb@130
  1429
/*
vb@130
  1430
** CAPI3REF: Initialize The SQLite Library
vb@130
  1431
**
vb@130
  1432
** ^The sqlite3_initialize() routine initializes the
vb@130
  1433
** SQLite library.  ^The sqlite3_shutdown() routine
vb@130
  1434
** deallocates any resources that were allocated by sqlite3_initialize().
vb@130
  1435
** These routines are designed to aid in process initialization and
vb@130
  1436
** shutdown on embedded systems.  Workstation applications using
vb@130
  1437
** SQLite normally do not need to invoke either of these routines.
vb@130
  1438
**
vb@130
  1439
** A call to sqlite3_initialize() is an "effective" call if it is
vb@130
  1440
** the first time sqlite3_initialize() is invoked during the lifetime of
vb@130
  1441
** the process, or if it is the first time sqlite3_initialize() is invoked
vb@130
  1442
** following a call to sqlite3_shutdown().  ^(Only an effective call
vb@130
  1443
** of sqlite3_initialize() does any initialization.  All other calls
vb@130
  1444
** are harmless no-ops.)^
vb@130
  1445
**
vb@130
  1446
** A call to sqlite3_shutdown() is an "effective" call if it is the first
vb@130
  1447
** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
vb@130
  1448
** an effective call to sqlite3_shutdown() does any deinitialization.
vb@130
  1449
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
vb@130
  1450
**
vb@130
  1451
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
vb@130
  1452
** is not.  The sqlite3_shutdown() interface must only be called from a
vb@130
  1453
** single thread.  All open [database connections] must be closed and all
vb@130
  1454
** other SQLite resources must be deallocated prior to invoking
vb@130
  1455
** sqlite3_shutdown().
vb@130
  1456
**
vb@130
  1457
** Among other things, ^sqlite3_initialize() will invoke
vb@130
  1458
** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
vb@130
  1459
** will invoke sqlite3_os_end().
vb@130
  1460
**
vb@130
  1461
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
vb@130
  1462
** ^If for some reason, sqlite3_initialize() is unable to initialize
vb@130
  1463
** the library (perhaps it is unable to allocate a needed resource such
vb@130
  1464
** as a mutex) it returns an [error code] other than [SQLITE_OK].
vb@130
  1465
**
vb@130
  1466
** ^The sqlite3_initialize() routine is called internally by many other
vb@130
  1467
** SQLite interfaces so that an application usually does not need to
vb@130
  1468
** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
vb@130
  1469
** calls sqlite3_initialize() so the SQLite library will be automatically
vb@130
  1470
** initialized when [sqlite3_open()] is called if it has not be initialized
vb@130
  1471
** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
vb@130
  1472
** compile-time option, then the automatic calls to sqlite3_initialize()
vb@130
  1473
** are omitted and the application must call sqlite3_initialize() directly
vb@130
  1474
** prior to using any other SQLite interface.  For maximum portability,
vb@130
  1475
** it is recommended that applications always invoke sqlite3_initialize()
vb@130
  1476
** directly prior to using any other SQLite interface.  Future releases
vb@130
  1477
** of SQLite may require this.  In other words, the behavior exhibited
vb@130
  1478
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
vb@130
  1479
** default behavior in some future release of SQLite.
vb@130
  1480
**
vb@130
  1481
** The sqlite3_os_init() routine does operating-system specific
vb@130
  1482
** initialization of the SQLite library.  The sqlite3_os_end()
vb@130
  1483
** routine undoes the effect of sqlite3_os_init().  Typical tasks
vb@130
  1484
** performed by these routines include allocation or deallocation
vb@130
  1485
** of static resources, initialization of global variables,
vb@130
  1486
** setting up a default [sqlite3_vfs] module, or setting up
vb@130
  1487
** a default configuration using [sqlite3_config()].
vb@130
  1488
**
vb@130
  1489
** The application should never invoke either sqlite3_os_init()
vb@130
  1490
** or sqlite3_os_end() directly.  The application should only invoke
vb@130
  1491
** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
vb@130
  1492
** interface is called automatically by sqlite3_initialize() and
vb@130
  1493
** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
vb@130
  1494
** implementations for sqlite3_os_init() and sqlite3_os_end()
vb@130
  1495
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
vb@130
  1496
** When [custom builds | built for other platforms]
vb@130
  1497
** (using the [SQLITE_OS_OTHER=1] compile-time
vb@130
  1498
** option) the application must supply a suitable implementation for
vb@130
  1499
** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
vb@130
  1500
** implementation of sqlite3_os_init() or sqlite3_os_end()
vb@130
  1501
** must return [SQLITE_OK] on success and some other [error code] upon
vb@130
  1502
** failure.
vb@130
  1503
*/
edouard@1912
  1504
SQLITE_API int sqlite3_initialize(void);
edouard@1912
  1505
SQLITE_API int sqlite3_shutdown(void);
edouard@1912
  1506
SQLITE_API int sqlite3_os_init(void);
edouard@1912
  1507
SQLITE_API int sqlite3_os_end(void);
vb@130
  1508
vb@130
  1509
/*
vb@130
  1510
** CAPI3REF: Configuring The SQLite Library
vb@130
  1511
**
vb@130
  1512
** The sqlite3_config() interface is used to make global configuration
vb@130
  1513
** changes to SQLite in order to tune SQLite to the specific needs of
vb@130
  1514
** the application.  The default configuration is recommended for most
vb@130
  1515
** applications and so this routine is usually not necessary.  It is
vb@130
  1516
** provided to support rare applications with unusual needs.
vb@130
  1517
**
Edouard@491
  1518
** <b>The sqlite3_config() interface is not threadsafe. The application
Edouard@491
  1519
** must ensure that no other SQLite interfaces are invoked by other
Edouard@491
  1520
** threads while sqlite3_config() is running.</b>
Edouard@491
  1521
**
Edouard@491
  1522
** The sqlite3_config() interface
vb@130
  1523
** may only be invoked prior to library initialization using
vb@130
  1524
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
vb@130
  1525
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
vb@130
  1526
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
vb@130
  1527
** Note, however, that ^sqlite3_config() can be called as part of the
vb@130
  1528
** implementation of an application-defined [sqlite3_os_init()].
vb@130
  1529
**
vb@130
  1530
** The first argument to sqlite3_config() is an integer
vb@130
  1531
** [configuration option] that determines
vb@130
  1532
** what property of SQLite is to be configured.  Subsequent arguments
vb@130
  1533
** vary depending on the [configuration option]
vb@130
  1534
** in the first argument.
vb@130
  1535
**
vb@130
  1536
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
vb@130
  1537
** ^If the option is unknown or SQLite is unable to set the option
vb@130
  1538
** then this routine returns a non-zero [error code].
vb@130
  1539
*/
edouard@1912
  1540
SQLITE_API int sqlite3_config(int, ...);
vb@130
  1541
vb@130
  1542
/*
vb@130
  1543
** CAPI3REF: Configure database connections
Edouard@491
  1544
** METHOD: sqlite3
vb@130
  1545
**
vb@130
  1546
** The sqlite3_db_config() interface is used to make configuration
vb@130
  1547
** changes to a [database connection].  The interface is similar to
vb@130
  1548
** [sqlite3_config()] except that the changes apply to a single
vb@130
  1549
** [database connection] (specified in the first argument).
vb@130
  1550
**
vb@130
  1551
** The second argument to sqlite3_db_config(D,V,...)  is the
vb@130
  1552
** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 
vb@130
  1553
** that indicates what aspect of the [database connection] is being configured.
vb@130
  1554
** Subsequent arguments vary depending on the configuration verb.
vb@130
  1555
**
vb@130
  1556
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
vb@130
  1557
** the call is considered successful.
vb@130
  1558
*/
edouard@1912
  1559
SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
vb@130
  1560
vb@130
  1561
/*
vb@130
  1562
** CAPI3REF: Memory Allocation Routines
vb@130
  1563
**
vb@130
  1564
** An instance of this object defines the interface between SQLite
vb@130
  1565
** and low-level memory allocation routines.
vb@130
  1566
**
vb@130
  1567
** This object is used in only one place in the SQLite interface.
vb@130
  1568
** A pointer to an instance of this object is the argument to
vb@130
  1569
** [sqlite3_config()] when the configuration option is
vb@130
  1570
** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].  
vb@130
  1571
** By creating an instance of this object
vb@130
  1572
** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
vb@130
  1573
** during configuration, an application can specify an alternative
vb@130
  1574
** memory allocation subsystem for SQLite to use for all of its
vb@130
  1575
** dynamic memory needs.
vb@130
  1576
**
vb@130
  1577
** Note that SQLite comes with several [built-in memory allocators]
vb@130
  1578
** that are perfectly adequate for the overwhelming majority of applications
vb@130
  1579
** and that this object is only useful to a tiny minority of applications
vb@130
  1580
** with specialized memory allocation requirements.  This object is
vb@130
  1581
** also used during testing of SQLite in order to specify an alternative
vb@130
  1582
** memory allocator that simulates memory out-of-memory conditions in
vb@130
  1583
** order to verify that SQLite recovers gracefully from such
vb@130
  1584
** conditions.
vb@130
  1585
**
vb@130
  1586
** The xMalloc, xRealloc, and xFree methods must work like the
vb@130
  1587
** malloc(), realloc() and free() functions from the standard C library.
vb@130
  1588
** ^SQLite guarantees that the second argument to
vb@130
  1589
** xRealloc is always a value returned by a prior call to xRoundup.
vb@130
  1590
**
vb@130
  1591
** xSize should return the allocated size of a memory allocation
vb@130
  1592
** previously obtained from xMalloc or xRealloc.  The allocated size
vb@130
  1593
** is always at least as big as the requested size but may be larger.
vb@130
  1594
**
vb@130
  1595
** The xRoundup method returns what would be the allocated size of
vb@130
  1596
** a memory allocation given a particular requested size.  Most memory
vb@130
  1597
** allocators round up memory allocations at least to the next multiple
vb@130
  1598
** of 8.  Some allocators round up to a larger multiple or to a power of 2.
vb@130
  1599
** Every memory allocation request coming in through [sqlite3_malloc()]
vb@130
  1600
** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0, 
vb@130
  1601
** that causes the corresponding memory allocation to fail.
vb@130
  1602
**
vb@130
  1603
** The xInit method initializes the memory allocator.  For example,
vb@130
  1604
** it might allocate any require mutexes or initialize internal data
vb@130
  1605
** structures.  The xShutdown method is invoked (indirectly) by
vb@130
  1606
** [sqlite3_shutdown()] and should deallocate any resources acquired
vb@130
  1607
** by xInit.  The pAppData pointer is used as the only parameter to
vb@130
  1608
** xInit and xShutdown.
vb@130
  1609
**
vb@130
  1610
** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
vb@130
  1611
** the xInit method, so the xInit method need not be threadsafe.  The
vb@130
  1612
** xShutdown method is only called from [sqlite3_shutdown()] so it does
vb@130
  1613
** not need to be threadsafe either.  For all other methods, SQLite
vb@130
  1614
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
vb@130
  1615
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
vb@130
  1616
** it is by default) and so the methods are automatically serialized.
vb@130
  1617
** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
vb@130
  1618
** methods must be threadsafe or else make their own arrangements for
vb@130
  1619
** serialization.
vb@130
  1620
**
vb@130
  1621
** SQLite will never invoke xInit() more than once without an intervening
vb@130
  1622
** call to xShutdown().
vb@130
  1623
*/
vb@130
  1624
typedef struct sqlite3_mem_methods sqlite3_mem_methods;
vb@130
  1625
struct sqlite3_mem_methods {
vb@130
  1626
  void *(*xMalloc)(int);         /* Memory allocation function */
vb@130
  1627
  void (*xFree)(void*);          /* Free a prior allocation */
vb@130
  1628
  void *(*xRealloc)(void*,int);  /* Resize an allocation */
vb@130
  1629
  int (*xSize)(void*);           /* Return the size of an allocation */
vb@130
  1630
  int (*xRoundup)(int);          /* Round up request size to allocation size */
vb@130
  1631
  int (*xInit)(void*);           /* Initialize the memory allocator */
vb@130
  1632
  void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
vb@130
  1633
  void *pAppData;                /* Argument to xInit() and xShutdown() */
vb@130
  1634
};
vb@130
  1635
vb@130
  1636
/*
vb@130
  1637
** CAPI3REF: Configuration Options
vb@130
  1638
** KEYWORDS: {configuration option}
vb@130
  1639
**
vb@130
  1640
** These constants are the available integer configuration options that
vb@130
  1641
** can be passed as the first argument to the [sqlite3_config()] interface.
vb@130
  1642
**
vb@130
  1643
** New configuration options may be added in future releases of SQLite.
vb@130
  1644
** Existing configuration options might be discontinued.  Applications
vb@130
  1645
** should check the return code from [sqlite3_config()] to make sure that
vb@130
  1646
** the call worked.  The [sqlite3_config()] interface will return a
vb@130
  1647
** non-zero [error code] if a discontinued or unsupported configuration option
vb@130
  1648
** is invoked.
vb@130
  1649
**
vb@130
  1650
** <dl>
vb@130
  1651
** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
vb@130
  1652
** <dd>There are no arguments to this option.  ^This option sets the
vb@130
  1653
** [threading mode] to Single-thread.  In other words, it disables
vb@130
  1654
** all mutexing and puts SQLite into a mode where it can only be used
vb@130
  1655
** by a single thread.   ^If SQLite is compiled with
vb@130
  1656
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
vb@130
  1657
** it is not possible to change the [threading mode] from its default
vb@130
  1658
** value of Single-thread and so [sqlite3_config()] will return 
vb@130
  1659
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
vb@130
  1660
** configuration option.</dd>
vb@130
  1661
**
vb@130
  1662
** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
vb@130
  1663
** <dd>There are no arguments to this option.  ^This option sets the
vb@130
  1664
** [threading mode] to Multi-thread.  In other words, it disables
vb@130
  1665
** mutexing on [database connection] and [prepared statement] objects.
vb@130
  1666
** The application is responsible for serializing access to
vb@130
  1667
** [database connections] and [prepared statements].  But other mutexes
vb@130
  1668
** are enabled so that SQLite will be safe to use in a multi-threaded
vb@130
  1669
** environment as long as no two threads attempt to use the same
vb@130
  1670
** [database connection] at the same time.  ^If SQLite is compiled with
vb@130
  1671
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
vb@130
  1672
** it is not possible to set the Multi-thread [threading mode] and
vb@130
  1673
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
vb@130
  1674
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
vb@130
  1675
**
vb@130
  1676
** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
vb@130
  1677
** <dd>There are no arguments to this option.  ^This option sets the
vb@130
  1678
** [threading mode] to Serialized. In other words, this option enables
vb@130
  1679
** all mutexes including the recursive
vb@130
  1680
** mutexes on [database connection] and [prepared statement] objects.
vb@130
  1681
** In this mode (which is the default when SQLite is compiled with
vb@130
  1682
** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
vb@130
  1683
** to [database connections] and [prepared statements] so that the
vb@130
  1684
** application is free to use the same [database connection] or the
vb@130
  1685
** same [prepared statement] in different threads at the same time.
vb@130
  1686
** ^If SQLite is compiled with
vb@130
  1687
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
vb@130
  1688
** it is not possible to set the Serialized [threading mode] and
vb@130
  1689
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
vb@130
  1690
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
vb@130
  1691
**
vb@130
  1692
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
Edouard@491
  1693
** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is 
Edouard@491
  1694
** a pointer to an instance of the [sqlite3_mem_methods] structure.
Edouard@491
  1695
** The argument specifies
vb@130
  1696
** alternative low-level memory allocation routines to be used in place of
vb@130
  1697
** the memory allocation routines built into SQLite.)^ ^SQLite makes
vb@130
  1698
** its own private copy of the content of the [sqlite3_mem_methods] structure
vb@130
  1699
** before the [sqlite3_config()] call returns.</dd>
vb@130
  1700
**
vb@130
  1701
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
Edouard@491
  1702
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
Edouard@491
  1703
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
Edouard@491
  1704
** The [sqlite3_mem_methods]
vb@130
  1705
** structure is filled with the currently defined memory allocation routines.)^
vb@130
  1706
** This option can be used to overload the default memory allocation
vb@130
  1707
** routines with a wrapper that simulations memory allocation failure or
vb@130
  1708
** tracks memory usage, for example. </dd>
vb@130
  1709
**
dz@3192
  1710
** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
dz@3192
  1711
** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
dz@3192
  1712
** type int, interpreted as a boolean, which if true provides a hint to
dz@3192
  1713
** SQLite that it should avoid large memory allocations if possible.
dz@3192
  1714
** SQLite will run faster if it is free to make large memory allocations,
dz@3192
  1715
** but some application might prefer to run slower in exchange for
dz@3192
  1716
** guarantees about memory fragmentation that are possible if large
dz@3192
  1717
** allocations are avoided.  This hint is normally off.
dz@3192
  1718
** </dd>
dz@3192
  1719
**
vb@130
  1720
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
Edouard@491
  1721
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
Edouard@491
  1722
** interpreted as a boolean, which enables or disables the collection of
Edouard@491
  1723
** memory allocation statistics. ^(When memory allocation statistics are
Edouard@491
  1724
** disabled, the following SQLite interfaces become non-operational:
vb@130
  1725
**   <ul>
vb@130
  1726
**   <li> [sqlite3_memory_used()]
vb@130
  1727
**   <li> [sqlite3_memory_highwater()]
vb@130
  1728
**   <li> [sqlite3_soft_heap_limit64()]
Edouard@491
  1729
**   <li> [sqlite3_status64()]
vb@130
  1730
**   </ul>)^
vb@130
  1731
** ^Memory allocation statistics are enabled by default unless SQLite is
vb@130
  1732
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
vb@130
  1733
** allocation statistics are disabled by default.
vb@130
  1734
** </dd>
vb@130
  1735
**
vb@130
  1736
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
dz@3192
  1737
** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
Edouard@491
  1738
** </dd>
vb@130
  1739
**
vb@130
  1740
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
Edouard@491
  1741
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
Edouard@491
  1742
** that SQLite can use for the database page cache with the default page
Edouard@491
  1743
** cache implementation.  
Edouard@491
  1744
** This configuration option is a no-op if an application-define page
Edouard@491
  1745
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
Edouard@491
  1746
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
Edouard@491
  1747
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
Edouard@491
  1748
** and the number of cache lines (N).
vb@130
  1749
** The sz argument should be the size of the largest database page
Edouard@491
  1750
** (a power of two between 512 and 65536) plus some extra bytes for each
Edouard@491
  1751
** page header.  ^The number of extra bytes needed by the page header
Edouard@491
  1752
** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
Edouard@491
  1753
** ^It is harmless, apart from the wasted memory,
Edouard@491
  1754
** for the sz parameter to be larger than necessary.  The pMem
Edouard@491
  1755
** argument must be either a NULL pointer or a pointer to an 8-byte
Edouard@491
  1756
** aligned block of memory of at least sz*N bytes, otherwise
Edouard@491
  1757
** subsequent behavior is undefined.
Edouard@491
  1758
** ^When pMem is not NULL, SQLite will strive to use the memory provided
Edouard@491
  1759
** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
Edouard@491
  1760
** a page cache line is larger than sz bytes or if all of the pMem buffer
Edouard@491
  1761
** is exhausted.
Edouard@491
  1762
** ^If pMem is NULL and N is non-zero, then each database connection
Edouard@491
  1763
** does an initial bulk allocation for page cache memory
Edouard@491
  1764
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
Edouard@491
  1765
** of -1024*N bytes if N is negative, . ^If additional
Edouard@491
  1766
** page cache memory is needed beyond what is provided by the initial
Edouard@491
  1767
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
Edouard@491
  1768
** additional cache line. </dd>
vb@130
  1769
**
vb@130
  1770
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
Edouard@491
  1771
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer 
Edouard@491
  1772
** that SQLite will use for all of its dynamic memory allocation needs
dz@3192
  1773
** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
Edouard@491
  1774
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
Edouard@491
  1775
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
Edouard@491
  1776
** [SQLITE_ERROR] if invoked otherwise.
Edouard@491
  1777
** ^There are three arguments to SQLITE_CONFIG_HEAP:
Edouard@491
  1778
** An 8-byte aligned pointer to the memory,
vb@130
  1779
** the number of bytes in the memory buffer, and the minimum allocation size.
vb@130
  1780
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
vb@130
  1781
** to using its default memory allocator (the system malloc() implementation),
vb@130
  1782
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
Edouard@491
  1783
** memory pointer is not NULL then the alternative memory
vb@130
  1784
** allocator is engaged to handle all of SQLites memory allocation needs.
vb@130
  1785
** The first pointer (the memory pointer) must be aligned to an 8-byte
vb@130
  1786
** boundary or subsequent behavior of SQLite will be undefined.
vb@130
  1787
** The minimum allocation size is capped at 2**12. Reasonable values
vb@130
  1788
** for the minimum allocation size are 2**5 through 2**8.</dd>
vb@130
  1789
**
vb@130
  1790
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
Edouard@491
  1791
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
Edouard@491
  1792
** pointer to an instance of the [sqlite3_mutex_methods] structure.
Edouard@491
  1793
** The argument specifies alternative low-level mutex routines to be used
Edouard@491
  1794
** in place the mutex routines built into SQLite.)^  ^SQLite makes a copy of
Edouard@491
  1795
** the content of the [sqlite3_mutex_methods] structure before the call to
vb@130
  1796
** [sqlite3_config()] returns. ^If SQLite is compiled with
vb@130
  1797
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
vb@130
  1798
** the entire mutexing subsystem is omitted from the build and hence calls to
vb@130
  1799
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
vb@130
  1800
** return [SQLITE_ERROR].</dd>
vb@130
  1801
**
vb@130
  1802
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
Edouard@491
  1803
** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
Edouard@491
  1804
** is a pointer to an instance of the [sqlite3_mutex_methods] structure.  The
vb@130
  1805
** [sqlite3_mutex_methods]
vb@130
  1806
** structure is filled with the currently defined mutex routines.)^
vb@130
  1807
** This option can be used to overload the default mutex allocation
vb@130
  1808
** routines with a wrapper used to track mutex usage for performance
vb@130
  1809
** profiling or testing, for example.   ^If SQLite is compiled with
vb@130
  1810
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
vb@130
  1811
** the entire mutexing subsystem is omitted from the build and hence calls to
vb@130
  1812
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
vb@130
  1813
** return [SQLITE_ERROR].</dd>
vb@130
  1814
**
vb@130
  1815
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
Edouard@491
  1816
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
Edouard@491
  1817
** the default size of lookaside memory on each [database connection].
Edouard@491
  1818
** The first argument is the
vb@130
  1819
** size of each lookaside buffer slot and the second is the number of
Edouard@491
  1820
** slots allocated to each database connection.)^  ^(SQLITE_CONFIG_LOOKASIDE
Edouard@491
  1821
** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
Edouard@491
  1822
** option to [sqlite3_db_config()] can be used to change the lookaside
vb@130
  1823
** configuration on individual connections.)^ </dd>
vb@130
  1824
**
vb@130
  1825
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
Edouard@491
  1826
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is 
Edouard@491
  1827
** a pointer to an [sqlite3_pcache_methods2] object.  This object specifies
Edouard@491
  1828
** the interface to a custom page cache implementation.)^
Edouard@491
  1829
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
vb@130
  1830
**
vb@130
  1831
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
Edouard@491
  1832
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
Edouard@491
  1833
** is a pointer to an [sqlite3_pcache_methods2] object.  SQLite copies of
Edouard@491
  1834
** the current page cache implementation into that object.)^ </dd>
vb@130
  1835
**
vb@130
  1836
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
vb@130
  1837
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
vb@130
  1838
** global [error log].
vb@130
  1839
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
vb@130
  1840
** function with a call signature of void(*)(void*,int,const char*), 
vb@130
  1841
** and a pointer to void. ^If the function pointer is not NULL, it is
vb@130
  1842
** invoked by [sqlite3_log()] to process each logging event.  ^If the
vb@130
  1843
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
vb@130
  1844
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
vb@130
  1845
** passed through as the first parameter to the application-defined logger
vb@130
  1846
** function whenever that function is invoked.  ^The second parameter to
vb@130
  1847
** the logger function is a copy of the first parameter to the corresponding
vb@130
  1848
** [sqlite3_log()] call and is intended to be a [result code] or an
vb@130
  1849
** [extended result code].  ^The third parameter passed to the logger is
vb@130
  1850
** log message after formatting via [sqlite3_snprintf()].
vb@130
  1851
** The SQLite logging interface is not reentrant; the logger function
vb@130
  1852
** supplied by the application must not invoke any SQLite interface.
vb@130
  1853
** In a multi-threaded application, the application-defined logger
vb@130
  1854
** function must be threadsafe. </dd>
vb@130
  1855
**
vb@130
  1856
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
Edouard@491
  1857
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
Edouard@491
  1858
** If non-zero, then URI handling is globally enabled. If the parameter is zero,
Edouard@491
  1859
** then URI handling is globally disabled.)^ ^If URI handling is globally
Edouard@491
  1860
** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
Edouard@491
  1861
** [sqlite3_open16()] or
vb@130
  1862
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
vb@130
  1863
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
vb@130
  1864
** connection is opened. ^If it is globally disabled, filenames are
vb@130
  1865
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
vb@130
  1866
** database connection is opened. ^(By default, URI handling is globally
vb@130
  1867
** disabled. The default value may be changed by compiling with the
vb@130
  1868
** [SQLITE_USE_URI] symbol defined.)^
vb@130
  1869
**
vb@130
  1870
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
Edouard@491
  1871
** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
Edouard@491
  1872
** argument which is interpreted as a boolean in order to enable or disable
Edouard@491
  1873
** the use of covering indices for full table scans in the query optimizer.
Edouard@491
  1874
** ^The default setting is determined
vb@130
  1875
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
vb@130
  1876
** if that compile-time option is omitted.
vb@130
  1877
** The ability to disable the use of covering indices for full table scans
vb@130
  1878
** is because some incorrectly coded legacy applications might malfunction
vb@130
  1879
** when the optimization is enabled.  Providing the ability to
vb@130
  1880
** disable the optimization allows the older, buggy application code to work
vb@130
  1881
** without change even with newer versions of SQLite.
vb@130
  1882
**
vb@130
  1883
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
vb@130
  1884
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
vb@130
  1885
** <dd> These options are obsolete and should not be used by new code.
vb@130
  1886
** They are retained for backwards compatibility but are now no-ops.
vb@130
  1887
** </dd>
vb@130
  1888
**
vb@130
  1889
** [[SQLITE_CONFIG_SQLLOG]]
vb@130
  1890
** <dt>SQLITE_CONFIG_SQLLOG
vb@130
  1891
** <dd>This option is only available if sqlite is compiled with the
vb@130
  1892
** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
vb@130
  1893
** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
vb@130
  1894
** The second should be of type (void*). The callback is invoked by the library
vb@130
  1895
** in three separate circumstances, identified by the value passed as the
vb@130
  1896
** fourth parameter. If the fourth parameter is 0, then the database connection
vb@130
  1897
** passed as the second argument has just been opened. The third argument
vb@130
  1898
** points to a buffer containing the name of the main database file. If the
vb@130
  1899
** fourth parameter is 1, then the SQL statement that the third parameter
vb@130
  1900
** points to has just been executed. Or, if the fourth parameter is 2, then
vb@130
  1901
** the connection being passed as the second parameter is being closed. The
vb@130
  1902
** third parameter is passed NULL In this case.  An example of using this
vb@130
  1903
** configuration option can be seen in the "test_sqllog.c" source file in
vb@130
  1904
** the canonical SQLite source tree.</dd>
vb@130
  1905
**
vb@130
  1906
** [[SQLITE_CONFIG_MMAP_SIZE]]
vb@130
  1907
** <dt>SQLITE_CONFIG_MMAP_SIZE
vb@130
  1908
** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
vb@130
  1909
** that are the default mmap size limit (the default setting for
vb@130
  1910
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
vb@130
  1911
** ^The default setting can be overridden by each database connection using
vb@130
  1912
** either the [PRAGMA mmap_size] command, or by using the
vb@130
  1913
** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
Edouard@491
  1914
** will be silently truncated if necessary so that it does not exceed the
Edouard@491
  1915
** compile-time maximum mmap size set by the
vb@130
  1916
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
vb@130
  1917
** ^If either argument to this option is negative, then that argument is
vb@130
  1918
** changed to its compile-time default.
vb@130
  1919
**
vb@130
  1920
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
vb@130
  1921
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
Edouard@491
  1922
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
Edouard@491
  1923
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
Edouard@491
  1924
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
vb@130
  1925
** that specifies the maximum size of the created heap.
Edouard@491
  1926
**
Edouard@491
  1927
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
Edouard@491
  1928
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
Edouard@491
  1929
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
Edouard@491
  1930
** is a pointer to an integer and writes into that integer the number of extra
Edouard@491
  1931
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
Edouard@491
  1932
** The amount of extra space required can change depending on the compiler,
Edouard@491
  1933
** target platform, and SQLite version.
Edouard@491
  1934
**
Edouard@491
  1935
** [[SQLITE_CONFIG_PMASZ]]
Edouard@491
  1936
** <dt>SQLITE_CONFIG_PMASZ
Edouard@491
  1937
** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
Edouard@491
  1938
** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
Edouard@491
  1939
** sorter to that integer.  The default minimum PMA Size is set by the
Edouard@491
  1940
** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
Edouard@491
  1941
** to help with sort operations when multithreaded sorting
Edouard@491
  1942
** is enabled (using the [PRAGMA threads] command) and the amount of content
Edouard@491
  1943
** to be sorted exceeds the page size times the minimum of the
Edouard@491
  1944
** [PRAGMA cache_size] setting and this value.
vb@716
  1945
**
vb@716
  1946
** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
vb@716
  1947
** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
vb@716
  1948
** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
vb@716
  1949
** becomes the [statement journal] spill-to-disk threshold.  
vb@716
  1950
** [Statement journals] are held in memory until their size (in bytes)
vb@716
  1951
** exceeds this threshold, at which point they are written to disk.
vb@716
  1952
** Or if the threshold is -1, statement journals are always held
vb@716
  1953
** exclusively in memory.
vb@716
  1954
** Since many statement journals never become large, setting the spill
vb@716
  1955
** threshold to a value such as 64KiB can greatly reduce the amount of
vb@716
  1956
** I/O required to support statement rollback.
vb@716
  1957
** The default value for this setting is controlled by the
vb@716
  1958
** [SQLITE_STMTJRNL_SPILL] compile-time option.
dz@3192
  1959
**
dz@3192
  1960
** [[SQLITE_CONFIG_SORTERREF_SIZE]]
dz@3192
  1961
** <dt>SQLITE_CONFIG_SORTERREF_SIZE
dz@3192
  1962
** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
dz@3192
  1963
** of type (int) - the new value of the sorter-reference size threshold.
dz@3192
  1964
** Usually, when SQLite uses an external sort to order records according
dz@3192
  1965
** to an ORDER BY clause, all fields required by the caller are present in the
dz@3192
  1966
** sorted records. However, if SQLite determines based on the declared type
dz@3192
  1967
** of a table column that its values are likely to be very large - larger
dz@3192
  1968
** than the configured sorter-reference size threshold - then a reference
dz@3192
  1969
** is stored in each sorted record and the required column values loaded
dz@3192
  1970
** from the database as records are returned in sorted order. The default
dz@3192
  1971
** value for this option is to never use this optimization. Specifying a 
dz@3192
  1972
** negative value for this option restores the default behaviour.
dz@3192
  1973
** This option is only available if SQLite is compiled with the
dz@3192
  1974
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
vb@130
  1975
** </dl>
vb@130
  1976
*/
vb@130
  1977
#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
vb@130
  1978
#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
vb@130
  1979
#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
vb@130
  1980
#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
vb@130
  1981
#define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
dz@3192
  1982
#define SQLITE_CONFIG_SCRATCH       6  /* No longer used */
vb@130
  1983
#define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
vb@130
  1984
#define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
vb@130
  1985
#define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
vb@130
  1986
#define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
vb@130
  1987
#define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */
vb@130
  1988
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 
vb@130
  1989
#define SQLITE_CONFIG_LOOKASIDE    13  /* int int */
vb@130
  1990
#define SQLITE_CONFIG_PCACHE       14  /* no-op */
vb@130
  1991
#define SQLITE_CONFIG_GETPCACHE    15  /* no-op */
vb@130
  1992
#define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
vb@130
  1993
#define SQLITE_CONFIG_URI          17  /* int */
vb@130
  1994
#define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
vb@130
  1995
#define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
vb@130
  1996
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
vb@130
  1997
#define SQLITE_CONFIG_SQLLOG       21  /* xSqllog, void* */
vb@130
  1998
#define SQLITE_CONFIG_MMAP_SIZE    22  /* sqlite3_int64, sqlite3_int64 */
vb@130
  1999
#define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
Edouard@491
  2000
#define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
Edouard@491
  2001
#define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
vb@716
  2002
#define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
dz@3192
  2003
#define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
dz@3192
  2004
#define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
vb@130
  2005
vb@130
  2006
/*
vb@130
  2007
** CAPI3REF: Database Connection Configuration Options
vb@130
  2008
**
vb@130
  2009
** These constants are the available integer configuration options that
vb@130
  2010
** can be passed as the second argument to the [sqlite3_db_config()] interface.
vb@130
  2011
**
vb@130
  2012
** New configuration options may be added in future releases of SQLite.
vb@130
  2013
** Existing configuration options might be discontinued.  Applications
vb@130
  2014
** should check the return code from [sqlite3_db_config()] to make sure that
vb@130
  2015
** the call worked.  ^The [sqlite3_db_config()] interface will return a
vb@130
  2016
** non-zero [error code] if a discontinued or unsupported configuration option
vb@130
  2017
** is invoked.
vb@130
  2018
**
vb@130
  2019
** <dl>
dz@3192
  2020
** [[SQLITE_DBCONFIG_LOOKASIDE]]
vb@130
  2021
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
vb@130
  2022
** <dd> ^This option takes three additional arguments that determine the 
vb@130
  2023
** [lookaside memory allocator] configuration for the [database connection].
vb@130
  2024
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
vb@130
  2025
** pointer to a memory buffer to use for lookaside memory.
vb@130
  2026
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
vb@130
  2027
** may be NULL in which case SQLite will allocate the
vb@130
  2028
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
vb@130
  2029
** size of each lookaside buffer slot.  ^The third argument is the number of
vb@130
  2030
** slots.  The size of the buffer in the first argument must be greater than
vb@130
  2031
** or equal to the product of the second and third arguments.  The buffer
vb@130
  2032
** must be aligned to an 8-byte boundary.  ^If the second argument to
vb@130
  2033
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
vb@130
  2034
** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
vb@130
  2035
** configuration for a database connection can only be changed when that
vb@130
  2036
** connection is not currently using lookaside memory, or in other words
vb@130
  2037
** when the "current value" returned by
vb@130
  2038
** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
vb@130
  2039
** Any attempt to change the lookaside memory configuration when lookaside
vb@130
  2040
** memory is in use leaves the configuration unchanged and returns 
vb@130
  2041
** [SQLITE_BUSY].)^</dd>
vb@130
  2042
**
dz@3192
  2043
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
vb@130
  2044
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
vb@130
  2045
** <dd> ^This option is used to enable or disable the enforcement of
vb@130
  2046
** [foreign key constraints].  There should be two additional arguments.
vb@130
  2047
** The first argument is an integer which is 0 to disable FK enforcement,
vb@130
  2048
** positive to enable FK enforcement or negative to leave FK enforcement
vb@130
  2049
** unchanged.  The second parameter is a pointer to an integer into which
vb@130
  2050
** is written 0 or 1 to indicate whether FK enforcement is off or on
vb@130
  2051
** following this call.  The second parameter may be a NULL pointer, in
vb@130
  2052
** which case the FK enforcement setting is not reported back. </dd>
vb@130
  2053
**
dz@3192
  2054
** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
vb@130
  2055
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
vb@130
  2056
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
vb@130
  2057
** There should be two additional arguments.
vb@130
  2058
** The first argument is an integer which is 0 to disable triggers,
vb@130
  2059
** positive to enable triggers or negative to leave the setting unchanged.
vb@130
  2060
** The second parameter is a pointer to an integer into which
vb@130
  2061
** is written 0 or 1 to indicate whether triggers are disabled or enabled
vb@130
  2062
** following this call.  The second parameter may be a NULL pointer, in
vb@130
  2063
** which case the trigger setting is not reported back. </dd>
vb@130
  2064
**
dz@3192
  2065
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
vb@716
  2066
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
vb@716
  2067
** <dd> ^This option is used to enable or disable the two-argument
vb@716
  2068
** version of the [fts3_tokenizer()] function which is part of the
vb@716
  2069
** [FTS3] full-text search engine extension.
vb@716
  2070
** There should be two additional arguments.
vb@716
  2071
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
vb@716
  2072
** positive to enable fts3_tokenizer() or negative to leave the setting
vb@716
  2073
** unchanged.
vb@716
  2074
** The second parameter is a pointer to an integer into which
vb@716
  2075
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
vb@716
  2076
** following this call.  The second parameter may be a NULL pointer, in
vb@716
  2077
** which case the new setting is not reported back. </dd>
vb@716
  2078
**
dz@3192
  2079
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
vb@716
  2080
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
vb@716
  2081
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
vb@716
  2082
** interface independently of the [load_extension()] SQL function.
vb@716
  2083
** The [sqlite3_enable_load_extension()] API enables or disables both the
vb@716
  2084
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
vb@716
  2085
** There should be two additional arguments.
vb@716
  2086
** When the first argument to this interface is 1, then only the C-API is
edouard@1912
  2087
** enabled and the SQL function remains disabled.  If the first argument to
vb@716
  2088
** this interface is 0, then both the C-API and the SQL function are disabled.
vb@716
  2089
** If the first argument is -1, then no changes are made to state of either the
vb@716
  2090
** C-API or the SQL function.
vb@716
  2091
** The second parameter is a pointer to an integer into which
vb@716
  2092
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
vb@716
  2093
** is disabled or enabled following this call.  The second parameter may
vb@716
  2094
** be a NULL pointer, in which case the new setting is not reported back.
vb@716
  2095
** </dd>
vb@716
  2096
**
dz@3192
  2097
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
edouard@1912
  2098
** <dd> ^This option is used to change the name of the "main" database
edouard@1912
  2099
** schema.  ^The sole argument is a pointer to a constant UTF8 string
edouard@1912
  2100
** which will become the new schema name in place of "main".  ^SQLite
edouard@1912
  2101
** does not make a copy of the new main schema name string, so the application
edouard@1912
  2102
** must ensure that the argument passed into this DBCONFIG option is unchanged
edouard@1912
  2103
** until after the database connection closes.
edouard@1912
  2104
** </dd>
edouard@1912
  2105
**
dz@3192
  2106
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] 
edouard@1912
  2107
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
edouard@1912
  2108
** <dd> Usually, when a database in wal mode is closed or detached from a 
edouard@1912
  2109
** database handle, SQLite checks if this will mean that there are now no 
edouard@1912
  2110
** connections at all to the database. If so, it performs a checkpoint 
edouard@1912
  2111
** operation before closing the connection. This option may be used to
edouard@1912
  2112
** override this behaviour. The first parameter passed to this operation
dz@3192
  2113
** is an integer - positive to disable checkpoints-on-close, or zero (the
dz@3192
  2114
** default) to enable them, and negative to leave the setting unchanged.
dz@3192
  2115
** The second parameter is a pointer to an integer
edouard@1912
  2116
** into which is written 0 or 1 to indicate whether checkpoints-on-close
edouard@1912
  2117
** have been disabled - 0 if they are not disabled, 1 if they are.
edouard@1912
  2118
** </dd>
edouard@1912
  2119
**
dz@3192
  2120
** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
dz@3192
  2121
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
dz@3192
  2122
** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
dz@3192
  2123
** a single SQL query statement will always use the same algorithm regardless
dz@3192
  2124
** of values of [bound parameters].)^ The QPSG disables some query optimizations
dz@3192
  2125
** that look at the values of bound parameters, which can make some queries
dz@3192
  2126
** slower.  But the QPSG has the advantage of more predictable behavior.  With
dz@3192
  2127
** the QPSG active, SQLite will always use the same query plan in the field as
dz@3192
  2128
** was used during testing in the lab.
dz@3192
  2129
** The first argument to this setting is an integer which is 0 to disable 
dz@3192
  2130
** the QPSG, positive to enable QPSG, or negative to leave the setting
dz@3192
  2131
** unchanged. The second parameter is a pointer to an integer into which
dz@3192
  2132
** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
dz@3192
  2133
** following this call.
dz@3192
  2134
** </dd>
dz@3192
  2135
**
dz@3192
  2136
** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
dz@3192
  2137
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not 
dz@3192
  2138
** include output for any operations performed by trigger programs. This
dz@3192
  2139
** option is used to set or clear (the default) a flag that governs this
dz@3192
  2140
** behavior. The first parameter passed to this operation is an integer -
dz@3192
  2141
** positive to enable output for trigger programs, or zero to disable it,
dz@3192
  2142
** or negative to leave the setting unchanged.
dz@3192
  2143
** The second parameter is a pointer to an integer into which is written 
dz@3192
  2144
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if 
dz@3192
  2145
** it is not disabled, 1 if it is.  
dz@3192
  2146
** </dd>
dz@3192
  2147
**
dz@3192
  2148
** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
dz@3192
  2149
** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
dz@3192
  2150
** [VACUUM] in order to reset a database back to an empty database
dz@3192
  2151
** with no schema and no content. The following process works even for
dz@3192
  2152
** a badly corrupted database file:
dz@3192
  2153
** <ol>
dz@3192
  2154
** <li> If the database connection is newly opened, make sure it has read the
dz@3192
  2155
**      database schema by preparing then discarding some query against the
dz@3192
  2156
**      database, or calling sqlite3_table_column_metadata(), ignoring any
dz@3192
  2157
**      errors.  This step is only necessary if the application desires to keep
dz@3192
  2158
**      the database in WAL mode after the reset if it was in WAL mode before
dz@3192
  2159
**      the reset.  
dz@3192
  2160
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
dz@3192
  2161
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
dz@3192
  2162
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
dz@3192
  2163
** </ol>
dz@3192
  2164
** Because resetting a database is destructive and irreversible, the
dz@3192
  2165
** process requires the use of this obscure API and multiple steps to help
dz@3192
  2166
** ensure that it does not happen by accident.
dz@3192
  2167
**
dz@3192
  2168
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
dz@3192
  2169
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
dz@3192
  2170
** "defensive" flag for a database connection.  When the defensive
dz@3192
  2171
** flag is enabled, language features that allow ordinary SQL to 
dz@3192
  2172
** deliberately corrupt the database file are disabled.  The disabled
dz@3192
  2173
** features include but are not limited to the following:
dz@3192
  2174
** <ul>
dz@3192
  2175
** <li> The [PRAGMA writable_schema=ON] statement.
dz@3192
  2176
** <li> Writes to the [sqlite_dbpage] virtual table.
dz@3192
  2177
** <li> Direct writes to [shadow tables].
dz@3192
  2178
** </ul>
dz@3192
  2179
** </dd>
vb@130
  2180
** </dl>
vb@130
  2181
*/
edouard@1912
  2182
#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
vb@716
  2183
#define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
vb@716
  2184
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
vb@716
  2185
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
vb@716
  2186
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
vb@716
  2187
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
edouard@1912
  2188
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
dz@3192
  2189
#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
dz@3192
  2190
#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
dz@3192
  2191
#define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
dz@3192
  2192
#define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
dz@3192
  2193
#define SQLITE_DBCONFIG_MAX                   1010 /* Largest DBCONFIG */
vb@130
  2194
vb@130
  2195
/*
vb@130
  2196
** CAPI3REF: Enable Or Disable Extended Result Codes
Edouard@491
  2197
** METHOD: sqlite3
vb@130
  2198
**
vb@130
  2199
** ^The sqlite3_extended_result_codes() routine enables or disables the
vb@130
  2200
** [extended result codes] feature of SQLite. ^The extended result
vb@130
  2201
** codes are disabled by default for historical compatibility.
vb@130
  2202
*/
edouard@1912
  2203
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
vb@130
  2204
vb@130
  2205
/*
vb@130
  2206
** CAPI3REF: Last Insert Rowid
Edouard@491
  2207
** METHOD: sqlite3
vb@130
  2208
**
vb@130
  2209
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
vb@130
  2210
** has a unique 64-bit signed
vb@130
  2211
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
vb@130
  2212
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
vb@130
  2213
** names are not also used by explicitly declared columns. ^If
vb@130
  2214
** the table has a column of type [INTEGER PRIMARY KEY] then that column
vb@130
  2215
** is another alias for the rowid.
vb@130
  2216
**
edouard@1912
  2217
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
edouard@1912
  2218
** the most recent successful [INSERT] into a rowid table or [virtual table]
edouard@1912
  2219
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
edouard@1912
  2220
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred 
edouard@1912
  2221
** on the database connection D, then sqlite3_last_insert_rowid(D) returns 
edouard@1912
  2222
** zero.
edouard@1912
  2223
**
edouard@1912
  2224
** As well as being set automatically as rows are inserted into database
edouard@1912
  2225
** tables, the value returned by this function may be set explicitly by
edouard@1912
  2226
** [sqlite3_set_last_insert_rowid()]
edouard@1912
  2227
**
edouard@1912
  2228
** Some virtual table implementations may INSERT rows into rowid tables as
edouard@1912
  2229
** part of committing a transaction (e.g. to flush data accumulated in memory
edouard@1912
  2230
** to disk). In this case subsequent calls to this function return the rowid
edouard@1912
  2231
** associated with these internal INSERT operations, which leads to 
edouard@1912
  2232
** unintuitive results. Virtual table implementations that do write to rowid
edouard@1912
  2233
** tables in this way can avoid this problem by restoring the original 
edouard@1912
  2234
** rowid value using [sqlite3_set_last_insert_rowid()] before returning 
edouard@1912
  2235
** control to the user.
edouard@1912
  2236
**
edouard@1912
  2237
** ^(If an [INSERT] occurs within a trigger then this routine will 
edouard@1912
  2238
** return the [rowid] of the inserted row as long as the trigger is 
edouard@1912
  2239
** running. Once the trigger program ends, the value returned 
edouard@1912
  2240
** by this routine reverts to what it was before the trigger was fired.)^
vb@130
  2241
**
vb@130
  2242
** ^An [INSERT] that fails due to a constraint violation is not a
vb@130
  2243
** successful [INSERT] and does not change the value returned by this
vb@130
  2244
** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
vb@130
  2245
** and INSERT OR ABORT make no changes to the return value of this
vb@130
  2246
** routine when their insertion fails.  ^(When INSERT OR REPLACE
vb@130
  2247
** encounters a constraint violation, it does not fail.  The
vb@130
  2248
** INSERT continues to completion after deleting rows that caused
vb@130
  2249
** the constraint problem so INSERT OR REPLACE will always change
vb@130
  2250
** the return value of this interface.)^
vb@130
  2251
**
vb@130
  2252
** ^For the purposes of this routine, an [INSERT] is considered to
vb@130
  2253
** be successful even if it is subsequently rolled back.
vb@130
  2254
**
vb@130
  2255
** This function is accessible to SQL statements via the
vb@130
  2256
** [last_insert_rowid() SQL function].
vb@130
  2257
**
vb@130
  2258
** If a separate thread performs a new [INSERT] on the same
vb@130
  2259
** database connection while the [sqlite3_last_insert_rowid()]
vb@130
  2260
** function is running and thus changes the last insert [rowid],
vb@130
  2261
** then the value returned by [sqlite3_last_insert_rowid()] is
vb@130
  2262
** unpredictable and might not equal either the old or the new
vb@130
  2263
** last insert [rowid].
vb@130
  2264
*/
edouard@1912
  2265
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
edouard@1912
  2266
edouard@1912
  2267
/*
edouard@1912
  2268
** CAPI3REF: Set the Last Insert Rowid value.
edouard@1912
  2269
** METHOD: sqlite3
edouard@1912
  2270
**
edouard@1912
  2271
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
edouard@1912
  2272
** set the value returned by calling sqlite3_last_insert_rowid(D) to R 
edouard@1912
  2273
** without inserting a row into the database.
edouard@1912
  2274
*/
edouard@1912
  2275
SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
vb@130
  2276
vb@130
  2277
/*
vb@130
  2278
** CAPI3REF: Count The Number Of Rows Modified
Edouard@491
  2279
** METHOD: sqlite3
Edouard@491
  2280
**
Edouard@491
  2281
** ^This function returns the number of rows modified, inserted or
Edouard@491
  2282
** deleted by the most recently completed INSERT, UPDATE or DELETE
Edouard@491
  2283
** statement on the database connection specified by the only parameter.
Edouard@491
  2284
** ^Executing any other type of SQL statement does not modify the value
Edouard@491
  2285
** returned by this function.
Edouard@491
  2286
**
Edouard@491
  2287
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
Edouard@491
  2288
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], 
Edouard@491
  2289
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
Edouard@491
  2290
** 
Edouard@491
  2291
** Changes to a view that are intercepted by 
Edouard@491
  2292
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value 
Edouard@491
  2293
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or 
Edouard@491
  2294
** DELETE statement run on a view is always zero. Only changes made to real 
Edouard@491
  2295
** tables are counted.
Edouard@491
  2296
**
Edouard@491
  2297
** Things are more complicated if the sqlite3_changes() function is
Edouard@491
  2298
** executed while a trigger program is running. This may happen if the
Edouard@491
  2299
** program uses the [changes() SQL function], or if some other callback
Edouard@491
  2300
** function invokes sqlite3_changes() directly. Essentially:
Edouard@491
  2301
** 
Edouard@491
  2302
** <ul>
Edouard@491
  2303
**   <li> ^(Before entering a trigger program the value returned by
Edouard@491
  2304
**        sqlite3_changes() function is saved. After the trigger program 
Edouard@491
  2305
**        has finished, the original value is restored.)^
Edouard@491
  2306
** 
Edouard@491
  2307
**   <li> ^(Within a trigger program each INSERT, UPDATE and DELETE 
Edouard@491
  2308
**        statement sets the value returned by sqlite3_changes() 
Edouard@491
  2309
**        upon completion as normal. Of course, this value will not include 
Edouard@491
  2310
**        any changes performed by sub-triggers, as the sqlite3_changes() 
Edouard@491
  2311
**        value will be saved and restored after each sub-trigger has run.)^
Edouard@491
  2312
** </ul>
Edouard@491
  2313
** 
Edouard@491
  2314
** ^This means that if the changes() SQL function (or similar) is used
Edouard@491
  2315
** by the first INSERT, UPDATE or DELETE statement within a trigger, it 
Edouard@491
  2316
** returns the value as set when the calling statement began executing.
Edouard@491
  2317
** ^If it is used by the second or subsequent such statement within a trigger 
Edouard@491
  2318
** program, the value returned reflects the number of rows modified by the 
Edouard@491
  2319
** previous INSERT, UPDATE or DELETE statement within the same trigger.
vb@130
  2320
**
vb@130
  2321
** If a separate thread makes changes on the same database connection
vb@130
  2322
** while [sqlite3_changes()] is running then the value returned
vb@130
  2323
** is unpredictable and not meaningful.
dz@3192
  2324
**
dz@3192
  2325
** See also:
dz@3192
  2326
** <ul>
dz@3192
  2327
** <li> the [sqlite3_total_changes()] interface
dz@3192
  2328
** <li> the [count_changes pragma]
dz@3192
  2329
** <li> the [changes() SQL function]
dz@3192
  2330
** <li> the [data_version pragma]
dz@3192
  2331
** </ul>
vb@130
  2332
*/
edouard@1912
  2333
SQLITE_API int sqlite3_changes(sqlite3*);
vb@130
  2334
vb@130
  2335
/*
vb@130
  2336
** CAPI3REF: Total Number Of Rows Modified
Edouard@491
  2337
** METHOD: sqlite3
Edouard@491
  2338
**
Edouard@491
  2339
** ^This function returns the total number of rows inserted, modified or
Edouard@491
  2340
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
Edouard@491
  2341
** since the database connection was opened, including those executed as
Edouard@491
  2342
** part of trigger programs. ^Executing any other type of SQL statement
Edouard@491
  2343
** does not affect the value returned by sqlite3_total_changes().
Edouard@491
  2344
** 
Edouard@491
  2345
** ^Changes made as part of [foreign key actions] are included in the
Edouard@491
  2346
** count, but those made as part of REPLACE constraint resolution are
Edouard@491
  2347
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
Edouard@491
  2348
** are not counted.
dz@3192
  2349
**
dz@3192
  2350
** This the [sqlite3_total_changes(D)] interface only reports the number
dz@3192
  2351
** of rows that changed due to SQL statement run against database
dz@3192
  2352
** connection D.  Any changes by other database connections are ignored.
dz@3192
  2353
** To detect changes against a database file from other database
dz@3192
  2354
** connections use the [PRAGMA data_version] command or the
dz@3192
  2355
** [SQLITE_FCNTL_DATA_VERSION] [file control].
Edouard@491
  2356
** 
vb@130
  2357
** If a separate thread makes changes on the same database connection
vb@130
  2358
** while [sqlite3_total_changes()] is running then the value
vb@130
  2359
** returned is unpredictable and not meaningful.
dz@3192
  2360
**
dz@3192
  2361
** See also:
dz@3192
  2362
** <ul>
dz@3192
  2363
** <li> the [sqlite3_changes()] interface
dz@3192
  2364
** <li> the [count_changes pragma]
dz@3192
  2365
** <li> the [changes() SQL function]
dz@3192
  2366
** <li> the [data_version pragma]
dz@3192
  2367
** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
dz@3192
  2368
** </ul>
vb@130
  2369
*/
edouard@1912
  2370
SQLITE_API int sqlite3_total_changes(sqlite3*);
vb@130
  2371
vb@130
  2372
/*
vb@130
  2373
** CAPI3REF: Interrupt A Long-Running Query
Edouard@491
  2374
** METHOD: sqlite3
vb@130
  2375
**
vb@130
  2376
** ^This function causes any pending database operation to abort and
vb@130
  2377
** return at its earliest opportunity. This routine is typically
vb@130
  2378
** called in response to a user action such as pressing "Cancel"
vb@130
  2379
** or Ctrl-C where the user wants a long query operation to halt
vb@130
  2380
** immediately.
vb@130
  2381
**
vb@130
  2382
** ^It is safe to call this routine from a thread different from the
vb@130
  2383
** thread that is currently running the database operation.  But it
vb@130
  2384
** is not safe to call this routine with a [database connection] that
vb@130
  2385
** is closed or might close before sqlite3_interrupt() returns.
vb@130
  2386
**
vb@130
  2387
** ^If an SQL operation is very nearly finished at the time when
vb@130
  2388
** sqlite3_interrupt() is called, then it might not have an opportunity
vb@130
  2389
** to be interrupted and might continue to completion.
vb@130
  2390
**
vb@130
  2391
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
vb@130
  2392
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
vb@130
  2393
** that is inside an explicit transaction, then the entire transaction
vb@130
  2394
** will be rolled back automatically.
vb@130
  2395
**
vb@130
  2396
** ^The sqlite3_interrupt(D) call is in effect until all currently running
vb@130
  2397
** SQL statements on [database connection] D complete.  ^Any new SQL statements
vb@130
  2398
** that are started after the sqlite3_interrupt() call and before the 
vb@130
  2399
** running statements reaches zero are interrupted as if they had been
vb@130
  2400
** running prior to the sqlite3_interrupt() call.  ^New SQL statements
vb@130
  2401
** that are started after the running statement count reaches zero are
vb@130
  2402
** not effected by the sqlite3_interrupt().
vb@130
  2403
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
vb@130
  2404
** SQL statements is a no-op and has no effect on SQL statements
vb@130
  2405
** that are started after the sqlite3_interrupt() call returns.
edouard@1912
  2406
*/
edouard@1912
  2407
SQLITE_API void sqlite3_interrupt(sqlite3*);
vb@130
  2408
vb@130
  2409
/*
vb@130
  2410
** CAPI3REF: Determine If An SQL Statement Is Complete
vb@130
  2411
**
vb@130
  2412
** These routines are useful during command-line input to determine if the
vb@130
  2413
** currently entered text seems to form a complete SQL statement or
vb@130
  2414
** if additional input is needed before sending the text into
vb@130
  2415
** SQLite for parsing.  ^These routines return 1 if the input string
vb@130
  2416
** appears to be a complete SQL statement.  ^A statement is judged to be
vb@130
  2417
** complete if it ends with a semicolon token and is not a prefix of a
vb@130
  2418
** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
vb@130
  2419
** string literals or quoted identifier names or comments are not
vb@130
  2420
** independent tokens (they are part of the token in which they are
vb@130
  2421
** embedded) and thus do not count as a statement terminator.  ^Whitespace
vb@130
  2422
** and comments that follow the final semicolon are ignored.
vb@130
  2423
**
vb@130
  2424
** ^These routines return 0 if the statement is incomplete.  ^If a
vb@130
  2425
** memory allocation fails, then SQLITE_NOMEM is returned.
vb@130
  2426
**
vb@130
  2427
** ^These routines do not parse the SQL statements thus
vb@130
  2428
** will not detect syntactically incorrect SQL.
vb@130
  2429
**
vb@130
  2430
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 
vb@130
  2431
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
vb@130
  2432
** automatically by sqlite3_complete16().  If that initialization fails,
vb@130
  2433
** then the return value from sqlite3_complete16() will be non-zero
vb@130
  2434
** regardless of whether or not the input SQL is complete.)^
vb@130
  2435
**
vb@130
  2436
** The input to [sqlite3_complete()] must be a zero-terminated
vb@130
  2437
** UTF-8 string.
vb@130
  2438
**
vb@130
  2439
** The input to [sqlite3_complete16()] must be a zero-terminated
vb@130
  2440
** UTF-16 string in native byte order.
vb@130
  2441
*/
edouard@1912
  2442
SQLITE_API int sqlite3_complete(const char *sql);
edouard@1912
  2443
SQLITE_API int sqlite3_complete16(const void *sql);
vb@130
  2444
vb@130
  2445
/*
vb@130
  2446
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
Edouard@491
  2447
** KEYWORDS: {busy-handler callback} {busy handler}
Edouard@491
  2448
** METHOD: sqlite3
vb@130
  2449
**
vb@130
  2450
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
vb@130
  2451
** that might be invoked with argument P whenever
vb@130
  2452
** an attempt is made to access a database table associated with
vb@130
  2453
** [database connection] D when another thread
vb@130
  2454
** or process has the table locked.
vb@130
  2455
** The sqlite3_busy_handler() interface is used to implement
vb@130
  2456
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
vb@130
  2457
**
vb@130
  2458
** ^If the busy callback is NULL, then [SQLITE_BUSY]
vb@130
  2459
** is returned immediately upon encountering the lock.  ^If the busy callback
vb@130
  2460
** is not NULL, then the callback might be invoked with two arguments.
vb@130
  2461
**
vb@130
  2462
** ^The first argument to the busy handler is a copy of the void* pointer which
vb@130
  2463
** is the third argument to sqlite3_busy_handler().  ^The second argument to
vb@130
  2464
** the busy handler callback is the number of times that the busy handler has
Edouard@491
  2465
** been invoked previously for the same locking event.  ^If the
vb@130
  2466
** busy callback returns 0, then no additional attempts are made to
vb@130
  2467
** access the database and [SQLITE_BUSY] is returned
vb@130
  2468
** to the application.
vb@130
  2469
** ^If the callback returns non-zero, then another attempt
vb@130
  2470
** is made to access the database and the cycle repeats.
vb@130
  2471
**
vb@130
  2472
** The presence of a busy handler does not guarantee that it will be invoked
vb@130
  2473
** when there is lock contention. ^If SQLite determines that invoking the busy
vb@130
  2474
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
vb@130
  2475
** to the application instead of invoking the 
vb@130
  2476
** busy handler.
vb@130
  2477
** Consider a scenario where one process is holding a read lock that
vb@130
  2478
** it is trying to promote to a reserved lock and
vb@130
  2479
** a second process is holding a reserved lock that it is trying
vb@130
  2480
** to promote to an exclusive lock.  The first process cannot proceed
vb@130
  2481
** because it is blocked by the second and the second process cannot
vb@130
  2482
** proceed because it is blocked by the first.  If both processes
vb@130
  2483
** invoke the busy handlers, neither will make any progress.  Therefore,
vb@130
  2484
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
vb@130
  2485
** will induce the first process to release its read lock and allow
vb@130
  2486
** the second process to proceed.
vb@130
  2487
**
vb@130
  2488
** ^The default busy callback is NULL.
vb@130
  2489
**
vb@130
  2490
** ^(There can only be a single busy handler defined for each
vb@130
  2491
** [database connection].  Setting a new busy handler clears any
vb@130
  2492
** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
vb@130
  2493
** or evaluating [PRAGMA busy_timeout=N] will change the
vb@130
  2494
** busy handler and thus clear any previously set busy handler.
vb@130
  2495
**
vb@130
  2496
** The busy callback should not take any actions which modify the
vb@130
  2497
** database connection that invoked the busy handler.  In other words,
vb@130
  2498
** the busy handler is not reentrant.  Any such actions
vb@130
  2499
** result in undefined behavior.
vb@130
  2500
** 
vb@130
  2501
** A busy handler must not close the database connection
vb@130
  2502
** or [prepared statement] that invoked the busy handler.
vb@130
  2503
*/
edouard@1912
  2504
SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
vb@130
  2505
vb@130
  2506
/*
vb@130
  2507
** CAPI3REF: Set A Busy Timeout
Edouard@491
  2508
** METHOD: sqlite3
vb@130
  2509
**
vb@130
  2510
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
vb@130
  2511
** for a specified amount of time when a table is locked.  ^The handler
vb@130
  2512
** will sleep multiple times until at least "ms" milliseconds of sleeping
vb@130
  2513
** have accumulated.  ^After at least "ms" milliseconds of sleeping,
vb@130
  2514
** the handler returns 0 which causes [sqlite3_step()] to return
vb@130
  2515
** [SQLITE_BUSY].
vb@130
  2516
**
vb@130
  2517
** ^Calling this routine with an argument less than or equal to zero
vb@130
  2518
** turns off all busy handlers.
vb@130
  2519
**
vb@130
  2520
** ^(There can only be a single busy handler for a particular
Edouard@491
  2521
** [database connection] at any given moment.  If another busy handler
vb@130
  2522
** was defined  (using [sqlite3_busy_handler()]) prior to calling
vb@130
  2523
** this routine, that other busy handler is cleared.)^
vb@130
  2524
**
vb@130
  2525
** See also:  [PRAGMA busy_timeout]
vb@130
  2526
*/
edouard@1912
  2527
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
vb@130
  2528
vb@130
  2529
/*
vb@130
  2530
** CAPI3REF: Convenience Routines For Running Queries
Edouard@491
  2531
** METHOD: sqlite3
vb@130
  2532
**
vb@130
  2533
** This is a legacy interface that is preserved for backwards compatibility.
vb@130
  2534
** Use of this interface is not recommended.
vb@130
  2535
**
vb@130
  2536
** Definition: A <b>result table</b> is memory data structure created by the
vb@130
  2537
** [sqlite3_get_table()] interface.  A result table records the
vb@130
  2538
** complete query results from one or more queries.
vb@130
  2539
**
vb@130
  2540
** The table conceptually has a number of rows and columns.  But
vb@130
  2541
** these numbers are not part of the result table itself.  These
vb@130
  2542
** numbers are obtained separately.  Let N be the number of rows
vb@130
  2543
** and M be the number of columns.
vb@130
  2544
**
vb@130
  2545
** A result table is an array of pointers to zero-terminated UTF-8 strings.
vb@130
  2546
** There are (N+1)*M elements in the array.  The first M pointers point
vb@130
  2547
** to zero-terminated strings that  contain the names of the columns.
vb@130
  2548
** The remaining entries all point to query results.  NULL values result
vb@130
  2549
** in NULL pointers.  All other values are in their UTF-8 zero-terminated
vb@130
  2550
** string representation as returned by [sqlite3_column_text()].
vb@130
  2551
**
vb@130
  2552
** A result table might consist of one or more memory allocations.
vb@130
  2553
** It is not safe to pass a result table directly to [sqlite3_free()].
vb@130
  2554
** A result table should be deallocated using [sqlite3_free_table()].
vb@130
  2555
**
vb@130
  2556
** ^(As an example of the result table format, suppose a query result
vb@130
  2557
** is as follows:
vb@130
  2558
**
vb@130
  2559
** <blockquote><pre>
vb@130
  2560
**        Name        | Age
vb@130
  2561
**        -----------------------
vb@130
  2562
**        Alice       | 43
vb@130
  2563
**        Bob         | 28
vb@130
  2564
**        Cindy       | 21
vb@130
  2565
** </pre></blockquote>
vb@130
  2566
**
vb@130
  2567
** There are two column (M==2) and three rows (N==3).  Thus the
vb@130
  2568
** result table has 8 entries.  Suppose the result table is stored
vb@130
  2569
** in an array names azResult.  Then azResult holds this content:
vb@130
  2570
**
vb@130
  2571
** <blockquote><pre>
vb@130
  2572
**        azResult&#91;0] = "Name";
vb@130
  2573
**        azResult&#91;1] = "Age";
vb@130
  2574
**        azResult&#91;2] = "Alice";
vb@130
  2575
**        azResult&#91;3] = "43";
vb@130
  2576
**        azResult&#91;4] = "Bob";
vb@130
  2577
**        azResult&#91;5] = "28";
vb@130
  2578
**        azResult&#91;6] = "Cindy";
vb@130
  2579
**        azResult&#91;7] = "21";
vb@130
  2580
** </pre></blockquote>)^
vb@130
  2581
**
vb@130
  2582
** ^The sqlite3_get_table() function evaluates one or more
vb@130
  2583
** semicolon-separated SQL statements in the zero-terminated UTF-8
vb@130
  2584
** string of its 2nd parameter and returns a result table to the
vb@130
  2585
** pointer given in its 3rd parameter.
vb@130
  2586
**
vb@130
  2587
** After the application has finished with the result from sqlite3_get_table(),
vb@130
  2588
** it must pass the result table pointer to sqlite3_free_table() in order to
vb@130
  2589
** release the memory that was malloced.  Because of the way the
vb@130
  2590
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
vb@130
  2591
** function must not try to call [sqlite3_free()] directly.  Only
vb@130
  2592
** [sqlite3_free_table()] is able to release the memory properly and safely.
vb@130
  2593
**
vb@130
  2594
** The sqlite3_get_table() interface is implemented as a wrapper around
vb@130
  2595
** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
vb@130
  2596
** to any internal data structures of SQLite.  It uses only the public
vb@130
  2597
** interface defined here.  As a consequence, errors that occur in the
vb@130
  2598
** wrapper layer outside of the internal [sqlite3_exec()] call are not
vb@130
  2599
** reflected in subsequent calls to [sqlite3_errcode()] or
vb@130
  2600
** [sqlite3_errmsg()].
vb@130
  2601
*/
edouard@1912
  2602
SQLITE_API int sqlite3_get_table(
vb@130
  2603
  sqlite3 *db,          /* An open database */
vb@130
  2604
  const char *zSql,     /* SQL to be evaluated */
vb@130
  2605
  char ***pazResult,    /* Results of the query */
vb@130
  2606
  int *pnRow,           /* Number of result rows written here */
vb@130
  2607
  int *pnColumn,        /* Number of result columns written here */
vb@130
  2608
  char **pzErrmsg       /* Error msg written here */
vb@130
  2609
);
edouard@1912
  2610
SQLITE_API void sqlite3_free_table(char **result);
vb@130
  2611
vb@130
  2612
/*
vb@130
  2613
** CAPI3REF: Formatted String Printing Functions
vb@130
  2614
**
vb@130
  2615
** These routines are work-alikes of the "printf()" family of functions
vb@130
  2616
** from the standard C library.
dz@3192
  2617
** These routines understand most of the common formatting options from
dz@3192
  2618
** the standard library printf() 
dz@3192
  2619
** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
dz@3192
  2620
** See the [built-in printf()] documentation for details.
vb@130
  2621
**
vb@130
  2622
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
dz@3192
  2623
** results into memory obtained from [sqlite3_malloc64()].
vb@130
  2624
** The strings returned by these two routines should be
vb@130
  2625
** released by [sqlite3_free()].  ^Both routines return a
dz@3192
  2626
** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
vb@130
  2627
** memory to hold the resulting string.
vb@130
  2628
**
vb@130
  2629
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
vb@130
  2630
** the standard C library.  The result is written into the
vb@130
  2631
** buffer supplied as the second parameter whose size is given by
vb@130
  2632
** the first parameter. Note that the order of the
vb@130
  2633
** first two parameters is reversed from snprintf().)^  This is an
vb@130
  2634
** historical accident that cannot be fixed without breaking
vb@130
  2635
** backwards compatibility.  ^(Note also that sqlite3_snprintf()
vb@130
  2636
** returns a pointer to its buffer instead of the number of
vb@130
  2637
** characters actually written into the buffer.)^  We admit that
vb@130
  2638
** the number of characters written would be a more useful return
vb@130
  2639
** value but we cannot change the implementation of sqlite3_snprintf()
vb@130
  2640
** now without breaking compatibility.
vb@130
  2641
**
vb@130
  2642
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
vb@130
  2643
** guarantees that the buffer is always zero-terminated.  ^The first
vb@130
  2644
** parameter "n" is the total size of the buffer, including space for
vb@130
  2645
** the zero terminator.  So the longest string that can be completely
vb@130
  2646
** written will be n-1 characters.
vb@130
  2647
**
vb@130
  2648
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
vb@130
  2649
**
dz@3192
  2650
** See also:  [built-in printf()], [printf() SQL function]
vb@130
  2651
*/
edouard@1912
  2652
SQLITE_API char *sqlite3_mprintf(const char*,...);
edouard@1912
  2653
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
edouard@1912
  2654
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
edouard@1912
  2655
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
vb@130
  2656
vb@130
  2657
/*
vb@130
  2658
** CAPI3REF: Memory Allocation Subsystem
vb@130
  2659
**
vb@130
  2660
** The SQLite core uses these three routines for all of its own
vb@130
  2661
** internal memory allocation needs. "Core" in the previous sentence
vb@130
  2662
** does not include operating-system specific VFS implementation.  The
vb@130
  2663
** Windows VFS uses native malloc() and free() for some operations.
vb@130
  2664
**
vb@130
  2665
** ^The sqlite3_malloc() routine returns a pointer to a block
vb@130
  2666
** of memory at least N bytes in length, where N is the parameter.
vb@130
  2667
** ^If sqlite3_malloc() is unable to obtain sufficient free
vb@130
  2668
** memory, it returns a NULL pointer.  ^If the parameter N to
vb@130
  2669
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
vb@130
  2670
** a NULL pointer.
vb@130
  2671
**
Edouard@491
  2672
** ^The sqlite3_malloc64(N) routine works just like
Edouard@491
  2673
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
Edouard@491
  2674
** of a signed 32-bit integer.
Edouard@491
  2675
**
vb@130
  2676
** ^Calling sqlite3_free() with a pointer previously returned
vb@130
  2677
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
vb@130
  2678
** that it might be reused.  ^The sqlite3_free() routine is
vb@130
  2679
** a no-op if is called with a NULL pointer.  Passing a NULL pointer
vb@130
  2680
** to sqlite3_free() is harmless.  After being freed, memory
vb@130
  2681
** should neither be read nor written.  Even reading previously freed
vb@130
  2682
** memory might result in a segmentation fault or other severe error.
vb@130
  2683
** Memory corruption, a segmentation fault, or other severe error
vb@130
  2684
** might result if sqlite3_free() is called with a non-NULL pointer that
vb@130
  2685
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
vb@130
  2686
**