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