extensions/sqlite/sqlite-source/sqlite3.h
author David Anderson <dvander@alliedmods.net>
Sun Oct 28 05:48:06 2007 +0000 (2007-10-28)
changeset 1645 27307df4d711
parent 1203 633c25ce6405
permissions -rw-r--r--
updated to sqlite-3.5.1 now that it's stable
used new shared cache functionality (yay)
dvander@1203
     1
/*
dvander@1203
     2
** 2001 September 15
dvander@1203
     3
**
dvander@1203
     4
** The author disclaims copyright to this source code.  In place of
dvander@1203
     5
** a legal notice, here is a blessing:
dvander@1203
     6
**
dvander@1203
     7
**    May you do good and not evil.
dvander@1203
     8
**    May you find forgiveness for yourself and forgive others.
dvander@1203
     9
**    May you share freely, never taking more than you give.
dvander@1203
    10
**
dvander@1203
    11
*************************************************************************
dvander@1203
    12
** This header file defines the interface that the SQLite library
dvander@1203
    13
** presents to client programs.  If a C-function, structure, datatype,
dvander@1203
    14
** or constant definition does not appear in this file, then it is
dvander@1203
    15
** not a published API of SQLite, is subject to change without
dvander@1203
    16
** notice, and should not be referenced by programs that use SQLite.
dvander@1203
    17
**
dvander@1203
    18
** Some of the definitions that are in this file are marked as
dvander@1203
    19
** "experimental".  Experimental interfaces are normally new
dvander@1203
    20
** features recently added to SQLite.  We do not anticipate changes 
dvander@1203
    21
** to experimental interfaces but reserve to make minor changes if
dvander@1203
    22
** experience from use "in the wild" suggest such changes are prudent.
dvander@1203
    23
**
dvander@1203
    24
** The official C-language API documentation for SQLite is derived
dvander@1203
    25
** from comments in this file.  This file is the authoritative source
dvander@1203
    26
** on how SQLite interfaces are suppose to operate.
dvander@1203
    27
**
dvander@1203
    28
** The name of this file under configuration management is "sqlite.h.in".
dvander@1203
    29
** The makefile makes some minor changes to this file (such as inserting
dvander@1203
    30
** the version number) and changes its name to "sqlite3.h" as
dvander@1203
    31
** part of the build process.
dvander@1203
    32
**
dvander@1203
    33
** @(#) $Id$
dvander@1203
    34
*/
dvander@1203
    35
#ifndef _SQLITE3_H_
dvander@1203
    36
#define _SQLITE3_H_
dvander@1203
    37
#include <stdarg.h>     /* Needed for the definition of va_list */
dvander@1203
    38
dvander@1203
    39
/*
dvander@1203
    40
** Make sure we can call this stuff from C++.
dvander@1203
    41
*/
dvander@1203
    42
#ifdef __cplusplus
dvander@1203
    43
extern "C" {
dvander@1203
    44
#endif
dvander@1203
    45
dvander@1645
    46
dvander@1645
    47
/*
dvander@1645
    48
** Add the ability to override 'extern'
dvander@1645
    49
*/
dvander@1645
    50
#ifndef SQLITE_EXTERN
dvander@1645
    51
# define SQLITE_EXTERN extern
dvander@1645
    52
#endif
dvander@1645
    53
dvander@1203
    54
/*
dvander@1203
    55
** Make sure these symbols where not defined by some previous header
dvander@1203
    56
** file.
dvander@1203
    57
*/
dvander@1203
    58
#ifdef SQLITE_VERSION
dvander@1203
    59
# undef SQLITE_VERSION
dvander@1203
    60
#endif
dvander@1203
    61
#ifdef SQLITE_VERSION_NUMBER
dvander@1203
    62
# undef SQLITE_VERSION_NUMBER
dvander@1203
    63
#endif
dvander@1203
    64
dvander@1203
    65
/*
dvander@1203
    66
** CAPI3REF: Compile-Time Library Version Numbers
dvander@1203
    67
**
dvander@1203
    68
** The version of the SQLite library is contained in the sqlite3.h
dvander@1203
    69
** header file in a #define named SQLITE_VERSION.  The SQLITE_VERSION
dvander@1203
    70
** macro resolves to a string constant.
dvander@1203
    71
**
dvander@1203
    72
** The format of the version string is "X.Y.Z", where
dvander@1203
    73
** X is the major version number, Y is the minor version number and Z
dvander@1203
    74
** is the release number.  The X.Y.Z might be followed by "alpha" or "beta".
dvander@1203
    75
** For example "3.1.1beta".
dvander@1203
    76
**
dvander@1203
    77
** The X value is always 3 in SQLite.  The X value only changes when
dvander@1203
    78
** backwards compatibility is broken and we intend to never break
dvander@1203
    79
** backwards compatibility.  The Y value only changes when
dvander@1203
    80
** there are major feature enhancements that are forwards compatible
dvander@1203
    81
** but not backwards compatible.  The Z value is incremented with
dvander@1203
    82
** each release but resets back to 0 when Y is incremented.
dvander@1203
    83
**
dvander@1203
    84
** The SQLITE_VERSION_NUMBER is an integer with the value 
dvander@1203
    85
** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", 
dvander@1203
    86
** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
dvander@1203
    87
** version 3.1.1 or greater at compile time, programs may use the test 
dvander@1203
    88
** (SQLITE_VERSION_NUMBER>=3001001).
dvander@1203
    89
**
dvander@1203
    90
** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
dvander@1203
    91
*/
dvander@1645
    92
#define SQLITE_VERSION         "3.5.1"
dvander@1645
    93
#define SQLITE_VERSION_NUMBER 3005001
dvander@1203
    94
dvander@1203
    95
/*
dvander@1203
    96
** CAPI3REF: Run-Time Library Version Numbers
dvander@1203
    97
**
dvander@1203
    98
** These routines return values equivalent to the header constants
dvander@1203
    99
** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER].  The values returned
dvander@1203
   100
** by this routines should only be different from the header values
dvander@1203
   101
** if you compile your program using an sqlite3.h header from a
dvander@1203
   102
** different version of SQLite that the version of the library you
dvander@1203
   103
** link against.
dvander@1203
   104
**
dvander@1203
   105
** The sqlite3_version[] string constant contains the text of the
dvander@1203
   106
** [SQLITE_VERSION] string.  The sqlite3_libversion() function returns
dvander@1203
   107
** a poiner to the sqlite3_version[] string constant.  The function
dvander@1203
   108
** is provided for DLL users who can only access functions and not
dvander@1203
   109
** constants within the DLL.
dvander@1203
   110
*/
dvander@1645
   111
SQLITE_EXTERN const char sqlite3_version[];
dvander@1203
   112
const char *sqlite3_libversion(void);
dvander@1203
   113
int sqlite3_libversion_number(void);
dvander@1203
   114
dvander@1203
   115
/*
dvander@1645
   116
** CAPI3REF: Test To See If The Library Is Threadsafe
dvander@1645
   117
**
dvander@1645
   118
** This routine returns TRUE (nonzero) if SQLite was compiled with
dvander@1645
   119
** all of its mutexes enabled and is thus threadsafe.  It returns
dvander@1645
   120
** zero if the particular build is for single-threaded operation
dvander@1645
   121
** only.
dvander@1645
   122
**
dvander@1645
   123
** Really all this routine does is return true if SQLite was compiled
dvander@1645
   124
** with the -DSQLITE_THREADSAFE=1 option and false if
dvander@1645
   125
** compiled with -DSQLITE_THREADSAFE=0.  If SQLite uses an
dvander@1645
   126
** application-defined mutex subsystem, malloc subsystem, collating
dvander@1645
   127
** sequence, VFS, SQL function, progress callback, commit hook,
dvander@1645
   128
** extension, or other accessories and these add-ons are not
dvander@1645
   129
** threadsafe, then clearly the combination will not be threadsafe
dvander@1645
   130
** either.  Hence, this routine never reports that the library
dvander@1645
   131
** is guaranteed to be threadsafe, only when it is guaranteed not
dvander@1645
   132
** to be.
dvander@1645
   133
**
dvander@1645
   134
** This is an experimental API and may go away or change in future
dvander@1645
   135
** releases.
dvander@1645
   136
*/
dvander@1645
   137
int sqlite3_threadsafe(void);
dvander@1645
   138
dvander@1645
   139
/*
dvander@1203
   140
** CAPI3REF: Database Connection Handle
dvander@1203
   141
**
dvander@1203
   142
** Each open SQLite database is represented by pointer to an instance of the
dvander@1203
   143
** opaque structure named "sqlite3".  It is useful to think of an sqlite3
dvander@1645
   144
** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
dvander@1645
   145
** [sqlite3_open_v2()] interfaces are its constructors
dvander@1645
   146
** and [sqlite3_close()] is its destructor.  There are many other interfaces
dvander@1645
   147
** (such as [sqlite3_prepare_v2()], [sqlite3_create_function()], and
dvander@1645
   148
** [sqlite3_busy_timeout()] to name but three) that are methods on this
dvander@1203
   149
** object.
dvander@1203
   150
*/
dvander@1203
   151
typedef struct sqlite3 sqlite3;
dvander@1203
   152
dvander@1203
   153
dvander@1203
   154
/*
dvander@1203
   155
** CAPI3REF: 64-Bit Integer Types
dvander@1203
   156
**
dvander@1203
   157
** Some compilers do not support the "long long" datatype.  So we have
dvander@1203
   158
** to do compiler-specific typedefs for 64-bit signed and unsigned integers.
dvander@1203
   159
**
dvander@1203
   160
** Many SQLite interface functions require a 64-bit integer arguments.
dvander@1203
   161
** Those interfaces are declared using this typedef.
dvander@1203
   162
*/
dvander@1203
   163
#ifdef SQLITE_INT64_TYPE
dvander@1203
   164
  typedef SQLITE_INT64_TYPE sqlite_int64;
dvander@1203
   165
  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
dvander@1203
   166
#elif defined(_MSC_VER) || defined(__BORLANDC__)
dvander@1203
   167
  typedef __int64 sqlite_int64;
dvander@1203
   168
  typedef unsigned __int64 sqlite_uint64;
dvander@1203
   169
#else
dvander@1203
   170
  typedef long long int sqlite_int64;
dvander@1203
   171
  typedef unsigned long long int sqlite_uint64;
dvander@1203
   172
#endif
dvander@1645
   173
typedef sqlite_int64 sqlite3_int64;
dvander@1645
   174
typedef sqlite_uint64 sqlite3_uint64;
dvander@1203
   175
dvander@1203
   176
/*
dvander@1203
   177
** If compiling for a processor that lacks floating point support,
dvander@1203
   178
** substitute integer for floating-point
dvander@1203
   179
*/
dvander@1203
   180
#ifdef SQLITE_OMIT_FLOATING_POINT
dvander@1645
   181
# define double sqlite3_int64
dvander@1203
   182
#endif
dvander@1203
   183
dvander@1203
   184
/*
dvander@1203
   185
** CAPI3REF: Closing A Database Connection
dvander@1203
   186
**
dvander@1203
   187
** Call this function with a pointer to a structure that was previously
dvander@1645
   188
** returned from [sqlite3_open()], [sqlite3_open16()], or
dvander@1645
   189
** [sqlite3_open_v2()] and the corresponding database will by
dvander@1203
   190
** closed.
dvander@1203
   191
**
dvander@1203
   192
** All SQL statements prepared using [sqlite3_prepare_v2()] or
dvander@1203
   193
** [sqlite3_prepare16_v2()] must be destroyed using [sqlite3_finalize()]
dvander@1203
   194
** before this routine is called. Otherwise, SQLITE_BUSY is returned and the
dvander@1203
   195
** database connection remains open.
dvander@1645
   196
**
dvander@1645
   197
** Passing this routine a database connection that has already been
dvander@1645
   198
** closed results in undefined behavior.  If other interfaces that
dvander@1645
   199
** reference the same database connection are pending (either in the
dvander@1645
   200
** same thread or in different threads) when this routine is called,
dvander@1645
   201
** then the behavior is undefined and is almost certainly undesirable.
dvander@1203
   202
*/
dvander@1203
   203
int sqlite3_close(sqlite3 *);
dvander@1203
   204
dvander@1203
   205
/*
dvander@1203
   206
** The type for a callback function.
dvander@1203
   207
** This is legacy and deprecated.  It is included for historical
dvander@1203
   208
** compatibility and is not documented.
dvander@1203
   209
*/
dvander@1203
   210
typedef int (*sqlite3_callback)(void*,int,char**, char**);
dvander@1203
   211
dvander@1203
   212
/*
dvander@1203
   213
** CAPI3REF: One-Step Query Execution Interface
dvander@1203
   214
**
dvander@1203
   215
** This interface is used to do a one-time evaluatation of zero
dvander@1203
   216
** or more SQL statements.  UTF-8 text of the SQL statements to
dvander@1203
   217
** be evaluted is passed in as the second parameter.  The statements
dvander@1203
   218
** are prepared one by one using [sqlite3_prepare()], evaluated
dvander@1203
   219
** using [sqlite3_step()], then destroyed using [sqlite3_finalize()].
dvander@1203
   220
**
dvander@1203
   221
** If one or more of the SQL statements are queries, then
dvander@1203
   222
** the callback function specified by the 3rd parameter is
dvander@1203
   223
** invoked once for each row of the query result.  This callback
dvander@1203
   224
** should normally return 0.  If the callback returns a non-zero
dvander@1203
   225
** value then the query is aborted, all subsequent SQL statements
dvander@1645
   226
** are skipped and the sqlite3_exec() function returns the [SQLITE_ABORT].
dvander@1203
   227
**
dvander@1203
   228
** The 4th parameter to this interface is an arbitrary pointer that is
dvander@1203
   229
** passed through to the callback function as its first parameter.
dvander@1203
   230
**
dvander@1203
   231
** The 2nd parameter to the callback function is the number of
dvander@1203
   232
** columns in the query result.  The 3rd parameter to the callback
dvander@1203
   233
** is an array of strings holding the values for each column
dvander@1203
   234
** as extracted using [sqlite3_column_text()].
dvander@1203
   235
** The 4th parameter to the callback is an array of strings
dvander@1203
   236
** obtained using [sqlite3_column_name()] and holding
dvander@1203
   237
** the names of each column.
dvander@1203
   238
**
dvander@1203
   239
** The callback function may be NULL, even for queries.  A NULL
dvander@1203
   240
** callback is not an error.  It just means that no callback
dvander@1203
   241
** will be invoked.
dvander@1203
   242
**
dvander@1203
   243
** If an error occurs while parsing or evaluating the SQL (but
dvander@1203
   244
** not while executing the callback) then an appropriate error
dvander@1203
   245
** message is written into memory obtained from [sqlite3_malloc()] and
dvander@1203
   246
** *errmsg is made to point to that message.  The calling function
dvander@1645
   247
** is responsible for freeing the memory using [sqlite3_free()].
dvander@1645
   248
** If errmsg==NULL, then no error message is ever written.
dvander@1203
   249
**
dvander@1203
   250
** The return value is is SQLITE_OK if there are no errors and
dvander@1203
   251
** some other [SQLITE_OK | return code] if there is an error.  
dvander@1203
   252
** The particular return value depends on the type of error. 
dvander@1203
   253
**
dvander@1203
   254
*/
dvander@1203
   255
int sqlite3_exec(
dvander@1203
   256
  sqlite3*,                                  /* An open database */
dvander@1203
   257
  const char *sql,                           /* SQL to be evaluted */
dvander@1203
   258
  int (*callback)(void*,int,char**,char**),  /* Callback function */
dvander@1203
   259
  void *,                                    /* 1st argument to callback */
dvander@1203
   260
  char **errmsg                              /* Error msg written here */
dvander@1203
   261
);
dvander@1203
   262
dvander@1203
   263
/*
dvander@1203
   264
** CAPI3REF: Result Codes
dvander@1203
   265
** KEYWORDS: SQLITE_OK
dvander@1203
   266
**
dvander@1203
   267
** Many SQLite functions return an integer result code from the set shown
dvander@1203
   268
** above in order to indicates success or failure.
dvander@1203
   269
**
dvander@1203
   270
** The result codes above are the only ones returned by SQLite in its
dvander@1203
   271
** default configuration.  However, the [sqlite3_extended_result_codes()]
dvander@1203
   272
** API can be used to set a database connectoin to return more detailed
dvander@1203
   273
** result codes.
dvander@1203
   274
**
dvander@1203
   275
** See also: [SQLITE_IOERR_READ | extended result codes]
dvander@1203
   276
**
dvander@1203
   277
*/
dvander@1203
   278
#define SQLITE_OK           0   /* Successful result */
dvander@1203
   279
/* beginning-of-error-codes */
dvander@1203
   280
#define SQLITE_ERROR        1   /* SQL error or missing database */
dvander@1203
   281
#define SQLITE_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
dvander@1203
   282
#define SQLITE_PERM         3   /* Access permission denied */
dvander@1203
   283
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
dvander@1203
   284
#define SQLITE_BUSY         5   /* The database file is locked */
dvander@1203
   285
#define SQLITE_LOCKED       6   /* A table in the database is locked */
dvander@1203
   286
#define SQLITE_NOMEM        7   /* A malloc() failed */
dvander@1203
   287
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
dvander@1203
   288
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
dvander@1203
   289
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
dvander@1203
   290
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
dvander@1203
   291
#define SQLITE_NOTFOUND    12   /* NOT USED. Table or record not found */
dvander@1203
   292
#define SQLITE_FULL        13   /* Insertion failed because database is full */
dvander@1203
   293
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
dvander@1203
   294
#define SQLITE_PROTOCOL    15   /* NOT USED. Database lock protocol error */
dvander@1203
   295
#define SQLITE_EMPTY       16   /* Database is empty */
dvander@1203
   296
#define SQLITE_SCHEMA      17   /* The database schema changed */
dvander@1203
   297
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
dvander@1645
   298
#define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
dvander@1203
   299
#define SQLITE_MISMATCH    20   /* Data type mismatch */
dvander@1203
   300
#define SQLITE_MISUSE      21   /* Library used incorrectly */
dvander@1203
   301
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
dvander@1203
   302
#define SQLITE_AUTH        23   /* Authorization denied */
dvander@1203
   303
#define SQLITE_FORMAT      24   /* Auxiliary database format error */
dvander@1203
   304
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
dvander@1203
   305
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
dvander@1203
   306
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
dvander@1203
   307
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
dvander@1203
   308
/* end-of-error-codes */
dvander@1203
   309
dvander@1203
   310
/*
dvander@1203
   311
** CAPI3REF: Extended Result Codes
dvander@1203
   312
**
dvander@1203
   313
** In its default configuration, SQLite API routines return one of 26 integer
dvander@1203
   314
** result codes described at result-codes.  However, experience has shown that
dvander@1203
   315
** many of these result codes are too course-grained.  They do not provide as
dvander@1203
   316
** much information about problems as users might like.  In an effort to
dvander@1203
   317
** address this, newer versions of SQLite (version 3.3.8 and later) include
dvander@1203
   318
** support for additional result codes that provide more detailed information
dvander@1203
   319
** about errors.  The extended result codes are enabled (or disabled) for 
dvander@1203
   320
** each database
dvander@1203
   321
** connection using the [sqlite3_extended_result_codes()] API.
dvander@1203
   322
** 
dvander@1203
   323
** Some of the available extended result codes are listed above.
dvander@1203
   324
** We expect the number of extended result codes will be expand
dvander@1203
   325
** over time.  Software that uses extended result codes should expect
dvander@1203
   326
** to see new result codes in future releases of SQLite.
dvander@1203
   327
** 
dvander@1203
   328
** The symbolic name for an extended result code always contains a related
dvander@1203
   329
** primary result code as a prefix.  Primary result codes contain a single
dvander@1203
   330
** "_" character.  Extended result codes contain two or more "_" characters.
dvander@1203
   331
** The numeric value of an extended result code can be converted to its
dvander@1203
   332
** corresponding primary result code by masking off the lower 8 bytes.
dvander@1203
   333
**
dvander@1203
   334
** The SQLITE_OK result code will never be extended.  It will always
dvander@1203
   335
** be exactly zero.
dvander@1203
   336
*/
dvander@1203
   337
#define SQLITE_IOERR_READ          (SQLITE_IOERR | (1<<8))
dvander@1203
   338
#define SQLITE_IOERR_SHORT_READ    (SQLITE_IOERR | (2<<8))
dvander@1203
   339
#define SQLITE_IOERR_WRITE         (SQLITE_IOERR | (3<<8))
dvander@1203
   340
#define SQLITE_IOERR_FSYNC         (SQLITE_IOERR | (4<<8))
dvander@1203
   341
#define SQLITE_IOERR_DIR_FSYNC     (SQLITE_IOERR | (5<<8))
dvander@1203
   342
#define SQLITE_IOERR_TRUNCATE      (SQLITE_IOERR | (6<<8))
dvander@1203
   343
#define SQLITE_IOERR_FSTAT         (SQLITE_IOERR | (7<<8))
dvander@1203
   344
#define SQLITE_IOERR_UNLOCK        (SQLITE_IOERR | (8<<8))
dvander@1203
   345
#define SQLITE_IOERR_RDLOCK        (SQLITE_IOERR | (9<<8))
dvander@1203
   346
#define SQLITE_IOERR_DELETE        (SQLITE_IOERR | (10<<8))
dvander@1203
   347
#define SQLITE_IOERR_BLOCKED       (SQLITE_IOERR | (11<<8))
dvander@1645
   348
#define SQLITE_IOERR_NOMEM         (SQLITE_IOERR | (12<<8))
dvander@1645
   349
dvander@1645
   350
/*
dvander@1645
   351
** CAPI3REF: Flags For File Open Operations
dvander@1645
   352
**
dvander@1645
   353
** Combination of the following bit values are used as the
dvander@1645
   354
** third argument to the [sqlite3_open_v2()] interface and
dvander@1645
   355
** as fourth argument to the xOpen method of the
dvander@1645
   356
** [sqlite3_vfs] object.
dvander@1645
   357
**
dvander@1645
   358
*/
dvander@1645
   359
#define SQLITE_OPEN_READONLY         0x00000001
dvander@1645
   360
#define SQLITE_OPEN_READWRITE        0x00000002
dvander@1645
   361
#define SQLITE_OPEN_CREATE           0x00000004
dvander@1645
   362
#define SQLITE_OPEN_DELETEONCLOSE    0x00000008
dvander@1645
   363
#define SQLITE_OPEN_EXCLUSIVE        0x00000010
dvander@1645
   364
#define SQLITE_OPEN_MAIN_DB          0x00000100
dvander@1645
   365
#define SQLITE_OPEN_TEMP_DB          0x00000200
dvander@1645
   366
#define SQLITE_OPEN_TRANSIENT_DB     0x00000400
dvander@1645
   367
#define SQLITE_OPEN_MAIN_JOURNAL     0x00000800
dvander@1645
   368
#define SQLITE_OPEN_TEMP_JOURNAL     0x00001000
dvander@1645
   369
#define SQLITE_OPEN_SUBJOURNAL       0x00002000
dvander@1645
   370
#define SQLITE_OPEN_MASTER_JOURNAL   0x00004000
dvander@1645
   371
dvander@1645
   372
/*
dvander@1645
   373
** CAPI3REF: Device Characteristics
dvander@1645
   374
**
dvander@1645
   375
** The xDeviceCapabilities method of the [sqlite3_io_methods]
dvander@1645
   376
** object returns an integer which is a vector of the following
dvander@1645
   377
** bit values expressing I/O characteristics of the mass storage
dvander@1645
   378
** device that holds the file that the [sqlite3_io_methods]
dvander@1645
   379
** refers to.
dvander@1645
   380
**
dvander@1645
   381
** The SQLITE_IOCAP_ATOMIC property means that all writes of
dvander@1645
   382
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
dvander@1645
   383
** mean that writes of blocks that are nnn bytes in size and
dvander@1645
   384
** are aligned to an address which is an integer multiple of
dvander@1645
   385
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
dvander@1645
   386
** that when data is appended to a file, the data is appended
dvander@1645
   387
** first then the size of the file is extended, never the other
dvander@1645
   388
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
dvander@1645
   389
** information is written to disk in the same order as calls
dvander@1645
   390
** to xWrite().
dvander@1645
   391
*/
dvander@1645
   392
#define SQLITE_IOCAP_ATOMIC          0x00000001
dvander@1645
   393
#define SQLITE_IOCAP_ATOMIC512       0x00000002
dvander@1645
   394
#define SQLITE_IOCAP_ATOMIC1K        0x00000004
dvander@1645
   395
#define SQLITE_IOCAP_ATOMIC2K        0x00000008
dvander@1645
   396
#define SQLITE_IOCAP_ATOMIC4K        0x00000010
dvander@1645
   397
#define SQLITE_IOCAP_ATOMIC8K        0x00000020
dvander@1645
   398
#define SQLITE_IOCAP_ATOMIC16K       0x00000040
dvander@1645
   399
#define SQLITE_IOCAP_ATOMIC32K       0x00000080
dvander@1645
   400
#define SQLITE_IOCAP_ATOMIC64K       0x00000100
dvander@1645
   401
#define SQLITE_IOCAP_SAFE_APPEND     0x00000200
dvander@1645
   402
#define SQLITE_IOCAP_SEQUENTIAL      0x00000400
dvander@1645
   403
dvander@1645
   404
/*
dvander@1645
   405
** CAPI3REF: File Locking Levels
dvander@1645
   406
**
dvander@1645
   407
** SQLite uses one of the following integer values as the second
dvander@1645
   408
** argument to calls it makes to the xLock() and xUnlock() methods
dvander@1645
   409
** of an [sqlite3_io_methods] object.
dvander@1645
   410
*/
dvander@1645
   411
#define SQLITE_LOCK_NONE          0
dvander@1645
   412
#define SQLITE_LOCK_SHARED        1
dvander@1645
   413
#define SQLITE_LOCK_RESERVED      2
dvander@1645
   414
#define SQLITE_LOCK_PENDING       3
dvander@1645
   415
#define SQLITE_LOCK_EXCLUSIVE     4
dvander@1645
   416
dvander@1645
   417
/*
dvander@1645
   418
** CAPI3REF: Synchronization Type Flags
dvander@1645
   419
**
dvander@1645
   420
** When SQLite invokes the xSync() method of an [sqlite3_io_methods]
dvander@1645
   421
** object it uses a combination of the following integer values as
dvander@1645
   422
** the second argument.
dvander@1645
   423
**
dvander@1645
   424
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
dvander@1645
   425
** sync operation only needs to flush data to mass storage.  Inode
dvander@1645
   426
** information need not be flushed.  The SQLITE_SYNC_NORMAL means 
dvander@1645
   427
** to use normal fsync() semantics.  The SQLITE_SYNC_FULL flag means 
dvander@1645
   428
** to use Mac OS-X style fullsync instead of fsync().
dvander@1645
   429
*/
dvander@1645
   430
#define SQLITE_SYNC_NORMAL        0x00002
dvander@1645
   431
#define SQLITE_SYNC_FULL          0x00003
dvander@1645
   432
#define SQLITE_SYNC_DATAONLY      0x00010
dvander@1645
   433
dvander@1645
   434
dvander@1645
   435
/*
dvander@1645
   436
** CAPI3REF: OS Interface Open File Handle
dvander@1645
   437
**
dvander@1645
   438
** An [sqlite3_file] object represents an open file in the OS
dvander@1645
   439
** interface layer.  Individual OS interface implementations will
dvander@1645
   440
** want to subclass this object by appending additional fields
dvander@1645
   441
** for their own use.  The pMethods entry is a pointer to an
dvander@1645
   442
** [sqlite3_io_methods] object that defines methods for performing
dvander@1645
   443
** I/O operations on the open file.
dvander@1645
   444
*/
dvander@1645
   445
typedef struct sqlite3_file sqlite3_file;
dvander@1645
   446
struct sqlite3_file {
dvander@1645
   447
  const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
dvander@1645
   448
};
dvander@1645
   449
dvander@1645
   450
/*
dvander@1645
   451
** CAPI3REF: OS Interface File Virtual Methods Object
dvander@1645
   452
**
dvander@1645
   453
** Every file opened by the [sqlite3_vfs] xOpen method contains a pointer to
dvander@1645
   454
** an instance of the this object.  This object defines the
dvander@1645
   455
** methods used to perform various operations against the open file.
dvander@1645
   456
**
dvander@1645
   457
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
dvander@1645
   458
** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
dvander@1645
   459
*  The second choice is an
dvander@1645
   460
** OS-X style fullsync.  The SQLITE_SYNC_DATA flag may be ORed in to
dvander@1645
   461
** indicate that only the data of the file and not its inode needs to be
dvander@1645
   462
** synced.
dvander@1645
   463
** 
dvander@1645
   464
** The integer values to xLock() and xUnlock() are one of
dvander@1645
   465
** <ul>
dvander@1645
   466
** <li> [SQLITE_LOCK_NONE],
dvander@1645
   467
** <li> [SQLITE_LOCK_SHARED],
dvander@1645
   468
** <li> [SQLITE_LOCK_RESERVED],
dvander@1645
   469
** <li> [SQLITE_LOCK_PENDING], or
dvander@1645
   470
** <li> [SQLITE_LOCK_EXCLUSIVE].
dvander@1645
   471
** </ul>
dvander@1645
   472
** xLock() increases the lock. xUnlock() decreases the lock.  
dvander@1645
   473
** The xCheckReservedLock() method looks
dvander@1645
   474
** to see if any database connection, either in this
dvander@1645
   475
** process or in some other process, is holding an RESERVED,
dvander@1645
   476
** PENDING, or EXCLUSIVE lock on the file.  It returns true
dvander@1645
   477
** if such a lock exists and false if not.
dvander@1645
   478
** 
dvander@1645
   479
** The xFileControl() method is a generic interface that allows custom
dvander@1645
   480
** VFS implementations to directly control an open file using the
dvander@1645
   481
** [sqlite3_file_control()] interface.  The second "op" argument
dvander@1645
   482
** is an integer opcode.   The third
dvander@1645
   483
** argument is a generic pointer which is intended to be a pointer
dvander@1645
   484
** to a structure that may contain arguments or space in which to
dvander@1645
   485
** write return values.  Potential uses for xFileControl() might be
dvander@1645
   486
** functions to enable blocking locks with timeouts, to change the
dvander@1645
   487
** locking strategy (for example to use dot-file locks), to inquire
dvander@1645
   488
** about the status of a lock, or to break stale locks.  The SQLite
dvander@1645
   489
** core reserves opcodes less than 100 for its own use. 
dvander@1645
   490
** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
dvander@1645
   491
** Applications that define a custom xFileControl method should use opcodes 
dvander@1645
   492
** greater than 100 to avoid conflicts.
dvander@1645
   493
**
dvander@1645
   494
** The xSectorSize() method returns the sector size of the
dvander@1645
   495
** device that underlies the file.  The sector size is the
dvander@1645
   496
** minimum write that can be performed without disturbing
dvander@1645
   497
** other bytes in the file.  The xDeviceCharacteristics()
dvander@1645
   498
** method returns a bit vector describing behaviors of the
dvander@1645
   499
** underlying device:
dvander@1645
   500
**
dvander@1645
   501
** <ul>
dvander@1645
   502
** <li> [SQLITE_IOCAP_ATOMIC]
dvander@1645
   503
** <li> [SQLITE_IOCAP_ATOMIC512]
dvander@1645
   504
** <li> [SQLITE_IOCAP_ATOMIC1K]
dvander@1645
   505
** <li> [SQLITE_IOCAP_ATOMIC2K]
dvander@1645
   506
** <li> [SQLITE_IOCAP_ATOMIC4K]
dvander@1645
   507
** <li> [SQLITE_IOCAP_ATOMIC8K]
dvander@1645
   508
** <li> [SQLITE_IOCAP_ATOMIC16K]
dvander@1645
   509
** <li> [SQLITE_IOCAP_ATOMIC32K]
dvander@1645
   510
** <li> [SQLITE_IOCAP_ATOMIC64K]
dvander@1645
   511
** <li> [SQLITE_IOCAP_SAFE_APPEND]
dvander@1645
   512
** <li> [SQLITE_IOCAP_SEQUENTIAL]
dvander@1645
   513
** </ul>
dvander@1645
   514
**
dvander@1645
   515
** The SQLITE_IOCAP_ATOMIC property means that all writes of
dvander@1645
   516
** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
dvander@1645
   517
** mean that writes of blocks that are nnn bytes in size and
dvander@1645
   518
** are aligned to an address which is an integer multiple of
dvander@1645
   519
** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
dvander@1645
   520
** that when data is appended to a file, the data is appended
dvander@1645
   521
** first then the size of the file is extended, never the other
dvander@1645
   522
** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
dvander@1645
   523
** information is written to disk in the same order as calls
dvander@1645
   524
** to xWrite().
dvander@1645
   525
*/
dvander@1645
   526
typedef struct sqlite3_io_methods sqlite3_io_methods;
dvander@1645
   527
struct sqlite3_io_methods {
dvander@1645
   528
  int iVersion;
dvander@1645
   529
  int (*xClose)(sqlite3_file*);
dvander@1645
   530
  int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
dvander@1645
   531
  int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
dvander@1645
   532
  int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
dvander@1645
   533
  int (*xSync)(sqlite3_file*, int flags);
dvander@1645
   534
  int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
dvander@1645
   535
  int (*xLock)(sqlite3_file*, int);
dvander@1645
   536
  int (*xUnlock)(sqlite3_file*, int);
dvander@1645
   537
  int (*xCheckReservedLock)(sqlite3_file*);
dvander@1645
   538
  int (*xFileControl)(sqlite3_file*, int op, void *pArg);
dvander@1645
   539
  int (*xSectorSize)(sqlite3_file*);
dvander@1645
   540
  int (*xDeviceCharacteristics)(sqlite3_file*);
dvander@1645
   541
  /* Additional methods may be added in future releases */
dvander@1645
   542
};
dvander@1645
   543
dvander@1645
   544
/*
dvander@1645
   545
** CAPI3REF: Standard File Control Opcodes
dvander@1645
   546
**
dvander@1645
   547
** These integer constants are opcodes for the xFileControl method
dvander@1645
   548
** of the [sqlite3_io_methods] object and to the [sqlite3_file_control()]
dvander@1645
   549
** interface.
dvander@1645
   550
**
dvander@1645
   551
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
dvander@1645
   552
** opcode cases the xFileControl method to write the current state of
dvander@1645
   553
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
dvander@1645
   554
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
dvander@1645
   555
** into an integer that the pArg argument points to.  This capability
dvander@1645
   556
** is used during testing and only needs to be supported when SQLITE_TEST
dvander@1645
   557
** is defined.
dvander@1645
   558
*/
dvander@1645
   559
#define SQLITE_FCNTL_LOCKSTATE        1
dvander@1645
   560
dvander@1645
   561
/*
dvander@1645
   562
** CAPI3REF: Mutex Handle
dvander@1645
   563
**
dvander@1645
   564
** The mutex module within SQLite defines [sqlite3_mutex] to be an
dvander@1645
   565
** abstract type for a mutex object.  The SQLite core never looks
dvander@1645
   566
** at the internal representation of an [sqlite3_mutex].  It only
dvander@1645
   567
** deals with pointers to the [sqlite3_mutex] object.
dvander@1645
   568
**
dvander@1645
   569
** Mutexes are created using [sqlite3_mutex_alloc()].
dvander@1645
   570
*/
dvander@1645
   571
typedef struct sqlite3_mutex sqlite3_mutex;
dvander@1645
   572
dvander@1645
   573
/*
dvander@1645
   574
** CAPI3REF: OS Interface Object
dvander@1645
   575
**
dvander@1645
   576
** An instance of this object defines the interface between the
dvander@1645
   577
** SQLite core and the underlying operating system.  The "vfs"
dvander@1645
   578
** in the name of the object stands for "virtual file system".
dvander@1645
   579
**
dvander@1645
   580
** The iVersion field is initially 1 but may be larger for future
dvander@1645
   581
** versions of SQLite.  Additional fields may be appended to this
dvander@1645
   582
** object when the iVersion value is increased.
dvander@1645
   583
**
dvander@1645
   584
** The szOsFile field is the size of the subclassed [sqlite3_file]
dvander@1645
   585
** structure used by this VFS.  mxPathname is the maximum length of
dvander@1645
   586
** a pathname in this VFS.
dvander@1645
   587
**
dvander@1645
   588
** Registered vfs modules are kept on a linked list formed by
dvander@1645
   589
** the pNext pointer.  The [sqlite3_vfs_register()]
dvander@1645
   590
** and [sqlite3_vfs_unregister()] interfaces manage this list
dvander@1645
   591
** in a thread-safe way.  The [sqlite3_vfs_find()] interface
dvander@1645
   592
** searches the list.
dvander@1645
   593
**
dvander@1645
   594
** The pNext field is the only fields in the sqlite3_vfs 
dvander@1645
   595
** structure that SQLite will ever modify.  SQLite will only access
dvander@1645
   596
** or modify this field while holding a particular static mutex.
dvander@1645
   597
** The application should never modify anything within the sqlite3_vfs
dvander@1645
   598
** object once the object has been registered.
dvander@1645
   599
**
dvander@1645
   600
** The zName field holds the name of the VFS module.  The name must
dvander@1645
   601
** be unique across all VFS modules.
dvander@1645
   602
**
dvander@1645
   603
** SQLite will guarantee that the zFilename string passed to
dvander@1645
   604
** xOpen() is a full pathname as generated by xFullPathname() and
dvander@1645
   605
** that the string will be valid and unchanged until xClose() is
dvander@1645
   606
** called.  So the [sqlite3_file] can store a pointer to the
dvander@1645
   607
** filename if it needs to remember the filename for some reason.
dvander@1645
   608
**
dvander@1645
   609
** The flags argument to xOpen() is a copy of the flags argument
dvander@1645
   610
** to [sqlite3_open_v2()].  If [sqlite3_open()] or [sqlite3_open16()]
dvander@1645
   611
** is used, then flags is [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
dvander@1645
   612
** If xOpen() opens a file read-only then it sets *pOutFlags to
dvander@1645
   613
** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be
dvander@1645
   614
** set.
dvander@1645
   615
** 
dvander@1645
   616
** SQLite will also add one of the following flags to the xOpen()
dvander@1645
   617
** call, depending on the object being opened:
dvander@1645
   618
** 
dvander@1645
   619
** <ul>
dvander@1645
   620
** <li>  [SQLITE_OPEN_MAIN_DB]
dvander@1645
   621
** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
dvander@1645
   622
** <li>  [SQLITE_OPEN_TEMP_DB]
dvander@1645
   623
** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
dvander@1645
   624
** <li>  [SQLITE_OPEN_TRANSIENT_DB]
dvander@1645
   625
** <li>  [SQLITE_OPEN_SUBJOURNAL]
dvander@1645
   626
** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
dvander@1645
   627
** </ul>
dvander@1645
   628
**
dvander@1645
   629
** The file I/O implementation can use the object type flags to
dvander@1645
   630
** changes the way it deals with files.  For example, an application
dvander@1645
   631
** that does not care about crash recovery or rollback, might make
dvander@1645
   632
** the open of a journal file a no-op.  Writes to this journal are
dvander@1645
   633
** also a no-op.  Any attempt to read the journal return SQLITE_IOERR.
dvander@1645
   634
** Or the implementation might recognize the a database file will
dvander@1645
   635
** be doing page-aligned sector reads and writes in a random order
dvander@1645
   636
** and set up its I/O subsystem accordingly.
dvander@1645
   637
** 
dvander@1645
   638
** SQLite might also add one of the following flags to the xOpen
dvander@1645
   639
** method:
dvander@1645
   640
** 
dvander@1645
   641
** <ul>
dvander@1645
   642
** <li> [SQLITE_OPEN_DELETEONCLOSE]
dvander@1645
   643
** <li> [SQLITE_OPEN_EXCLUSIVE]
dvander@1645
   644
** </ul>
dvander@1645
   645
** 
dvander@1645
   646
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
dvander@1645
   647
** deleted when it is closed.  This will always be set for TEMP 
dvander@1645
   648
** databases and journals and for subjournals.  The 
dvander@1645
   649
** [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
dvander@1645
   650
** for exclusive access.  This flag is set for all files except
dvander@1645
   651
** for the main database file.
dvander@1645
   652
** 
dvander@1645
   653
** Space to hold the  [sqlite3_file] structure passed as the third 
dvander@1645
   654
** argument to xOpen is allocated by caller (the SQLite core). 
dvander@1645
   655
** szOsFile bytes are allocated for this object.  The xOpen method
dvander@1645
   656
** fills in the allocated space.
dvander@1645
   657
** 
dvander@1645
   658
** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 
dvander@1645
   659
** to test for the existance of a file,
dvander@1645
   660
** or [SQLITE_ACCESS_READWRITE] to test to see
dvander@1645
   661
** if a file is readable and writable, or [SQLITE_ACCESS_READ]
dvander@1645
   662
** to test to see if a file is at least readable.  The file can be a 
dvander@1645
   663
** directory.
dvander@1645
   664
** 
dvander@1645
   665
** SQLite will always allocate at least mxPathname+1 byte for
dvander@1645
   666
** the output buffers for xGetTempname and xFullPathname. The exact
dvander@1645
   667
** size of the output buffer is also passed as a parameter to both 
dvander@1645
   668
** methods. If the output buffer is not large enough, SQLITE_CANTOPEN
dvander@1645
   669
** should be returned. As this is handled as a fatal error by SQLite,
dvander@1645
   670
** vfs implementations should endevour to prevent this by setting 
dvander@1645
   671
** mxPathname to a sufficiently large value.
dvander@1645
   672
** 
dvander@1645
   673
** The xRandomness(), xSleep(), and xCurrentTime() interfaces
dvander@1645
   674
** are not strictly a part of the filesystem, but they are
dvander@1645
   675
** included in the VFS structure for completeness.
dvander@1645
   676
** The xRandomness() function attempts to return nBytes bytes
dvander@1645
   677
** of good-quality randomness into zOut.  The return value is
dvander@1645
   678
** the actual number of bytes of randomness obtained.  The
dvander@1645
   679
** xSleep() method cause the calling thread to sleep for at
dvander@1645
   680
** least the number of microseconds given.  The xCurrentTime()
dvander@1645
   681
** method returns a Julian Day Number for the current date and
dvander@1645
   682
** time.
dvander@1645
   683
*/
dvander@1645
   684
typedef struct sqlite3_vfs sqlite3_vfs;
dvander@1645
   685
struct sqlite3_vfs {
dvander@1645
   686
  int iVersion;            /* Structure version number */
dvander@1645
   687
  int szOsFile;            /* Size of subclassed sqlite3_file */
dvander@1645
   688
  int mxPathname;          /* Maximum file pathname length */
dvander@1645
   689
  sqlite3_vfs *pNext;      /* Next registered VFS */
dvander@1645
   690
  const char *zName;       /* Name of this virtual file system */
dvander@1645
   691
  void *pAppData;          /* Pointer to application-specific data */
dvander@1645
   692
  int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
dvander@1645
   693
               int flags, int *pOutFlags);
dvander@1645
   694
  int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
dvander@1645
   695
  int (*xAccess)(sqlite3_vfs*, const char *zName, int flags);
dvander@1645
   696
  int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut);
