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