dvander@1645
   697
  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
dvander@1645
   698
  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
dvander@1645
   699
  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
dvander@1645
   700
  void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
dvander@1645
   701
  void (*xDlClose)(sqlite3_vfs*, void*);
dvander@1645
   702
  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
dvander@1645
   703
  int (*xSleep)(sqlite3_vfs*, int microseconds);
dvander@1645
   704
  int (*xCurrentTime)(sqlite3_vfs*, double*);
dvander@1645
   705
  /* New fields may be appended in figure versions.  The iVersion
dvander@1645
   706
  ** value will increment whenever this happens. */
dvander@1645
   707
};
dvander@1645
   708
dvander@1645
   709
/*
dvander@1645
   710
** CAPI3REF: Flags for the xAccess VFS method
dvander@1645
   711
**
dvander@1645
   712
** These integer constants can be used as the third parameter to
dvander@1645
   713
** the xAccess method of an [sqlite3_vfs] object.  They determine
dvander@1645
   714
** the kind of what kind of permissions the xAccess method is
dvander@1645
   715
** looking for.  With SQLITE_ACCESS_EXISTS, the xAccess method
dvander@1645
   716
** simply checks to see if the file exists.  With SQLITE_ACCESS_READWRITE,
dvander@1645
   717
** the xAccess method checks to see if the file is both readable
dvander@1645
   718
** and writable.  With SQLITE_ACCESS_READ the xAccess method
dvander@1645
   719
** checks to see if the file is readable.
dvander@1645
   720
*/
dvander@1645
   721
#define SQLITE_ACCESS_EXISTS    0
dvander@1645
   722
#define SQLITE_ACCESS_READWRITE 1
dvander@1645
   723
#define SQLITE_ACCESS_READ      2
dvander@1203
   724
dvander@1203
   725
/*
dvander@1203
   726
** CAPI3REF: Enable Or Disable Extended Result Codes
dvander@1203
   727
**
dvander@1203
   728
** This routine enables or disables the
dvander@1203
   729
** [SQLITE_IOERR_READ | extended result codes] feature.
dvander@1203
   730
** By default, SQLite API routines return one of only 26 integer
dvander@1203
   731
** [SQLITE_OK | result codes].  When extended result codes
dvander@1203
   732
** are enabled by this routine, the repetoire of result codes can be
dvander@1203
   733
** much larger and can (hopefully) provide more detailed information
dvander@1203
   734
** about the cause of an error.
dvander@1203
   735
**
dvander@1203
   736
** The second argument is a boolean value that turns extended result
dvander@1203
   737
** codes on and off.  Extended result codes are off by default for
dvander@1203
   738
** backwards compatibility with older versions of SQLite.
dvander@1203
   739
*/
dvander@1203
   740
int sqlite3_extended_result_codes(sqlite3*, int onoff);
dvander@1203
   741
dvander@1203
   742
/*
dvander@1203
   743
** CAPI3REF: Last Insert Rowid
dvander@1203
   744
**
dvander@1203
   745
** Each entry in an SQLite table has a unique 64-bit signed integer key
dvander@1203
   746
** called the "rowid". The rowid is always available as an undeclared
dvander@1203
   747
** column named ROWID, OID, or _ROWID_.  If the table has a column of
dvander@1203
   748
** type INTEGER PRIMARY KEY then that column is another an alias for the
dvander@1203
   749
** rowid.
dvander@1203
   750
**
dvander@1203
   751
** This routine returns the rowid of the most recent INSERT into
dvander@1203
   752
** the database from the database connection given in the first 
dvander@1203
   753
** argument.  If no inserts have ever occurred on this database
dvander@1203
   754
** connection, zero is returned.
dvander@1203
   755
**
dvander@1203
   756
** If an INSERT occurs within a trigger, then the rowid of the
dvander@1203
   757
** inserted row is returned by this routine as long as the trigger
dvander@1203
   758
** is running.  But once the trigger terminates, the value returned
dvander@1203
   759
** by this routine reverts to the last value inserted before the
dvander@1203
   760
** trigger fired.
dvander@1645
   761
**
dvander@1645
   762
** If another thread does a new insert on the same database connection
dvander@1645
   763
** while this routine is running and thus changes the last insert rowid,
dvander@1645
   764
** then the return value of this routine is undefined.
dvander@1203
   765
*/
dvander@1645
   766
sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
dvander@1203
   767
dvander@1203
   768
/*
dvander@1203
   769
** CAPI3REF: Count The Number Of Rows Modified
dvander@1203
   770
**
dvander@1203
   771
** This function returns the number of database rows that were changed
dvander@1203
   772
** (or inserted or deleted) by the most recent SQL statement.  Only
dvander@1203
   773
** changes that are directly specified by the INSERT, UPDATE, or
dvander@1203
   774
** DELETE statement are counted.  Auxiliary changes caused by
dvander@1203
   775
** triggers are not counted.  Use the [sqlite3_total_changes()] function
dvander@1203
   776
** to find the total number of changes including changes caused by triggers.
dvander@1203
   777
**
dvander@1203
   778
** Within the body of a trigger, the sqlite3_changes() interface can be
dvander@1203
   779
** called to find the number of
dvander@1203
   780
** changes in the most recently completed INSERT, UPDATE, or DELETE
dvander@1203
   781
** statement within the body of the trigger.
dvander@1203
   782
**
dvander@1203
   783
** All changes are counted, even if they were later undone by a
dvander@1203
   784
** ROLLBACK or ABORT.  Except, changes associated with creating and
dvander@1203
   785
** dropping tables are not counted.
dvander@1203
   786
**
dvander@1203
   787
** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively,
dvander@1203
   788
** then the changes in the inner, recursive call are counted together
dvander@1203
   789
** with the changes in the outer call.
dvander@1203
   790
**
dvander@1203
   791
** SQLite implements the command "DELETE FROM table" without a WHERE clause
dvander@1203
   792
** by dropping and recreating the table.  (This is much faster than going
dvander@1203
   793
** through and deleting individual elements from the table.)  Because of
dvander@1203
   794
** this optimization, the change count for "DELETE FROM table" will be
dvander@1203
   795
** zero regardless of the number of elements that were originally in the
dvander@1203
   796
** table. To get an accurate count of the number of rows deleted, use
dvander@1203
   797
** "DELETE FROM table WHERE 1" instead.
dvander@1645
   798
**
dvander@1645
   799
** If another thread makes changes on the same database connection
dvander@1645
   800
** while this routine is running then the return value of this routine
dvander@1645
   801
** is undefined.
dvander@1203
   802
*/
dvander@1203
   803
int sqlite3_changes(sqlite3*);
dvander@1203
   804
dvander@1203
   805
/*
dvander@1203
   806
** CAPI3REF: Total Number Of Rows Modified
dvander@1203
   807
***
dvander@1203
   808
** This function returns the number of database rows that have been
dvander@1203
   809
** modified by INSERT, UPDATE or DELETE statements since the database handle
dvander@1203
   810
** was opened. This includes UPDATE, INSERT and DELETE statements executed
dvander@1203
   811
** as part of trigger programs. All changes are counted as soon as the
dvander@1203
   812
** statement that makes them is completed (when the statement handle is
dvander@1645
   813
** passed to [sqlite3_reset()] or [sqlite3_finalize()]).
dvander@1203
   814
**
dvander@1203
   815
** See also the [sqlite3_change()] interface.
dvander@1203
   816
**
dvander@1203
   817
** SQLite implements the command "DELETE FROM table" without a WHERE clause
dvander@1203
   818
** by dropping and recreating the table.  (This is much faster than going
dvander@1203
   819
** through and deleting individual elements form the table.)  Because of
dvander@1203
   820
** this optimization, the change count for "DELETE FROM table" will be
dvander@1203
   821
** zero regardless of the number of elements that were originally in the
dvander@1203
   822
** table. To get an accurate count of the number of rows deleted, use
dvander@1203
   823
** "DELETE FROM table WHERE 1" instead.
dvander@1645
   824
**
dvander@1645
   825
** If another thread makes changes on the same database connection
dvander@1645
   826
** while this routine is running then the return value of this routine
dvander@1645
   827
** is undefined.
dvander@1203
   828
*/
dvander@1203
   829
int sqlite3_total_changes(sqlite3*);
dvander@1203
   830
dvander@1203
   831
/*
dvander@1203
   832
** CAPI3REF: Interrupt A Long-Running Query
dvander@1203
   833
**
dvander@1203
   834
** This function causes any pending database operation to abort and
dvander@1203
   835
** return at its earliest opportunity.  This routine is typically
dvander@1203
   836
** called in response to a user action such as pressing "Cancel"
dvander@1203
   837
** or Ctrl-C where the user wants a long query operation to halt
dvander@1203
   838
** immediately.
dvander@1203
   839
**
dvander@1203
   840
** It is safe to call this routine from a thread different from the
dvander@1645
   841
** thread that is currently running the database operation.  But it
dvander@1645
   842
** is not safe to call this routine with a database connection that
dvander@1645
   843
** is closed or might close before sqlite3_interrupt() returns.
dvander@1203
   844
**
dvander@1203
   845
** The SQL operation that is interrupted will return [SQLITE_INTERRUPT].
dvander@1203
   846
** If an interrupted operation was an update that is inside an
dvander@1203
   847
** explicit transaction, then the entire transaction will be rolled
dvander@1203
   848
** back automatically.
dvander@1203
   849
*/
dvander@1203
   850
void sqlite3_interrupt(sqlite3*);
dvander@1203
   851
dvander@1203
   852
/*
dvander@1203
   853
** CAPI3REF: Determine If An SQL Statement Is Complete
dvander@1203
   854
**
dvander@1203
   855
** These functions return true if the given input string comprises
dvander@1203
   856
** one or more complete SQL statements. For the sqlite3_complete() call,
dvander@1203
   857
** the parameter must be a nul-terminated UTF-8 string. For
dvander@1203
   858
** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string
dvander@1203
   859
** is required.
dvander@1203
   860
**
dvander@1203
   861
** These routines are useful for command-line input to determine if the
dvander@1203
   862
** currently entered text forms one or more complete SQL statements or
dvander@1203
   863
** if additional input is needed before sending the statements into
dvander@1203
   864
** SQLite for parsing. The algorithm is simple.  If the 
dvander@1203
   865
** last token other than spaces and comments is a semicolon, then return 
dvander@1203
   866
** true.  Actually, the algorithm is a little more complicated than that
dvander@1203
   867
** in order to deal with triggers, but the basic idea is the same:  the
dvander@1203
   868
** statement is not complete unless it ends in a semicolon.
dvander@1203
   869
*/
dvander@1203
   870
int sqlite3_complete(const char *sql);
dvander@1203
   871
int sqlite3_complete16(const void *sql);
dvander@1203
   872
dvander@1203
   873
/*
dvander@1203
   874
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
dvander@1203
   875
**
dvander@1203
   876
** This routine identifies a callback function that might be invoked
dvander@1203
   877
** whenever an attempt is made to open a database table 
dvander@1203
   878
** that another thread or process has locked.
dvander@1203
   879
** If the busy callback is NULL, then [SQLITE_BUSY]
dvander@1203
   880
** (or sometimes [SQLITE_IOERR_BLOCKED])
dvander@1203
   881
** is returned immediately upon encountering the lock.
dvander@1203
   882
** If the busy callback is not NULL, then the
dvander@1203
   883
** callback will be invoked with two arguments.  The
dvander@1203
   884
** first argument to the handler is a copy of the void* pointer which
dvander@1203
   885
** is the third argument to this routine.  The second argument to
dvander@1203
   886
** the handler is the number of times that the busy handler has
dvander@1203
   887
** been invoked for this locking event. If the
dvander@1203
   888
** busy callback returns 0, then no additional attempts are made to
dvander@1203
   889
** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
dvander@1203
   890
** If the callback returns non-zero, then another attempt is made to open the
dvander@1203
   891
** database for reading and the cycle repeats.
dvander@1203
   892
**
dvander@1203
   893
** The presence of a busy handler does not guarantee that
dvander@1203
   894
** it will be invoked when there is lock contention.
dvander@1203
   895
** If SQLite determines that invoking the busy handler could result in
dvander@1203
   896
** a deadlock, it will return [SQLITE_BUSY] instead.
dvander@1203
   897
** Consider a scenario where one process is holding a read lock that
dvander@1203
   898
** it is trying to promote to a reserved lock and
dvander@1203
   899
** a second process is holding a reserved lock that it is trying
dvander@1203
   900
** to promote to an exclusive lock.  The first process cannot proceed
dvander@1203
   901
** because it is blocked by the second and the second process cannot
dvander@1203
   902
** proceed because it is blocked by the first.  If both processes
dvander@1203
   903
** invoke the busy handlers, neither will make any progress.  Therefore,
dvander@1203
   904
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
dvander@1203
   905
** will induce the first process to release its read lock and allow
dvander@1203
   906
** the second process to proceed.
dvander@1203
   907
**
dvander@1203
   908
** The default busy callback is NULL.
dvander@1203
   909
**
dvander@1203
   910
** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] when
dvander@1203
   911
** SQLite is in the middle of a large transaction where all the
dvander@1203
   912
** changes will not fit into the in-memory cache.  SQLite will
dvander@1203
   913
** already hold a RESERVED lock on the database file, but it needs
dvander@1203
   914
** to promote this lock to EXCLUSIVE so that it can spill cache
dvander@1203
   915
** pages into the database file without harm to concurrent
dvander@1203
   916
** readers.  If it is unable to promote the lock, then the in-memory
dvander@1203
   917
** cache will be left in an inconsistent state and so the error
dvander@1203
   918
** code is promoted from the relatively benign [SQLITE_BUSY] to
dvander@1203
   919
** the more severe [SQLITE_IOERR_BLOCKED].  This error code promotion
dvander@1203
   920
** forces an automatic rollback of the changes. See the
dvander@1203
   921
** <a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">
dvander@1203
   922
** CorruptionFollowingBusyError</a> wiki page for a discussion of why
dvander@1203
   923
** this is important.
dvander@1203
   924
**	
dvander@1203
   925
** Sqlite is re-entrant, so the busy handler may start a new query. 
dvander@1203
   926
** (It is not clear why anyone would every want to do this, but it
dvander@1203
   927
** is allowed, in theory.)  But the busy handler may not close the
dvander@1203
   928
** database.  Closing the database from a busy handler will delete 
dvander@1203
   929
** data structures out from under the executing query and will 
dvander@1203
   930
** probably result in a segmentation fault or other runtime error.
dvander@1203
   931
**
dvander@1203
   932
** There can only be a single busy handler defined for each database
dvander@1203
   933
** connection.  Setting a new busy handler clears any previous one.
dvander@1203
   934
** Note that calling [sqlite3_busy_timeout()] will also set or clear
dvander@1203
   935
** the busy handler.
dvander@1645
   936
**
dvander@1645
   937
** When operating in [sqlite3_enable_shared_cache | shared cache mode],
dvander@1645
   938
** only a single busy handler can be defined for each database file.
dvander@1645
   939
** So if two database connections share a single cache, then changing
dvander@1645
   940
** the busy handler on one connection will also change the busy
dvander@1645
   941
** handler in the other connection.  The busy handler is invoked
dvander@1645
   942
** in the thread that was running when the SQLITE_BUSY was hit.
dvander@1203
   943
*/
dvander@1203
   944
int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
dvander@1203
   945
dvander@1203
   946
/*
dvander@1203
   947
** CAPI3REF: Set A Busy Timeout
dvander@1203
   948
**
dvander@1203
   949
** This routine sets a busy handler that sleeps for a while when a
dvander@1203
   950
** table is locked.  The handler will sleep multiple times until 
dvander@1203
   951
** at least "ms" milliseconds of sleeping have been done.  After
dvander@1203
   952
** "ms" milliseconds of sleeping, the handler returns 0 which
dvander@1203
   953
** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
dvander@1203
   954
**
dvander@1203
   955
** Calling this routine with an argument less than or equal to zero
dvander@1203
   956
** turns off all busy handlers.
dvander@1203
   957
**
dvander@1203
   958
** There can only be a single busy handler for a particular database
dvander@1203
   959
** connection.  If another busy handler was defined  
dvander@1203
   960
** (using [sqlite3_busy_handler()]) prior to calling
dvander@1203
   961
** this routine, that other busy handler is cleared.
dvander@1203
   962
*/
dvander@1203
   963
int sqlite3_busy_timeout(sqlite3*, int ms);
dvander@1203
   964
dvander@1203
   965
/*
dvander@1203
   966
** CAPI3REF: Convenience Routines For Running Queries
dvander@1203
   967
**
dvander@1203
   968
** This next routine is a convenience wrapper around [sqlite3_exec()].
dvander@1203
   969
** Instead of invoking a user-supplied callback for each row of the
dvander@1203
   970
** result, this routine remembers each row of the result in memory
dvander@1203
   971
** obtained from [sqlite3_malloc()], then returns all of the result after the
dvander@1203
   972
** query has finished. 
dvander@1203
   973
**
dvander@1203
   974
** As an example, suppose the query result where this table:
dvander@1203
   975
**
dvander@1645
   976
** <blockquote><pre>
dvander@1203
   977
**        Name        | Age
dvander@1203
   978
**        -----------------------
dvander@1203
   979
**        Alice       | 43
dvander@1203
   980
**        Bob         | 28
dvander@1203
   981
**        Cindy       | 21
dvander@1645
   982
** </pre></blockquote>
dvander@1203
   983
**
dvander@1203
   984
** If the 3rd argument were &azResult then after the function returns
dvander@1203
   985
** azResult will contain the following data:
dvander@1203
   986
**
dvander@1645
   987
** <blockquote><pre>
dvander@1645
   988
**        azResult&#91;0] = "Name";
dvander@1645
   989
**        azResult&#91;1] = "Age";
dvander@1645
   990
**        azResult&#91;2] = "Alice";
dvander@1645
   991
**        azResult&#91;3] = "43";
dvander@1645
   992
**        azResult&#91;4] = "Bob";
dvander@1645
   993
**        azResult&#91;5] = "28";
dvander@1645
   994
**        azResult&#91;6] = "Cindy";
dvander@1645
   995
**        azResult&#91;7] = "21";
dvander@1645
   996
** </pre></blockquote>
dvander@1203
   997
**
dvander@1203
   998
** Notice that there is an extra row of data containing the column
dvander@1203
   999
** headers.  But the *nrow return value is still 3.  *ncolumn is
dvander@1203
  1000
** set to 2.  In general, the number of values inserted into azResult
dvander@1203
  1001
** will be ((*nrow) + 1)*(*ncolumn).
dvander@1203
  1002
**
dvander@1203
  1003
** After the calling function has finished using the result, it should 
dvander@1203
  1004
** pass the result data pointer to sqlite3_free_table() in order to 
dvander@1203
  1005
** release the memory that was malloc-ed.  Because of the way the 
dvander@1203
  1006
** [sqlite3_malloc()] happens, the calling function must not try to call 
dvander@1203
  1007
** [sqlite3_free()] directly.  Only [sqlite3_free_table()] is able to release 
dvander@1203
  1008
** the memory properly and safely.
dvander@1203
  1009
**
dvander@1203
  1010
** The return value of this routine is the same as from [sqlite3_exec()].
dvander@1203
  1011
*/
dvander@1203
  1012
int sqlite3_get_table(
dvander@1203
  1013
  sqlite3*,              /* An open database */
dvander@1203
  1014
  const char *sql,       /* SQL to be executed */
dvander@1203
  1015
  char ***resultp,       /* Result written to a char *[]  that this points to */
dvander@1203
  1016
  int *nrow,             /* Number of result rows written here */
dvander@1203
  1017
  int *ncolumn,          /* Number of result columns written here */
dvander@1203
  1018
  char **errmsg          /* Error msg written here */
dvander@1203
  1019
);
dvander@1203
  1020
void sqlite3_free_table(char **result);
dvander@1203
  1021
dvander@1203
  1022
/*
dvander@1203
  1023
** CAPI3REF: Formatted String Printing Functions
dvander@1203
  1024
**
dvander@1203
  1025
** These routines are workalikes of the "printf()" family of functions
dvander@1203
  1026
** from the standard C library.
dvander@1203
  1027
**
dvander@1203
  1028
** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
dvander@1645
  1029
** results into memory obtained from [sqlite3_malloc()].
dvander@1203
  1030
** The strings returned by these two routines should be
dvander@1203
  1031
** released by [sqlite3_free()].  Both routines return a
dvander@1203
  1032
** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
dvander@1203
  1033
** memory to hold the resulting string.
dvander@1203
  1034
**
dvander@1203
  1035
** In sqlite3_snprintf() routine is similar to "snprintf()" from
dvander@1203
  1036
** the standard C library.  The result is written into the
dvander@1203
  1037
** buffer supplied as the second parameter whose size is given by
dvander@1203
  1038
** the first parameter.  Note that the order of the
dvander@1203
  1039
** first two parameters is reversed from snprintf().  This is an
dvander@1203
  1040
** historical accident that cannot be fixed without breaking
dvander@1203
  1041
** backwards compatibility.  Note also that sqlite3_snprintf()
dvander@1203
  1042
** returns a pointer to its buffer instead of the number of
dvander@1203
  1043
** characters actually written into the buffer.  We admit that
dvander@1203
  1044
** the number of characters written would be a more useful return
dvander@1203
  1045
** value but we cannot change the implementation of sqlite3_snprintf()
dvander@1203
  1046
** now without breaking compatibility.
dvander@1203
  1047
**
dvander@1203
  1048
** As long as the buffer size is greater than zero, sqlite3_snprintf()
dvander@1203
  1049
** guarantees that the buffer is always zero-terminated.  The first
dvander@1203
  1050
** parameter "n" is the total size of the buffer, including space for
dvander@1203
  1051
** the zero terminator.  So the longest string that can be completely
dvander@1203
  1052
** written will be n-1 characters.
dvander@1203
  1053
**
dvander@1203
  1054
** These routines all implement some additional formatting
dvander@1203
  1055
** options that are useful for constructing SQL statements.
dvander@1203
  1056
** All of the usual printf formatting options apply.  In addition, there
dvander@1645
  1057
** is are "%q", "%Q", and "%z" options.
dvander@1203
  1058
**
dvander@1203
  1059
** The %q option works like %s in that it substitutes a null-terminated
dvander@1203
  1060
** string from the argument list.  But %q also doubles every '\'' character.
dvander@1203
  1061
** %q is designed for use inside a string literal.  By doubling each '\''
dvander@1203
  1062
** character it escapes that character and allows it to be inserted into
dvander@1203
  1063
** the string.
dvander@1203
  1064
**
dvander@1203
  1065
** For example, so some string variable contains text as follows:
dvander@1203
  1066
**
dvander@1203
  1067
** <blockquote><pre>
dvander@1203
  1068
**  char *zText = "It's a happy day!";
dvander@1203
  1069
** </pre></blockquote>
dvander@1203
  1070
**
dvander@1203
  1071
** One can use this text in an SQL statement as follows:
dvander@1203
  1072
**
dvander@1203
  1073
** <blockquote><pre>
dvander@1203
  1074
**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
dvander@1203
  1075
**  sqlite3_exec(db, zSQL, 0, 0, 0);
dvander@1203
  1076
**  sqlite3_free(zSQL);
dvander@1203
  1077
** </pre></blockquote>
dvander@1203
  1078
**
dvander@1203
  1079
** Because the %q format string is used, the '\'' character in zText
dvander@1203
  1080
** is escaped and the SQL generated is as follows:
dvander@1203
  1081
**
dvander@1203
  1082
** <blockquote><pre>
dvander@1203
  1083
**  INSERT INTO table1 VALUES('It''s a happy day!')
dvander@1203
  1084
** </pre></blockquote>
dvander@1203
  1085
**
dvander@1203
  1086
** This is correct.  Had we used %s instead of %q, the generated SQL
dvander@1203
  1087
** would have looked like this:
dvander@1203
  1088
**
dvander@1203
  1089
** <blockquote><pre>
dvander@1203
  1090
**  INSERT INTO table1 VALUES('It's a happy day!');
dvander@1203
  1091
** </pre></blockquote>
dvander@1203
  1092
**
dvander@1203
  1093
** This second example is an SQL syntax error.  As a general rule you
dvander@1203
  1094
** should always use %q instead of %s when inserting text into a string 
dvander@1203
  1095
** literal.
dvander@1203
  1096
**
dvander@1203
  1097
** The %Q option works like %q except it also adds single quotes around
dvander@1203
  1098
** the outside of the total string.  Or if the parameter in the argument
dvander@1203
  1099
** list is a NULL pointer, %Q substitutes the text "NULL" (without single
dvander@1203
  1100
** quotes) in place of the %Q option.  So, for example, one could say:
dvander@1203
  1101
**
dvander@1203
  1102
** <blockquote><pre>
dvander@1203
  1103
**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
dvander@1203
  1104
**  sqlite3_exec(db, zSQL, 0, 0, 0);
dvander@1203
  1105
**  sqlite3_free(zSQL);
dvander@1203
  1106
** </pre></blockquote>
dvander@1203
  1107
**
dvander@1203
  1108
** The code above will render a correct SQL statement in the zSQL
dvander@1203
  1109
** variable even if the zText variable is a NULL pointer.
dvander@1645
  1110
**
dvander@1645
  1111
** The "%z" formatting option works exactly like "%s" with the
dvander@1645
  1112
** addition that after the string has been read and copied into
dvander@1645
  1113
** the result, [sqlite3_free()] is called on the input string.
dvander@1203
  1114
*/
dvander@1203
  1115
char *sqlite3_mprintf(const char*,...);
dvander@1203
  1116
char *sqlite3_vmprintf(const char*, va_list);
dvander@1203
  1117
char *sqlite3_snprintf(int,char*,const char*, ...);
dvander@1203
  1118
dvander@1203
  1119
/*
dvander@1645
  1120
** CAPI3REF: Memory Allocation Subsystem
dvander@1645
  1121
**
dvander@1645
  1122
** The SQLite core uses these three routines for all of its own
dvander@1645
  1123
** internal memory allocation needs. (See the exception below.)
dvander@1645
  1124
** The default implementation
dvander@1645
  1125
** of the memory allocation subsystem uses the malloc(), realloc()
dvander@1645
  1126
** and free() provided by the standard C library.  However, if 
dvander@1645
  1127
** SQLite is compiled with the following C preprocessor macro
dvander@1645
  1128
**
dvander@1645
  1129
** <blockquote> SQLITE_OMIT_MEMORY_ALLOCATION </blockquote>
dvander@1645
  1130
**
dvander@1645
  1131
** then no implementation is provided for these routines by
dvander@1645
  1132
** SQLite.  The application that links against SQLite is
dvander@1645
  1133
** expected to provide its own implementation.  If the application
dvander@1645
  1134
** does provide its own implementation for these routines, then
dvander@1645
  1135
** it must also provide an implementations for
dvander@1645
  1136
** [sqlite3_memory_alarm()], [sqlite3_memory_used()], and
dvander@1645
  1137
** [sqlite3_memory_highwater()].  The alternative implementations
dvander@1645
  1138
** for these last three routines need not actually work, but
dvander@1645
  1139
** stub functions at least are needed to statisfy the linker.
dvander@1645
  1140
** SQLite never calls [sqlite3_memory_highwater()] itself, but
dvander@1645
  1141
** the symbol is included in a table as part of the
dvander@1645
  1142
** [sqlite3_load_extension()] interface.  The
dvander@1645
  1143
** [sqlite3_memory_alarm()] and [sqlite3_memory_used()] interfaces
dvander@1645
  1144
** are called by [sqlite3_soft_heap_limit()] and working implementations
dvander@1645
  1145
** of both routines must be provided if [sqlite3_soft_heap_limit()]
dvander@1645
  1146
** is to operate correctly.
dvander@1645
  1147
**
dvander@1645
  1148
** <b>Exception:</b> The windows OS interface layer calls
dvander@1645
  1149
** the system malloc() and free() directly when converting
dvander@1645
  1150
** filenames between the UTF-8 encoding used by SQLite
dvander@1645
  1151
** and whatever filename encoding is used by the particular windows
dvander@1645
  1152
** installation.  Memory allocation errors are detected, but
dvander@1645
  1153
** they are reported back as [SQLITE_CANTOPEN] or
dvander@1645
  1154
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
dvander@1203
  1155
*/
dvander@1203
  1156
void *sqlite3_malloc(int);
dvander@1203
  1157
void *sqlite3_realloc(void*, int);
dvander@1203
  1158
void sqlite3_free(void*);
dvander@1203
  1159
dvander@1203
  1160
/*
dvander@1645
  1161
** CAPI3REF: Memory Allocator Statistics
dvander@1645
  1162
**
dvander@1645
  1163
** In addition to the basic three allocation routines 
dvander@1645
  1164
** [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()],
dvander@1645
  1165
** the memory allocation subsystem included with the SQLite
dvander@1645
  1166
** sources provides the interfaces shown below.
dvander@1645
  1167
**
dvander@1645
  1168
** The first of these two routines returns the amount of memory 
dvander@1645
  1169
** currently outstanding (malloced but not freed).  The second
dvander@1645
  1170
** returns the largest instantaneous amount of outstanding
dvander@1645
  1171
** memory.  The highwater mark is reset if the argument is
dvander@1645
  1172
** true.
dvander@1645
  1173
**
dvander@1645
  1174
** The implementation of these routines in the SQLite core
dvander@1645
  1175
** is omitted if the application is compiled with the
dvander@1645
  1176
** SQLITE_OMIT_MEMORY_ALLOCATION macro defined.  In that case,
dvander@1645
  1177
** the application that links SQLite must provide its own
dvander@1645
  1178
** alternative implementation.  See the documentation on
dvander@1645
  1179
** [sqlite3_malloc()] for additional information.
dvander@1645
  1180
*/
dvander@1645
  1181
sqlite3_int64 sqlite3_memory_used(void);
dvander@1645
  1182
sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
dvander@1645
  1183
dvander@1645
  1184
/*
dvander@1645
  1185
** CAPI3REF: Memory Allocation Alarms
dvander@1645
  1186
**
dvander@1645
  1187
** The [sqlite3_memory_alarm] routine is used to register
dvander@1645
  1188
** a callback on memory allocation events.
dvander@1645
  1189
**
dvander@1645
  1190
** This routine registers or clears a callbacks that fires when
dvander@1645
  1191
** the amount of memory allocated exceeds iThreshold.  Only
dvander@1645
  1192
** a single callback can be registered at a time.  Each call
dvander@1645
  1193
** to [sqlite3_memory_alarm()] overwrites the previous callback.
dvander@1645
  1194
** The callback is disabled by setting xCallback to a NULL
dvander@1645
  1195
** pointer.
dvander@1645
  1196
** 
dvander@1645
  1197
** The parameters to the callback are the pArg value, the 
dvander@1645
  1198
** amount of memory currently in use, and the size of the
dvander@1645
  1199
** allocation that provoked the callback.  The callback will
dvander@1645
  1200
** presumably invoke [sqlite3_free()] to free up memory space.
dvander@1645
  1201
** The callback may invoke [sqlite3_malloc()] or [sqlite3_realloc()]
dvander@1645
  1202
** but if it does, no additional callbacks will be invoked by
dvander@1645
  1203
** the recursive calls.
dvander@1645
  1204
**
dvander@1645
  1205
** The [sqlite3_soft_heap_limit()] interface works by registering
dvander@1645
  1206
** a memory alarm at the soft heap limit and invoking 
dvander@1645
  1207
** [sqlite3_release_memory()] in the alarm callback.  Application
dvander@1645
  1208
** programs should not attempt to use the [sqlite3_memory_alarm()]
dvander@1645
  1209
** interface because doing so will interfere with the
dvander@1645
  1210
** [sqlite3_soft_heap_limit()] module.  This interface is exposed
dvander@1645
  1211
** only so that applications can provide their own
dvander@1645
  1212
** alternative implementation when the SQLite core is
dvander@1645
  1213
** compiled with SQLITE_OMIT_MEMORY_ALLOCATION.
dvander@1645
  1214
*/
dvander@1645
  1215
int sqlite3_memory_alarm(
dvander@1645
  1216
  void(*xCallback)(void *pArg, sqlite3_int64 used, int N),
dvander@1645
  1217
  void *pArg,
dvander@1645
  1218
  sqlite3_int64 iThreshold
dvander@1645
  1219
);
dvander@1645
  1220
dvander@1645
  1221
dvander@1645
  1222
/*
dvander@1203
  1223
** CAPI3REF: Compile-Time Authorization Callbacks
dvander@1203
  1224
***
dvander@1203
  1225
** This routine registers a authorizer callback with the SQLite library.  
dvander@1203
  1226
** The authorizer callback is invoked as SQL statements are being compiled
dvander@1203
  1227
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
dvander@1203
  1228
** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  At various
dvander@1203
  1229
** points during the compilation process, as logic is being created
dvander@1203
  1230
** to perform various actions, the authorizer callback is invoked to
dvander@1203
  1231
** see if those actions are allowed.  The authorizer callback should
dvander@1203
  1232
** return SQLITE_OK to allow the action, [SQLITE_IGNORE] to disallow the
dvander@1203
  1233
** specific action but allow the SQL statement to continue to be
dvander@1203
  1234
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
dvander@1203
  1235
** rejected with an error.  
dvander@1203
  1236
**
dvander@1203
  1237
** Depending on the action, the [SQLITE_IGNORE] and [SQLITE_DENY] return
dvander@1203
  1238
** codes might mean something different or they might mean the same
dvander@1203
  1239
** thing.  If the action is, for example, to perform a delete opertion,
dvander@1203
  1240
** then [SQLITE_IGNORE] and [SQLITE_DENY] both cause the statement compilation
dvander@1203
  1241
** to fail with an error.  But if the action is to read a specific column
dvander@1203
  1242
** from a specific table, then [SQLITE_DENY] will cause the entire
dvander@1203
  1243
** statement to fail but [SQLITE_IGNORE] will cause a NULL value to be
dvander@1203
  1244
** read instead of the actual column value.
dvander@1203
  1245
**
dvander@1203
  1246
** The first parameter to the authorizer callback is a copy of
dvander@1203
  1247
** the third parameter to the sqlite3_set_authorizer() interface.
dvander@1203
  1248
** The second parameter to the callback is an integer 
dvander@1203
  1249
** [SQLITE_COPY | action code] that specifies the particular action
dvander@1203
  1250
** to be authorized.  The available action codes are
dvander@1203
  1251
** [SQLITE_COPY | documented separately].  The third through sixth
dvander@1203
  1252
** parameters to the callback are strings that contain additional
dvander@1203
  1253
** details about the action to be authorized.
dvander@1203
  1254
**
dvander@1203
  1255
** An authorizer is used when preparing SQL statements from an untrusted
dvander@1203
  1256
** source, to ensure that the SQL statements do not try to access data
dvander@1203
  1257
** that they are not allowed to see, or that they do not try to
dvander@1203
  1258
** execute malicious statements that damage the database.  For
dvander@1203
  1259
** example, an application may allow a user to enter arbitrary
dvander@1203
  1260
** SQL queries for evaluation by a database.  But the application does
dvander@1203
  1261
** not want the user to be able to make arbitrary changes to the
dvander@1203
  1262
** database.  An authorizer could then be put in place while the
dvander@1203
  1263
** user-entered SQL is being prepared that disallows everything
dvander@1203
  1264
** except SELECT statements.  
dvander@1203
  1265
**
dvander@1203
  1266
** Only a single authorizer can be in place on a database connection
dvander@1203
  1267
** at a time.  Each call to sqlite3_set_authorizer overrides the
dvander@1203
  1268
** previous call.  A NULL authorizer means that no authorization
dvander@1203
  1269
** callback is invoked.  The default authorizer is NULL.
dvander@1203
  1270
**
dvander@1203
  1271
** Note that the authorizer callback is invoked only during 
dvander@1203
  1272
** [sqlite3_prepare()] or its variants.  Authorization is not
dvander@1203
  1273
** performed during statement evaluation in [sqlite3_step()].
dvander@1203
  1274
*/
dvander@1203
  1275
int sqlite3_set_authorizer(
dvander@1203
  1276
  sqlite3*,
dvander@1203
  1277
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
dvander@1203
  1278
  void *pUserData
dvander@1203
  1279
);
dvander@1203
  1280
dvander@1203
  1281
/*
dvander@1203
  1282
** CAPI3REF: Authorizer Return Codes
dvander@1203
  1283
**
dvander@1203
  1284
** The [sqlite3_set_authorizer | authorizer callback function] must
dvander@1203
  1285
** return either [SQLITE_OK] or one of these two constants in order
dvander@1203
  1286
** to signal SQLite whether or not the action is permitted.  See the
dvander@1203
  1287
** [sqlite3_set_authorizer | authorizer documentation] for additional
dvander@1203
  1288
** information.
dvander@1203
  1289
*/
dvander@1203
  1290
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
dvander@1203
  1291
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
dvander@1203
  1292
dvander@1203
  1293
/*
dvander@1203
  1294
** CAPI3REF: Authorizer Action Codes
dvander@1203
  1295
**
dvander@1203
  1296
** The [sqlite3_set_authorizer()] interface registers a callback function
dvander@1203
  1297
** that is invoked to authorizer certain SQL statement actions.  The
dvander@1203
  1298
** second parameter to the callback is an integer code that specifies
dvander@1203
  1299
** what action is being authorized.  These are the integer action codes that
dvander@1203
  1300
** the authorizer callback may be passed.
dvander@1203
  1301
**
dvander@1203
  1302
** These action code values signify what kind of operation is to be 
dvander@1203
  1303
** authorized.  The 3rd and 4th parameters to the authorization callback
dvander@1203
  1304
** function will be parameters or NULL depending on which of these
dvander@1203
  1305
** codes is used as the second parameter.  The 5th parameter to the
dvander@1203
  1306
** authorizer callback is the name of the database ("main", "temp", 
dvander@1203
  1307
** etc.) if applicable.  The 6th parameter to the authorizer callback
dvander@1203
  1308
** is the name of the inner-most trigger or view that is responsible for
dvander@1203
  1309
** the access attempt or NULL if this access attempt is directly from 
dvander@1203
  1310
** top-level SQL code.
dvander@1203
  1311
*/
dvander@1203
  1312
/******************************************* 3rd ************ 4th ***********/
dvander@1203
  1313
#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
dvander@1203
  1314
#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
dvander@1203
  1315
#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
dvander@1203
  1316
#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
dvander@1203
  1317
#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
dvander@1203
  1318
#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
dvander@1203
  1319
#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
dvander@1203
  1320
#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
dvander@1203
  1321
#define SQLITE_DELETE                9   /* Table Name      NULL            */
dvander@1203
  1322
#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
dvander@1203
  1323
#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
dvander@1203
  1324
#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
dvander@1203
  1325
#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
dvander@1203
  1326
#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
dvander@1203
  1327
#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
dvander@1203
  1328
#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
dvander@1203
  1329
#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
dvander@1203
  1330
#define SQLITE_INSERT               18   /* Table Name      NULL            */
dvander@1203
  1331
#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
dvander@1203
  1332
#define SQLITE_READ                 20   /* Table Name      Column Name     */
dvander@1203
  1333
#define SQLITE_SELECT               21   /* NULL            NULL            */
dvander@1203
  1334
#define SQLITE_TRANSACTION          22   /* NULL            NULL            */
dvander@1203
  1335
#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
dvander@1203
  1336
#define SQLITE_ATTACH               24   /* Filename        NULL            */
dvander@1203
  1337
#define SQLITE_DETACH               25   /* Database Name   NULL            */
dvander@1203
  1338
#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
dvander@1203
  1339
#define SQLITE_REINDEX              27   /* Index Name      NULL            */
dvander@1203
  1340
#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
dvander@1203
  1341
#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
dvander@1203
  1342
#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
dvander@1203
  1343
#define SQLITE_FUNCTION             31   /* Function Name   NULL            */
dvander@1203
  1344
#define SQLITE_COPY                  0   /* No longer used */
dvander@1203
  1345
dvander@1203
  1346
/*
dvander@1203
  1347
** CAPI3REF: Tracing And Profiling Functions
dvander@1203
  1348
**
dvander@1203
  1349
** These routines register callback functions that can be used for
dvander@1203
  1350
** tracing and profiling the execution of SQL statements.
dvander@1203
  1351
** The callback function registered by sqlite3_trace() is invoked
dvander@1203
  1352
** at the first [sqlite3_step()] for the evaluation of an SQL statement.
dvander@1203
  1353
** The callback function registered by sqlite3_profile() is invoked
dvander@1203
  1354
** as each SQL statement finishes and includes
dvander@1203
  1355
** information on how long that statement ran.
dvander@1203
  1356
**
dvander@1203
  1357
** The sqlite3_profile() API is currently considered experimental and
dvander@1203
  1358
** is subject to change.
dvander@1203
  1359
*/
dvander@1203
  1360
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
dvander@1203
  1361
void *sqlite3_profile(sqlite3*,
dvander@1645
  1362
   void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
dvander@1203
  1363
dvander@1203
  1364
/*
dvander@1203
  1365
** CAPI3REF: Query Progress Callbacks
dvander@1203
  1366
**
dvander@1203
  1367
** This routine configures a callback function - the progress callback - that
dvander@1203
  1368
** is invoked periodically during long running calls to [sqlite3_exec()],
dvander@1203
  1369
** [sqlite3_step()] and [sqlite3_get_table()].  An example use for this 
dvander@1203
  1370
** interface is to keep a GUI updated during a large query.
dvander@1203
  1371
**
dvander@1203
  1372
** The progress callback is invoked once for every N virtual machine opcodes,
dvander@1203
  1373
** where N is the second argument to this function. The progress callback
dvander@1203
  1374
** itself is identified by the third argument to this function. The fourth
dvander@1203
  1375
** argument to this function is a void pointer passed to the progress callback
dvander@1203
  1376
** function each time it is invoked.
dvander@1203
  1377
**
dvander@1203
  1378
** If a call to [sqlite3_exec()], [sqlite3_step()], or [sqlite3_get_table()]
dvander@1203
  1379
** results in fewer than N opcodes being executed, then the progress 
dvander@1203
  1380
** callback is never invoked.
dvander@1203
  1381
** 
dvander@1203
  1382
** Only a single progress callback function may be registered for each
dvander@1203
  1383
** open database connection.  Every call to sqlite3_progress_handler()
dvander@1203
  1384
** overwrites the results of the previous call.
dvander@1203
  1385
** To remove the progress callback altogether, pass NULL as the third
dvander@1203
  1386
** argument to this function.
dvander@1203
  1387
**
dvander@1203
  1388
** If the progress callback returns a result other than 0, then the current 
dvander@1203
  1389
** query is immediately terminated and any database changes rolled back.
dvander@1203
  1390
** The containing [sqlite3_exec()], [sqlite3_step()], or
dvander@1203
  1391
** [sqlite3_get_table()] call returns SQLITE_INTERRUPT.   This feature
dvander@1203
  1392
** can be used, for example, to implement the "Cancel" button on a
dvander@1203
  1393
** progress dialog box in a GUI.
dvander@1203
  1394
*/
dvander@1203
  1395
void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
dvander@1203
  1396
dvander@1203
  1397
/*
dvander@1203
  1398
** CAPI3REF: Opening A New Database Connection
dvander@1203
  1399
**
dvander@1203
  1400
** Open the sqlite database file "filename".  The "filename" is UTF-8
dvander@1645
  1401
** encoded for [sqlite3_open()] and [sqlite3_open_v2()] and UTF-16 encoded
dvander@1645
  1402
** in the native byte order for [sqlite3_open16()].
dvander@1645
  1403
** An [sqlite3*] handle is returned in *ppDb, even
dvander@1203
  1404
** if an error occurs. If the database is opened (or created) successfully,
dvander@1645
  1405
** then [SQLITE_OK] is returned. Otherwise an error code is returned. The
dvander@1645
  1406
** [sqlite3_errmsg()] or [sqlite3_errmsg16()]  routines can be used to obtain
dvander@1203
  1407
** an English language description of the error.
dvander@1203
  1408
**
dvander@1645
  1409
** The default encoding for the database will be UTF-8 if
dvander@1645
  1410
** [sqlite3_open()] or [sqlite3_open_v2()] is called and
dvander@1645
  1411
** UTF-16 if [sqlite3_open16()] is used.
dvander@1203
  1412
**
dvander@1203
  1413
** Whether or not an error occurs when it is opened, resources associated
dvander@1203
  1414
** with the [sqlite3*] handle should be released by passing it to
dvander@1645
  1415
** [sqlite3_close()] when it is no longer required.
dvander@1645
  1416
**
dvander@1645
  1417
** The [sqlite3_open_v2()] interface works like [sqlite3_open()] except that
dvander@1645
  1418
** provides two additional parameters for additional control over the
dvander@1645
  1419
** new database connection.  The flags parameter can be one of:
dvander@1645
  1420
**
dvander@1645
  1421
** <ol>
dvander@1645
  1422
** <li>  [SQLITE_OPEN_READONLY]
dvander@1645
  1423
** <li>  [SQLITE_OPEN_READWRITE]
dvander@1645
  1424
** <li>  [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]
dvander@1645
  1425
** </ol>
dvander@1645
  1426
**
dvander@1645
  1427
** The first value opens the database read-only.  If the database does
dvander@1645
  1428
** not previously exist, an error is returned.  The second option opens
dvander@1645
  1429
** the database for reading and writing if possible, or reading only if
dvander@1645
  1430
** if the file is write protected.  In either case the database must already
dvander@1645
  1431
** exist or an error is returned.  The third option opens the database
dvander@1645
  1432
** for reading and writing and creates it if it does not already exist.
dvander@1645
  1433
** The third options is behavior that is always used for [sqlite3_open()]
dvander@1645
  1434
** and [sqlite3_open16()].
dvander@1645
  1435
**
dvander@1645
  1436
** If the filename is ":memory:", then an private
dvander@1645
  1437
** in-memory database is created for the connection.  This in-memory
dvander@1645
  1438
** database will vanish when the database connection is closed.  Future
dvander@1645
  1439
** version of SQLite might make use of additional special filenames
dvander@1645
  1440
** that begin with the ":" character.  It is recommended that 
dvander@1645
  1441
** when a database filename really does begin with
dvander@1645
  1442
** ":" that you prefix the filename with a pathname like "./" to
dvander@1645
  1443
** avoid ambiguity.
dvander@1645
  1444
**
dvander@1645
  1445
** If the filename is an empty string, then a private temporary
dvander@1645
  1446
** on-disk database will be created.  This private database will be
dvander@1645
  1447
** automatically deleted as soon as the database connection is closed.
dvander@1645
  1448
**
dvander@1645
  1449
** The fourth parameter to sqlite3_open_v2() is the name of the
dvander@1645
  1450
** [sqlite3_vfs] object that defines the operating system 
dvander@1645
  1451
** interface that the new database connection should use.  If the
dvander@1645
  1452
** fourth parameter is a NULL pointer then the default [sqlite3_vfs]
dvander@1645
  1453
** object is used.
dvander@1645
  1454
**
dvander@1645
  1455
** <b>Note to windows users:</b>  The encoding used for the filename argument
dvander@1645
  1456
** of [sqlite3_open()] and [sqlite3_open_v2()] must be UTF-8, not whatever
dvander@1645
  1457
** codepage is currently defined.  Filenames containing international
dvander@1645
  1458
** characters must be converted to UTF-8 prior to passing them into
dvander@1645
  1459
** [sqlite3_open()] or [sqlite3_open_v2()].
dvander@1203
  1460
*/
dvander@1203
  1461
int sqlite3_open(
dvander@1203
  1462
  const char *filename,   /* Database filename (UTF-8) */
dvander@1203
  1463
  sqlite3 **ppDb          /* OUT: SQLite db handle */
dvander@1203
  1464
);
dvander@1203
  1465
int sqlite3_open16(
dvander@1203
  1466
  const void *filename,   /* Database filename (UTF-16) */
dvander@1203
  1467
  sqlite3 **ppDb          /* OUT: SQLite db handle */
dvander@1203
  1468
);
dvander@1645
  1469
int sqlite3_open_v2(
dvander@1645
  1470
  const char *filename,   /* Database filename (UTF-8) */
dvander@1645
  1471
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
dvander@1645
  1472
  int flags,              /* Flags */
dvander@1645
  1473
  const char *zVfs        /* Name of VFS module to use */
dvander@1645
  1474
);
dvander@1203
  1475
dvander@1203
  1476
/*
dvander@1203
  1477
** CAPI3REF: Error Codes And Messages
dvander@1203
  1478
**
dvander@1203
  1479
** The sqlite3_errcode() interface returns the numeric
dvander@1203
  1480
** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
dvander@1203
  1481
** for the most recent failed sqlite3_* API call associated
dvander@1203
  1482
** with [sqlite3] handle 'db'.  If a prior API call failed but the
dvander@1203
  1483
** most recent API call succeeded, the return value from sqlite3_errcode()
dvander@1203
  1484
** is undefined. 
dvander@1203
  1485
**
dvander@1645
  1486
** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
dvander@1203
  1487
** text that describes the error, as either UTF8 or UTF16 respectively.
dvander@1203
  1488
** Memory to hold the error message string is managed internally.  The 
dvander@1203
  1489
** string may be overwritten or deallocated by subsequent calls to SQLite
dvander@1203
  1490
** interface functions.
dvander@1203
  1491
**
dvander@1203
  1492
** Calls to many sqlite3_* functions set the error code and string returned
dvander@1203
  1493
** by [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()]
dvander@1203
  1494
** (overwriting the previous values). Note that calls to [sqlite3_errcode()],
dvander@1203
  1495
** [sqlite3_errmsg()], and [sqlite3_errmsg16()] themselves do not affect the
dvander@1203
  1496
** results of future invocations.  Calls to API routines that do not return
dvander@1645
  1497
** an error code (example: [sqlite3_data_count()]) do not
dvander@1645
  1498
** change the error code returned by this routine.  Interfaces that are
dvander@1645
  1499
** not associated with a specific database connection (examples:
dvander@1645
  1500
** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()] do not change
dvander@1645
  1501
** the return code.  
dvander@1203
  1502
**
dvander@1203
  1503
** Assuming no other intervening sqlite3_* API calls are made, the error
dvander@1203
  1504
** code returned by this function is associated with the same error as
dvander@1203
  1505
** the strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()].
dvander@1203
  1506
*/
dvander@1203
  1507
int sqlite3_errcode(sqlite3 *db);
dvander@1203
  1508
const char *sqlite3_errmsg(sqlite3*);
dvander@1203
  1509
const void *sqlite3_errmsg16(sqlite3*);
dvander@1203
  1510
dvander@1203
  1511
/*
dvander@1203
  1512
** CAPI3REF: SQL Statement Object
dvander@1203
  1513
**
dvander@1203
  1514
** Instance of this object represent single SQL statements.  This
dvander@1203
  1515
** is variously known as a "prepared statement" or a 
dvander@1203
  1516
** "compiled SQL statement" or simply as a "statement".
dvander@1203
  1517
** 
dvander@1203
  1518
** The life of a statement object goes something like this:
dvander@1203
  1519
**
dvander@1203
  1520
** <ol>
dvander@1203
  1521
** <li> Create the object using [sqlite3_prepare_v2()] or a related
dvander@1203
  1522
**      function.
dvander@1203
  1523
** <li> Bind values to host parameters using
dvander@1203
  1524
**      [sqlite3_bind_blob | sqlite3_bind_* interfaces].
dvander@1203
  1525
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
dvander@1203
  1526
** <li> Reset the statement using [sqlite3_reset()] then go back
dvander@1203
  1527
**      to step 2.  Do this zero or more times.
dvander@1203
  1528
** <li> Destroy the object using [sqlite3_finalize()].
dvander@1203
  1529
** </ol>
dvander@1203
  1530
**
dvander@1203
  1531
** Refer to documentation on individual methods above for additional
dvander@1203
  1532
** information.
dvander@1203
  1533
*/
dvander@1203
  1534
typedef struct sqlite3_stmt sqlite3_stmt;
dvander@1203
  1535
dvander@1203
  1536
/*
dvander@1203
  1537
** CAPI3REF: Compiling An SQL Statement
dvander@1203
  1538
**
dvander@1203
  1539
** To execute an SQL query, it must first be compiled into a byte-code
dvander@1203
  1540
** program using one of these routines. 
dvander@1203
  1541
**
dvander@1203
  1542
** The first argument "db" is an [sqlite3 | SQLite database handle] 
dvander@1645
  1543
** obtained from a prior call to [sqlite3_open()], [sqlite3_open_v2()]
dvander@1645
  1544
** or [sqlite3_open16()].
dvander@1203
  1545
** The second argument "zSql" is the statement to be compiled, encoded
dvander@1203
  1546
** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
dvander@1203
  1547
** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2()
dvander@1203
  1548
** use UTF-16.
dvander@1203
  1549
**
dvander@1203
  1550
** If the nByte argument is less
dvander@1203
  1551
** than zero, then zSql is read up to the first zero terminator.  If
dvander@1203
  1552
** nByte is non-negative, then it is the maximum number of 
dvander@1203
  1553
** bytes read from zSql.  When nByte is non-negative, the
dvander@1203
  1554
** zSql string ends at either the first '\000' character or 
dvander@1203
  1555
** until the nByte-th byte, whichever comes first.
dvander@1203
  1556
**
dvander@1203
  1557
** *pzTail is made to point to the first byte past the end of the first
dvander@1203
  1558
** SQL statement in zSql.  This routine only compiles the first statement
dvander@1203
  1559
** in zSql, so *pzTail is left pointing to what remains uncompiled.
dvander@1203
  1560
**
dvander@1203
  1561
** *ppStmt is left pointing to a compiled 
dvander@1203
  1562
** [sqlite3_stmt | SQL statement structure] that can be
dvander@1203
  1563
** executed using [sqlite3_step()].  Or if there is an error, *ppStmt may be
dvander@1203
  1564
** set to NULL.  If the input text contained no SQL (if the input is and
dvander@1203
  1565
** empty string or a comment) then *ppStmt is set to NULL.  The calling
dvander@1203
  1566
** procedure is responsible for deleting the compiled SQL statement
dvander@1203
  1567
** using [sqlite3_finalize()] after it has finished with it.
dvander@1203
  1568
**
dvander@1203
  1569
** On success, [SQLITE_OK] is returned.  Otherwise an 
dvander@1203
  1570
** [SQLITE_ERROR | error code] is returned.
dvander@1203
  1571
**
dvander@1203
  1572
** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
dvander@1203
  1573
** recommended for all new programs. The two older interfaces are retained
dvander@1203
  1574
** for backwards compatibility, but their use is discouraged.
dvander@1203
  1575
** In the "v2" interfaces, the prepared statement
dvander@1203
  1576
** that is returned (the [sqlite3_stmt] object) contains a copy of the 
dvander@1203
  1577
** original SQL text. This causes the [sqlite3_step()] interface to
dvander@1203
  1578
** behave a differently in two ways:
dvander@1203
  1579
**
dvander@1203
  1580
** <ol>
dvander@1203
  1581
** <li>
dvander@1203
  1582
** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
dvander@1203
  1583
** always used to do, [sqlite3_step()] will automatically recompile the SQL
dvander@1203
  1584
** statement and try to run it again.  If the schema has changed in a way
dvander@1203
  1585
** that makes the statement no longer valid, [sqlite3_step()] will still
dvander@1203
  1586
** return [SQLITE_SCHEMA].  But unlike the legacy behavior, [SQLITE_SCHEMA] is
dvander@1203
  1587
** now a fatal error.  Calling [sqlite3_prepare_v2()] again will not make the
dvander@1203
  1588
** error go away.  Note: use [sqlite3_errmsg()] to find the text of the parsing
dvander@1203
  1589
** error that results in an [SQLITE_SCHEMA] return.
dvander@1203
  1590
** </li>
dvander@1203
  1591
**
dvander@1203
  1592
** <li>
dvander@1203
  1593
** When an error occurs, 
dvander@1203
  1594
** [sqlite3_step()] will return one of the detailed 
dvander@1203
  1595
** [SQLITE_ERROR | result codes] or
dvander@1203
  1596
** [SQLITE_IOERR_READ | extended result codes] such as directly.
dvander@1203
  1597
** The legacy behavior was that [sqlite3_step()] would only return a generic
dvander@1203
  1598
** [SQLITE_ERROR] result code and you would have to make a second call to
dvander@1203
  1599
** [sqlite3_reset()] in order to find the underlying cause of the problem.
dvander@1203
  1600
** With the "v2" prepare interfaces, the underlying reason for the error is
dvander@1203
  1601
** returned immediately.
dvander@1203
  1602
** </li>
dvander@1203
  1603
** </ol>
dvander@1203
  1604
*/
dvander@1203
  1605
int sqlite3_prepare(
dvander@1203
  1606
  sqlite3 *db,            /* Database handle */
dvander@1203
  1607
  const char *zSql,       /* SQL statement, UTF-8 encoded */
dvander@1203
  1608
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1609
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1610
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1611
);
dvander@1203
  1612
int sqlite3_prepare_v2(
dvander@1203
  1613
  sqlite3 *db,            /* Database handle */
dvander@1203
  1614
  const char *zSql,       /* SQL statement, UTF-8 encoded */
dvander@1203
  1615
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1616
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1617
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1618
);
dvander@1203
  1619
int sqlite3_prepare16(
dvander@1203
  1620
  sqlite3 *db,            /* Database handle */
dvander@1203
  1621
  const void *zSql,       /* SQL statement, UTF-16 encoded */
dvander@1203
  1622
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1623
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1624
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1625
);
dvander@1203
  1626
int sqlite3_prepare16_v2(
dvander@1203
  1627
  sqlite3 *db,            /* Database handle */
dvander@1203
  1628
  const void *zSql,       /* SQL statement, UTF-16 encoded */
dvander@1203
  1629
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1630
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1631
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1632
);
dvander@1203
  1633
dvander@1203
  1634
/*
dvander@1203
  1635
** CAPI3REF:  Dynamically Typed Value Object
dvander@1203
  1636
**
dvander@1203
  1637
** SQLite uses dynamic typing for the values it stores.  Values can 
dvander@1203
  1638
** be integers, floating point values, strings, BLOBs, or NULL.  When
dvander@1203
  1639
** passing around values internally, each value is represented as
dvander@1203
  1640
** an instance of the sqlite3_value object.
dvander@1203
  1641
*/
dvander@1203
  1642
typedef struct Mem sqlite3_value;
dvander@1203
  1643
dvander@1203
  1644
/*
dvander@1203
  1645
** CAPI3REF:  SQL Function Context Object
dvander@1203
  1646
**
dvander@1203
  1647
** The context in which an SQL function executes is stored in an
dvander@1203
  1648
** sqlite3_context object.  A pointer to such an object is the
dvander@1203
  1649
** first parameter to user-defined SQL functions.
dvander@1203
  1650
*/
dvander@1203
  1651
typedef struct sqlite3_context sqlite3_context;
dvander@1203
  1652
dvander@1203
  1653
/*
dvander@1203
  1654
** CAPI3REF:  Binding Values To Prepared Statements
dvander@1203
  1655
**
dvander@1203
  1656
** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
dvander@1203
  1657
** one or more literals can be replace by a parameter in one of these
dvander@1203
  1658
** forms:
dvander@1203
  1659
**
dvander@1203
  1660
** <ul>
dvander@1203
  1661
** <li>  ?
dvander@1203
  1662
** <li>  ?NNN
dvander@1203
  1663
** <li>  :AAA
dvander@1203
  1664
** <li>  @AAA
dvander@1203
  1665
** <li>  $VVV
dvander@1203
  1666
** </ul>
dvander@1203
  1667
**
dvander@1203
  1668
** In the parameter forms shown above NNN is an integer literal,
dvander@1203
  1669
** AAA is an alphanumeric identifier and VVV is a variable name according
dvander@1203
  1670
** to the syntax rules of the TCL programming language.
dvander@1203
  1671
** The values of these parameters (also called "host parameter names")
dvander@1203
  1672
** can be set using the sqlite3_bind_*() routines defined here.
dvander@1203
  1673
**
dvander@1203
  1674
** The first argument to the sqlite3_bind_*() routines always is a pointer
dvander@1203
  1675
** to the [sqlite3_stmt] object returned from [sqlite3_prepare_v2()] or
dvander@1203
  1676
** its variants.  The second
dvander@1203
  1677
** argument is the index of the parameter to be set.  The first parameter has
dvander@1203
  1678
** an index of 1. When the same named parameter is used more than once, second
dvander@1203
  1679
** and subsequent
dvander@1203
  1680
** occurrences have the same index as the first occurrence.  The index for
dvander@1203
  1681
** named parameters can be looked up using the
dvander@1203
  1682
** [sqlite3_bind_parameter_name()] API if desired.  The index for "?NNN"
dvander@1203
  1683
** parametes is the value of NNN.
dvander@1203
  1684
** The NNN value must be between 1 and the compile-time
dvander@1203
  1685
** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999).
dvander@1203
  1686
** See <a href="limits.html">limits.html</a> for additional information.
dvander@1203
  1687
**
dvander@1203
  1688
** The third argument is the value to bind to the parameter.
dvander@1203
  1689
**
dvander@1203
  1690
** In those
dvander@1203
  1691
** routines that have a fourth argument, its value is the number of bytes
dvander@1203
  1692
** in the parameter.  To be clear: the value is the number of bytes in the
dvander@1203
  1693
** string, not the number of characters.  The number
dvander@1203
  1694
** of bytes does not include the zero-terminator at the end of strings.
dvander@1203
  1695
** If the fourth parameter is negative, the length of the string is
dvander@1203
  1696
** number of bytes up to the first zero terminator.
dvander@1203
  1697
**
dvander@1203
  1698
** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
dvander@1203
  1699
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
dvander@1203
  1700
** text after SQLite has finished with it.  If the fifth argument is the
dvander@1203
  1701
** special value [SQLITE_STATIC], then the library assumes that the information
dvander@1203
  1702
** is in static, unmanaged space and does not need to be freed.  If the
dvander@1203
  1703
** fifth argument has the value [SQLITE_TRANSIENT], then SQLite makes its
dvander@1203
  1704
** own private copy of the data immediately, before the sqlite3_bind_*()
dvander@1203
  1705
** routine returns.
dvander@1203
  1706
**
dvander@1203
  1707
** The sqlite3_bind_zeroblob() routine binds a BLOB of length n that
dvander@1203
  1708
** is filled with zeros.  A zeroblob uses a fixed amount of memory
dvander@1203
  1709
** (just an integer to hold it size) while it is being processed.
dvander@1203
  1710
** Zeroblobs are intended to serve as place-holders for BLOBs whose
dvander@1203
  1711
** content is later written using 
dvander@1645
  1712
** [sqlite3_blob_open | increment BLOB I/O] routines.  A negative
dvander@1645
  1713
** value for the zeroblob results in a zero-length BLOB.
dvander@1203
  1714
**
dvander@1203
  1715
** The sqlite3_bind_*() routines must be called after
dvander@1203
  1716
** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
dvander@1203
  1717
** before [sqlite3_step()].
dvander@1203
  1718
** Bindings are not cleared by the [sqlite3_reset()] routine.
dvander@1203
  1719
** Unbound parameters are interpreted as NULL.
dvander@1203
  1720
**
dvander@1203
  1721
** These routines return [SQLITE_OK] on success or an error code if
dvander@1203
  1722
** anything goes wrong.  [SQLITE_RANGE] is returned if the parameter
dvander@1203
  1723
** index is out of range.  [SQLITE_NOMEM] is returned if malloc fails.
dvander@1203
  1724
** [SQLITE_MISUSE] is returned if these routines are called on a virtual
dvander@1203
  1725
** machine that is the wrong state or which has already been finalized.
dvander@1203
  1726
*/
dvander@1203
  1727
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
dvander@1203
  1728
int sqlite3_bind_double(sqlite3_stmt*, int, double);
dvander@1203
  1729
int sqlite3_bind_int(sqlite3_stmt*, int, int);
dvander@1645
  1730
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
dvander@1203
  1731
int sqlite3_bind_null(sqlite3_stmt*, int);
dvander@1203
  1732
int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
dvander@1203
  1733
int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
dvander@1203
  1734
int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
dvander@1203
  1735
int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
dvander@1203
  1736
dvander@1203
  1737
/*
dvander@1203
  1738
** CAPI3REF: Number Of Host Parameters
dvander@1203
  1739
**
dvander@1203
  1740
** Return the largest host parameter index in the precompiled statement given
dvander@1203
  1741
** as the argument.  When the host parameters are of the forms like ":AAA"
dvander@1203
  1742
** or "?", then they are assigned sequential increasing numbers beginning
dvander@1203
  1743
** with one, so the value returned is the number of parameters.  However
dvander@1203
  1744
** if the same host parameter name is used multiple times, each occurrance
dvander@1203
  1745
** is given the same number, so the value returned in that case is the number
dvander@1203
  1746
** of unique host parameter names.  If host parameters of the form "?NNN"
dvander@1203
  1747
** are used (where NNN is an integer) then there might be gaps in the
dvander@1203
  1748
** numbering and the value returned by this interface is the index of the
dvander@1203
  1749
** host parameter with the largest index value.
dvander@1645
  1750
**
dvander@1645
  1751
** The prepared statement must not be [sqlite3_finalize | finalized]
dvander@1645
  1752
** prior to this routine returnning.  Otherwise the results are undefined
dvander@1645
  1753
** and probably undesirable.
dvander@1203
  1754
*/
dvander@1203
  1755
int sqlite3_bind_parameter_count(sqlite3_stmt*);
dvander@1203
  1756
dvander@1203
  1757
/*
dvander@1203
  1758
** CAPI3REF: Name Of A Host Parameter
dvander@1203
  1759
**
dvander@1203
  1760
** This routine returns a pointer to the name of the n-th parameter in a 
dvander@1203
  1761
** [sqlite3_stmt | prepared statement].
dvander@1203
  1762
** Host parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
dvander@1203
  1763
** which is the string ":AAA" or "@AAA" or "$VVV".  
dvander@1203
  1764
** In other words, the initial ":" or "$" or "@"
dvander@1203
  1765
** is included as part of the name.
dvander@1203
  1766
** Parameters of the form "?" or "?NNN" have no name.
dvander@1203
  1767
**
dvander@1203
  1768
** The first bound parameter has an index of 1, not 0.
dvander@1203
  1769
**
dvander@1203
  1770
** If the value n is out of range or if the n-th parameter is nameless,
dvander@1203
  1771
** then NULL is returned.  The returned string is always in the
dvander@1203
  1772
** UTF-8 encoding even if the named parameter was originally specified
dvander@1203
  1773
** as UTF-16 in [sqlite3_prepare16()] or [sqlite3_prepare16_v2()].
dvander@1203
  1774
*/
dvander@1203
  1775
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
dvander@1203
  1776
dvander@1203
  1777
/*
dvander@1203
  1778
** CAPI3REF: Index Of A Parameter With A Given Name
dvander@1203
  1779
**
dvander@1203
  1780
** This routine returns the index of a host parameter with the given name.
dvander@1203
  1781
** The name must match exactly.  If no parameter with the given name is 
dvander@1203
  1782
** found, return 0.  Parameter names must be UTF8.
dvander@1203
  1783
*/
dvander@1203
  1784
int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
dvander@1203
  1785
dvander@1203
  1786
/*
dvander@1203
  1787
** CAPI3REF: Reset All Bindings On A Prepared Statement
dvander@1203
  1788
**
dvander@1203
  1789
** Contrary to the intuition of many, [sqlite3_reset()] does not
dvander@1203
  1790
** reset the [sqlite3_bind_blob | bindings] on a 
dvander@1203
  1791
** [sqlite3_stmt | prepared statement].  Use this routine to
dvander@1203
  1792
** reset all host parameters to NULL.
dvander@1203
  1793
*/
dvander@1203
  1794
int sqlite3_clear_bindings(sqlite3_stmt*);
dvander@1203
  1795
dvander@1203
  1796
/*
dvander@1203
  1797
** CAPI3REF: Number Of Columns In A Result Set
dvander@1203
  1798
**
dvander@1203
  1799
** Return the number of columns in the result set returned by the 
dvander@1203
  1800
** [sqlite3_stmt | compiled SQL statement]. This routine returns 0
dvander@1203
  1801
** if pStmt is an SQL statement that does not return data (for 
dvander@1203
  1802
** example an UPDATE).
dvander@1203
  1803
*/
dvander@1203
  1804
int sqlite3_column_count(sqlite3_stmt *pStmt);
dvander@1203
  1805
dvander@1203
  1806
/*
dvander@1203
  1807
** CAPI3REF: Column Names In A Result Set
dvander@1203
  1808
**
dvander@1203
  1809
** These routines return the name assigned to a particular column
dvander@1203
  1810
** in the result set of a SELECT statement.  The sqlite3_column_name()
dvander@1203
  1811
** interface returns a pointer to a UTF8 string and sqlite3_column_name16()
dvander@1203
  1812
** returns a pointer to a UTF16 string.  The first parameter is the
dvander@1645
  1813
** [sqlite3_stmt | prepared statement] that implements the SELECT statement.
dvander@1203
  1814
** The second parameter is the column number.  The left-most column is
dvander@1203
  1815
** number 0.
dvander@1203
  1816
**
dvander@1203
  1817
** The returned string pointer is valid until either the 
dvander@1645
  1818
** [sqlite3_stmt | prepared statement] is destroyed by [sqlite3_finalize()]
dvander@1203
  1819
** or until the next call sqlite3_column_name() or sqlite3_column_name16()
dvander@1203
  1820
** on the same column.
dvander@1645
  1821
**
dvander@1645
  1822
** If sqlite3_malloc() fails during the processing of either routine
dvander@1645
  1823
** (for example during a conversion from UTF-8 to UTF-16) then a
dvander@1645
  1824
** NULL pointer is returned.
dvander@1203
  1825
*/
dvander@1203
  1826
const char *sqlite3_column_name(sqlite3_stmt*, int N);
dvander@1203
  1827
const void *sqlite3_column_name16(sqlite3_stmt*, int N);
dvander@1203
  1828
dvander@1203
  1829
/*
dvander@1203
  1830
** CAPI3REF: Source Of Data In A Query Result
dvander@1203
  1831
**
dvander@1203
  1832
** These routines provide a means to determine what column of what
dvander@1203
  1833
** table in which database a result of a SELECT statement comes from.
dvander@1203
  1834
** The name of the database or table or column can be returned as
dvander@1203
  1835
** either a UTF8 or UTF16 string.  The _database_ routines return
dvander@1203
  1836
** the database name, the _table_ routines return the table name, and
dvander@1203
  1837
** the origin_ routines return the column name.
dvander@1203
  1838
** The returned string is valid until
dvander@1203
  1839
** the [sqlite3_stmt | prepared statement] is destroyed using
dvander@1203
  1840
** [sqlite3_finalize()] or until the same information is requested
dvander@1203
  1841
** again in a different encoding.
dvander@1203
  1842
**
dvander@1203
  1843
** The names returned are the original un-aliased names of the
dvander@1203
  1844
** database, table, and column.
dvander@1203
  1845
**
dvander@1203
  1846
** The first argument to the following calls is a 
dvander@1203
  1847
** [sqlite3_stmt | compiled SQL statement].
dvander@1203
  1848
** These functions return information about the Nth column returned by 
dvander@1203
  1849
** the statement, where N is the second function argument.
dvander@1203
  1850
**
dvander@1203
  1851
** If the Nth column returned by the statement is an expression
dvander@1203
  1852
** or subquery and is not a column value, then all of these functions
dvander@1203
  1853
** return NULL. Otherwise, they return the 
dvander@1203
  1854
** name of the attached database, table and column that query result
dvander@1203
  1855
** column was extracted from.
dvander@1203
  1856
**
dvander@1203
  1857
** As with all other SQLite APIs, those postfixed with "16" return UTF-16
dvander@1203
  1858
** encoded strings, the other functions return UTF-8.
dvander@1203
  1859
**
dvander@1203
  1860
** These APIs are only available if the library was compiled with the 
dvander@1203
  1861
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
dvander@1645
  1862
**
dvander@1645
  1863
** If two or more threads call one or more of these routines against the same
dvander@1645
  1864
** prepared statement and column at the same time then the results are
dvander@1645
  1865
** undefined.
dvander@1203
  1866
*/
dvander@1203
  1867
const char *sqlite3_column_database_name(sqlite3_stmt*,int);
dvander@1203
  1868
const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
dvander@1203
  1869
const char *sqlite3_column_table_name(sqlite3_stmt*,int);
dvander@1203
  1870
const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
dvander@1203
  1871
const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
dvander@1203
  1872
const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
dvander@1203
  1873
dvander@1203
  1874
/*
dvander@1203
  1875
** CAPI3REF: Declared Datatype Of A Query Result
dvander@1203
  1876
**
dvander@1203
  1877
** The first parameter is a [sqlite3_stmt | compiled SQL statement]. 
dvander@1203
  1878
** If this statement is a SELECT statement and the Nth column of the 
dvander@1203
  1879
** returned result set  of that SELECT is a table column (not an
dvander@1203
  1880
** expression or subquery) then the declared type of the table
dvander@1203
  1881
** column is returned. If the Nth column of the result set is an
dvander@1203
  1882
** expression or subquery, then a NULL pointer is returned.
dvander@1203
  1883
** The returned string is always UTF-8 encoded. For example, in
dvander@1203
  1884
** the database schema:
dvander@1203
  1885
**
dvander@1203
  1886
** CREATE TABLE t1(c1 VARIANT);
dvander@1203
  1887
**
dvander@1203
  1888
** And the following statement compiled:
dvander@1203
  1889
**
dvander@1203
  1890
** SELECT c1 + 1, c1 FROM t1;
dvander@1203
  1891
**
dvander@1203
  1892
** Then this routine would return the string "VARIANT" for the second
dvander@1203
  1893
** result column (i==1), and a NULL pointer for the first result column
dvander@1203
  1894
** (i==0).
dvander@1203
  1895
**
dvander@1203
  1896
** SQLite uses dynamic run-time typing.  So just because a column
dvander@1203
  1897
** is declared to contain a particular type does not mean that the
dvander@1203
  1898
** data stored in that column is of the declared type.  SQLite is
dvander@1203
  1899
** strongly typed, but the typing is dynamic not static.  Type
dvander@1203
  1900
** is associated with individual values, not with the containers
dvander@1203
  1901
** used to hold those values.
dvander@1203
  1902
*/
dvander@1203
  1903
const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
dvander@1203
  1904
const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
dvander@1203
  1905
dvander@1203
  1906
/* 
dvander@1203
  1907
** CAPI3REF:  Evaluate An SQL Statement
dvander@1203
  1908
**
dvander@1203
  1909
** After an [sqlite3_stmt | SQL statement] has been prepared with a call
dvander@1203
  1910
** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of
dvander@1203
  1911
** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()],
dvander@1203
  1912
** then this function must be called one or more times to evaluate the 
dvander@1203
  1913
** statement.
dvander@1203
  1914
**
dvander@1203
  1915
** The details of the behavior of this sqlite3_step() interface depend
dvander@1203
  1916
** on whether the statement was prepared using the newer "v2" interface
dvander@1203
  1917
** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
dvander@1203
  1918
** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
dvander@1203
  1919
** new "v2" interface is recommended for new applications but the legacy
dvander@1203
  1920
** interface will continue to be supported.
dvander@1203
  1921
**
dvander@1203
  1922
** In the lagacy interface, the return value will be either [SQLITE_BUSY], 
dvander@1203
  1923
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
dvander@1203
  1924
** With the "v2" interface, any of the other [SQLITE_OK | result code]
dvander@1203
  1925
** or [SQLITE_IOERR_READ | extended result code] might be returned as
dvander@1203
  1926
** well.
dvander@1203
  1927
**
dvander@1203
  1928
** [SQLITE_BUSY] means that the database engine was unable to acquire the
dvander@1203
  1929
** database locks it needs to do its job.  If the statement is a COMMIT
dvander@1203
  1930
** or occurs outside of an explicit transaction, then you can retry the
dvander@1203
  1931
** statement.  If the statement is not a COMMIT and occurs within a
dvander@1203
  1932
** explicit transaction then you should rollback the transaction before
dvander@1203
  1933
** continuing.
dvander@1203
  1934
**
dvander@1203
  1935
** [SQLITE_DONE] means that the statement has finished executing
dvander@1203
  1936
** successfully.  sqlite3_step() should not be called again on this virtual
dvander@1203
  1937
** machine without first calling [sqlite3_reset()] to reset the virtual
dvander@1203
  1938
** machine back to its initial state.
dvander@1203
  1939
**
dvander@1203
  1940
** If the SQL statement being executed returns any data, then 
dvander@1203
  1941
** [SQLITE_ROW] is returned each time a new row of data is ready
dvander@1203
  1942
** for processing by the caller. The values may be accessed using
dvander@1203
  1943
** the [sqlite3_column_int | column access functions].
dvander@1203
  1944
** sqlite3_step() is called again to retrieve the next row of data.
dvander@1203
  1945
** 
dvander@1203
  1946
** [SQLITE_ERROR] means that a run-time error (such as a constraint
dvander@1203
  1947
** violation) has occurred.  sqlite3_step() should not be called again on
dvander@1203
  1948
** the VM. More information may be found by calling [sqlite3_errmsg()].
dvander@1203
  1949
** With the legacy interface, a more specific error code (example:
dvander@1203
  1950
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
dvander@1203
  1951
** can be obtained by calling [sqlite3_reset()] on the
dvander@1645
  1952
** [sqlite3_stmt | prepared statement].  In the "v2" interface,
dvander@1203
  1953
** the more specific error code is returned directly by sqlite3_step().
dvander@1203
  1954
**
dvander@1203
  1955
** [SQLITE_MISUSE] means that the this routine was called inappropriately.
dvander@1645
  1956
** Perhaps it was called on a [sqlite3_stmt | prepared statement] that has
dvander@1203
  1957
** already been [sqlite3_finalize | finalized] or on one that had 
dvander@1203
  1958
** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
dvander@1203
  1959
** be the case that the same database connection is being used by two or
dvander@1203
  1960
** more threads at the same moment in time.
dvander@1203
  1961
**
dvander@1203
  1962
** <b>Goofy Interface Alert:</b>
dvander@1203
  1963
** In the legacy interface, 
dvander@1203
  1964
** the sqlite3_step() API always returns a generic error code,
dvander@1203
  1965
** [SQLITE_ERROR], following any error other than [SQLITE_BUSY]
dvander@1203
  1966
** and [SQLITE_MISUSE].  You must call [sqlite3_reset()] or
dvander@1203
  1967
** [sqlite3_finalize()] in order to find one of the specific
dvander@1203
  1968
** [SQLITE_ERROR | result codes] that better describes the error.
dvander@1203
  1969
** We admit that this is a goofy design.  The problem has been fixed
dvander@1203
  1970
** with the "v2" interface.  If you prepare all of your SQL statements
dvander@1203
  1971
** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
dvander@1203
  1972
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the 
dvander@1203
  1973
** more specific [SQLITE_ERROR | result codes] are returned directly
dvander@1203
  1974
** by sqlite3_step().  The use of the "v2" interface is recommended.
dvander@1203
  1975
*/
dvander@1203
  1976
int sqlite3_step(sqlite3_stmt*);
dvander@1203
  1977
dvander@1203
  1978
/*
dvander@1203
  1979
** CAPI3REF:
dvander@1203
  1980
**
dvander@1203
  1981
** Return the number of values in the current row of the result set.
dvander@1203
  1982
**
dvander@1203
  1983
** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine
dvander@1203
  1984
** will return the same value as the [sqlite3_column_count()] function.
dvander@1203
  1985
** After [sqlite3_step()] has returned an [SQLITE_DONE], [SQLITE_BUSY], or
dvander@1203
  1986
** a [SQLITE_ERROR | error code], or before [sqlite3_step()] has been 
dvander@1645
  1987
** called on the [sqlite3_stmt | prepared statement] for the first time,
dvander@1203
  1988
** this routine returns zero.
dvander@1203
  1989
*/
dvander@1203
  1990
int sqlite3_data_count(sqlite3_stmt *pStmt);
dvander@1203
  1991
dvander@1203
  1992
/*
dvander@1203
  1993
** CAPI3REF: Fundamental Datatypes
dvander@1203
  1994
**
dvander@1203
  1995
** Every value in SQLite has one of five fundamental datatypes:
dvander@1203
  1996
**
dvander@1203
  1997
** <ul>
dvander@1203
  1998
** <li> 64-bit signed integer
dvander@1203
  1999
** <li> 64-bit IEEE floating point number
dvander@1203
  2000
** <li> string
dvander@1203
  2001
** <li> BLOB
dvander@1203
  2002
** <li> NULL
dvander@1203
  2003
** </ul>
dvander@1203
  2004
**
dvander@1203
  2005
** These constants are codes for each of those types.
dvander@1203
  2006
**
dvander@1203
  2007
** Note that the SQLITE_TEXT constant was also used in SQLite version 2
dvander@1203
  2008
** for a completely different meaning.  Software that links against both
dvander@1203
  2009
** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not
dvander@1203
  2010
** SQLITE_TEXT.
dvander@1203
  2011
*/
dvander@1203
  2012
#define SQLITE_INTEGER  1
dvander@1203
  2013
#define SQLITE_FLOAT    2
dvander@1203
  2014
#define SQLITE_BLOB     4
dvander@1203
  2015
#define SQLITE_NULL     5
dvander@1203
  2016
#ifdef SQLITE_TEXT
dvander@1203
  2017
# undef SQLITE_TEXT
dvander@1203
  2018
#else
dvander@1203
  2019
# define SQLITE_TEXT     3
dvander@1203
  2020
#endif
dvander@1203
  2021
#define SQLITE3_TEXT     3
dvander@1203
  2022
dvander@1203
  2023
/*
dvander@1203
  2024
** CAPI3REF: Results Values From A Query
dvander@1203
  2025
**
dvander@1645
  2026
** These routines return information about
dvander@1645
  2027
** a single column of the current result row of a query.  In every
dvander@1203
  2028
** case the first argument is a pointer to the 
dvander@1203
  2029
** [sqlite3_stmt | SQL statement] that is being
dvander@1645
  2030
** evaluated (the [sqlite3_stmt*] that was returned from 
dvander@1203
  2031
** [sqlite3_prepare_v2()] or one of its variants) and
dvander@1203
  2032
** the second argument is the index of the column for which information 
dvander@1645
  2033
** should be returned.  The left-most column of the result set
dvander@1645
  2034
** has an index of 0.
dvander@1203
  2035
**
dvander@1203
  2036
** If the SQL statement is not currently point to a valid row, or if the
dvander@1645
  2037
** the column index is out of range, the result is undefined. 
dvander@1645
  2038
** These routines may only be called when the most recent call to
dvander@1645
  2039
** [sqlite3_step()] has returned [SQLITE_ROW] and neither
dvander@1645
  2040
** [sqlite3_reset()] nor [sqlite3_finalize()] has been call subsequently.
dvander@1645
  2041
** If any of these routines are called after [sqlite3_reset()] or
dvander@1645
  2042
** [sqlite3_finalize()] or after [sqlite3_step()] has returned
dvander@1645
  2043
** something other than [SQLITE_ROW], the results are undefined.
dvander@1645
  2044
** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
dvander@1645
  2045
** are called from a different thread while any of these routines
dvander@1645
  2046
** are pending, then the results are undefined.  
dvander@1203
  2047
**
dvander@1203
  2048
** The sqlite3_column_type() routine returns 
dvander@1203
  2049
** [SQLITE_INTEGER | datatype code] for the initial data type
dvander@1203
  2050
** of the result column.  The returned value is one of [SQLITE_INTEGER],
dvander@1203
  2051
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
dvander@1203
  2052
** returned by sqlite3_column_type() is only meaningful if no type
dvander@1203
  2053
** conversions have occurred as described below.  After a type conversion,
dvander@1203
  2054
** the value returned by sqlite3_column_type() is undefined.  Future
dvander@1203
  2055
** versions of SQLite may change the behavior of sqlite3_column_type()
dvander@1203
  2056
** following a type conversion.
dvander@1203
  2057
**
dvander@1203
  2058
** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 
dvander@1203
  2059
** routine returns the number of bytes in that BLOB or string.
dvander@1203
  2060
** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
dvander@1203
  2061
** the string to UTF-8 and then returns the number of bytes.
dvander@1203
  2062
** If the result is a numeric value then sqlite3_column_bytes() uses
dvander@1203
  2063
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
dvander@1203
  2064
** the number of bytes in that string.
dvander@1203
  2065
** The value returned does not include the zero terminator at the end
dvander@1203
  2066
** of the string.  For clarity: the value returned is the number of
dvander@1203
  2067
** bytes in the string, not the number of characters.
dvander@1203
  2068
**
dvander@1645
  2069
** Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
dvander@1645
  2070
** even zero-length strings, are always zero terminated.  The return
dvander@1645
  2071
** value from sqlite3_column_blob() for a zero-length blob is an arbitrary
dvander@1645
  2072
** pointer, possibly even a NULL pointer.
dvander@1645
  2073
**
dvander@1203
  2074
** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
dvander@1203
  2075
** but leaves the result in UTF-16 instead of UTF-8.  
dvander@1203
  2076
** The zero terminator is not included in this count.
dvander@1203
  2077
**
dvander@1203
  2078
** These routines attempt to convert the value where appropriate.  For
dvander@1203
  2079
** example, if the internal representation is FLOAT and a text result
dvander@1203
  2080
** is requested, [sqlite3_snprintf()] is used internally to do the conversion
dvander@1203
  2081
** automatically.  The following table details the conversions that
dvander@1203
  2082
** are applied:
dvander@1203
  2083
**
dvander@1203
  2084
** <blockquote>
dvander@1203
  2085
** <table border="1">
dvander@1645
  2086
** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
dvander@1203
  2087
**
dvander@1203
  2088
** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
dvander@1203
  2089
** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
dvander@1203
  2090
** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
dvander@1203
  2091
** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
dvander@1203
  2092
** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
dvander@1203
  2093
** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
dvander@1203
  2094
** <tr><td> INTEGER  <td>   BLOB    <td> Same as for INTEGER->TEXT
dvander@1203
  2095
** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
dvander@1203
  2096
** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
dvander@1203
  2097
** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
dvander@1203
  2098
** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
dvander@1203
  2099
** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
dvander@1203
  2100
** <tr><td>  TEXT    <td>   BLOB    <td> No change
dvander@1203
  2101
** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
dvander@1203
  2102
** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
dvander@1203
  2103
** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
dvander@1203
  2104
** </table>
dvander@1203
  2105
** </blockquote>
dvander@1203
  2106
**
dvander@1203
  2107
** The table above makes reference to standard C library functions atoi()
dvander@1203
  2108
** and atof().  SQLite does not really use these functions.  It has its
dvander@1203
  2109
** on equavalent internal routines.  The atoi() and atof() names are
dvander@1203
  2110
** used in the table for brevity and because they are familiar to most
dvander@1203
  2111
** C programmers.
dvander@1203
  2112
**
dvander@1203
  2113
** Note that when type conversions occur, pointers returned by prior
dvander@1203
  2114
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
dvander@1203
  2115
** sqlite3_column_text16() may be invalidated. 
dvander@1203
  2116
** Type conversions and pointer invalidations might occur
dvander@1203
  2117
** in the following cases:
dvander@1203
  2118
**
dvander@1203
  2119
** <ul>
dvander@1203
  2120
** <li><p>  The initial content is a BLOB and sqlite3_column_text() 
dvander@1203
  2121
**          or sqlite3_column_text16() is called.  A zero-terminator might
dvander@1203
  2122
**          need to be added to the string.</p></li>
dvander@1203
  2123
**
dvander@1203
  2124
** <li><p>  The initial content is UTF-8 text and sqlite3_column_bytes16() or
dvander@1203
  2125
**          sqlite3_column_text16() is called.  The content must be converted
dvander@1203
  2126
**          to UTF-16.</p></li>
dvander@1203
  2127
**
dvander@1203
  2128
** <li><p>  The initial content is UTF-16 text and sqlite3_column_bytes() or
dvander@1203
  2129
**          sqlite3_column_text() is called.  The content must be converted
dvander@1203
  2130
**          to UTF-8.</p></li>
dvander@1203
  2131
** </ul>
dvander@1203
  2132
**
dvander@1203
  2133
** Conversions between UTF-16be and UTF-16le are always done in place and do
dvander@1203
  2134
** not invalidate a prior pointer, though of course the content of the buffer
dvander@1203
  2135
** that the prior pointer points to will have been modified.  Other kinds
dvander@1203
  2136
** of conversion are done in place when it is possible, but sometime it is
dvander@1203
  2137
** not possible and in those cases prior pointers are invalidated.  
dvander@1203
  2138
**
dvander@1203
  2139
** The safest and easiest to remember policy is to invoke these routines
dvander@1203
  2140
** in one of the following ways:
dvander@1203
  2141
**
dvander@1203
  2142
**  <ul>
dvander@1203
  2143
**  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
dvander@1203
  2144
**  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
dvander@1203
  2145
**  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
dvander@1203
  2146
**  </ul>
dvander@1203
  2147
**
dvander@1203
  2148
** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(),
dvander@1203
  2149
** or sqlite3_column_text16() first to force the result into the desired
dvander@1203
  2150
** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to
dvander@1203
  2151
** find the size of the result.  Do not mix call to sqlite3_column_text() or
dvander@1203
  2152
** sqlite3_column_blob() with calls to sqlite3_column_bytes16().  And do not
dvander@1203
  2153
** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes().
dvander@1645
  2154
**
dvander@1645
  2155
** The pointers returned are valid until a type conversion occurs as
dvander@1645
  2156
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
dvander@1645
  2157
** [sqlite3_finalize()] is called.  The memory space used to hold strings
dvander@1645
  2158
** and blobs is freed automatically.  Do <b>not</b> pass the pointers returned
dvander@1645
  2159
** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 
dvander@1645
  2160
** [sqlite3_free()].
dvander@1645
  2161
**
dvander@1645
  2162
** If a memory allocation error occurs during the evaluation of any
dvander@1645
  2163
** of these routines, a default value is returned.  The default value
dvander@1645
  2164
** is either the integer 0, the floating point number 0.0, or a NULL
dvander@1645
  2165
** pointer.  Subsequent calls to [sqlite3_errcode()] will return
dvander@1645
  2166
** [SQLITE_NOMEM].
dvander@1203
  2167
*/
dvander@1203
  2168
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
dvander@1203
  2169
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
dvander@1203
  2170
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
dvander@1203
  2171
double sqlite3_column_double(sqlite3_stmt*, int iCol);
dvander@1203
  2172
int sqlite3_column_int(sqlite3_stmt*, int iCol);
dvander@1645
  2173
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
dvander@1203
  2174
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
dvander@1203
  2175
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
dvander@1203
  2176
int sqlite3_column_type(sqlite3_stmt*, int iCol);
dvander@1203
  2177
sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
dvander@1203
  2178
dvander@1203
  2179
/*
dvander@1203
  2180
** CAPI3REF: Destroy A Prepared Statement Object
dvander@1203
  2181
**
dvander@1203
  2182
** The sqlite3_finalize() function is called to delete a 
dvander@1203
  2183
** [sqlite3_stmt | compiled SQL statement]. If the statement was
dvander@1203
  2184
** executed successfully, or not executed at all, then SQLITE_OK is returned.
dvander@1203
  2185
** If execution of the statement failed then an 
dvander@1203
  2186
** [SQLITE_ERROR | error code] or [SQLITE_IOERR_READ | extended error code]
dvander@1203
  2187
** is returned. 
dvander@1203
  2188
**
dvander@1203
  2189
** This routine can be called at any point during the execution of the
dvander@1203
  2190
** [sqlite3_stmt | virtual machine].  If the virtual machine has not 
dvander@1203
  2191
** completed execution when this routine is called, that is like
dvander@1203
  2192
** encountering an error or an interrupt.  (See [sqlite3_interrupt()].) 
dvander@1203
  2193
** Incomplete updates may be rolled back and transactions cancelled,  
dvander@1203
  2194
** depending on the circumstances, and the 
dvander@1203
  2195
** [SQLITE_ERROR | result code] returned will be [SQLITE_ABORT].
dvander@1203
  2196
*/
dvander@1203
  2197
int sqlite3_finalize(sqlite3_stmt *pStmt);
dvander@1203
  2198
dvander@1203
  2199
/*
dvander@1203
  2200
** CAPI3REF: Reset A Prepared Statement Object
dvander@1203
  2201
**
dvander@1203
  2202
** The sqlite3_reset() function is called to reset a 
dvander@1645
  2203
** [sqlite3_stmt | compiled SQL statement] object.
dvander@1203
  2204
** back to it's initial state, ready to be re-executed.
dvander@1203
  2205
** Any SQL statement variables that had values bound to them using
dvander@1203
  2206
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
dvander@1203
  2207
** Use [sqlite3_clear_bindings()] to reset the bindings.
dvander@1203
  2208
*/
dvander@1203
  2209
int sqlite3_reset(sqlite3_stmt *pStmt);
dvander@1203
  2210
dvander@1203
  2211
/*
dvander@1203
  2212
** CAPI3REF: Create Or Redefine SQL Functions
dvander@1203
  2213
**
dvander@1203
  2214
** The following two functions are used to add SQL functions or aggregates
dvander@1203
  2215
** or to redefine the behavior of existing SQL functions or aggregates.  The
dvander@1203
  2216
** difference only between the two is that the second parameter, the
dvander@1203
  2217
** name of the (scalar) function or aggregate, is encoded in UTF-8 for
dvander@1203
  2218
** sqlite3_create_function() and UTF-16 for sqlite3_create_function16().
dvander@1203
  2219
**
dvander@1203
  2220
** The first argument is the [sqlite3 | database handle] that holds the
dvander@1203
  2221
** SQL function or aggregate is to be added or redefined. If a single
dvander@1203
  2222
** program uses more than one database handle internally, then SQL
dvander@1203
  2223
** functions or aggregates must be added individually to each database
dvander@1203
  2224
** handle with which they will be used.
dvander@1203
  2225
**
dvander@1203
  2226
** The second parameter is the name of the SQL function to be created
dvander@1203
  2227
** or redefined.
dvander@1203
  2228
** The length of the name is limited to 255 bytes, exclusive of the 
dvander@1203
  2229
** zero-terminator.  Note that the name length limit is in bytes, not
dvander@1203
  2230
** characters.  Any attempt to create a function with a longer name
dvander@1203
  2231
** will result in an SQLITE_ERROR error.
dvander@1203
  2232
**
dvander@1203
  2233
** The third parameter is the number of arguments that the SQL function or
dvander@1203
  2234
** aggregate takes. If this parameter is negative, then the SQL function or
dvander@1203
  2235
** aggregate may take any number of arguments.
dvander@1203
  2236
**
dvander@1203
  2237
** The fourth parameter, eTextRep, specifies what 
dvander@1203
  2238
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
dvander@1203
  2239
** its parameters.  Any SQL function implementation should be able to work
dvander@1203
  2240
** work with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
dvander@1203
  2241
** more efficient with one encoding than another.  It is allowed to
dvander@1645
  2242
** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
dvander@1203
  2243
** times with the same function but with different values of eTextRep.
dvander@1203
  2244
** When multiple implementations of the same function are available, SQLite
dvander@1203
  2245
** will pick the one that involves the least amount of data conversion.
dvander@1203
  2246
** If there is only a single implementation which does not care what
dvander@1203
  2247
** text encoding is used, then the fourth argument should be
dvander@1203
  2248
** [SQLITE_ANY].
dvander@1203
  2249
**
dvander@1203
  2250
** The fifth parameter is an arbitrary pointer.  The implementation
dvander@1203
  2251
** of the function can gain access to this pointer using
dvander@1645
  2252
** [sqlite3_user_data()].
dvander@1203
  2253
**
dvander@1203
  2254
** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
dvander@1203
  2255
** pointers to C-language functions that implement the SQL
dvander@1203
  2256
** function or aggregate. A scalar SQL function requires an implementation of
dvander@1203
  2257
** the xFunc callback only, NULL pointers should be passed as the xStep
dvander@1203
  2258
** and xFinal parameters. An aggregate SQL function requires an implementation
dvander@1203
  2259
** of xStep and xFinal and NULL should be passed for xFunc. To delete an
dvander@1203
  2260
** existing SQL function or aggregate, pass NULL for all three function
dvander@1203
  2261
** callback.
dvander@1203
  2262
**
dvander@1203
  2263
** It is permitted to register multiple implementations of the same
dvander@1203
  2264
** functions with the same name but with either differing numbers of
dvander@1203
  2265
** arguments or differing perferred text encodings.  SQLite will use
dvander@1203
  2266
** the implementation most closely matches the way in which the
dvander@1203
  2267
** SQL function is used.
dvander@1203
  2268
*/
dvander@1203
  2269
int sqlite3_create_function(
dvander@1203
  2270
  sqlite3 *,
dvander@1203
  2271
  const char *zFunctionName,
dvander@1203
  2272
  int nArg,
dvander@1203
  2273
  int eTextRep,
dvander@1203
  2274
  void*,
dvander@1203
  2275
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  2276
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  2277
  void (*xFinal)(sqlite3_context*)
dvander@1203
  2278
);
dvander@1203
  2279
int sqlite3_create_function16(
dvander@1203
  2280
  sqlite3*,
dvander@1203
  2281
  const void *zFunctionName,
dvander@1203
  2282
  int nArg,
dvander@1203
  2283
  int eTextRep,
dvander@1203
  2284
  void*,
dvander@1203
  2285
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  2286
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  2287
  void (*xFinal)(sqlite3_context*)
dvander@1203
  2288
);
dvander@1203
  2289
dvander@1203
  2290
/*
dvander@1203
  2291
** CAPI3REF: Text Encodings
dvander@1203
  2292
**
dvander@1203
  2293
** These constant define integer codes that represent the various
dvander@1203
  2294
** text encodings supported by SQLite.
dvander@1203
  2295
*/
dvander@1203
  2296
#define SQLITE_UTF8           1
dvander@1203
  2297
#define SQLITE_UTF16LE        2
dvander@1203
  2298
#define SQLITE_UTF16BE        3
dvander@1203
  2299
#define SQLITE_UTF16          4    /* Use native byte order */
dvander@1203
  2300
#define SQLITE_ANY            5    /* sqlite3_create_function only */
dvander@1203
  2301
#define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
dvander@1203
  2302
dvander@1203
  2303
/*
dvander@1203
  2304
** CAPI3REF: Obsolete Functions
dvander@1203
  2305
**
dvander@1203
  2306
** These functions are all now obsolete.  In order to maintain
dvander@1203
  2307
** backwards compatibility with older code, we continue to support
dvander@1203
  2308
** these functions.  However, new development projects should avoid
dvander@1203
  2309
** the use of these functions.  To help encourage people to avoid
dvander@1203
  2310
** using these functions, we are not going to tell you want they do.
dvander@1203
  2311
*/
dvander@1203
  2312
int sqlite3_aggregate_count(sqlite3_context*);
dvander@1203
  2313
int sqlite3_expired(sqlite3_stmt*);
dvander@1203
  2314
int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
dvander@1203
  2315
int sqlite3_global_recover(void);
dvander@1645
  2316
void sqlite3_thread_cleanup(void);
dvander@1203
  2317
dvander@1203
  2318
/*
dvander@1203
  2319
** CAPI3REF: Obtaining SQL Function Parameter Values
dvander@1203
  2320
**
dvander@1203
  2321
** The C-language implementation of SQL functions and aggregates uses
dvander@1203
  2322
** this set of interface routines to access the parameter values on
dvander@1203
  2323
** the function or aggregate.
dvander@1203
  2324
**
dvander@1203
  2325
** The xFunc (for scalar functions) or xStep (for aggregates) parameters
dvander@1203
  2326
** to [sqlite3_create_function()] and [sqlite3_create_function16()]
dvander@1203
  2327
** define callbacks that implement the SQL functions and aggregates.
dvander@1203
  2328
** The 4th parameter to these callbacks is an array of pointers to
dvander@1203
  2329
** [sqlite3_value] objects.  There is one [sqlite3_value] object for
dvander@1203
  2330
** each parameter to the SQL function.  These routines are used to
dvander@1203
  2331
** extract values from the [sqlite3_value] objects.
dvander@1203
  2332
**
dvander@1203
  2333
** These routines work just like the corresponding 
dvander@1203
  2334
** [sqlite3_column_blob | sqlite3_column_* routines] except that 
dvander@1203
  2335
** these routines take a single [sqlite3_value*] pointer instead
dvander@1203
  2336
** of an [sqlite3_stmt*] pointer and an integer column number.
dvander@1203
  2337
**
dvander@1203
  2338
** The sqlite3_value_text16() interface extracts a UTF16 string
dvander@1203
  2339
** in the native byte-order of the host machine.  The
dvander@1203
  2340
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
dvander@1203
  2341
** extract UTF16 strings as big-endian and little-endian respectively.
dvander@1203
  2342
**
dvander@1203
  2343
** The sqlite3_value_numeric_type() interface attempts to apply
dvander@1203
  2344
** numeric affinity to the value.  This means that an attempt is
dvander@1203
  2345
** made to convert the value to an integer or floating point.  If
dvander@1203
  2346
** such a conversion is possible without loss of information (in order
dvander@1203
  2347
** words if the value is original a string that looks like a number)
dvander@1203
  2348
** then it is done.  Otherwise no conversion occurs.  The 
dvander@1203
  2349
** [SQLITE_INTEGER | datatype] after conversion is returned.
dvander@1203
  2350
**
dvander@1203
  2351
** Please pay particular attention to the fact that the pointer that
dvander@1203
  2352
** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or
dvander@1203
  2353
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
dvander@1645
  2354
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
dvander@1203
  2355
** or [sqlite3_value_text16()].  
dvander@1645
  2356
**
dvander@1645
  2357
** These routines must be called from the same thread as
dvander@1645
  2358
** the SQL function that supplied the sqlite3_value* parameters.
dvander@1645
  2359
** Or, if the sqlite3_value* argument comes from the [sqlite3_column_value()]
dvander@1645
  2360
** interface, then these routines should be called from the same thread
dvander@1645
  2361
** that ran [sqlite3_column_value()].
dvander@1203
  2362
*/
dvander@1203
  2363
const void *sqlite3_value_blob(sqlite3_value*);
dvander@1203
  2364
int sqlite3_value_bytes(sqlite3_value*);
dvander@1203
  2365
int sqlite3_value_bytes16(sqlite3_value*);
dvander@1203
  2366
double sqlite3_value_double(sqlite3_value*);
dvander@1203
  2367
int sqlite3_value_int(sqlite3_value*);
dvander@1645
  2368
sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
dvander@1203
  2369
const unsigned char *sqlite3_value_text(sqlite3_value*);
dvander@1203
  2370
const void *sqlite3_value_text16(sqlite3_value*);
dvander@1203
  2371
const void *sqlite3_value_text16le(sqlite3_value*);
dvander@1203
  2372
const void *sqlite3_value_text16be(sqlite3_value*);
dvander@1203
  2373
int sqlite3_value_type(sqlite3_value*);
dvander@1203
  2374
int sqlite3_value_numeric_type(sqlite3_value*);
dvander@1203
  2375
dvander@1203
  2376
/*
dvander@1203
  2377
** CAPI3REF: Obtain Aggregate Function Context
dvander@1203
  2378
**
dvander@1203
  2379
** The implementation of aggregate SQL functions use this routine to allocate
dvander@1203
  2380
** a structure for storing their state.  The first time this routine
dvander@1203
  2381
** is called for a particular aggregate, a new structure of size nBytes
dvander@1203
  2382
** is allocated, zeroed, and returned.  On subsequent calls (for the
dvander@1203
  2383
** same aggregate instance) the same buffer is returned.  The implementation
dvander@1203
  2384
** of the aggregate can use the returned buffer to accumulate data.
dvander@1203
  2385
**
dvander@1203
  2386
** The buffer allocated is freed automatically by SQLite whan the aggregate
dvander@1203
  2387
** query concludes.
dvander@1203
  2388
**
dvander@1203
  2389
** The first parameter should be a copy of the 
dvander@1203
  2390
** [sqlite3_context | SQL function context] that is the first
dvander@1203
  2391
** parameter to the callback routine that implements the aggregate
dvander@1203
  2392
** function.
dvander@1645
  2393
**
dvander@1645
  2394
** This routine must be called from the same thread in which
dvander@1645
  2395
** the aggregate SQL function is running.
dvander@1203
  2396
*/
dvander@1203
  2397
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
dvander@1203
  2398
dvander@1203
  2399
/*
dvander@1203
  2400
** CAPI3REF: User Data For Functions
dvander@1203
  2401
**
dvander@1203
  2402
** The pUserData parameter to the [sqlite3_create_function()]
dvander@1203
  2403
** and [sqlite3_create_function16()] routines
dvander@1203
  2404
** used to register user functions is available to
dvander@1203
  2405
** the implementation of the function using this call.
dvander@1645
  2406
**
dvander@1645
  2407
** This routine must be called from the same thread in which
dvander@1645
  2408
** the SQL function is running.
dvander@1203
  2409
*/
dvander@1203
  2410
void *sqlite3_user_data(sqlite3_context*);
dvander@1203
  2411
dvander@1203
  2412
/*
dvander@1203
  2413
** CAPI3REF: Function Auxiliary Data
dvander@1203
  2414
**
dvander@1203
  2415
** The following two functions may be used by scalar SQL functions to
dvander@1203
  2416
** associate meta-data with argument values. If the same value is passed to
dvander@1203
  2417
** multiple invocations of the same SQL function during query execution, under
dvander@1203
  2418
** some circumstances the associated meta-data may be preserved. This may
dvander@1203
  2419
** be used, for example, to add a regular-expression matching scalar
dvander@1203
  2420
** function. The compiled version of the regular expression is stored as
dvander@1203
  2421
** meta-data associated with the SQL value passed as the regular expression
dvander@1203
  2422
** pattern.  The compiled regular expression can be reused on multiple
dvander@1203
  2423
** invocations of the same function so that the original pattern string
dvander@1203
  2424
** does not need to be recompiled on each invocation.
dvander@1203
  2425
**
dvander@1203
  2426
** The sqlite3_get_auxdata() interface returns a pointer to the meta-data
dvander@1203
  2427
** associated with the Nth argument value to the current SQL function
dvander@1203
  2428
** call, where N is the second parameter. If no meta-data has been set for
dvander@1203
  2429
** that value, then a NULL pointer is returned.
dvander@1203
  2430
**
dvander@1203
  2431
** The sqlite3_set_auxdata() is used to associate meta-data with an SQL
dvander@1203
  2432
** function argument. The third parameter is a pointer to the meta-data
dvander@1203
  2433
** to be associated with the Nth user function argument value. The fourth
dvander@1203
  2434
** parameter specifies a destructor that will be called on the meta-
dvander@1203
  2435
** data pointer to release it when it is no longer required. If the 
dvander@1203
  2436
** destructor is NULL, it is not invoked.
dvander@1203
  2437
**
dvander@1203
  2438
** In practice, meta-data is preserved between function calls for
dvander@1203
  2439
** expressions that are constant at compile time. This includes literal
dvander@1203
  2440
** values and SQL variables.
dvander@1645
  2441
**
dvander@1645
  2442
** These routines must be called from the same thread in which
dvander@1645
  2443
** the SQL function is running.
dvander@1203
  2444
*/
dvander@1203
  2445
void *sqlite3_get_auxdata(sqlite3_context*, int);
dvander@1203
  2446
void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
dvander@1203
  2447
dvander@1203
  2448
dvander@1203
  2449
/*
dvander@1203
  2450
** CAPI3REF: Constants Defining Special Destructor Behavior
dvander@1203
  2451
**
dvander@1203
  2452
** These are special value for the destructor that is passed in as the
dvander@1203
  2453
** final argument to routines like [sqlite3_result_blob()].  If the destructor
dvander@1203
  2454
** argument is SQLITE_STATIC, it means that the content pointer is constant
dvander@1203
  2455
** and will never change.  It does not need to be destroyed.  The 
dvander@1203
  2456
** SQLITE_TRANSIENT value means that the content will likely change in
dvander@1203
  2457
** the near future and that SQLite should make its own private copy of
dvander@1203
  2458
** the content before returning.
dvander@1203
  2459
**
dvander@1203
  2460
** The typedef is necessary to work around problems in certain
dvander@1203
  2461
** C++ compilers.  See ticket #2191.
dvander@1203
  2462
*/
dvander@1203
  2463
typedef void (*sqlite3_destructor_type)(void*);
dvander@1203
  2464
#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
dvander@1203
  2465
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
dvander@1203
  2466
dvander@1203
  2467
/*
dvander@1203
  2468
** CAPI3REF: Setting The Result Of An SQL Function
dvander@1203
  2469
**
dvander@1203
  2470
** These routines are used by the xFunc or xFinal callbacks that
dvander@1203
  2471
** implement SQL functions and aggregates.  See
dvander@1203
  2472
** [sqlite3_create_function()] and [sqlite3_create_function16()]
dvander@1203
  2473
** for additional information.
dvander@1203
  2474
**
dvander@1203
  2475
** These functions work very much like the 
dvander@1203
  2476
** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used
dvander@1203
  2477
** to bind values to host parameters in prepared statements.
dvander@1203
  2478
** Refer to the
dvander@1203
  2479
** [sqlite3_bind_blob | sqlite3_bind_* documentation] for
dvander@1203
  2480
** additional information.
dvander@1203
  2481
**
dvander@1203
  2482
** The sqlite3_result_error() and sqlite3_result_error16() functions
dvander@1203
  2483
** cause the implemented SQL function to throw an exception.  The
dvander@1203
  2484
** parameter to sqlite3_result_error() or sqlite3_result_error16()
dvander@1203
  2485
** is the text of an error message.
dvander@1203
  2486
**
dvander@1203
  2487
** The sqlite3_result_toobig() cause the function implementation
dvander@1203
  2488
** to throw and error indicating that a string or BLOB is to long
dvander@1203
  2489
** to represent.
dvander@1645
  2490
**
dvander@1645
  2491
** These routines must be called from within the same thread as
dvander@1645
  2492
** the SQL function associated with the [sqlite3_context] pointer.
dvander@1203
  2493
*/
dvander@1203
  2494
void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
dvander@1203
  2495
void sqlite3_result_double(sqlite3_context*, double);
dvander@1203
  2496
void sqlite3_result_error(sqlite3_context*, const char*, int);
dvander@1203
  2497
void sqlite3_result_error16(sqlite3_context*, const void*, int);
dvander@1203
  2498
void sqlite3_result_error_toobig(sqlite3_context*);
dvander@1645
  2499
void sqlite3_result_error_nomem(sqlite3_context*);
dvander@1203
  2500
void sqlite3_result_int(sqlite3_context*, int);
dvander@1645
  2501
void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
dvander@1203
  2502
void sqlite3_result_null(sqlite3_context*);
dvander@1203
  2503
void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
dvander@1203
  2504
void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
dvander@1203
  2505
void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
dvander@1203
  2506
void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
dvander@1203
  2507
void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
dvander@1203
  2508
void sqlite3_result_zeroblob(sqlite3_context*, int n);
dvander@1203
  2509
dvander@1203
  2510
/*
dvander@1203
  2511
** CAPI3REF: Define New Collating Sequences
dvander@1203
  2512
**
dvander@1203
  2513
** These functions are used to add new collation sequences to the
dvander@1203
  2514
** [sqlite3*] handle specified as the first argument. 
dvander@1203
  2515
**
dvander@1203
  2516
** The name of the new collation sequence is specified as a UTF-8 string
dvander@1203
  2517
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
dvander@1203
  2518
** and a UTF-16 string for sqlite3_create_collation16().  In all cases
dvander@1203
  2519
** the name is passed as the second function argument.
dvander@1203
  2520
**
dvander@1203
  2521
** The third argument must be one of the constants [SQLITE_UTF8],
dvander@1203
  2522
** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
dvander@1203
  2523
** routine expects to be passed pointers to strings encoded using UTF-8,
dvander@1203
  2524
** UTF-16 little-endian or UTF-16 big-endian respectively.
dvander@1203
  2525
**
dvander@1203
  2526
** A pointer to the user supplied routine must be passed as the fifth
dvander@1203
  2527
** argument. If it is NULL, this is the same as deleting the collation
dvander@1203
  2528
** sequence (so that SQLite cannot call it anymore). Each time the user
dvander@1203
  2529
** supplied function is invoked, it is passed a copy of the void* passed as
dvander@1203
  2530
** the fourth argument to sqlite3_create_collation() or
dvander@1203
  2531
** sqlite3_create_collation16() as its first parameter.
dvander@1203
  2532
**
dvander@1203
  2533
** The remaining arguments to the user-supplied routine are two strings,
dvander@1203
  2534
** each represented by a [length, data] pair and encoded in the encoding
dvander@1203
  2535
** that was passed as the third argument when the collation sequence was
dvander@1203
  2536
** registered. The user routine should return negative, zero or positive if
dvander@1203
  2537
** the first string is less than, equal to, or greater than the second
dvander@1203
  2538
** string. i.e. (STRING1 - STRING2).
dvander@1203
  2539
**
dvander@1203
  2540
** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
dvander@1203
  2541
** excapt that it takes an extra argument which is a destructor for
dvander@1203
  2542
** the collation.  The destructor is called when the collation is
dvander@1203
  2543
** destroyed and is passed a copy of the fourth parameter void* pointer
dvander@1203
  2544
** of the sqlite3_create_collation_v2().  Collations are destroyed when
dvander@1203
  2545
** they are overridden by later calls to the collation creation functions
dvander@1203
  2546
** or when the [sqlite3*] database handle is closed using [sqlite3_close()].
dvander@1203
  2547
**
dvander@1203
  2548
** The sqlite3_create_collation_v2() interface is experimental and
dvander@1203
  2549
** subject to change in future releases.  The other collation creation
dvander@1203
  2550
** functions are stable.
dvander@1203
  2551
*/
dvander@1203
  2552
int sqlite3_create_collation(
dvander@1203
  2553
  sqlite3*, 
dvander@1203
  2554
  const char *zName, 
dvander@1203
  2555
  int eTextRep, 
dvander@1203
  2556
  void*,
dvander@1203
  2557
  int(*xCompare)(void*,int,const void*,int,const void*)
dvander@1203
  2558
);
dvander@1203
  2559
int sqlite3_create_collation_v2(
dvander@1203
  2560
  sqlite3*, 
dvander@1203
  2561
  const char *zName, 
dvander@1203
  2562
  int eTextRep, 
dvander@1203
  2563
  void*,
dvander@1203
  2564
  int(*xCompare)(void*,int,const void*,int,const void*),
dvander@1203
  2565
  void(*xDestroy)(void*)
dvander@1203
  2566
);
dvander@1203
  2567
int sqlite3_create_collation16(
dvander@1203
  2568
  sqlite3*, 
dvander@1203
  2569
  const char *zName, 
dvander@1203
  2570
  int eTextRep, 
dvander@1203
  2571
  void*,
dvander@1203
  2572
  int(*xCompare)(void*,int,const void*,int,const void*)
dvander@1203
  2573
);
dvander@1203
  2574
dvander@1203
  2575
/*
dvander@1203
  2576
** CAPI3REF: Collation Needed Callbacks
dvander@1203
  2577
**
dvander@1203
  2578
** To avoid having to register all collation sequences before a database
dvander@1203
  2579
** can be used, a single callback function may be registered with the
dvander@1203
  2580
** database handle to be called whenever an undefined collation sequence is
dvander@1203
  2581
** required.
dvander@1203
  2582
**
dvander@1203
  2583
** If the function is registered using the sqlite3_collation_needed() API,
dvander@1203
  2584
** then it is passed the names of undefined collation sequences as strings
dvander@1203
  2585
** encoded in UTF-8. If sqlite3_collation_needed16() is used, the names
dvander@1203
  2586
** are passed as UTF-16 in machine native byte order. A call to either
dvander@1203
  2587
** function replaces any existing callback.
dvander@1203
  2588
**
dvander@1203
  2589
** When the callback is invoked, the first argument passed is a copy
dvander@1203
  2590
** of the second argument to sqlite3_collation_needed() or
dvander@1203
  2591
** sqlite3_collation_needed16(). The second argument is the database
dvander@1203
  2592
** handle. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], or
dvander@1203
  2593
** [SQLITE_UTF16LE], indicating the most desirable form of the collation
dvander@1203
  2594
** sequence function required. The fourth parameter is the name of the
dvander@1203
  2595
** required collation sequence.
dvander@1203
  2596
**
dvander@1203
  2597
** The callback function should register the desired collation using
dvander@1203
  2598
** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
dvander@1203
  2599
** [sqlite3_create_collation_v2()].
dvander@1203
  2600
*/
dvander@1203
  2601
int sqlite3_collation_needed(
dvander@1203
  2602
  sqlite3*, 
dvander@1203
  2603
  void*, 
dvander@1203
  2604
  void(*)(void*,sqlite3*,int eTextRep,const char*)
dvander@1203
  2605
);
dvander@1203
  2606
int sqlite3_collation_needed16(
dvander@1203
  2607
  sqlite3*, 
dvander@1203
  2608
  void*,
dvander@1203
  2609
  void(*)(void*,sqlite3*,int eTextRep,const void*)
dvander@1203
  2610
);
dvander@1203
  2611
dvander@1203
  2612
/*
dvander@1203
  2613
** Specify the key for an encrypted database.  This routine should be
dvander@1203
  2614
** called right after sqlite3_open().
dvander@1203
  2615
**
dvander@1203
  2616
** The code to implement this API is not available in the public release
dvander@1203
  2617
** of SQLite.
dvander@1203
  2618
*/
dvander@1203
  2619
int sqlite3_key(
dvander@1203
  2620
  sqlite3 *db,                   /* Database to be rekeyed */
dvander@1203
  2621
  const void *pKey, int nKey     /* The key */
dvander@1203
  2622
);
dvander@1203
  2623
dvander@1203
  2624
/*
dvander@1203
  2625
** Change the key on an open database.  If the current database is not
dvander@1203
  2626
** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
dvander@1203
  2627
** database is decrypted.
dvander@1203
  2628
**
dvander@1203
  2629
** The code to implement this API is not available in the public release
dvander@1203
  2630
** of SQLite.
dvander@1203
  2631
*/
dvander@1203
  2632
int sqlite3_rekey(
dvander@1203
  2633
  sqlite3 *db,                   /* Database to be rekeyed */
dvander@1203
  2634
  const void *pKey, int nKey     /* The new key */
dvander@1203
  2635
);
dvander@1203
  2636
dvander@1203
  2637
/*
dvander@1203
  2638
** CAPI3REF:  Suspend Execution For A Short Time
dvander@1203
  2639
**
dvander@1203
  2640
** This function causes the current thread to suspend execution
dvander@1203
  2641
** a number of milliseconds specified in its parameter.
dvander@1203
  2642
**
dvander@1203
  2643
** If the operating system does not support sleep requests with 
dvander@1203
  2644
** millisecond time resolution, then the time will be rounded up to 
dvander@1203
  2645
** the nearest second. The number of milliseconds of sleep actually 
dvander@1203
  2646
** requested from the operating system is returned.
dvander@1645
  2647
**
dvander@1645
  2648
** SQLite implements this interface by calling the xSleep()
dvander@1645
  2649
** method of the default [sqlite3_vfs] object.
dvander@1203
  2650
*/
dvander@1203
  2651
int sqlite3_sleep(int);
dvander@1203
  2652
dvander@1203
  2653
/*
dvander@1203
  2654
** CAPI3REF:  Name Of The Folder Holding Temporary Files
dvander@1203
  2655
**
dvander@1203
  2656
** If this global variable is made to point to a string which is
dvander@1203
  2657
** the name of a folder (a.ka. directory), then all temporary files
dvander@1203
  2658
** created by SQLite will be placed in that directory.  If this variable
dvander@1203
  2659
** is NULL pointer, then SQLite does a search for an appropriate temporary
dvander@1203
  2660
** file directory.
dvander@1203
  2661
**
dvander@1645
  2662
** It is not safe to modify this variable once a database connection
dvander@1645
  2663
** has been opened.  It is intended that this variable be set once
dvander@1645
  2664
** as part of process initialization and before any SQLite interface
dvander@1645
  2665
** routines have been call and remain unchanged thereafter.
dvander@1203
  2666
*/
dvander@1645
  2667
SQLITE_EXTERN char *sqlite3_temp_directory;
dvander@1203
  2668
dvander@1203
  2669
/*
dvander@1645
  2670
** CAPI3REF:  Test To See If The Database Is In Auto-Commit Mode
dvander@1203
  2671
**
dvander@1203
  2672
** Test to see whether or not the database connection is in autocommit
dvander@1203
  2673
** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
dvander@1203
  2674
** by default.  Autocommit is disabled by a BEGIN statement and reenabled
dvander@1203
  2675
** by the next COMMIT or ROLLBACK.
dvander@1645
  2676
**
dvander@1645
  2677
** If certain kinds of errors occur on a statement within a multi-statement
dvander@1645
  2678
** transactions (errors including [SQLITE_FULL], [SQLITE_IOERR], 
dvander@1645
  2679
** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
dvander@1645
  2680
** transaction might be rolled back automatically.  The only way to
dvander@1645
  2681
** find out if SQLite automatically rolled back the transaction after
dvander@1645
  2682
** an error is to use this function.
dvander@1645
  2683
**
dvander@1645
  2684
** If another thread changes the autocommit status of the database
dvander@1645
  2685
** connection while this routine is running, then the return value
dvander@1645
  2686
** is undefined.
dvander@1203
  2687
*/
dvander@1203
  2688
int sqlite3_get_autocommit(sqlite3*);
dvander@1203
  2689
dvander@1203
  2690
/*
dvander@1203
  2691
** CAPI3REF:  Find The Database Handle Associated With A Prepared Statement
dvander@1203
  2692
**
dvander@1203
  2693
** Return the [sqlite3*] database handle to which a
dvander@1203
  2694
** [sqlite3_stmt | prepared statement] belongs.
dvander@1203
  2695
** This is the same database handle that was
dvander@1203
  2696
** the first argument to the [sqlite3_prepare_v2()] or its variants
dvander@1203
  2697
** that was used to create the statement in the first place.
dvander@1203
  2698
*/
dvander@1203
  2699
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
dvander@1203
  2700
dvander@1203
  2701
dvander@1203
  2702
/*
dvander@1203
  2703
** CAPI3REF: Commit And Rollback Notification Callbacks
dvander@1203
  2704
**
dvander@1203
  2705
** These routines
dvander@1203
  2706
** register callback functions to be invoked whenever a transaction
dvander@1203
  2707
** is committed or rolled back.  The pArg argument is passed through
dvander@1203
  2708
** to the callback.  If the callback on a commit hook function 
dvander@1203
  2709
** returns non-zero, then the commit is converted into a rollback.
dvander@1203
  2710
**
dvander@1203
  2711
** If another function was previously registered, its pArg value is returned.
dvander@1203
  2712
** Otherwise NULL is returned.
dvander@1203
  2713
**
dvander@1203
  2714
** Registering a NULL function disables the callback.
dvander@1203
  2715
**
dvander@1203
  2716
** For the purposes of this API, a transaction is said to have been 
dvander@1203
  2717
** rolled back if an explicit "ROLLBACK" statement is executed, or
dvander@1203
  2718
** an error or constraint causes an implicit rollback to occur. The 
dvander@1203
  2719
** callback is not invoked if a transaction is automatically rolled
dvander@1203
  2720
** back because the database connection is closed.
dvander@1203
  2721
**
dvander@1203
  2722
** These are experimental interfaces and are subject to change.
dvander@1203
  2723
*/
dvander@1203
  2724
void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
dvander@1203
  2725
void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
dvander@1203
  2726
dvander@1203
  2727
/*
dvander@1203
  2728
** CAPI3REF: Data Change Notification Callbacks
dvander@1203
  2729
**
dvander@1203
  2730
** Register a callback function with the database connection identified by the 
dvander@1203
  2731
** first argument to be invoked whenever a row is updated, inserted or deleted.
dvander@1203
  2732
** Any callback set by a previous call to this function for the same 
dvander@1203
  2733
** database connection is overridden.
dvander@1203
  2734
**
dvander@1203
  2735
** The second argument is a pointer to the function to invoke when a 
dvander@1203
  2736
** row is updated, inserted or deleted. The first argument to the callback is
dvander@1203
  2737
** a copy of the third argument to sqlite3_update_hook(). The second callback 
dvander@1203
  2738
** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
dvander@1203
  2739
** on the operation that caused the callback to be invoked. The third and 
dvander@1203
  2740
** fourth arguments to the callback contain pointers to the database and 
dvander@1203
  2741
** table name containing the affected row. The final callback parameter is 
dvander@1203
  2742
** the rowid of the row. In the case of an update, this is the rowid after 
dvander@1203
  2743
** the update takes place.
dvander@1203
  2744
**
dvander@1203
  2745
** The update hook is not invoked when internal system tables are
dvander@1203
  2746
** modified (i.e. sqlite_master and sqlite_sequence).
dvander@1203
  2747
**
dvander@1203
  2748
** If another function was previously registered, its pArg value is returned.
dvander@1203
  2749
** Otherwise NULL is returned.
dvander@1203
  2750
*/
dvander@1203
  2751
void *sqlite3_update_hook(
dvander@1203
  2752
  sqlite3*, 
dvander@1645
  2753
  void(*)(void *,int ,char const *,char const *,sqlite3_int64),
dvander@1203
  2754
  void*
dvander@1203
  2755
);
dvander@1203
  2756
dvander@1203
  2757
/*
dvander@1203
  2758
** CAPI3REF:  Enable Or Disable Shared Pager Cache
dvander@1203
  2759
**
dvander@1203
  2760
** This routine enables or disables the sharing of the database cache
dvander@1203
  2761
** and schema data structures between connections to the same database.
dvander@1203
  2762
** Sharing is enabled if the argument is true and disabled if the argument
dvander@1203
  2763
** is false.
dvander@1203
  2764
**
dvander@1645
  2765
** Beginning in SQLite version 3.5.0, cache sharing is enabled and disabled
dvander@1645
  2766
** for an entire process.  In prior versions of SQLite, sharing was
dvander@1645
  2767
** enabled or disabled for each thread separately.
dvander@1645
  2768
**
dvander@1645
  2769
** The cache sharing mode set by this interface effects all subsequent
dvander@1645
  2770
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
dvander@1645
  2771
** Existing database connections continue use the sharing mode that was
dvander@1645
  2772
** in effect at the time they were opened.
dvander@1203
  2773
**
dvander@1203
  2774
** Virtual tables cannot be used with a shared cache.  When shared
dvander@1645
  2775
** cache is enabled, the [sqlite3_create_module()] API used to register
dvander@1203
  2776
** virtual tables will always return an error.
dvander@1203
  2777
**
dvander@1203
  2778
** This routine returns [SQLITE_OK] if shared cache was
dvander@1203
  2779
** enabled or disabled successfully.  An [SQLITE_ERROR | error code]
dvander@1203
  2780
** is returned otherwise.
dvander@1203
  2781
**
dvander@1645
  2782
** Shared cache is disabled by default.  But this might change in
dvander@1645
  2783
** future releases of SQLite.  Applications that care about shared
dvander@1645
  2784
** cache setting should set it explicitly.
dvander@1203
  2785
*/
dvander@1203
  2786
int sqlite3_enable_shared_cache(int);
dvander@1203
  2787
dvander@1203
  2788
/*
dvander@1203
  2789
** CAPI3REF:  Attempt To Free Heap Memory
dvander@1203
  2790
**
dvander@1203
  2791
** Attempt to free N bytes of heap memory by deallocating non-essential
dvander@1203
  2792
** memory allocations held by the database library (example: memory 
dvander@1203
  2793
** used to cache database pages to improve performance).
dvander@1203
  2794
*/
dvander@1203
  2795
int sqlite3_release_memory(int);
dvander@1203
  2796
dvander@1203
  2797
/*
dvander@1203
  2798
** CAPI3REF:  Impose A Limit On Heap Size
dvander@1203
  2799
**
dvander@1645
  2800
** Place a "soft" limit on the amount of heap memory that may be allocated
dvander@1645
  2801
** by SQLite.  If an internal allocation is requested 
dvander@1645
  2802
** that would exceed the specified limit, [sqlite3_release_memory()] is
dvander@1645
  2803
** invoked one or more times to free up some space before the allocation
dvander@1645
  2804
** is made.
dvander@1645
  2805
**
dvander@1645
  2806
** The limit is called "soft", because if [sqlite3_release_memory()] cannot
dvander@1645
  2807
** free sufficient memory to prevent the limit from being exceeded,
dvander@1645
  2808
** the memory is allocated anyway and the current operation proceeds.
dvander@1203
  2809
**
dvander@1203
  2810
** A negative or zero value for N means that there is no soft heap limit and
dvander@1645
  2811
** [sqlite3_release_memory()] will only be called when memory is exhausted.
dvander@1203
  2812
** The default value for the soft heap limit is zero.
dvander@1203
  2813
**
dvander@1203
  2814
** SQLite makes a best effort to honor the soft heap limit.  But if it
dvander@1203
  2815
** is unable to reduce memory usage below the soft limit, execution will
dvander@1203
  2816
** continue without error or notification.  This is why the limit is 
dvander@1203
  2817
** called a "soft" limit.  It is advisory only.
dvander@1203
  2818
**
dvander@1645
  2819
** The soft heap limit is implemented using the [sqlite3_memory_alarm()]
dvander@1645
  2820
** interface.  Only a single memory alarm is available in the default
dvander@1645
  2821
** implementation.  This means that if the application also uses the
dvander@1645
  2822
** memory alarm interface it will interfere with the operation of the
dvander@1645
  2823
** soft heap limit and undefined behavior will result.  
dvander@1645
  2824
**
dvander@1645
  2825
** Prior to SQLite version 3.5.0, this routine only constrained the memory
dvander@1645
  2826
** allocated by a single thread - the same thread in which this routine
dvander@1645
  2827
** runs.  Beginning with SQLite version 3.5.0, the soft heap limit is
dvander@1645
  2828
** applied to all threads.  The value specified for the soft heap limit
dvander@1645
  2829
** is an upper bound on the total memory allocation for all threads.  In
dvander@1645
  2830
** version 3.5.0 there is no mechanism for limiting the heap usage for
dvander@1645
  2831
** individual threads.
dvander@1203
  2832
*/
dvander@1203
  2833
void sqlite3_soft_heap_limit(int);
dvander@1203
  2834
dvander@1203
  2835
/*
dvander@1203
  2836
** CAPI3REF:  Extract Metadata About A Column Of A Table
dvander@1203
  2837
**
dvander@1203
  2838
** This routine
dvander@1203
  2839
** returns meta-data about a specific column of a specific database
dvander@1203
  2840
** table accessible using the connection handle passed as the first function 
dvander@1203
  2841
** argument.
dvander@1203
  2842
**
dvander@1203
  2843
** The column is identified by the second, third and fourth parameters to 
dvander@1203
  2844
** this function. The second parameter is either the name of the database
dvander@1203
  2845
** (i.e. "main", "temp" or an attached database) containing the specified
dvander@1203
  2846
** table or NULL. If it is NULL, then all attached databases are searched
dvander@1203
  2847
** for the table using the same algorithm as the database engine uses to 
dvander@1203
  2848
** resolve unqualified table references.
dvander@1203
  2849
**
dvander@1203
  2850
** The third and fourth parameters to this function are the table and column 
dvander@1203
  2851
** name of the desired column, respectively. Neither of these parameters 
dvander@1203
  2852
** may be NULL.
dvander@1203
  2853
**
dvander@1203
  2854
** Meta information is returned by writing to the memory locations passed as
dvander@1203
  2855
** the 5th and subsequent parameters to this function. Any of these 
dvander@1203
  2856
** arguments may be NULL, in which case the corresponding element of meta 
dvander@1203
  2857
** information is ommitted.
dvander@1203
  2858
**
dvander@1203
  2859
** <pre>
dvander@1203
  2860
** Parameter     Output Type      Description
dvander@1203
  2861
** -----------------------------------
dvander@1203
  2862
**
dvander@1203
  2863
**   5th         const char*      Data type
dvander@1203
  2864
**   6th         const char*      Name of the default collation sequence 
dvander@1203
  2865
**   7th         int              True if the column has a NOT NULL constraint
dvander@1203
  2866
**   8th         int              True if the column is part of the PRIMARY KEY
dvander@1203
  2867
**   9th         int              True if the column is AUTOINCREMENT
dvander@1203
  2868
** </pre>
dvander@1203
  2869
**
dvander@1203
  2870
**
dvander@1203
  2871
** The memory pointed to by the character pointers returned for the 
dvander@1203
  2872
** declaration type and collation sequence is valid only until the next 
dvander@1203
  2873
** call to any sqlite API function.
dvander@1203
  2874
**
dvander@1203
  2875
** If the specified table is actually a view, then an error is returned.
dvander@1203
  2876
**
dvander@1203
  2877
** If the specified column is "rowid", "oid" or "_rowid_" and an 
dvander@1203
  2878
** INTEGER PRIMARY KEY column has been explicitly declared, then the output 
dvander@1203
  2879
** parameters are set for the explicitly declared column. If there is no
dvander@1203
  2880
** explicitly declared IPK column, then the output parameters are set as 
dvander@1203
  2881
** follows:
dvander@1203
  2882
**
dvander@1203
  2883
** <pre>
dvander@1203
  2884
**     data type: "INTEGER"
dvander@1203
  2885
**     collation sequence: "BINARY"
dvander@1203
  2886
**     not null: 0
dvander@1203
  2887
**     primary key: 1
dvander@1203
  2888
**     auto increment: 0
dvander@1203
  2889
** </pre>
dvander@1203
  2890
**
dvander@1203
  2891
** This function may load one or more schemas from database files. If an
dvander@1203
  2892
** error occurs during this process, or if the requested table or column
dvander@1203
  2893
** cannot be found, an SQLITE error code is returned and an error message
dvander@1203
  2894
** left in the database handle (to be retrieved using sqlite3_errmsg()).
dvander@1203
  2895
**
dvander@1203
  2896
** This API is only available if the library was compiled with the
dvander@1203
  2897
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
dvander@1203
  2898
*/
dvander@1203
  2899
int sqlite3_table_column_metadata(
dvander@1203
  2900
  sqlite3 *db,                /* Connection handle */
dvander@1203
  2901
  const char *zDbName,        /* Database name or NULL */
dvander@1203
  2902
  const char *zTableName,     /* Table name */
dvander@1203
  2903
  const char *zColumnName,    /* Column name */
dvander@1203
  2904
  char const **pzDataType,    /* OUTPUT: Declared data type */
dvander@1203
  2905
  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
dvander@1203
  2906
  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
dvander@1203
  2907
  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
dvander@1645
  2908
  int *pAutoinc               /* OUTPUT: True if column is auto-increment */
dvander@1203
  2909
);
dvander@1203
  2910
dvander@1203
  2911
/*
dvander@1203
  2912
** CAPI3REF: Load An Extension
dvander@1203
  2913
**
dvander@1203
  2914
** Attempt to load an SQLite extension library contained in the file
dvander@1203
  2915
** zFile.  The entry point is zProc.  zProc may be 0 in which case the
dvander@1203
  2916
** name of the entry point defaults to "sqlite3_extension_init".
dvander@1203
  2917
**
dvander@1203
  2918
** Return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
dvander@1203
  2919
**
dvander@1203
  2920
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
dvander@1203
  2921
** error message text.  The calling function should free this memory
dvander@1203
  2922
** by calling [sqlite3_free()].
dvander@1203
  2923
**
dvander@1203
  2924
** Extension loading must be enabled using [sqlite3_enable_load_extension()]
dvander@1203
  2925
** prior to calling this API or an error will be returned.
dvander@1203
  2926
*/
dvander@1203
  2927
int sqlite3_load_extension(
dvander@1203
  2928
  sqlite3 *db,          /* Load the extension into this database connection */
dvander@1203
  2929
  const char *zFile,    /* Name of the shared library containing extension */
dvander@1203
  2930
  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
dvander@1203
  2931
  char **pzErrMsg       /* Put error message here if not 0 */
dvander@1203
  2932
);
dvander@1203
  2933
dvander@1203
  2934
/*
dvander@1203
  2935
** CAPI3REF:  Enable Or Disable Extension Loading
dvander@1203
  2936
**
dvander@1203
  2937
** So as not to open security holes in older applications that are
dvander@1203
  2938
** unprepared to deal with extension loading, and as a means of disabling
dvander@1203
  2939
** extension loading while evaluating user-entered SQL, the following
dvander@1203
  2940
** API is provided to turn the [sqlite3_load_extension()] mechanism on and
dvander@1203
  2941
** off.  It is off by default.  See ticket #1863.
dvander@1203
  2942
**
dvander@1203
  2943
** Call this routine with onoff==1 to turn extension loading on
dvander@1203
  2944
** and call it with onoff==0 to turn it back off again.
dvander@1203
  2945
*/
dvander@1203
  2946
int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
dvander@1203
  2947
dvander@1203
  2948
/*
dvander@1203
  2949
** CAPI3REF: Make Arrangements To Automatically Load An Extension
dvander@1203
  2950
**
dvander@1203
  2951
** Register an extension entry point that is automatically invoked
dvander@1203
  2952
** whenever a new database connection is opened using
dvander@1645
  2953
** [sqlite3_open()], [sqlite3_open16()], or [sqlite3_open_v2()].
dvander@1203
  2954
**
dvander@1203
  2955
** This API can be invoked at program startup in order to register
dvander@1203
  2956
** one or more statically linked extensions that will be available
dvander@1203
  2957
** to all new database connections.
dvander@1203
  2958
**
dvander@1203
  2959
** Duplicate extensions are detected so calling this routine multiple
dvander@1203
  2960
** times with the same extension is harmless.
dvander@1203
  2961
**
dvander@1203
  2962
** This routine stores a pointer to the extension in an array
dvander@1203
  2963
** that is obtained from malloc().  If you run a memory leak
dvander@1203
  2964
** checker on your program and it reports a leak because of this
dvander@1203
  2965
** array, then invoke [sqlite3_automatic_extension_reset()] prior
dvander@1203
  2966
** to shutdown to free the memory.
dvander@1203
  2967
**
dvander@1203
  2968
** Automatic extensions apply across all threads.
dvander@1203
  2969
**
dvander@1203
  2970
** This interface is experimental and is subject to change or
dvander@1203
  2971
** removal in future releases of SQLite.
dvander@1203
  2972
*/
dvander@1203
  2973
int sqlite3_auto_extension(void *xEntryPoint);
dvander@1203
  2974
dvander@1203
  2975
dvander@1203
  2976
/*
dvander@1203
  2977
** CAPI3REF: Reset Automatic Extension Loading
dvander@1203
  2978
**
dvander@1203
  2979
** Disable all previously registered automatic extensions.  This
dvander@1203
  2980
** routine undoes the effect of all prior [sqlite3_automatic_extension()]
dvander@1203
  2981
** calls.
dvander@1203
  2982
**
dvander@1203
  2983
** This call disabled automatic extensions in all threads.
dvander@1203
  2984
**
dvander@1203
  2985
** This interface is experimental and is subject to change or
dvander@1203
  2986
** removal in future releases of SQLite.
dvander@1203
  2987
*/
dvander@1203
  2988
void sqlite3_reset_auto_extension(void);
dvander@1203
  2989
dvander@1203
  2990
dvander@1203
  2991
/*
dvander@1203
  2992
****** EXPERIMENTAL - subject to change without notice **************
dvander@1203
  2993
**
dvander@1203
  2994
** The interface to the virtual-table mechanism is currently considered
dvander@1203
  2995
** to be experimental.  The interface might change in incompatible ways.
dvander@1203
  2996
** If this is a problem for you, do not use the interface at this time.
dvander@1203
  2997
**
dvander@1203
  2998
** When the virtual-table mechanism stablizes, we will declare the
dvander@1203
  2999
** interface fixed, support it indefinitely, and remove this comment.
dvander@1203
  3000
*/
dvander@1203
  3001
dvander@1203
  3002
/*
dvander@1203
  3003
** Structures used by the virtual table interface
dvander@1203
  3004
*/
dvander@1203
  3005
typedef struct sqlite3_vtab sqlite3_vtab;
dvander@1203
  3006
typedef struct sqlite3_index_info sqlite3_index_info;
dvander@1203
  3007
typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
dvander@1203
  3008
typedef struct sqlite3_module sqlite3_module;
dvander@1203
  3009
dvander@1203
  3010
/*
dvander@1203
  3011
** A module is a class of virtual tables.  Each module is defined
dvander@1203
  3012
** by an instance of the following structure.  This structure consists
dvander@1203
  3013
** mostly of methods for the module.
dvander@1203
  3014
*/
dvander@1203
  3015
struct sqlite3_module {
dvander@1203
  3016
  int iVersion;
dvander@1203
  3017
  int (*xCreate)(sqlite3*, void *pAux,
dvander@1203
  3018
               int argc, const char *const*argv,
dvander@1203
  3019
               sqlite3_vtab **ppVTab, char**);
dvander@1203
  3020
  int (*xConnect)(sqlite3*, void *pAux,
dvander@1203
  3021
               int argc, const char *const*argv,
dvander@1203
  3022
               sqlite3_vtab **ppVTab, char**);
dvander@1203
  3023
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
dvander@1203
  3024
  int (*xDisconnect)(sqlite3_vtab *pVTab);
dvander@1203
  3025
  int (*xDestroy)(sqlite3_vtab *pVTab);
dvander@1203
  3026
  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
dvander@1203
  3027
  int (*xClose)(sqlite3_vtab_cursor*);
dvander@1203
  3028
  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
dvander@1203
  3029
                int argc, sqlite3_value **argv);
dvander@1203
  3030
  int (*xNext)(sqlite3_vtab_cursor*);
dvander@1203
  3031
  int (*xEof)(sqlite3_vtab_cursor*);
dvander@1203
  3032
  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
dvander@1645
  3033
  int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
dvander@1645
  3034
  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
dvander@1203
  3035
  int (*xBegin)(sqlite3_vtab *pVTab);
dvander@1203
  3036
  int (*xSync)(sqlite3_vtab *pVTab);
dvander@1203
  3037
  int (*xCommit)(sqlite3_vtab *pVTab);
dvander@1203
  3038
  int (*xRollback)(sqlite3_vtab *pVTab);
dvander@1203
  3039
  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
dvander@1203
  3040
                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  3041
                       void **ppArg);
dvander@1203
  3042
dvander@1203
  3043
  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
dvander@1203
  3044
};
dvander@1203
  3045
dvander@1203
  3046
/*
dvander@1203
  3047
** The sqlite3_index_info structure and its substructures is used to
dvander@1203
  3048
** pass information into and receive the reply from the xBestIndex
dvander@1203
  3049
** method of an sqlite3_module.  The fields under **Inputs** are the
dvander@1203
  3050
** inputs to xBestIndex and are read-only.  xBestIndex inserts its
dvander@1203
  3051
** results into the **Outputs** fields.
dvander@1203
  3052
**
dvander@1203
  3053
** The aConstraint[] array records WHERE clause constraints of the
dvander@1203
  3054
** form:
dvander@1203
  3055
**
dvander@1203
  3056
**         column OP expr
dvander@1203
  3057
**
dvander@1203
  3058
** Where OP is =, <, <=, >, or >=.  The particular operator is stored
dvander@1203
  3059
** in aConstraint[].op.  The index of the column is stored in 
dvander@1203
  3060
** aConstraint[].iColumn.  aConstraint[].usable is TRUE if the
dvander@1203
  3061
** expr on the right-hand side can be evaluated (and thus the constraint
dvander@1203
  3062
** is usable) and false if it cannot.
dvander@1203
  3063
**
dvander@1203
  3064
** The optimizer automatically inverts terms of the form "expr OP column"
dvander@1645
  3065
** and makes other simplifications to the WHERE clause in an attempt to
dvander@1203
  3066
** get as many WHERE clause terms into the form shown above as possible.
dvander@1203
  3067
** The aConstraint[] array only reports WHERE clause terms in the correct
dvander@1203
  3068
** form that refer to the particular virtual table being queried.
dvander@1203
  3069
**
dvander@1203
  3070
** Information about the ORDER BY clause is stored in aOrderBy[].
dvander@1203
  3071
** Each term of aOrderBy records a column of the ORDER BY clause.
dvander@1203
  3072
**
dvander@1203
  3073
** The xBestIndex method must fill aConstraintUsage[] with information
dvander@1203
  3074
** about what parameters to pass to xFilter.  If argvIndex>0 then
dvander@1203
  3075
** the right-hand side of the corresponding aConstraint[] is evaluated
dvander@1203
  3076
** and becomes the argvIndex-th entry in argv.  If aConstraintUsage[].omit
dvander@1203
  3077
** is true, then the constraint is assumed to be fully handled by the
dvander@1203
  3078
** virtual table and is not checked again by SQLite.
dvander@1203
  3079
**
dvander@1203
  3080
** The idxNum and idxPtr values are recorded and passed into xFilter.
dvander@1203
  3081
** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
dvander@1203
  3082
**
dvander@1203
  3083
** The orderByConsumed means that output from xFilter will occur in
dvander@1203
  3084
** the correct order to satisfy the ORDER BY clause so that no separate
dvander@1203
  3085
** sorting step is required.
dvander@1203
  3086
**
dvander@1203
  3087
** The estimatedCost value is an estimate of the cost of doing the
dvander@1203
  3088
** particular lookup.  A full scan of a table with N entries should have
dvander@1203
  3089
** a cost of N.  A binary search of a table of N entries should have a
dvander@1203
  3090
** cost of approximately log(N).
dvander@1203
  3091
*/
dvander@1203
  3092
struct sqlite3_index_info {
dvander@1203
  3093
  /* Inputs */
dvander@1645
  3094
  int nConstraint;           /* Number of entries in aConstraint */
dvander@1645
  3095
  struct sqlite3_index_constraint {
dvander@1203
  3096
     int iColumn;              /* Column on left-hand side of constraint */
dvander@1203
  3097
     unsigned char op;         /* Constraint operator */
dvander@1203
  3098
     unsigned char usable;     /* True if this constraint is usable */
dvander@1203
  3099
     int iTermOffset;          /* Used internally - xBestIndex should ignore */
dvander@1645
  3100
  } *aConstraint;            /* Table of WHERE clause constraints */
dvander@1645
  3101
  int nOrderBy;              /* Number of terms in the ORDER BY clause */
dvander@1645
  3102
  struct sqlite3_index_orderby {
dvander@1203
  3103
     int iColumn;              /* Column number */
dvander@1203
  3104
     unsigned char desc;       /* True for DESC.  False for ASC. */
dvander@1645
  3105
  } *aOrderBy;               /* The ORDER BY clause */
dvander@1203
  3106
dvander@1203
  3107
  /* Outputs */
dvander@1203
  3108
  struct sqlite3_index_constraint_usage {
dvander@1203
  3109
    int argvIndex;           /* if >0, constraint is part of argv to xFilter */
dvander@1203
  3110
    unsigned char omit;      /* Do not code a test for this constraint */
dvander@1645
  3111
  } *aConstraintUsage;
dvander@1203
  3112
  int idxNum;                /* Number used to identify the index */
dvander@1203
  3113
  char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
dvander@1203
  3114
  int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
dvander@1203
  3115
  int orderByConsumed;       /* True if output is already ordered */
dvander@1203
  3116
  double estimatedCost;      /* Estimated cost of using this index */
dvander@1203
  3117
};
dvander@1203
  3118
#define SQLITE_INDEX_CONSTRAINT_EQ    2
dvander@1203
  3119
#define SQLITE_INDEX_CONSTRAINT_GT    4
dvander@1203
  3120
#define SQLITE_INDEX_CONSTRAINT_LE    8
dvander@1203
  3121
#define SQLITE_INDEX_CONSTRAINT_LT    16
dvander@1203
  3122
#define SQLITE_INDEX_CONSTRAINT_GE    32
dvander@1203
  3123
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
dvander@1203
  3124
dvander@1203
  3125
/*
dvander@1203
  3126
** This routine is used to register a new module name with an SQLite
dvander@1203
  3127
** connection.  Module names must be registered before creating new
dvander@1203
  3128
** virtual tables on the module, or before using preexisting virtual
dvander@1203
  3129
** tables of the module.
dvander@1203
  3130
*/
dvander@1203
  3131
int sqlite3_create_module(
dvander@1203
  3132
  sqlite3 *db,               /* SQLite connection to register module with */
dvander@1203
  3133
  const char *zName,         /* Name of the module */
dvander@1203
  3134
  const sqlite3_module *,    /* Methods for the module */
dvander@1203
  3135
  void *                     /* Client data for xCreate/xConnect */
dvander@1203
  3136
);
dvander@1203
  3137
dvander@1203
  3138
/*
dvander@1203
  3139
** This routine is identical to the sqlite3_create_module() method above,
dvander@1203
  3140
** except that it allows a destructor function to be specified. It is
dvander@1203
  3141
** even more experimental than the rest of the virtual tables API.
dvander@1203
  3142
*/
dvander@1203
  3143
int sqlite3_create_module_v2(
dvander@1203
  3144
  sqlite3 *db,               /* SQLite connection to register module with */
dvander@1203
  3145
  const char *zName,         /* Name of the module */
dvander@1203
  3146
  const sqlite3_module *,    /* Methods for the module */
dvander@1203
  3147
  void *,                    /* Client data for xCreate/xConnect */
dvander@1203
  3148
  void(*xDestroy)(void*)     /* Module destructor function */
dvander@1203
  3149
);
dvander@1203
  3150
dvander@1203
  3151
/*
dvander@1203
  3152
** Every module implementation uses a subclass of the following structure
dvander@1203
  3153
** to describe a particular instance of the module.  Each subclass will
dvander@1645
  3154
** be tailored to the specific needs of the module implementation.   The
dvander@1203
  3155
** purpose of this superclass is to define certain fields that are common
dvander@1203
  3156
** to all module implementations.
dvander@1203
  3157
**
dvander@1203
  3158
** Virtual tables methods can set an error message by assigning a
dvander@1203
  3159
** string obtained from sqlite3_mprintf() to zErrMsg.  The method should
dvander@1203
  3160
** take care that any prior string is freed by a call to sqlite3_free()
dvander@1203
  3161
** prior to assigning a new string to zErrMsg.  After the error message
dvander@1203
  3162
** is delivered up to the client application, the string will be automatically
dvander@1203
  3163
** freed by sqlite3_free() and the zErrMsg field will be zeroed.  Note
dvander@1203
  3164
** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
dvander@1203
  3165
** since virtual tables are commonly implemented in loadable extensions which
dvander@1203
  3166
** do not have access to sqlite3MPrintf() or sqlite3Free().
dvander@1203
  3167
*/
dvander@1203
  3168
struct sqlite3_vtab {
dvander@1203
  3169
  const sqlite3_module *pModule;  /* The module for this virtual table */
dvander@1203
  3170
  int nRef;                       /* Used internally */
dvander@1203
  3171
  char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
dvander@1203
  3172
  /* Virtual table implementations will typically add additional fields */
dvander@1203
  3173
};
dvander@1203
  3174
dvander@1203
  3175
/* Every module implementation uses a subclass of the following structure
dvander@1203
  3176
** to describe cursors that point into the virtual table and are used
dvander@1203
  3177
** to loop through the virtual table.  Cursors are created using the
dvander@1203
  3178
** xOpen method of the module.  Each module implementation will define
dvander@1203
  3179
** the content of a cursor structure to suit its own needs.
dvander@1203
  3180
**
dvander@1203
  3181
** This superclass exists in order to define fields of the cursor that
dvander@1203
  3182
** are common to all implementations.
dvander@1203
  3183
*/
dvander@1203
  3184
struct sqlite3_vtab_cursor {
dvander@1203
  3185
  sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
dvander@1203
  3186
  /* Virtual table implementations will typically add additional fields */
dvander@1203
  3187
};
dvander@1203
  3188
dvander@1203
  3189
/*
dvander@1203
  3190
** The xCreate and xConnect methods of a module use the following API
dvander@1203
  3191
** to declare the format (the names and datatypes of the columns) of
dvander@1203
  3192
** the virtual tables they implement.
dvander@1203
  3193
*/
dvander@1203
  3194
int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
dvander@1203
  3195
dvander@1203
  3196
/*
dvander@1203
  3197
** Virtual tables can provide alternative implementations of functions
dvander@1203
  3198
** using the xFindFunction method.  But global versions of those functions
dvander@1203
  3199
** must exist in order to be overloaded.
dvander@1203
  3200
**
dvander@1203
  3201
** This API makes sure a global version of a function with a particular
dvander@1203
  3202
** name and number of parameters exists.  If no such function exists
dvander@1203
  3203
** before this API is called, a new function is created.  The implementation
dvander@1203
  3204
** of the new function always causes an exception to be thrown.  So
dvander@1203
  3205
** the new function is not good for anything by itself.  Its only
dvander@1203
  3206
** purpose is to be a place-holder function that can be overloaded
dvander@1203
  3207
** by virtual tables.
dvander@1203
  3208
**
dvander@1203
  3209
** This API should be considered part of the virtual table interface,
dvander@1203
  3210
** which is experimental and subject to change.
dvander@1203
  3211
*/
dvander@1203
  3212
int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
dvander@1203
  3213
dvander@1203
  3214
/*
dvander@1203
  3215
** The interface to the virtual-table mechanism defined above (back up
dvander@1203
  3216
** to a comment remarkably similar to this one) is currently considered
dvander@1203
  3217
** to be experimental.  The interface might change in incompatible ways.
dvander@1203
  3218
** If this is a problem for you, do not use the interface at this time.
dvander@1203
  3219
**
dvander@1645
  3220
** When the virtual-table mechanism stabilizes, we will declare the
dvander@1203
  3221
** interface fixed, support it indefinitely, and remove this comment.
dvander@1203
  3222
**
dvander@1203
  3223
****** EXPERIMENTAL - subject to change without notice **************
dvander@1203
  3224
*/
dvander@1203
  3225
dvander@1203
  3226
/*
dvander@1203
  3227
** CAPI3REF: A Handle To An Open BLOB
dvander@1203
  3228
**
dvander@1203
  3229
** An instance of the following opaque structure is used to 
dvander@1203
  3230
** represent an blob-handle.  A blob-handle is created by
dvander@1203
  3231
** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()].
dvander@1203
  3232
** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
dvander@1203
  3233
** can be used to read or write small subsections of the blob.
dvander@1645
  3234
** The [sqlite3_blob_bytes()] interface returns the size of the
dvander@1203
  3235
** blob in bytes.
dvander@1203
  3236
*/
dvander@1203
  3237
typedef struct sqlite3_blob sqlite3_blob;
dvander@1203
  3238
dvander@1203
  3239
/*
dvander@1203
  3240
** CAPI3REF: Open A BLOB For Incremental I/O
dvander@1203
  3241
**
dvander@1203
  3242
** Open a handle to the blob located in row iRow,, column zColumn, 
dvander@1203
  3243
** table zTable in database zDb. i.e. the same blob that would
dvander@1203
  3244
** be selected by:
dvander@1203
  3245
**
dvander@1203
  3246
** <pre>
dvander@1203
  3247
**     SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
dvander@1203
  3248
** </pre>
dvander@1203
  3249
**
dvander@1203
  3250
** If the flags parameter is non-zero, the blob is opened for 
dvander@1203
  3251
** read and write access. If it is zero, the blob is opened for read 
dvander@1203
  3252
** access.
dvander@1203
  3253
**
dvander@1203
  3254
** On success, [SQLITE_OK] is returned and the new 
dvander@1203
  3255
** [sqlite3_blob | blob handle] is written to *ppBlob.
dvander@1203
  3256
** Otherwise an error code is returned and 
dvander@1203
  3257
** any value written to *ppBlob should not be used by the caller.
dvander@1203
  3258
** This function sets the database-handle error code and message
dvander@1203
  3259
** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
dvander@1203
  3260
*/
dvander@1203
  3261
int sqlite3_blob_open(
dvander@1203
  3262
  sqlite3*,
dvander@1203
  3263
  const char *zDb,
dvander@1203
  3264
  const char *zTable,
dvander@1203
  3265
  const char *zColumn,
dvander@1645
  3266
  sqlite3_int64 iRow,
dvander@1203
  3267
  int flags,
dvander@1203
  3268
  sqlite3_blob **ppBlob
dvander@1203
  3269
);
dvander@1203
  3270
dvander@1203
  3271
/*
dvander@1203
  3272
** CAPI3REF:  Close A BLOB Handle
dvander@1203
  3273
**
dvander@1203
  3274
** Close an open [sqlite3_blob | blob handle].
dvander@1203
  3275
*/
dvander@1203
  3276
int sqlite3_blob_close(sqlite3_blob *);
dvander@1203
  3277
dvander@1203
  3278
/*
dvander@1203
  3279
** CAPI3REF:  Return The Size Of An Open BLOB
dvander@1203
  3280
**
dvander@1203
  3281
** Return the size in bytes of the blob accessible via the open 
dvander@1203
  3282
** [sqlite3_blob | blob-handle] passed as an argument.
dvander@1203
  3283
*/
dvander@1203
  3284
int sqlite3_blob_bytes(sqlite3_blob *);
dvander@1203
  3285
dvander@1203
  3286
/*
dvander@1203
  3287
** CAPI3REF:  Read Data From A BLOB Incrementally
dvander@1203
  3288
**
dvander@1203
  3289
** This function is used to read data from an open 
dvander@1203
  3290
** [sqlite3_blob | blob-handle] into a caller supplied buffer.
dvander@1203
  3291
** n bytes of data are copied into buffer
dvander@1203
  3292
** z from the open blob, starting at offset iOffset.
dvander@1203
  3293
**
dvander@1203
  3294
** On success, SQLITE_OK is returned. Otherwise, an 
dvander@1203
  3295
** [SQLITE_ERROR | SQLite error code] or an
dvander@1203
  3296
** [SQLITE_IOERR_READ | extended error code] is returned.
dvander@1203
  3297
*/
dvander@1203
  3298
int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset);
dvander@1203
  3299
dvander@1203
  3300
/*
dvander@1203
  3301
** CAPI3REF:  Write Data Into A BLOB Incrementally
dvander@1203
  3302
**
dvander@1203
  3303
** This function is used to write data into an open 
dvander@1203
  3304
** [sqlite3_blob | blob-handle] from a user supplied buffer.
dvander@1203
  3305
** n bytes of data are copied from the buffer
dvander@1203
  3306
** pointed to by z into the open blob, starting at offset iOffset.
dvander@1203
  3307
**
dvander@1203
  3308
** If the [sqlite3_blob | blob-handle] passed as the first argument
dvander@1203
  3309
** was not opened for writing (the flags parameter to [sqlite3_blob_open()]
dvander@1203
  3310
*** was zero), this function returns [SQLITE_READONLY].
dvander@1203
  3311
**
dvander@1203
  3312
** This function may only modify the contents of the blob, it is
dvander@1203
  3313
** not possible to increase the size of a blob using this API. If
dvander@1203
  3314
** offset iOffset is less than n bytes from the end of the blob, 
dvander@1203
  3315
** [SQLITE_ERROR] is returned and no data is written.
dvander@1203
  3316
**
dvander@1203
  3317
** On success, SQLITE_OK is returned. Otherwise, an 
dvander@1203
  3318
** [SQLITE_ERROR | SQLite error code] or an
dvander@1203
  3319
** [SQLITE_IOERR_READ | extended error code] is returned.
dvander@1203
  3320
*/
dvander@1203
  3321
int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
dvander@1203
  3322
dvander@1203
  3323
/*
dvander@1645
  3324
** CAPI3REF:  Virtual File System Objects
dvander@1645
  3325
**
dvander@1645
  3326
** A virtual filesystem (VFS) is an [sqlite3_vfs] object
dvander@1645
  3327
** that SQLite uses to interact
dvander@1645
  3328
** with the underlying operating system.  Most builds come with a
dvander@1645
  3329
** single default VFS that is appropriate for the host computer.
dvander@1645
  3330
** New VFSes can be registered and existing VFSes can be unregistered.
dvander@1645
  3331
** The following interfaces are provided.
dvander@1645
  3332
**
dvander@1645
  3333
** The sqlite3_vfs_find() interface returns a pointer to a VFS given its
dvander@1645
  3334
** name.  Names are case sensitive.  If there is no match, a NULL
dvander@1645
  3335
** pointer is returned.  If zVfsName is NULL then the default 
dvander@1645
  3336
** VFS is returned.
dvander@1645
  3337
**
dvander@1645
  3338
** New VFSes are registered with sqlite3_vfs_register().  Each
dvander@1645
  3339
** new VFS becomes the default VFS if the makeDflt flag is set.
dvander@1645
  3340
** The same VFS can be registered multiple times without injury.
dvander@1645
  3341
** To make an existing VFS into the default VFS, register it again
dvander@1645
  3342
** with the makeDflt flag set.  If two different VFSes with the
dvander@1645
  3343
** same name are registered, the behavior is undefined.  If a
dvander@1645
  3344
** VFS is registered with a name that is NULL or an empty string,
dvander@1645
  3345
** then the behavior is undefined.
dvander@1645
  3346
** 
dvander@1645
  3347
** Unregister a VFS with the sqlite3_vfs_unregister() interface.
dvander@1645
  3348
** If the default VFS is unregistered, another VFS is chosen as
dvander@1645
  3349
** the default.  The choice for the new VFS is arbitrary.
dvander@1645
  3350
*/
dvander@1645
  3351
sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
dvander@1645
  3352
int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
dvander@1645
  3353
int sqlite3_vfs_unregister(sqlite3_vfs*);
dvander@1645
  3354
dvander@1645
  3355
/*
dvander@1645
  3356
** CAPI3REF: Mutexes
dvander@1645
  3357
**
dvander@1645
  3358
** The SQLite core uses these routines for thread
dvander@1645
  3359
** synchronization.  Though they are intended for internal
dvander@1645
  3360
** use by SQLite, code that links against SQLite is
dvander@1645
  3361
** permitted to use any of these routines.
dvander@1645
  3362
**
dvander@1645
  3363
** The SQLite source code contains multiple implementations 
dvander@1645
  3364
** of these mutex routines.  An appropriate implementation
dvander@1645
  3365
** is selected automatically at compile-time.  The following
dvander@1645
  3366
** implementations are available in the SQLite core:
dvander@1645
  3367
**
dvander@1645
  3368
** <ul>
dvander@1645
  3369
** <li>   SQLITE_MUTEX_OS2
dvander@1645
  3370
** <li>   SQLITE_MUTEX_PTHREAD
dvander@1645
  3371
** <li>   SQLITE_MUTEX_W32
dvander@1645
  3372
** <li>   SQLITE_MUTEX_NOOP
dvander@1645
  3373
** </ul>
dvander@1645
  3374
**
dvander@1645
  3375
** The SQLITE_MUTEX_NOOP implementation is a set of routines 
dvander@1645
  3376
** that does no real locking and is appropriate for use in 
dvander@1645
  3377
** a single-threaded application.  The SQLITE_MUTEX_OS2,
dvander@1645
  3378
** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
dvander@1645
  3379
** are appropriate for use on os/2, unix, and windows.
dvander@1645
  3380
** 
dvander@1645
  3381
** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
dvander@1645
  3382
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
dvander@1645
  3383
** implementation is included with the library.  The
dvander@1645
  3384
** mutex interface routines defined here become external
dvander@1645
  3385
** references in the SQLite library for which implementations
dvander@1645
  3386
** must be provided by the application.  This facility allows an
dvander@1645
  3387
** application that links against SQLite to provide its own mutex
dvander@1645
  3388
** implementation without having to modify the SQLite core.
dvander@1645
  3389
**
dvander@1645
  3390
** The sqlite3_mutex_alloc() routine allocates a new
dvander@1645
  3391
** mutex and returns a pointer to it.  If it returns NULL
dvander@1645
  3392
** that means that a mutex could not be allocated.  SQLite
dvander@1645
  3393
** will unwind its stack and return an error.  The argument
dvander@1645
  3394
** to sqlite3_mutex_alloc() is one of these integer constants:
dvander@1645
  3395
**
dvander@1645
  3396
** <ul>
dvander@1645
  3397
** <li>  SQLITE_MUTEX_FAST
dvander@1645
  3398
** <li>  SQLITE_MUTEX_RECURSIVE
dvander@1645
  3399
** <li>  SQLITE_MUTEX_STATIC_MASTER
dvander@1645
  3400
** <li>  SQLITE_MUTEX_STATIC_MEM
dvander@1645
  3401
** <li>  SQLITE_MUTEX_STATIC_MEM2
dvander@1645
  3402
** <li>  SQLITE_MUTEX_STATIC_PRNG
dvander@1645
  3403
** <li>  SQLITE_MUTEX_STATIC_LRU
dvander@1645
  3404
** </ul>
dvander@1645
  3405
**
dvander@1645
  3406
** The first two constants cause sqlite3_mutex_alloc() to create
dvander@1645
  3407
** a new mutex.  The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
dvander@1645
  3408
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
dvander@1645
  3409
** The mutex implementation does not need to make a distinction
dvander@1645
  3410
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
dvander@1645
  3411
** not want to.  But SQLite will only request a recursive mutex in
dvander@1645
  3412
** cases where it really needs one.  If a faster non-recursive mutex
dvander@1645
  3413
** implementation is available on the host platform, the mutex subsystem
dvander@1645
  3414
** might return such a mutex in response to SQLITE_MUTEX_FAST.
dvander@1645
  3415
**
dvander@1645
  3416
** The other allowed parameters to sqlite3_mutex_alloc() each return
dvander@1645
  3417
** a pointer to a static preexisting mutex.  Four static mutexes are
dvander@1645
  3418
** used by the current version of SQLite.  Future versions of SQLite
dvander@1645
  3419
** may add additional static mutexes.  Static mutexes are for internal
dvander@1645
  3420
** use by SQLite only.  Applications that use SQLite mutexes should
dvander@1645
  3421
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
dvander@1645
  3422
** SQLITE_MUTEX_RECURSIVE.
dvander@1645
  3423
**
dvander@1645
  3424
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
dvander@1645
  3425
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
dvander@1645
  3426
** returns a different mutex on every call.  But for the static 
dvander@1645
  3427
** mutex types, the same mutex is returned on every call that has
dvander@1645
  3428
** the same type number.
dvander@1645
  3429
**
dvander@1645
  3430
** The sqlite3_mutex_free() routine deallocates a previously
dvander@1645
  3431
** allocated dynamic mutex.  SQLite is careful to deallocate every
dvander@1645
  3432
** dynamic mutex that it allocates.  The dynamic mutexes must not be in 
dvander@1645
  3433
** use when they are deallocated.  Attempting to deallocate a static
dvander@1645
  3434
** mutex results in undefined behavior.  SQLite never deallocates
dvander@1645
  3435
** a static mutex.
dvander@1645
  3436
**
dvander@1645
  3437
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
dvander@1645
  3438
** to enter a mutex.  If another thread is already within the mutex,
dvander@1645
  3439
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
dvander@1645
  3440
** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
dvander@1645
  3441
** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
dvander@1645
  3442
** be entered multiple times by the same thread.  In such cases the,
dvander@1645
  3443
** mutex must be exited an equal number of times before another thread
dvander@1645
  3444
** can enter.  If the same thread tries to enter any other kind of mutex
dvander@1645
  3445
** more than once, the behavior is undefined.   SQLite will never exhibit
dvander@1645
  3446
** such behavior in its own use of mutexes.
dvander@1645
  3447
**
dvander@1645
  3448
** Some systems (ex: windows95) do not the operation implemented by
dvander@1645
  3449
** sqlite3_mutex_try().  On those systems, sqlite3_mutex_try() will
dvander@1645
  3450
** always return SQLITE_BUSY.  The SQLite core only ever uses
dvander@1645
  3451
** sqlite3_mutex_try() as an optimization so this is acceptable behavior.
dvander@1645
  3452
**
dvander@1645
  3453
** The sqlite3_mutex_leave() routine exits a mutex that was
dvander@1645
  3454
** previously entered by the same thread.  The behavior
dvander@1645
  3455
** is undefined if the mutex is not currently entered by the
dvander@1645
  3456
** calling thread or is not currently allocated.  SQLite will
dvander@1645
  3457
** never do either.
dvander@1645
  3458
**
dvander@1645
  3459
** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
dvander@1645
  3460
*/
dvander@1645
  3461
sqlite3_mutex *sqlite3_mutex_alloc(int);
dvander@1645
  3462
void sqlite3_mutex_free(sqlite3_mutex*);
dvander@1645
  3463
void sqlite3_mutex_enter(sqlite3_mutex*);
dvander@1645
  3464
int sqlite3_mutex_try(sqlite3_mutex*);
dvander@1645
  3465
void sqlite3_mutex_leave(sqlite3_mutex*);
dvander@1645
  3466
dvander@1645
  3467
/*
dvander@1645
  3468
** CAPI3REF: Mutex Verifcation Routines
dvander@1645
  3469
**
dvander@1645
  3470
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
dvander@1645
  3471
** are intended for use inside assert() statements.  The SQLite core
dvander@1645
  3472
** never uses these routines except inside an assert() and applications
dvander@1645
  3473
** are advised to follow the lead of the core.  The core only
dvander@1645
  3474
** provides implementations for these routines when it is compiled
dvander@1645
  3475
** with the SQLITE_DEBUG flag.  External mutex implementations
dvander@1645
  3476
** are only required to provide these routines if SQLITE_DEBUG is
dvander@1645
  3477
** defined and if NDEBUG is not defined.
dvander@1645
  3478
**
dvander@1645
  3479
** These routines should return true if the mutex in their argument
dvander@1645
  3480
** is held or not held, respectively, by the calling thread.
dvander@1645
  3481
**
dvander@1645
  3482
** The implementation is not required to provided versions of these
dvander@1645
  3483
** routines that actually work.
dvander@1645
  3484
** If the implementation does not provide working
dvander@1645
  3485
** versions of these routines, it should at least provide stubs
dvander@1645
  3486
** that always return true so that one does not get spurious
dvander@1645
  3487
** assertion failures.
dvander@1645
  3488
**
dvander@1645
  3489
** If the argument to sqlite3_mutex_held() is a NULL pointer then
dvander@1645
  3490
** the routine should return 1.  This seems counter-intuitive since
dvander@1645
  3491
** clearly the mutex cannot be held if it does not exist.  But the
dvander@1645
  3492
** the reason the mutex does not exist is because the build is not
dvander@1645
  3493
** using mutexes.  And we do not want the assert() containing the
dvander@1645
  3494
** call to sqlite3_mutex_held() to fail, so a non-zero return is
dvander@1645
  3495
** the appropriate thing to do.  The sqlite3_mutex_notheld() 
dvander@1645
  3496
** interface should also return 1 when given a NULL pointer.
dvander@1645
  3497
*/
dvander@1645
  3498
int sqlite3_mutex_held(sqlite3_mutex*);
dvander@1645
  3499
int sqlite3_mutex_notheld(sqlite3_mutex*);
dvander@1645
  3500
dvander@1645
  3501
/*
dvander@1645
  3502
** CAPI3REF: Mutex Types
dvander@1645
  3503
**
dvander@1645
  3504
** The [sqlite3_mutex_alloc()] interface takes a single argument
dvander@1645
  3505
** which is one of these integer constants.
dvander@1645
  3506
*/
dvander@1645
  3507
#define SQLITE_MUTEX_FAST             0
dvander@1645
  3508
#define SQLITE_MUTEX_RECURSIVE        1
dvander@1645
  3509
#define SQLITE_MUTEX_STATIC_MASTER    2
dvander@1645
  3510
#define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
dvander@1645
  3511
#define SQLITE_MUTEX_STATIC_MEM2      4  /* sqlite3_release_memory() */
dvander@1645
  3512
#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
dvander@1645
  3513
#define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
dvander@1645
  3514
dvander@1645
  3515
/*
dvander@1645
  3516
** CAPI3REF: Low-Level Control Of Database Files
dvander@1645
  3517
**
dvander@1645
  3518
** The [sqlite3_file_control()] interface makes a direct call to the
dvander@1645
  3519
** xFileControl method for the [sqlite3_io_methods] object associated
dvander@1645
  3520
** with a particular database identified by the second argument.  The
dvander@1645
  3521
** name of the database is the name assigned to the database by the
dvander@1645
  3522
** <a href="lang_attach.html">ATTACH</a> SQL command that opened the
dvander@1645
  3523
** database.  To control the main database file, use the name "main"
dvander@1645
  3524
** or a NULL pointer.  The third and fourth parameters to this routine
dvander@1645
  3525
** are passed directly through to the second and third parameters of
dvander@1645
  3526
** the xFileControl method.  The return value of the xFileControl
dvander@1645
  3527
** method becomes the return value of this routine.
dvander@1645
  3528
**
dvander@1645
  3529
** If the second parameter (zDbName) does not match the name of any
dvander@1645
  3530
** open database file, then SQLITE_ERROR is returned.  This error
dvander@1645
  3531
** code is not remembered and will not be recalled by [sqlite3_errcode()]
dvander@1645
  3532
** or [sqlite3_errmsg()].  The underlying xFileControl method might
dvander@1645
  3533
** also return SQLITE_ERROR.  There is no way to distinguish between
dvander@1645
  3534
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
dvander@1645
  3535
** xFileControl method.
dvander@1645
  3536
**
dvander@1645
  3537
** See also: [SQLITE_FCNTL_LOCKSTATE]
dvander@1645
  3538
*/
dvander@1645
  3539
int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
dvander@1645
  3540
dvander@1645
  3541
/*
dvander@1203
  3542
** Undo the hack that converts floating point types to integer for
dvander@1203
  3543
** builds on processors without floating point support.
dvander@1203
  3544
*/
dvander@1203
  3545
#ifdef SQLITE_OMIT_FLOATING_POINT
dvander@1203
  3546
# undef double
dvander@1203
  3547
#endif
dvander@1203
  3548
dvander@1203
  3549
#ifdef __cplusplus
dvander@1203
  3550
}  /* End of the 'extern "C"' block */
dvander@1203
  3551
#endif
dvander@1203
  3552
#endif