extensions/sqlite/sqlite-source/sqlite3.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 29 01:15:31 2007 +0000 (2007-07-29)
changeset 1203 633c25ce6405
child 1645 27307df4d711
permissions -rw-r--r--
initial import of sqlite extension
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@1203
    46
/*
dvander@1203
    47
** Make sure these symbols where not defined by some previous header
dvander@1203
    48
** file.
dvander@1203
    49
*/
dvander@1203
    50
#ifdef SQLITE_VERSION
dvander@1203
    51
# undef SQLITE_VERSION
dvander@1203
    52
#endif
dvander@1203
    53
#ifdef SQLITE_VERSION_NUMBER
dvander@1203
    54
# undef SQLITE_VERSION_NUMBER
dvander@1203
    55
#endif
dvander@1203
    56
dvander@1203
    57
/*
dvander@1203
    58
** CAPI3REF: Compile-Time Library Version Numbers
dvander@1203
    59
**
dvander@1203
    60
** The version of the SQLite library is contained in the sqlite3.h
dvander@1203
    61
** header file in a #define named SQLITE_VERSION.  The SQLITE_VERSION
dvander@1203
    62
** macro resolves to a string constant.
dvander@1203
    63
**
dvander@1203
    64
** The format of the version string is "X.Y.Z", where
dvander@1203
    65
** X is the major version number, Y is the minor version number and Z
dvander@1203
    66
** is the release number.  The X.Y.Z might be followed by "alpha" or "beta".
dvander@1203
    67
** For example "3.1.1beta".
dvander@1203
    68
**
dvander@1203
    69
** The X value is always 3 in SQLite.  The X value only changes when
dvander@1203
    70
** backwards compatibility is broken and we intend to never break
dvander@1203
    71
** backwards compatibility.  The Y value only changes when
dvander@1203
    72
** there are major feature enhancements that are forwards compatible
dvander@1203
    73
** but not backwards compatible.  The Z value is incremented with
dvander@1203
    74
** each release but resets back to 0 when Y is incremented.
dvander@1203
    75
**
dvander@1203
    76
** The SQLITE_VERSION_NUMBER is an integer with the value 
dvander@1203
    77
** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", 
dvander@1203
    78
** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
dvander@1203
    79
** version 3.1.1 or greater at compile time, programs may use the test 
dvander@1203
    80
** (SQLITE_VERSION_NUMBER>=3001001).
dvander@1203
    81
**
dvander@1203
    82
** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
dvander@1203
    83
*/
dvander@1203
    84
#define SQLITE_VERSION         "3.4.1"
dvander@1203
    85
#define SQLITE_VERSION_NUMBER 3004001
dvander@1203
    86
dvander@1203
    87
/*
dvander@1203
    88
** CAPI3REF: Run-Time Library Version Numbers
dvander@1203
    89
**
dvander@1203
    90
** These routines return values equivalent to the header constants
dvander@1203
    91
** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER].  The values returned
dvander@1203
    92
** by this routines should only be different from the header values
dvander@1203
    93
** if you compile your program using an sqlite3.h header from a
dvander@1203
    94
** different version of SQLite that the version of the library you
dvander@1203
    95
** link against.
dvander@1203
    96
**
dvander@1203
    97
** The sqlite3_version[] string constant contains the text of the
dvander@1203
    98
** [SQLITE_VERSION] string.  The sqlite3_libversion() function returns
dvander@1203
    99
** a poiner to the sqlite3_version[] string constant.  The function
dvander@1203
   100
** is provided for DLL users who can only access functions and not
dvander@1203
   101
** constants within the DLL.
dvander@1203
   102
*/
dvander@1203
   103
extern const char sqlite3_version[];
dvander@1203
   104
const char *sqlite3_libversion(void);
dvander@1203
   105
int sqlite3_libversion_number(void);
dvander@1203
   106
dvander@1203
   107
/*
dvander@1203
   108
** CAPI3REF: Database Connection Handle
dvander@1203
   109
**
dvander@1203
   110
** Each open SQLite database is represented by pointer to an instance of the
dvander@1203
   111
** opaque structure named "sqlite3".  It is useful to think of an sqlite3
dvander@1203
   112
** pointer as an object.  The [sqlite3_open] interface is its constructor
dvander@1203
   113
** and [sqlite3_close] is its destructor.  There are many other interfaces
dvander@1203
   114
** (such as [sqlite3_prepare_v2], [sqlite3_create_function], and
dvander@1203
   115
** [sqlite3_busy_timeout] to name but three) that are methods on this
dvander@1203
   116
** object.
dvander@1203
   117
*/
dvander@1203
   118
typedef struct sqlite3 sqlite3;
dvander@1203
   119
dvander@1203
   120
dvander@1203
   121
/*
dvander@1203
   122
** CAPI3REF: 64-Bit Integer Types
dvander@1203
   123
**
dvander@1203
   124
** Some compilers do not support the "long long" datatype.  So we have
dvander@1203
   125
** to do compiler-specific typedefs for 64-bit signed and unsigned integers.
dvander@1203
   126
**
dvander@1203
   127
** Many SQLite interface functions require a 64-bit integer arguments.
dvander@1203
   128
** Those interfaces are declared using this typedef.
dvander@1203
   129
*/
dvander@1203
   130
#ifdef SQLITE_INT64_TYPE
dvander@1203
   131
  typedef SQLITE_INT64_TYPE sqlite_int64;
dvander@1203
   132
  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
dvander@1203
   133
#elif defined(_MSC_VER) || defined(__BORLANDC__)
dvander@1203
   134
  typedef __int64 sqlite_int64;
dvander@1203
   135
  typedef unsigned __int64 sqlite_uint64;
dvander@1203
   136
#else
dvander@1203
   137
  typedef long long int sqlite_int64;
dvander@1203
   138
  typedef unsigned long long int sqlite_uint64;
dvander@1203
   139
#endif
dvander@1203
   140
dvander@1203
   141
/*
dvander@1203
   142
** If compiling for a processor that lacks floating point support,
dvander@1203
   143
** substitute integer for floating-point
dvander@1203
   144
*/
dvander@1203
   145
#ifdef SQLITE_OMIT_FLOATING_POINT
dvander@1203
   146
# define double sqlite_int64
dvander@1203
   147
#endif
dvander@1203
   148
dvander@1203
   149
/*
dvander@1203
   150
** CAPI3REF: Closing A Database Connection
dvander@1203
   151
**
dvander@1203
   152
** Call this function with a pointer to a structure that was previously
dvander@1203
   153
** returned from [sqlite3_open()] and the corresponding database will by
dvander@1203
   154
** closed.
dvander@1203
   155
**
dvander@1203
   156
** All SQL statements prepared using [sqlite3_prepare_v2()] or
dvander@1203
   157
** [sqlite3_prepare16_v2()] must be destroyed using [sqlite3_finalize()]
dvander@1203
   158
** before this routine is called. Otherwise, SQLITE_BUSY is returned and the
dvander@1203
   159
** database connection remains open.
dvander@1203
   160
*/
dvander@1203
   161
int sqlite3_close(sqlite3 *);
dvander@1203
   162
dvander@1203
   163
/*
dvander@1203
   164
** The type for a callback function.
dvander@1203
   165
** This is legacy and deprecated.  It is included for historical
dvander@1203
   166
** compatibility and is not documented.
dvander@1203
   167
*/
dvander@1203
   168
typedef int (*sqlite3_callback)(void*,int,char**, char**);
dvander@1203
   169
dvander@1203
   170
/*
dvander@1203
   171
** CAPI3REF: One-Step Query Execution Interface
dvander@1203
   172
**
dvander@1203
   173
** This interface is used to do a one-time evaluatation of zero
dvander@1203
   174
** or more SQL statements.  UTF-8 text of the SQL statements to
dvander@1203
   175
** be evaluted is passed in as the second parameter.  The statements
dvander@1203
   176
** are prepared one by one using [sqlite3_prepare()], evaluated
dvander@1203
   177
** using [sqlite3_step()], then destroyed using [sqlite3_finalize()].
dvander@1203
   178
**
dvander@1203
   179
** If one or more of the SQL statements are queries, then
dvander@1203
   180
** the callback function specified by the 3rd parameter is
dvander@1203
   181
** invoked once for each row of the query result.  This callback
dvander@1203
   182
** should normally return 0.  If the callback returns a non-zero
dvander@1203
   183
** value then the query is aborted, all subsequent SQL statements
dvander@1203
   184
** are skipped and the sqlite3_exec() function returns the SQLITE_ABORT.
dvander@1203
   185
**
dvander@1203
   186
** The 4th parameter to this interface is an arbitrary pointer that is
dvander@1203
   187
** passed through to the callback function as its first parameter.
dvander@1203
   188
**
dvander@1203
   189
** The 2nd parameter to the callback function is the number of
dvander@1203
   190
** columns in the query result.  The 3rd parameter to the callback
dvander@1203
   191
** is an array of strings holding the values for each column
dvander@1203
   192
** as extracted using [sqlite3_column_text()].
dvander@1203
   193
** The 4th parameter to the callback is an array of strings
dvander@1203
   194
** obtained using [sqlite3_column_name()] and holding
dvander@1203
   195
** the names of each column.
dvander@1203
   196
**
dvander@1203
   197
** The callback function may be NULL, even for queries.  A NULL
dvander@1203
   198
** callback is not an error.  It just means that no callback
dvander@1203
   199
** will be invoked.
dvander@1203
   200
**
dvander@1203
   201
** If an error occurs while parsing or evaluating the SQL (but
dvander@1203
   202
** not while executing the callback) then an appropriate error
dvander@1203
   203
** message is written into memory obtained from [sqlite3_malloc()] and
dvander@1203
   204
** *errmsg is made to point to that message.  The calling function
dvander@1203
   205
** is responsible for freeing the memory that holds the error
dvander@1203
   206
** message.   Use [sqlite3_free()] for this.  If errmsg==NULL,
dvander@1203
   207
** then no error message is ever written.
dvander@1203
   208
**
dvander@1203
   209
** The return value is is SQLITE_OK if there are no errors and
dvander@1203
   210
** some other [SQLITE_OK | return code] if there is an error.  
dvander@1203
   211
** The particular return value depends on the type of error. 
dvander@1203
   212
**
dvander@1203
   213
*/
dvander@1203
   214
int sqlite3_exec(
dvander@1203
   215
  sqlite3*,                                  /* An open database */
dvander@1203
   216
  const char *sql,                           /* SQL to be evaluted */
dvander@1203
   217
  int (*callback)(void*,int,char**,char**),  /* Callback function */
dvander@1203
   218
  void *,                                    /* 1st argument to callback */
dvander@1203
   219
  char **errmsg                              /* Error msg written here */
dvander@1203
   220
);
dvander@1203
   221
dvander@1203
   222
/*
dvander@1203
   223
** CAPI3REF: Result Codes
dvander@1203
   224
** KEYWORDS: SQLITE_OK
dvander@1203
   225
**
dvander@1203
   226
** Many SQLite functions return an integer result code from the set shown
dvander@1203
   227
** above in order to indicates success or failure.
dvander@1203
   228
**
dvander@1203
   229
** The result codes above are the only ones returned by SQLite in its
dvander@1203
   230
** default configuration.  However, the [sqlite3_extended_result_codes()]
dvander@1203
   231
** API can be used to set a database connectoin to return more detailed
dvander@1203
   232
** result codes.
dvander@1203
   233
**
dvander@1203
   234
** See also: [SQLITE_IOERR_READ | extended result codes]
dvander@1203
   235
**
dvander@1203
   236
*/
dvander@1203
   237
#define SQLITE_OK           0   /* Successful result */
dvander@1203
   238
/* beginning-of-error-codes */
dvander@1203
   239
#define SQLITE_ERROR        1   /* SQL error or missing database */
dvander@1203
   240
#define SQLITE_INTERNAL     2   /* NOT USED. Internal logic error in SQLite */
dvander@1203
   241
#define SQLITE_PERM         3   /* Access permission denied */
dvander@1203
   242
#define SQLITE_ABORT        4   /* Callback routine requested an abort */
dvander@1203
   243
#define SQLITE_BUSY         5   /* The database file is locked */
dvander@1203
   244
#define SQLITE_LOCKED       6   /* A table in the database is locked */
dvander@1203
   245
#define SQLITE_NOMEM        7   /* A malloc() failed */
dvander@1203
   246
#define SQLITE_READONLY     8   /* Attempt to write a readonly database */
dvander@1203
   247
#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
dvander@1203
   248
#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
dvander@1203
   249
#define SQLITE_CORRUPT     11   /* The database disk image is malformed */
dvander@1203
   250
#define SQLITE_NOTFOUND    12   /* NOT USED. Table or record not found */
dvander@1203
   251
#define SQLITE_FULL        13   /* Insertion failed because database is full */
dvander@1203
   252
#define SQLITE_CANTOPEN    14   /* Unable to open the database file */
dvander@1203
   253
#define SQLITE_PROTOCOL    15   /* NOT USED. Database lock protocol error */
dvander@1203
   254
#define SQLITE_EMPTY       16   /* Database is empty */
dvander@1203
   255
#define SQLITE_SCHEMA      17   /* The database schema changed */
dvander@1203
   256
#define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
dvander@1203
   257
#define SQLITE_CONSTRAINT  19   /* Abort due to contraint violation */
dvander@1203
   258
#define SQLITE_MISMATCH    20   /* Data type mismatch */
dvander@1203
   259
#define SQLITE_MISUSE      21   /* Library used incorrectly */
dvander@1203
   260
#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
dvander@1203
   261
#define SQLITE_AUTH        23   /* Authorization denied */
dvander@1203
   262
#define SQLITE_FORMAT      24   /* Auxiliary database format error */
dvander@1203
   263
#define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
dvander@1203
   264
#define SQLITE_NOTADB      26   /* File opened that is not a database file */
dvander@1203
   265
#define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
dvander@1203
   266
#define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
dvander@1203
   267
/* end-of-error-codes */
dvander@1203
   268
dvander@1203
   269
/*
dvander@1203
   270
** CAPI3REF: Extended Result Codes
dvander@1203
   271
**
dvander@1203
   272
** In its default configuration, SQLite API routines return one of 26 integer
dvander@1203
   273
** result codes described at result-codes.  However, experience has shown that
dvander@1203
   274
** many of these result codes are too course-grained.  They do not provide as
dvander@1203
   275
** much information about problems as users might like.  In an effort to
dvander@1203
   276
** address this, newer versions of SQLite (version 3.3.8 and later) include
dvander@1203
   277
** support for additional result codes that provide more detailed information
dvander@1203
   278
** about errors.  The extended result codes are enabled (or disabled) for 
dvander@1203
   279
** each database
dvander@1203
   280
** connection using the [sqlite3_extended_result_codes()] API.
dvander@1203
   281
** 
dvander@1203
   282
** Some of the available extended result codes are listed above.
dvander@1203
   283
** We expect the number of extended result codes will be expand
dvander@1203
   284
** over time.  Software that uses extended result codes should expect
dvander@1203
   285
** to see new result codes in future releases of SQLite.
dvander@1203
   286
** 
dvander@1203
   287
** The symbolic name for an extended result code always contains a related
dvander@1203
   288
** primary result code as a prefix.  Primary result codes contain a single
dvander@1203
   289
** "_" character.  Extended result codes contain two or more "_" characters.
dvander@1203
   290
** The numeric value of an extended result code can be converted to its
dvander@1203
   291
** corresponding primary result code by masking off the lower 8 bytes.
dvander@1203
   292
**
dvander@1203
   293
** The SQLITE_OK result code will never be extended.  It will always
dvander@1203
   294
** be exactly zero.
dvander@1203
   295
*/
dvander@1203
   296
#define SQLITE_IOERR_READ          (SQLITE_IOERR | (1<<8))
dvander@1203
   297
#define SQLITE_IOERR_SHORT_READ    (SQLITE_IOERR | (2<<8))
dvander@1203
   298
#define SQLITE_IOERR_WRITE         (SQLITE_IOERR | (3<<8))
dvander@1203
   299
#define SQLITE_IOERR_FSYNC         (SQLITE_IOERR | (4<<8))
dvander@1203
   300
#define SQLITE_IOERR_DIR_FSYNC     (SQLITE_IOERR | (5<<8))
dvander@1203
   301
#define SQLITE_IOERR_TRUNCATE      (SQLITE_IOERR | (6<<8))
dvander@1203
   302
#define SQLITE_IOERR_FSTAT         (SQLITE_IOERR | (7<<8))
dvander@1203
   303
#define SQLITE_IOERR_UNLOCK        (SQLITE_IOERR | (8<<8))
dvander@1203
   304
#define SQLITE_IOERR_RDLOCK        (SQLITE_IOERR | (9<<8))
dvander@1203
   305
#define SQLITE_IOERR_DELETE        (SQLITE_IOERR | (10<<8))
dvander@1203
   306
#define SQLITE_IOERR_BLOCKED       (SQLITE_IOERR | (11<<8))
dvander@1203
   307
dvander@1203
   308
/*
dvander@1203
   309
** CAPI3REF: Enable Or Disable Extended Result Codes
dvander@1203
   310
**
dvander@1203
   311
** This routine enables or disables the
dvander@1203
   312
** [SQLITE_IOERR_READ | extended result codes] feature.
dvander@1203
   313
** By default, SQLite API routines return one of only 26 integer
dvander@1203
   314
** [SQLITE_OK | result codes].  When extended result codes
dvander@1203
   315
** are enabled by this routine, the repetoire of result codes can be
dvander@1203
   316
** much larger and can (hopefully) provide more detailed information
dvander@1203
   317
** about the cause of an error.
dvander@1203
   318
**
dvander@1203
   319
** The second argument is a boolean value that turns extended result
dvander@1203
   320
** codes on and off.  Extended result codes are off by default for
dvander@1203
   321
** backwards compatibility with older versions of SQLite.
dvander@1203
   322
*/
dvander@1203
   323
int sqlite3_extended_result_codes(sqlite3*, int onoff);
dvander@1203
   324
dvander@1203
   325
/*
dvander@1203
   326
** CAPI3REF: Last Insert Rowid
dvander@1203
   327
**
dvander@1203
   328
** Each entry in an SQLite table has a unique 64-bit signed integer key
dvander@1203
   329
** called the "rowid". The rowid is always available as an undeclared
dvander@1203
   330
** column named ROWID, OID, or _ROWID_.  If the table has a column of
dvander@1203
   331
** type INTEGER PRIMARY KEY then that column is another an alias for the
dvander@1203
   332
** rowid.
dvander@1203
   333
**
dvander@1203
   334
** This routine returns the rowid of the most recent INSERT into
dvander@1203
   335
** the database from the database connection given in the first 
dvander@1203
   336
** argument.  If no inserts have ever occurred on this database
dvander@1203
   337
** connection, zero is returned.
dvander@1203
   338
**
dvander@1203
   339
** If an INSERT occurs within a trigger, then the rowid of the
dvander@1203
   340
** inserted row is returned by this routine as long as the trigger
dvander@1203
   341
** is running.  But once the trigger terminates, the value returned
dvander@1203
   342
** by this routine reverts to the last value inserted before the
dvander@1203
   343
** trigger fired.
dvander@1203
   344
*/
dvander@1203
   345
sqlite_int64 sqlite3_last_insert_rowid(sqlite3*);
dvander@1203
   346
dvander@1203
   347
/*
dvander@1203
   348
** CAPI3REF: Count The Number Of Rows Modified
dvander@1203
   349
**
dvander@1203
   350
** This function returns the number of database rows that were changed
dvander@1203
   351
** (or inserted or deleted) by the most recent SQL statement.  Only
dvander@1203
   352
** changes that are directly specified by the INSERT, UPDATE, or
dvander@1203
   353
** DELETE statement are counted.  Auxiliary changes caused by
dvander@1203
   354
** triggers are not counted.  Use the [sqlite3_total_changes()] function
dvander@1203
   355
** to find the total number of changes including changes caused by triggers.
dvander@1203
   356
**
dvander@1203
   357
** Within the body of a trigger, the sqlite3_changes() interface can be
dvander@1203
   358
** called to find the number of
dvander@1203
   359
** changes in the most recently completed INSERT, UPDATE, or DELETE
dvander@1203
   360
** statement within the body of the trigger.
dvander@1203
   361
**
dvander@1203
   362
** All changes are counted, even if they were later undone by a
dvander@1203
   363
** ROLLBACK or ABORT.  Except, changes associated with creating and
dvander@1203
   364
** dropping tables are not counted.
dvander@1203
   365
**
dvander@1203
   366
** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively,
dvander@1203
   367
** then the changes in the inner, recursive call are counted together
dvander@1203
   368
** with the changes in the outer call.
dvander@1203
   369
**
dvander@1203
   370
** SQLite implements the command "DELETE FROM table" without a WHERE clause
dvander@1203
   371
** by dropping and recreating the table.  (This is much faster than going
dvander@1203
   372
** through and deleting individual elements from the table.)  Because of
dvander@1203
   373
** this optimization, the change count for "DELETE FROM table" will be
dvander@1203
   374
** zero regardless of the number of elements that were originally in the
dvander@1203
   375
** table. To get an accurate count of the number of rows deleted, use
dvander@1203
   376
** "DELETE FROM table WHERE 1" instead.
dvander@1203
   377
*/
dvander@1203
   378
int sqlite3_changes(sqlite3*);
dvander@1203
   379
dvander@1203
   380
/*
dvander@1203
   381
** CAPI3REF: Total Number Of Rows Modified
dvander@1203
   382
***
dvander@1203
   383
** This function returns the number of database rows that have been
dvander@1203
   384
** modified by INSERT, UPDATE or DELETE statements since the database handle
dvander@1203
   385
** was opened. This includes UPDATE, INSERT and DELETE statements executed
dvander@1203
   386
** as part of trigger programs. All changes are counted as soon as the
dvander@1203
   387
** statement that makes them is completed (when the statement handle is
dvander@1203
   388
** passed to [sqlite3_reset()] or [sqlite_finalise()]).
dvander@1203
   389
**
dvander@1203
   390
** See also the [sqlite3_change()] interface.
dvander@1203
   391
**
dvander@1203
   392
** SQLite implements the command "DELETE FROM table" without a WHERE clause
dvander@1203
   393
** by dropping and recreating the table.  (This is much faster than going
dvander@1203
   394
** through and deleting individual elements form the table.)  Because of
dvander@1203
   395
** this optimization, the change count for "DELETE FROM table" will be
dvander@1203
   396
** zero regardless of the number of elements that were originally in the
dvander@1203
   397
** table. To get an accurate count of the number of rows deleted, use
dvander@1203
   398
** "DELETE FROM table WHERE 1" instead.
dvander@1203
   399
*/
dvander@1203
   400
int sqlite3_total_changes(sqlite3*);
dvander@1203
   401
dvander@1203
   402
/*
dvander@1203
   403
** CAPI3REF: Interrupt A Long-Running Query
dvander@1203
   404
**
dvander@1203
   405
** This function causes any pending database operation to abort and
dvander@1203
   406
** return at its earliest opportunity.  This routine is typically
dvander@1203
   407
** called in response to a user action such as pressing "Cancel"
dvander@1203
   408
** or Ctrl-C where the user wants a long query operation to halt
dvander@1203
   409
** immediately.
dvander@1203
   410
**
dvander@1203
   411
** It is safe to call this routine from a thread different from the
dvander@1203
   412
** thread that is currently running the database operation.
dvander@1203
   413
**
dvander@1203
   414
** The SQL operation that is interrupted will return [SQLITE_INTERRUPT].
dvander@1203
   415
** If an interrupted operation was an update that is inside an
dvander@1203
   416
** explicit transaction, then the entire transaction will be rolled
dvander@1203
   417
** back automatically.
dvander@1203
   418
*/
dvander@1203
   419
void sqlite3_interrupt(sqlite3*);
dvander@1203
   420
dvander@1203
   421
/*
dvander@1203
   422
** CAPI3REF: Determine If An SQL Statement Is Complete
dvander@1203
   423
**
dvander@1203
   424
** These functions return true if the given input string comprises
dvander@1203
   425
** one or more complete SQL statements. For the sqlite3_complete() call,
dvander@1203
   426
** the parameter must be a nul-terminated UTF-8 string. For
dvander@1203
   427
** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string
dvander@1203
   428
** is required.
dvander@1203
   429
**
dvander@1203
   430
** These routines are useful for command-line input to determine if the
dvander@1203
   431
** currently entered text forms one or more complete SQL statements or
dvander@1203
   432
** if additional input is needed before sending the statements into
dvander@1203
   433
** SQLite for parsing. The algorithm is simple.  If the 
dvander@1203
   434
** last token other than spaces and comments is a semicolon, then return 
dvander@1203
   435
** true.  Actually, the algorithm is a little more complicated than that
dvander@1203
   436
** in order to deal with triggers, but the basic idea is the same:  the
dvander@1203
   437
** statement is not complete unless it ends in a semicolon.
dvander@1203
   438
*/
dvander@1203
   439
int sqlite3_complete(const char *sql);
dvander@1203
   440
int sqlite3_complete16(const void *sql);
dvander@1203
   441
dvander@1203
   442
/*
dvander@1203
   443
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
dvander@1203
   444
**
dvander@1203
   445
** This routine identifies a callback function that might be invoked
dvander@1203
   446
** whenever an attempt is made to open a database table 
dvander@1203
   447
** that another thread or process has locked.
dvander@1203
   448
** If the busy callback is NULL, then [SQLITE_BUSY]
dvander@1203
   449
** (or sometimes [SQLITE_IOERR_BLOCKED])
dvander@1203
   450
** is returned immediately upon encountering the lock.
dvander@1203
   451
** If the busy callback is not NULL, then the
dvander@1203
   452
** callback will be invoked with two arguments.  The
dvander@1203
   453
** first argument to the handler is a copy of the void* pointer which
dvander@1203
   454
** is the third argument to this routine.  The second argument to
dvander@1203
   455
** the handler is the number of times that the busy handler has
dvander@1203
   456
** been invoked for this locking event. If the
dvander@1203
   457
** busy callback returns 0, then no additional attempts are made to
dvander@1203
   458
** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
dvander@1203
   459
** If the callback returns non-zero, then another attempt is made to open the
dvander@1203
   460
** database for reading and the cycle repeats.
dvander@1203
   461
**
dvander@1203
   462
** The presence of a busy handler does not guarantee that
dvander@1203
   463
** it will be invoked when there is lock contention.
dvander@1203
   464
** If SQLite determines that invoking the busy handler could result in
dvander@1203
   465
** a deadlock, it will return [SQLITE_BUSY] instead.
dvander@1203
   466
** Consider a scenario where one process is holding a read lock that
dvander@1203
   467
** it is trying to promote to a reserved lock and
dvander@1203
   468
** a second process is holding a reserved lock that it is trying
dvander@1203
   469
** to promote to an exclusive lock.  The first process cannot proceed
dvander@1203
   470
** because it is blocked by the second and the second process cannot
dvander@1203
   471
** proceed because it is blocked by the first.  If both processes
dvander@1203
   472
** invoke the busy handlers, neither will make any progress.  Therefore,
dvander@1203
   473
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
dvander@1203
   474
** will induce the first process to release its read lock and allow
dvander@1203
   475
** the second process to proceed.
dvander@1203
   476
**
dvander@1203
   477
** The default busy callback is NULL.
dvander@1203
   478
**
dvander@1203
   479
** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] when
dvander@1203
   480
** SQLite is in the middle of a large transaction where all the
dvander@1203
   481
** changes will not fit into the in-memory cache.  SQLite will
dvander@1203
   482
** already hold a RESERVED lock on the database file, but it needs
dvander@1203
   483
** to promote this lock to EXCLUSIVE so that it can spill cache
dvander@1203
   484
** pages into the database file without harm to concurrent
dvander@1203
   485
** readers.  If it is unable to promote the lock, then the in-memory
dvander@1203
   486
** cache will be left in an inconsistent state and so the error
dvander@1203
   487
** code is promoted from the relatively benign [SQLITE_BUSY] to
dvander@1203
   488
** the more severe [SQLITE_IOERR_BLOCKED].  This error code promotion
dvander@1203
   489
** forces an automatic rollback of the changes. See the
dvander@1203
   490
** <a href="http://www.sqlite.org/cvstrac/wiki?p=CorruptionFollowingBusyError">
dvander@1203
   491
** CorruptionFollowingBusyError</a> wiki page for a discussion of why
dvander@1203
   492
** this is important.
dvander@1203
   493
**	
dvander@1203
   494
** Sqlite is re-entrant, so the busy handler may start a new query. 
dvander@1203
   495
** (It is not clear why anyone would every want to do this, but it
dvander@1203
   496
** is allowed, in theory.)  But the busy handler may not close the
dvander@1203
   497
** database.  Closing the database from a busy handler will delete 
dvander@1203
   498
** data structures out from under the executing query and will 
dvander@1203
   499
** probably result in a segmentation fault or other runtime error.
dvander@1203
   500
**
dvander@1203
   501
** There can only be a single busy handler defined for each database
dvander@1203
   502
** connection.  Setting a new busy handler clears any previous one.
dvander@1203
   503
** Note that calling [sqlite3_busy_timeout()] will also set or clear
dvander@1203
   504
** the busy handler.
dvander@1203
   505
*/
dvander@1203
   506
int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
dvander@1203
   507
dvander@1203
   508
/*
dvander@1203
   509
** CAPI3REF: Set A Busy Timeout
dvander@1203
   510
**
dvander@1203
   511
** This routine sets a busy handler that sleeps for a while when a
dvander@1203
   512
** table is locked.  The handler will sleep multiple times until 
dvander@1203
   513
** at least "ms" milliseconds of sleeping have been done.  After
dvander@1203
   514
** "ms" milliseconds of sleeping, the handler returns 0 which
dvander@1203
   515
** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
dvander@1203
   516
**
dvander@1203
   517
** Calling this routine with an argument less than or equal to zero
dvander@1203
   518
** turns off all busy handlers.
dvander@1203
   519
**
dvander@1203
   520
** There can only be a single busy handler for a particular database
dvander@1203
   521
** connection.  If another busy handler was defined  
dvander@1203
   522
** (using [sqlite3_busy_handler()]) prior to calling
dvander@1203
   523
** this routine, that other busy handler is cleared.
dvander@1203
   524
*/
dvander@1203
   525
int sqlite3_busy_timeout(sqlite3*, int ms);
dvander@1203
   526
dvander@1203
   527
/*
dvander@1203
   528
** CAPI3REF: Convenience Routines For Running Queries
dvander@1203
   529
**
dvander@1203
   530
** This next routine is a convenience wrapper around [sqlite3_exec()].
dvander@1203
   531
** Instead of invoking a user-supplied callback for each row of the
dvander@1203
   532
** result, this routine remembers each row of the result in memory
dvander@1203
   533
** obtained from [sqlite3_malloc()], then returns all of the result after the
dvander@1203
   534
** query has finished. 
dvander@1203
   535
**
dvander@1203
   536
** As an example, suppose the query result where this table:
dvander@1203
   537
**
dvander@1203
   538
** <pre>
dvander@1203
   539
**        Name        | Age
dvander@1203
   540
**        -----------------------
dvander@1203
   541
**        Alice       | 43
dvander@1203
   542
**        Bob         | 28
dvander@1203
   543
**        Cindy       | 21
dvander@1203
   544
** </pre>
dvander@1203
   545
**
dvander@1203
   546
** If the 3rd argument were &azResult then after the function returns
dvander@1203
   547
** azResult will contain the following data:
dvander@1203
   548
**
dvander@1203
   549
** <pre>
dvander@1203
   550
**        azResult[0] = "Name";
dvander@1203
   551
**        azResult[1] = "Age";
dvander@1203
   552
**        azResult[2] = "Alice";
dvander@1203
   553
**        azResult[3] = "43";
dvander@1203
   554
**        azResult[4] = "Bob";
dvander@1203
   555
**        azResult[5] = "28";
dvander@1203
   556
**        azResult[6] = "Cindy";
dvander@1203
   557
**        azResult[7] = "21";
dvander@1203
   558
** </pre>
dvander@1203
   559
**
dvander@1203
   560
** Notice that there is an extra row of data containing the column
dvander@1203
   561
** headers.  But the *nrow return value is still 3.  *ncolumn is
dvander@1203
   562
** set to 2.  In general, the number of values inserted into azResult
dvander@1203
   563
** will be ((*nrow) + 1)*(*ncolumn).
dvander@1203
   564
**
dvander@1203
   565
** After the calling function has finished using the result, it should 
dvander@1203
   566
** pass the result data pointer to sqlite3_free_table() in order to 
dvander@1203
   567
** release the memory that was malloc-ed.  Because of the way the 
dvander@1203
   568
** [sqlite3_malloc()] happens, the calling function must not try to call 
dvander@1203
   569
** [sqlite3_free()] directly.  Only [sqlite3_free_table()] is able to release 
dvander@1203
   570
** the memory properly and safely.
dvander@1203
   571
**
dvander@1203
   572
** The return value of this routine is the same as from [sqlite3_exec()].
dvander@1203
   573
*/
dvander@1203
   574
int sqlite3_get_table(
dvander@1203
   575
  sqlite3*,              /* An open database */
dvander@1203
   576
  const char *sql,       /* SQL to be executed */
dvander@1203
   577
  char ***resultp,       /* Result written to a char *[]  that this points to */
dvander@1203
   578
  int *nrow,             /* Number of result rows written here */
dvander@1203
   579
  int *ncolumn,          /* Number of result columns written here */
dvander@1203
   580
  char **errmsg          /* Error msg written here */
dvander@1203
   581
);
dvander@1203
   582
void sqlite3_free_table(char **result);
dvander@1203
   583
dvander@1203
   584
/*
dvander@1203
   585
** CAPI3REF: Formatted String Printing Functions
dvander@1203
   586
**
dvander@1203
   587
** These routines are workalikes of the "printf()" family of functions
dvander@1203
   588
** from the standard C library.
dvander@1203
   589
**
dvander@1203
   590
** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
dvander@1203
   591
** results into memory obtained from [sqlite_malloc()].
dvander@1203
   592
** The strings returned by these two routines should be
dvander@1203
   593
** released by [sqlite3_free()].  Both routines return a
dvander@1203
   594
** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
dvander@1203
   595
** memory to hold the resulting string.
dvander@1203
   596
**
dvander@1203
   597
** In sqlite3_snprintf() routine is similar to "snprintf()" from
dvander@1203
   598
** the standard C library.  The result is written into the
dvander@1203
   599
** buffer supplied as the second parameter whose size is given by
dvander@1203
   600
** the first parameter.  Note that the order of the
dvander@1203
   601
** first two parameters is reversed from snprintf().  This is an
dvander@1203
   602
** historical accident that cannot be fixed without breaking
dvander@1203
   603
** backwards compatibility.  Note also that sqlite3_snprintf()
dvander@1203
   604
** returns a pointer to its buffer instead of the number of
dvander@1203
   605
** characters actually written into the buffer.  We admit that
dvander@1203
   606
** the number of characters written would be a more useful return
dvander@1203
   607
** value but we cannot change the implementation of sqlite3_snprintf()
dvander@1203
   608
** now without breaking compatibility.
dvander@1203
   609
**
dvander@1203
   610
** As long as the buffer size is greater than zero, sqlite3_snprintf()
dvander@1203
   611
** guarantees that the buffer is always zero-terminated.  The first
dvander@1203
   612
** parameter "n" is the total size of the buffer, including space for
dvander@1203
   613
** the zero terminator.  So the longest string that can be completely
dvander@1203
   614
** written will be n-1 characters.
dvander@1203
   615
**
dvander@1203
   616
** These routines all implement some additional formatting
dvander@1203
   617
** options that are useful for constructing SQL statements.
dvander@1203
   618
** All of the usual printf formatting options apply.  In addition, there
dvander@1203
   619
** is are "%q" and "%Q" options.
dvander@1203
   620
**
dvander@1203
   621
** The %q option works like %s in that it substitutes a null-terminated
dvander@1203
   622
** string from the argument list.  But %q also doubles every '\'' character.
dvander@1203
   623
** %q is designed for use inside a string literal.  By doubling each '\''
dvander@1203
   624
** character it escapes that character and allows it to be inserted into
dvander@1203
   625
** the string.
dvander@1203
   626
**
dvander@1203
   627
** For example, so some string variable contains text as follows:
dvander@1203
   628
**
dvander@1203
   629
** <blockquote><pre>
dvander@1203
   630
**  char *zText = "It's a happy day!";
dvander@1203
   631
** </pre></blockquote>
dvander@1203
   632
**
dvander@1203
   633
** One can use this text in an SQL statement as follows:
dvander@1203
   634
**
dvander@1203
   635
** <blockquote><pre>
dvander@1203
   636
**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
dvander@1203
   637
**  sqlite3_exec(db, zSQL, 0, 0, 0);
dvander@1203
   638
**  sqlite3_free(zSQL);
dvander@1203
   639
** </pre></blockquote>
dvander@1203
   640
**
dvander@1203
   641
** Because the %q format string is used, the '\'' character in zText
dvander@1203
   642
** is escaped and the SQL generated is as follows:
dvander@1203
   643
**
dvander@1203
   644
** <blockquote><pre>
dvander@1203
   645
**  INSERT INTO table1 VALUES('It''s a happy day!')
dvander@1203
   646
** </pre></blockquote>
dvander@1203
   647
**
dvander@1203
   648
** This is correct.  Had we used %s instead of %q, the generated SQL
dvander@1203
   649
** would have looked like this:
dvander@1203
   650
**
dvander@1203
   651
** <blockquote><pre>
dvander@1203
   652
**  INSERT INTO table1 VALUES('It's a happy day!');
dvander@1203
   653
** </pre></blockquote>
dvander@1203
   654
**
dvander@1203
   655
** This second example is an SQL syntax error.  As a general rule you
dvander@1203
   656
** should always use %q instead of %s when inserting text into a string 
dvander@1203
   657
** literal.
dvander@1203
   658
**
dvander@1203
   659
** The %Q option works like %q except it also adds single quotes around
dvander@1203
   660
** the outside of the total string.  Or if the parameter in the argument
dvander@1203
   661
** list is a NULL pointer, %Q substitutes the text "NULL" (without single
dvander@1203
   662
** quotes) in place of the %Q option.  So, for example, one could say:
dvander@1203
   663
**
dvander@1203
   664
** <blockquote><pre>
dvander@1203
   665
**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
dvander@1203
   666
**  sqlite3_exec(db, zSQL, 0, 0, 0);
dvander@1203
   667
**  sqlite3_free(zSQL);
dvander@1203
   668
** </pre></blockquote>
dvander@1203
   669
**
dvander@1203
   670
** The code above will render a correct SQL statement in the zSQL
dvander@1203
   671
** variable even if the zText variable is a NULL pointer.
dvander@1203
   672
*/
dvander@1203
   673
char *sqlite3_mprintf(const char*,...);
dvander@1203
   674
char *sqlite3_vmprintf(const char*, va_list);
dvander@1203
   675
char *sqlite3_snprintf(int,char*,const char*, ...);
dvander@1203
   676
dvander@1203
   677
/*
dvander@1203
   678
** CAPI3REF: Memory Allocation Functions
dvander@1203
   679
**
dvander@1203
   680
** SQLite uses its own memory allocator.  On some installations, this
dvander@1203
   681
** memory allocator is identical to the standard malloc()/realloc()/free()
dvander@1203
   682
** and can be used interchangable.  On others, the implementations are
dvander@1203
   683
** different.  For maximum portability, it is best not to mix calls
dvander@1203
   684
** to the standard malloc/realloc/free with the sqlite versions.
dvander@1203
   685
*/
dvander@1203
   686
void *sqlite3_malloc(int);
dvander@1203
   687
void *sqlite3_realloc(void*, int);
dvander@1203
   688
void sqlite3_free(void*);
dvander@1203
   689
dvander@1203
   690
/*
dvander@1203
   691
** CAPI3REF: Compile-Time Authorization Callbacks
dvander@1203
   692
***
dvander@1203
   693
** This routine registers a authorizer callback with the SQLite library.  
dvander@1203
   694
** The authorizer callback is invoked as SQL statements are being compiled
dvander@1203
   695
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
dvander@1203
   696
** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  At various
dvander@1203
   697
** points during the compilation process, as logic is being created
dvander@1203
   698
** to perform various actions, the authorizer callback is invoked to
dvander@1203
   699
** see if those actions are allowed.  The authorizer callback should
dvander@1203
   700
** return SQLITE_OK to allow the action, [SQLITE_IGNORE] to disallow the
dvander@1203
   701
** specific action but allow the SQL statement to continue to be
dvander@1203
   702
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
dvander@1203
   703
** rejected with an error.  
dvander@1203
   704
**
dvander@1203
   705
** Depending on the action, the [SQLITE_IGNORE] and [SQLITE_DENY] return
dvander@1203
   706
** codes might mean something different or they might mean the same
dvander@1203
   707
** thing.  If the action is, for example, to perform a delete opertion,
dvander@1203
   708
** then [SQLITE_IGNORE] and [SQLITE_DENY] both cause the statement compilation
dvander@1203
   709
** to fail with an error.  But if the action is to read a specific column
dvander@1203
   710
** from a specific table, then [SQLITE_DENY] will cause the entire
dvander@1203
   711
** statement to fail but [SQLITE_IGNORE] will cause a NULL value to be
dvander@1203
   712
** read instead of the actual column value.
dvander@1203
   713
**
dvander@1203
   714
** The first parameter to the authorizer callback is a copy of
dvander@1203
   715
** the third parameter to the sqlite3_set_authorizer() interface.
dvander@1203
   716
** The second parameter to the callback is an integer 
dvander@1203
   717
** [SQLITE_COPY | action code] that specifies the particular action
dvander@1203
   718
** to be authorized.  The available action codes are
dvander@1203
   719
** [SQLITE_COPY | documented separately].  The third through sixth
dvander@1203
   720
** parameters to the callback are strings that contain additional
dvander@1203
   721
** details about the action to be authorized.
dvander@1203
   722
**
dvander@1203
   723
** An authorizer is used when preparing SQL statements from an untrusted
dvander@1203
   724
** source, to ensure that the SQL statements do not try to access data
dvander@1203
   725
** that they are not allowed to see, or that they do not try to
dvander@1203
   726
** execute malicious statements that damage the database.  For
dvander@1203
   727
** example, an application may allow a user to enter arbitrary
dvander@1203
   728
** SQL queries for evaluation by a database.  But the application does
dvander@1203
   729
** not want the user to be able to make arbitrary changes to the
dvander@1203
   730
** database.  An authorizer could then be put in place while the
dvander@1203
   731
** user-entered SQL is being prepared that disallows everything
dvander@1203
   732
** except SELECT statements.  
dvander@1203
   733
**
dvander@1203
   734
** Only a single authorizer can be in place on a database connection
dvander@1203
   735
** at a time.  Each call to sqlite3_set_authorizer overrides the
dvander@1203
   736
** previous call.  A NULL authorizer means that no authorization
dvander@1203
   737
** callback is invoked.  The default authorizer is NULL.
dvander@1203
   738
**
dvander@1203
   739
** Note that the authorizer callback is invoked only during 
dvander@1203
   740
** [sqlite3_prepare()] or its variants.  Authorization is not
dvander@1203
   741
** performed during statement evaluation in [sqlite3_step()].
dvander@1203
   742
*/
dvander@1203
   743
int sqlite3_set_authorizer(
dvander@1203
   744
  sqlite3*,
dvander@1203
   745
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
dvander@1203
   746
  void *pUserData
dvander@1203
   747
);
dvander@1203
   748
dvander@1203
   749
/*
dvander@1203
   750
** CAPI3REF: Authorizer Return Codes
dvander@1203
   751
**
dvander@1203
   752
** The [sqlite3_set_authorizer | authorizer callback function] must
dvander@1203
   753
** return either [SQLITE_OK] or one of these two constants in order
dvander@1203
   754
** to signal SQLite whether or not the action is permitted.  See the
dvander@1203
   755
** [sqlite3_set_authorizer | authorizer documentation] for additional
dvander@1203
   756
** information.
dvander@1203
   757
*/
dvander@1203
   758
#define SQLITE_DENY   1   /* Abort the SQL statement with an error */
dvander@1203
   759
#define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
dvander@1203
   760
dvander@1203
   761
/*
dvander@1203
   762
** CAPI3REF: Authorizer Action Codes
dvander@1203
   763
**
dvander@1203
   764
** The [sqlite3_set_authorizer()] interface registers a callback function
dvander@1203
   765
** that is invoked to authorizer certain SQL statement actions.  The
dvander@1203
   766
** second parameter to the callback is an integer code that specifies
dvander@1203
   767
** what action is being authorized.  These are the integer action codes that
dvander@1203
   768
** the authorizer callback may be passed.
dvander@1203
   769
**
dvander@1203
   770
** These action code values signify what kind of operation is to be 
dvander@1203
   771
** authorized.  The 3rd and 4th parameters to the authorization callback
dvander@1203
   772
** function will be parameters or NULL depending on which of these
dvander@1203
   773
** codes is used as the second parameter.  The 5th parameter to the
dvander@1203
   774
** authorizer callback is the name of the database ("main", "temp", 
dvander@1203
   775
** etc.) if applicable.  The 6th parameter to the authorizer callback
dvander@1203
   776
** is the name of the inner-most trigger or view that is responsible for
dvander@1203
   777
** the access attempt or NULL if this access attempt is directly from 
dvander@1203
   778
** top-level SQL code.
dvander@1203
   779
*/
dvander@1203
   780
/******************************************* 3rd ************ 4th ***********/
dvander@1203
   781
#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
dvander@1203
   782
#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
dvander@1203
   783
#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
dvander@1203
   784
#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
dvander@1203
   785
#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
dvander@1203
   786
#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
dvander@1203
   787
#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
dvander@1203
   788
#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
dvander@1203
   789
#define SQLITE_DELETE                9   /* Table Name      NULL            */
dvander@1203
   790
#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
dvander@1203
   791
#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
dvander@1203
   792
#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
dvander@1203
   793
#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
dvander@1203
   794
#define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
dvander@1203
   795
#define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
dvander@1203
   796
#define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
dvander@1203
   797
#define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
dvander@1203
   798
#define SQLITE_INSERT               18   /* Table Name      NULL            */
dvander@1203
   799
#define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
dvander@1203
   800
#define SQLITE_READ                 20   /* Table Name      Column Name     */
dvander@1203
   801
#define SQLITE_SELECT               21   /* NULL            NULL            */
dvander@1203
   802
#define SQLITE_TRANSACTION          22   /* NULL            NULL            */
dvander@1203
   803
#define SQLITE_UPDATE               23   /* Table Name      Column Name     */
dvander@1203
   804
#define SQLITE_ATTACH               24   /* Filename        NULL            */
dvander@1203
   805
#define SQLITE_DETACH               25   /* Database Name   NULL            */
dvander@1203
   806
#define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
dvander@1203
   807
#define SQLITE_REINDEX              27   /* Index Name      NULL            */
dvander@1203
   808
#define SQLITE_ANALYZE              28   /* Table Name      NULL            */
dvander@1203
   809
#define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
dvander@1203
   810
#define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
dvander@1203
   811
#define SQLITE_FUNCTION             31   /* Function Name   NULL            */
dvander@1203
   812
#define SQLITE_COPY                  0   /* No longer used */
dvander@1203
   813
dvander@1203
   814
/*
dvander@1203
   815
** CAPI3REF: Tracing And Profiling Functions
dvander@1203
   816
**
dvander@1203
   817
** These routines register callback functions that can be used for
dvander@1203
   818
** tracing and profiling the execution of SQL statements.
dvander@1203
   819
** The callback function registered by sqlite3_trace() is invoked
dvander@1203
   820
** at the first [sqlite3_step()] for the evaluation of an SQL statement.
dvander@1203
   821
** The callback function registered by sqlite3_profile() is invoked
dvander@1203
   822
** as each SQL statement finishes and includes
dvander@1203
   823
** information on how long that statement ran.
dvander@1203
   824
**
dvander@1203
   825
** The sqlite3_profile() API is currently considered experimental and
dvander@1203
   826
** is subject to change.
dvander@1203
   827
*/
dvander@1203
   828
void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
dvander@1203
   829
void *sqlite3_profile(sqlite3*,
dvander@1203
   830
   void(*xProfile)(void*,const char*,sqlite_uint64), void*);
dvander@1203
   831
dvander@1203
   832
/*
dvander@1203
   833
** CAPI3REF: Query Progress Callbacks
dvander@1203
   834
**
dvander@1203
   835
** This routine configures a callback function - the progress callback - that
dvander@1203
   836
** is invoked periodically during long running calls to [sqlite3_exec()],
dvander@1203
   837
** [sqlite3_step()] and [sqlite3_get_table()].  An example use for this 
dvander@1203
   838
** interface is to keep a GUI updated during a large query.
dvander@1203
   839
**
dvander@1203
   840
** The progress callback is invoked once for every N virtual machine opcodes,
dvander@1203
   841
** where N is the second argument to this function. The progress callback
dvander@1203
   842
** itself is identified by the third argument to this function. The fourth
dvander@1203
   843
** argument to this function is a void pointer passed to the progress callback
dvander@1203
   844
** function each time it is invoked.
dvander@1203
   845
**
dvander@1203
   846
** If a call to [sqlite3_exec()], [sqlite3_step()], or [sqlite3_get_table()]
dvander@1203
   847
** results in fewer than N opcodes being executed, then the progress 
dvander@1203
   848
** callback is never invoked.
dvander@1203
   849
** 
dvander@1203
   850
** Only a single progress callback function may be registered for each
dvander@1203
   851
** open database connection.  Every call to sqlite3_progress_handler()
dvander@1203
   852
** overwrites the results of the previous call.
dvander@1203
   853
** To remove the progress callback altogether, pass NULL as the third
dvander@1203
   854
** argument to this function.
dvander@1203
   855
**
dvander@1203
   856
** If the progress callback returns a result other than 0, then the current 
dvander@1203
   857
** query is immediately terminated and any database changes rolled back.
dvander@1203
   858
** The containing [sqlite3_exec()], [sqlite3_step()], or
dvander@1203
   859
** [sqlite3_get_table()] call returns SQLITE_INTERRUPT.   This feature
dvander@1203
   860
** can be used, for example, to implement the "Cancel" button on a
dvander@1203
   861
** progress dialog box in a GUI.
dvander@1203
   862
*/
dvander@1203
   863
void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
dvander@1203
   864
dvander@1203
   865
/*
dvander@1203
   866
** CAPI3REF: Opening A New Database Connection
dvander@1203
   867
**
dvander@1203
   868
** Open the sqlite database file "filename".  The "filename" is UTF-8
dvander@1203
   869
** encoded for sqlite3_open() and UTF-16 encoded in the native byte order
dvander@1203
   870
** for sqlite3_open16().  An [sqlite3*] handle is returned in *ppDb, even
dvander@1203
   871
** if an error occurs. If the database is opened (or created) successfully,
dvander@1203
   872
** then SQLITE_OK is returned. Otherwise an error code is returned. The
dvander@1203
   873
** sqlite3_errmsg() or sqlite3_errmsg16()  routines can be used to obtain
dvander@1203
   874
** an English language description of the error.
dvander@1203
   875
**
dvander@1203
   876
** If the database file does not exist, then a new database will be created
dvander@1203
   877
** as needed.  The default encoding for the database will be UTF-8 if
dvander@1203
   878
** sqlite3_open() is called and UTF-16 if sqlite3_open16 is used.
dvander@1203
   879
**
dvander@1203
   880
** Whether or not an error occurs when it is opened, resources associated
dvander@1203
   881
** with the [sqlite3*] handle should be released by passing it to
dvander@1203
   882
** sqlite3_close() when it is no longer required.
dvander@1203
   883
**
dvander@1203
   884
** Note to windows users:  The encoding used for the filename argument
dvander@1203
   885
** of sqlite3_open() must be UTF-8, not whatever codepage is currently
dvander@1203
   886
** defined.  Filenames containing international characters must be converted
dvander@1203
   887
** to UTF-8 prior to passing them into sqlite3_open().
dvander@1203
   888
*/
dvander@1203
   889
int sqlite3_open(
dvander@1203
   890
  const char *filename,   /* Database filename (UTF-8) */
dvander@1203
   891
  sqlite3 **ppDb          /* OUT: SQLite db handle */
dvander@1203
   892
);
dvander@1203
   893
int sqlite3_open16(
dvander@1203
   894
  const void *filename,   /* Database filename (UTF-16) */
dvander@1203
   895
  sqlite3 **ppDb          /* OUT: SQLite db handle */
dvander@1203
   896
);
dvander@1203
   897
dvander@1203
   898
/*
dvander@1203
   899
** CAPI3REF: Error Codes And Messages
dvander@1203
   900
**
dvander@1203
   901
** The sqlite3_errcode() interface returns the numeric
dvander@1203
   902
** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code]
dvander@1203
   903
** for the most recent failed sqlite3_* API call associated
dvander@1203
   904
** with [sqlite3] handle 'db'.  If a prior API call failed but the
dvander@1203
   905
** most recent API call succeeded, the return value from sqlite3_errcode()
dvander@1203
   906
** is undefined. 
dvander@1203
   907
**
dvander@1203
   908
** The sqlite3_errmsg() and sqlite3_errmsg16() return English-langauge
dvander@1203
   909
** text that describes the error, as either UTF8 or UTF16 respectively.
dvander@1203
   910
** Memory to hold the error message string is managed internally.  The 
dvander@1203
   911
** string may be overwritten or deallocated by subsequent calls to SQLite
dvander@1203
   912
** interface functions.
dvander@1203
   913
**
dvander@1203
   914
** Calls to many sqlite3_* functions set the error code and string returned
dvander@1203
   915
** by [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()]
dvander@1203
   916
** (overwriting the previous values). Note that calls to [sqlite3_errcode()],
dvander@1203
   917
** [sqlite3_errmsg()], and [sqlite3_errmsg16()] themselves do not affect the
dvander@1203
   918
** results of future invocations.  Calls to API routines that do not return
dvander@1203
   919
** an error code (examples: [sqlite3_data_count()] or [sqlite3_mprintf()]) do
dvander@1203
   920
** not change the error code returned by this routine.
dvander@1203
   921
**
dvander@1203
   922
** Assuming no other intervening sqlite3_* API calls are made, the error
dvander@1203
   923
** code returned by this function is associated with the same error as
dvander@1203
   924
** the strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()].
dvander@1203
   925
*/
dvander@1203
   926
int sqlite3_errcode(sqlite3 *db);
dvander@1203
   927
const char *sqlite3_errmsg(sqlite3*);
dvander@1203
   928
const void *sqlite3_errmsg16(sqlite3*);
dvander@1203
   929
dvander@1203
   930
/*
dvander@1203
   931
** CAPI3REF: SQL Statement Object
dvander@1203
   932
**
dvander@1203
   933
** Instance of this object represent single SQL statements.  This
dvander@1203
   934
** is variously known as a "prepared statement" or a 
dvander@1203
   935
** "compiled SQL statement" or simply as a "statement".
dvander@1203
   936
** 
dvander@1203
   937
** The life of a statement object goes something like this:
dvander@1203
   938
**
dvander@1203
   939
** <ol>
dvander@1203
   940
** <li> Create the object using [sqlite3_prepare_v2()] or a related
dvander@1203
   941
**      function.
dvander@1203
   942
** <li> Bind values to host parameters using
dvander@1203
   943
**      [sqlite3_bind_blob | sqlite3_bind_* interfaces].
dvander@1203
   944
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
dvander@1203
   945
** <li> Reset the statement using [sqlite3_reset()] then go back
dvander@1203
   946
**      to step 2.  Do this zero or more times.
dvander@1203
   947
** <li> Destroy the object using [sqlite3_finalize()].
dvander@1203
   948
** </ol>
dvander@1203
   949
**
dvander@1203
   950
** Refer to documentation on individual methods above for additional
dvander@1203
   951
** information.
dvander@1203
   952
*/
dvander@1203
   953
typedef struct sqlite3_stmt sqlite3_stmt;
dvander@1203
   954
dvander@1203
   955
/*
dvander@1203
   956
** CAPI3REF: Compiling An SQL Statement
dvander@1203
   957
**
dvander@1203
   958
** To execute an SQL query, it must first be compiled into a byte-code
dvander@1203
   959
** program using one of these routines. 
dvander@1203
   960
**
dvander@1203
   961
** The first argument "db" is an [sqlite3 | SQLite database handle] 
dvander@1203
   962
** obtained from a prior call to [sqlite3_open()] or [sqlite3_open16()].
dvander@1203
   963
** The second argument "zSql" is the statement to be compiled, encoded
dvander@1203
   964
** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
dvander@1203
   965
** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2()
dvander@1203
   966
** use UTF-16.
dvander@1203
   967
**
dvander@1203
   968
** If the nByte argument is less
dvander@1203
   969
** than zero, then zSql is read up to the first zero terminator.  If
dvander@1203
   970
** nByte is non-negative, then it is the maximum number of 
dvander@1203
   971
** bytes read from zSql.  When nByte is non-negative, the
dvander@1203
   972
** zSql string ends at either the first '\000' character or 
dvander@1203
   973
** until the nByte-th byte, whichever comes first.
dvander@1203
   974
**
dvander@1203
   975
** *pzTail is made to point to the first byte past the end of the first
dvander@1203
   976
** SQL statement in zSql.  This routine only compiles the first statement
dvander@1203
   977
** in zSql, so *pzTail is left pointing to what remains uncompiled.
dvander@1203
   978
**
dvander@1203
   979
** *ppStmt is left pointing to a compiled 
dvander@1203
   980
** [sqlite3_stmt | SQL statement structure] that can be
dvander@1203
   981
** executed using [sqlite3_step()].  Or if there is an error, *ppStmt may be
dvander@1203
   982
** set to NULL.  If the input text contained no SQL (if the input is and
dvander@1203
   983
** empty string or a comment) then *ppStmt is set to NULL.  The calling
dvander@1203
   984
** procedure is responsible for deleting the compiled SQL statement
dvander@1203
   985
** using [sqlite3_finalize()] after it has finished with it.
dvander@1203
   986
**
dvander@1203
   987
** On success, [SQLITE_OK] is returned.  Otherwise an 
dvander@1203
   988
** [SQLITE_ERROR | error code] is returned.
dvander@1203
   989
**
dvander@1203
   990
** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
dvander@1203
   991
** recommended for all new programs. The two older interfaces are retained
dvander@1203
   992
** for backwards compatibility, but their use is discouraged.
dvander@1203
   993
** In the "v2" interfaces, the prepared statement
dvander@1203
   994
** that is returned (the [sqlite3_stmt] object) contains a copy of the 
dvander@1203
   995
** original SQL text. This causes the [sqlite3_step()] interface to
dvander@1203
   996
** behave a differently in two ways:
dvander@1203
   997
**
dvander@1203
   998
** <ol>
dvander@1203
   999
** <li>
dvander@1203
  1000
** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
dvander@1203
  1001
** always used to do, [sqlite3_step()] will automatically recompile the SQL
dvander@1203
  1002
** statement and try to run it again.  If the schema has changed in a way
dvander@1203
  1003
** that makes the statement no longer valid, [sqlite3_step()] will still
dvander@1203
  1004
** return [SQLITE_SCHEMA].  But unlike the legacy behavior, [SQLITE_SCHEMA] is
dvander@1203
  1005
** now a fatal error.  Calling [sqlite3_prepare_v2()] again will not make the
dvander@1203
  1006
** error go away.  Note: use [sqlite3_errmsg()] to find the text of the parsing
dvander@1203
  1007
** error that results in an [SQLITE_SCHEMA] return.
dvander@1203
  1008
** </li>
dvander@1203
  1009
**
dvander@1203
  1010
** <li>
dvander@1203
  1011
** When an error occurs, 
dvander@1203
  1012
** [sqlite3_step()] will return one of the detailed 
dvander@1203
  1013
** [SQLITE_ERROR | result codes] or
dvander@1203
  1014
** [SQLITE_IOERR_READ | extended result codes] such as directly.
dvander@1203
  1015
** The legacy behavior was that [sqlite3_step()] would only return a generic
dvander@1203
  1016
** [SQLITE_ERROR] result code and you would have to make a second call to
dvander@1203
  1017
** [sqlite3_reset()] in order to find the underlying cause of the problem.
dvander@1203
  1018
** With the "v2" prepare interfaces, the underlying reason for the error is
dvander@1203
  1019
** returned immediately.
dvander@1203
  1020
** </li>
dvander@1203
  1021
** </ol>
dvander@1203
  1022
*/
dvander@1203
  1023
int sqlite3_prepare(
dvander@1203
  1024
  sqlite3 *db,            /* Database handle */
dvander@1203
  1025
  const char *zSql,       /* SQL statement, UTF-8 encoded */
dvander@1203
  1026
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1027
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1028
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1029
);
dvander@1203
  1030
int sqlite3_prepare_v2(
dvander@1203
  1031
  sqlite3 *db,            /* Database handle */
dvander@1203
  1032
  const char *zSql,       /* SQL statement, UTF-8 encoded */
dvander@1203
  1033
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1034
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1035
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1036
);
dvander@1203
  1037
int sqlite3_prepare16(
dvander@1203
  1038
  sqlite3 *db,            /* Database handle */
dvander@1203
  1039
  const void *zSql,       /* SQL statement, UTF-16 encoded */
dvander@1203
  1040
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1041
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1042
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1043
);
dvander@1203
  1044
int sqlite3_prepare16_v2(
dvander@1203
  1045
  sqlite3 *db,            /* Database handle */
dvander@1203
  1046
  const void *zSql,       /* SQL statement, UTF-16 encoded */
dvander@1203
  1047
  int nByte,              /* Maximum length of zSql in bytes. */
dvander@1203
  1048
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
dvander@1203
  1049
  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
dvander@1203
  1050
);
dvander@1203
  1051
dvander@1203
  1052
/*
dvander@1203
  1053
** CAPI3REF:  Dynamically Typed Value Object
dvander@1203
  1054
**
dvander@1203
  1055
** SQLite uses dynamic typing for the values it stores.  Values can 
dvander@1203
  1056
** be integers, floating point values, strings, BLOBs, or NULL.  When
dvander@1203
  1057
** passing around values internally, each value is represented as
dvander@1203
  1058
** an instance of the sqlite3_value object.
dvander@1203
  1059
*/
dvander@1203
  1060
typedef struct Mem sqlite3_value;
dvander@1203
  1061
dvander@1203
  1062
/*
dvander@1203
  1063
** CAPI3REF:  SQL Function Context Object
dvander@1203
  1064
**
dvander@1203
  1065
** The context in which an SQL function executes is stored in an
dvander@1203
  1066
** sqlite3_context object.  A pointer to such an object is the
dvander@1203
  1067
** first parameter to user-defined SQL functions.
dvander@1203
  1068
*/
dvander@1203
  1069
typedef struct sqlite3_context sqlite3_context;
dvander@1203
  1070
dvander@1203
  1071
/*
dvander@1203
  1072
** CAPI3REF:  Binding Values To Prepared Statements
dvander@1203
  1073
**
dvander@1203
  1074
** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
dvander@1203
  1075
** one or more literals can be replace by a parameter in one of these
dvander@1203
  1076
** forms:
dvander@1203
  1077
**
dvander@1203
  1078
** <ul>
dvander@1203
  1079
** <li>  ?
dvander@1203
  1080
** <li>  ?NNN
dvander@1203
  1081
** <li>  :AAA
dvander@1203
  1082
** <li>  @AAA
dvander@1203
  1083
** <li>  $VVV
dvander@1203
  1084
** </ul>
dvander@1203
  1085
**
dvander@1203
  1086
** In the parameter forms shown above NNN is an integer literal,
dvander@1203
  1087
** AAA is an alphanumeric identifier and VVV is a variable name according
dvander@1203
  1088
** to the syntax rules of the TCL programming language.
dvander@1203
  1089
** The values of these parameters (also called "host parameter names")
dvander@1203
  1090
** can be set using the sqlite3_bind_*() routines defined here.
dvander@1203
  1091
**
dvander@1203
  1092
** The first argument to the sqlite3_bind_*() routines always is a pointer
dvander@1203
  1093
** to the [sqlite3_stmt] object returned from [sqlite3_prepare_v2()] or
dvander@1203
  1094
** its variants.  The second
dvander@1203
  1095
** argument is the index of the parameter to be set.  The first parameter has
dvander@1203
  1096
** an index of 1. When the same named parameter is used more than once, second
dvander@1203
  1097
** and subsequent
dvander@1203
  1098
** occurrences have the same index as the first occurrence.  The index for
dvander@1203
  1099
** named parameters can be looked up using the
dvander@1203
  1100
** [sqlite3_bind_parameter_name()] API if desired.  The index for "?NNN"
dvander@1203
  1101
** parametes is the value of NNN.
dvander@1203
  1102
** The NNN value must be between 1 and the compile-time
dvander@1203
  1103
** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999).
dvander@1203
  1104
** See <a href="limits.html">limits.html</a> for additional information.
dvander@1203
  1105
**
dvander@1203
  1106
** The third argument is the value to bind to the parameter.
dvander@1203
  1107
**
dvander@1203
  1108
** In those
dvander@1203
  1109
** routines that have a fourth argument, its value is the number of bytes
dvander@1203
  1110
** in the parameter.  To be clear: the value is the number of bytes in the
dvander@1203
  1111
** string, not the number of characters.  The number
dvander@1203
  1112
** of bytes does not include the zero-terminator at the end of strings.
dvander@1203
  1113
** If the fourth parameter is negative, the length of the string is
dvander@1203
  1114
** number of bytes up to the first zero terminator.
dvander@1203
  1115
**
dvander@1203
  1116
** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
dvander@1203
  1117
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
dvander@1203
  1118
** text after SQLite has finished with it.  If the fifth argument is the
dvander@1203
  1119
** special value [SQLITE_STATIC], then the library assumes that the information
dvander@1203
  1120
** is in static, unmanaged space and does not need to be freed.  If the
dvander@1203
  1121
** fifth argument has the value [SQLITE_TRANSIENT], then SQLite makes its
dvander@1203
  1122
** own private copy of the data immediately, before the sqlite3_bind_*()
dvander@1203
  1123
** routine returns.
dvander@1203
  1124
**
dvander@1203
  1125
** The sqlite3_bind_zeroblob() routine binds a BLOB of length n that
dvander@1203
  1126
** is filled with zeros.  A zeroblob uses a fixed amount of memory
dvander@1203
  1127
** (just an integer to hold it size) while it is being processed.
dvander@1203
  1128
** Zeroblobs are intended to serve as place-holders for BLOBs whose
dvander@1203
  1129
** content is later written using 
dvander@1203
  1130
** [sqlite3_blob_open | increment BLOB I/O] routines.
dvander@1203
  1131
**
dvander@1203
  1132
** The sqlite3_bind_*() routines must be called after
dvander@1203
  1133
** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and
dvander@1203
  1134
** before [sqlite3_step()].
dvander@1203
  1135
** Bindings are not cleared by the [sqlite3_reset()] routine.
dvander@1203
  1136
** Unbound parameters are interpreted as NULL.
dvander@1203
  1137
**
dvander@1203
  1138
** These routines return [SQLITE_OK] on success or an error code if
dvander@1203
  1139
** anything goes wrong.  [SQLITE_RANGE] is returned if the parameter
dvander@1203
  1140
** index is out of range.  [SQLITE_NOMEM] is returned if malloc fails.
dvander@1203
  1141
** [SQLITE_MISUSE] is returned if these routines are called on a virtual
dvander@1203
  1142
** machine that is the wrong state or which has already been finalized.
dvander@1203
  1143
*/
dvander@1203
  1144
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
dvander@1203
  1145
int sqlite3_bind_double(sqlite3_stmt*, int, double);
dvander@1203
  1146
int sqlite3_bind_int(sqlite3_stmt*, int, int);
dvander@1203
  1147
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite_int64);
dvander@1203
  1148
int sqlite3_bind_null(sqlite3_stmt*, int);
dvander@1203
  1149
int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
dvander@1203
  1150
int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
dvander@1203
  1151
int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
dvander@1203
  1152
int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
dvander@1203
  1153
dvander@1203
  1154
/*
dvander@1203
  1155
** CAPI3REF: Number Of Host Parameters
dvander@1203
  1156
**
dvander@1203
  1157
** Return the largest host parameter index in the precompiled statement given
dvander@1203
  1158
** as the argument.  When the host parameters are of the forms like ":AAA"
dvander@1203
  1159
** or "?", then they are assigned sequential increasing numbers beginning
dvander@1203
  1160
** with one, so the value returned is the number of parameters.  However
dvander@1203
  1161
** if the same host parameter name is used multiple times, each occurrance
dvander@1203
  1162
** is given the same number, so the value returned in that case is the number
dvander@1203
  1163
** of unique host parameter names.  If host parameters of the form "?NNN"
dvander@1203
  1164
** are used (where NNN is an integer) then there might be gaps in the
dvander@1203
  1165
** numbering and the value returned by this interface is the index of the
dvander@1203
  1166
** host parameter with the largest index value.
dvander@1203
  1167
*/
dvander@1203
  1168
int sqlite3_bind_parameter_count(sqlite3_stmt*);
dvander@1203
  1169
dvander@1203
  1170
/*
dvander@1203
  1171
** CAPI3REF: Name Of A Host Parameter
dvander@1203
  1172
**
dvander@1203
  1173
** This routine returns a pointer to the name of the n-th parameter in a 
dvander@1203
  1174
** [sqlite3_stmt | prepared statement].
dvander@1203
  1175
** Host parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
dvander@1203
  1176
** which is the string ":AAA" or "@AAA" or "$VVV".  
dvander@1203
  1177
** In other words, the initial ":" or "$" or "@"
dvander@1203
  1178
** is included as part of the name.
dvander@1203
  1179
** Parameters of the form "?" or "?NNN" have no name.
dvander@1203
  1180
**
dvander@1203
  1181
** The first bound parameter has an index of 1, not 0.
dvander@1203
  1182
**
dvander@1203
  1183
** If the value n is out of range or if the n-th parameter is nameless,
dvander@1203
  1184
** then NULL is returned.  The returned string is always in the
dvander@1203
  1185
** UTF-8 encoding even if the named parameter was originally specified
dvander@1203
  1186
** as UTF-16 in [sqlite3_prepare16()] or [sqlite3_prepare16_v2()].
dvander@1203
  1187
*/
dvander@1203
  1188
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
dvander@1203
  1189
dvander@1203
  1190
/*
dvander@1203
  1191
** CAPI3REF: Index Of A Parameter With A Given Name
dvander@1203
  1192
**
dvander@1203
  1193
** This routine returns the index of a host parameter with the given name.
dvander@1203
  1194
** The name must match exactly.  If no parameter with the given name is 
dvander@1203
  1195
** found, return 0.  Parameter names must be UTF8.
dvander@1203
  1196
*/
dvander@1203
  1197
int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
dvander@1203
  1198
dvander@1203
  1199
/*
dvander@1203
  1200
** CAPI3REF: Reset All Bindings On A Prepared Statement
dvander@1203
  1201
**
dvander@1203
  1202
** Contrary to the intuition of many, [sqlite3_reset()] does not
dvander@1203
  1203
** reset the [sqlite3_bind_blob | bindings] on a 
dvander@1203
  1204
** [sqlite3_stmt | prepared statement].  Use this routine to
dvander@1203
  1205
** reset all host parameters to NULL.
dvander@1203
  1206
*/
dvander@1203
  1207
int sqlite3_clear_bindings(sqlite3_stmt*);
dvander@1203
  1208
dvander@1203
  1209
/*
dvander@1203
  1210
** CAPI3REF: Number Of Columns In A Result Set
dvander@1203
  1211
**
dvander@1203
  1212
** Return the number of columns in the result set returned by the 
dvander@1203
  1213
** [sqlite3_stmt | compiled SQL statement]. This routine returns 0
dvander@1203
  1214
** if pStmt is an SQL statement that does not return data (for 
dvander@1203
  1215
** example an UPDATE).
dvander@1203
  1216
*/
dvander@1203
  1217
int sqlite3_column_count(sqlite3_stmt *pStmt);
dvander@1203
  1218
dvander@1203
  1219
/*
dvander@1203
  1220
** CAPI3REF: Column Names In A Result Set
dvander@1203
  1221
**
dvander@1203
  1222
** These routines return the name assigned to a particular column
dvander@1203
  1223
** in the result set of a SELECT statement.  The sqlite3_column_name()
dvander@1203
  1224
** interface returns a pointer to a UTF8 string and sqlite3_column_name16()
dvander@1203
  1225
** returns a pointer to a UTF16 string.  The first parameter is the
dvander@1203
  1226
** [sqlite_stmt | prepared statement] that implements the SELECT statement.
dvander@1203
  1227
** The second parameter is the column number.  The left-most column is
dvander@1203
  1228
** number 0.
dvander@1203
  1229
**
dvander@1203
  1230
** The returned string pointer is valid until either the 
dvander@1203
  1231
** [sqlite_stmt | prepared statement] is destroyed by [sqlite3_finalize()]
dvander@1203
  1232
** or until the next call sqlite3_column_name() or sqlite3_column_name16()
dvander@1203
  1233
** on the same column.
dvander@1203
  1234
*/
dvander@1203
  1235
const char *sqlite3_column_name(sqlite3_stmt*, int N);
dvander@1203
  1236
const void *sqlite3_column_name16(sqlite3_stmt*, int N);
dvander@1203
  1237
dvander@1203
  1238
/*
dvander@1203
  1239
** CAPI3REF: Source Of Data In A Query Result
dvander@1203
  1240
**
dvander@1203
  1241
** These routines provide a means to determine what column of what
dvander@1203
  1242
** table in which database a result of a SELECT statement comes from.
dvander@1203
  1243
** The name of the database or table or column can be returned as
dvander@1203
  1244
** either a UTF8 or UTF16 string.  The _database_ routines return
dvander@1203
  1245
** the database name, the _table_ routines return the table name, and
dvander@1203
  1246
** the origin_ routines return the column name.
dvander@1203
  1247
** The returned string is valid until
dvander@1203
  1248
** the [sqlite3_stmt | prepared statement] is destroyed using
dvander@1203
  1249
** [sqlite3_finalize()] or until the same information is requested
dvander@1203
  1250
** again in a different encoding.
dvander@1203
  1251
**
dvander@1203
  1252
** The names returned are the original un-aliased names of the
dvander@1203
  1253
** database, table, and column.
dvander@1203
  1254
**
dvander@1203
  1255
** The first argument to the following calls is a 
dvander@1203
  1256
** [sqlite3_stmt | compiled SQL statement].
dvander@1203
  1257
** These functions return information about the Nth column returned by 
dvander@1203
  1258
** the statement, where N is the second function argument.
dvander@1203
  1259
**
dvander@1203
  1260
** If the Nth column returned by the statement is an expression
dvander@1203
  1261
** or subquery and is not a column value, then all of these functions
dvander@1203
  1262
** return NULL. Otherwise, they return the 
dvander@1203
  1263
** name of the attached database, table and column that query result
dvander@1203
  1264
** column was extracted from.
dvander@1203
  1265
**
dvander@1203
  1266
** As with all other SQLite APIs, those postfixed with "16" return UTF-16
dvander@1203
  1267
** encoded strings, the other functions return UTF-8.
dvander@1203
  1268
**
dvander@1203
  1269
** These APIs are only available if the library was compiled with the 
dvander@1203
  1270
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
dvander@1203
  1271
*/
dvander@1203
  1272
const char *sqlite3_column_database_name(sqlite3_stmt*,int);
dvander@1203
  1273
const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
dvander@1203
  1274
const char *sqlite3_column_table_name(sqlite3_stmt*,int);
dvander@1203
  1275
const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
dvander@1203
  1276
const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
dvander@1203
  1277
const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
dvander@1203
  1278
dvander@1203
  1279
/*
dvander@1203
  1280
** CAPI3REF: Declared Datatype Of A Query Result
dvander@1203
  1281
**
dvander@1203
  1282
** The first parameter is a [sqlite3_stmt | compiled SQL statement]. 
dvander@1203
  1283
** If this statement is a SELECT statement and the Nth column of the 
dvander@1203
  1284
** returned result set  of that SELECT is a table column (not an
dvander@1203
  1285
** expression or subquery) then the declared type of the table
dvander@1203
  1286
** column is returned. If the Nth column of the result set is an
dvander@1203
  1287
** expression or subquery, then a NULL pointer is returned.
dvander@1203
  1288
** The returned string is always UTF-8 encoded. For example, in
dvander@1203
  1289
** the database schema:
dvander@1203
  1290
**
dvander@1203
  1291
** CREATE TABLE t1(c1 VARIANT);
dvander@1203
  1292
**
dvander@1203
  1293
** And the following statement compiled:
dvander@1203
  1294
**
dvander@1203
  1295
** SELECT c1 + 1, c1 FROM t1;
dvander@1203
  1296
**
dvander@1203
  1297
** Then this routine would return the string "VARIANT" for the second
dvander@1203
  1298
** result column (i==1), and a NULL pointer for the first result column
dvander@1203
  1299
** (i==0).
dvander@1203
  1300
**
dvander@1203
  1301
** SQLite uses dynamic run-time typing.  So just because a column
dvander@1203
  1302
** is declared to contain a particular type does not mean that the
dvander@1203
  1303
** data stored in that column is of the declared type.  SQLite is
dvander@1203
  1304
** strongly typed, but the typing is dynamic not static.  Type
dvander@1203
  1305
** is associated with individual values, not with the containers
dvander@1203
  1306
** used to hold those values.
dvander@1203
  1307
*/
dvander@1203
  1308
const char *sqlite3_column_decltype(sqlite3_stmt *, int i);
dvander@1203
  1309
const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
dvander@1203
  1310
dvander@1203
  1311
/* 
dvander@1203
  1312
** CAPI3REF:  Evaluate An SQL Statement
dvander@1203
  1313
**
dvander@1203
  1314
** After an [sqlite3_stmt | SQL statement] has been prepared with a call
dvander@1203
  1315
** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of
dvander@1203
  1316
** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()],
dvander@1203
  1317
** then this function must be called one or more times to evaluate the 
dvander@1203
  1318
** statement.
dvander@1203
  1319
**
dvander@1203
  1320
** The details of the behavior of this sqlite3_step() interface depend
dvander@1203
  1321
** on whether the statement was prepared using the newer "v2" interface
dvander@1203
  1322
** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
dvander@1203
  1323
** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
dvander@1203
  1324
** new "v2" interface is recommended for new applications but the legacy
dvander@1203
  1325
** interface will continue to be supported.
dvander@1203
  1326
**
dvander@1203
  1327
** In the lagacy interface, the return value will be either [SQLITE_BUSY], 
dvander@1203
  1328
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
dvander@1203
  1329
** With the "v2" interface, any of the other [SQLITE_OK | result code]
dvander@1203
  1330
** or [SQLITE_IOERR_READ | extended result code] might be returned as
dvander@1203
  1331
** well.
dvander@1203
  1332
**
dvander@1203
  1333
** [SQLITE_BUSY] means that the database engine was unable to acquire the
dvander@1203
  1334
** database locks it needs to do its job.  If the statement is a COMMIT
dvander@1203
  1335
** or occurs outside of an explicit transaction, then you can retry the
dvander@1203
  1336
** statement.  If the statement is not a COMMIT and occurs within a
dvander@1203
  1337
** explicit transaction then you should rollback the transaction before
dvander@1203
  1338
** continuing.
dvander@1203
  1339
**
dvander@1203
  1340
** [SQLITE_DONE] means that the statement has finished executing
dvander@1203
  1341
** successfully.  sqlite3_step() should not be called again on this virtual
dvander@1203
  1342
** machine without first calling [sqlite3_reset()] to reset the virtual
dvander@1203
  1343
** machine back to its initial state.
dvander@1203
  1344
**
dvander@1203
  1345
** If the SQL statement being executed returns any data, then 
dvander@1203
  1346
** [SQLITE_ROW] is returned each time a new row of data is ready
dvander@1203
  1347
** for processing by the caller. The values may be accessed using
dvander@1203
  1348
** the [sqlite3_column_int | column access functions].
dvander@1203
  1349
** sqlite3_step() is called again to retrieve the next row of data.
dvander@1203
  1350
** 
dvander@1203
  1351
** [SQLITE_ERROR] means that a run-time error (such as a constraint
dvander@1203
  1352
** violation) has occurred.  sqlite3_step() should not be called again on
dvander@1203
  1353
** the VM. More information may be found by calling [sqlite3_errmsg()].
dvander@1203
  1354
** With the legacy interface, a more specific error code (example:
dvander@1203
  1355
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
dvander@1203
  1356
** can be obtained by calling [sqlite3_reset()] on the
dvander@1203
  1357
** [sqlite_stmt | prepared statement].  In the "v2" interface,
dvander@1203
  1358
** the more specific error code is returned directly by sqlite3_step().
dvander@1203
  1359
**
dvander@1203
  1360
** [SQLITE_MISUSE] means that the this routine was called inappropriately.
dvander@1203
  1361
** Perhaps it was called on a [sqlite_stmt | prepared statement] that has
dvander@1203
  1362
** already been [sqlite3_finalize | finalized] or on one that had 
dvander@1203
  1363
** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
dvander@1203
  1364
** be the case that the same database connection is being used by two or
dvander@1203
  1365
** more threads at the same moment in time.
dvander@1203
  1366
**
dvander@1203
  1367
** <b>Goofy Interface Alert:</b>
dvander@1203
  1368
** In the legacy interface, 
dvander@1203
  1369
** the sqlite3_step() API always returns a generic error code,
dvander@1203
  1370
** [SQLITE_ERROR], following any error other than [SQLITE_BUSY]
dvander@1203
  1371
** and [SQLITE_MISUSE].  You must call [sqlite3_reset()] or
dvander@1203
  1372
** [sqlite3_finalize()] in order to find one of the specific
dvander@1203
  1373
** [SQLITE_ERROR | result codes] that better describes the error.
dvander@1203
  1374
** We admit that this is a goofy design.  The problem has been fixed
dvander@1203
  1375
** with the "v2" interface.  If you prepare all of your SQL statements
dvander@1203
  1376
** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
dvander@1203
  1377
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the 
dvander@1203
  1378
** more specific [SQLITE_ERROR | result codes] are returned directly
dvander@1203
  1379
** by sqlite3_step().  The use of the "v2" interface is recommended.
dvander@1203
  1380
*/
dvander@1203
  1381
int sqlite3_step(sqlite3_stmt*);
dvander@1203
  1382
dvander@1203
  1383
/*
dvander@1203
  1384
** CAPI3REF:
dvander@1203
  1385
**
dvander@1203
  1386
** Return the number of values in the current row of the result set.
dvander@1203
  1387
**
dvander@1203
  1388
** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine
dvander@1203
  1389
** will return the same value as the [sqlite3_column_count()] function.
dvander@1203
  1390
** After [sqlite3_step()] has returned an [SQLITE_DONE], [SQLITE_BUSY], or
dvander@1203
  1391
** a [SQLITE_ERROR | error code], or before [sqlite3_step()] has been 
dvander@1203
  1392
** called on the [sqlite_stmt | prepared statement] for the first time,
dvander@1203
  1393
** this routine returns zero.
dvander@1203
  1394
*/
dvander@1203
  1395
int sqlite3_data_count(sqlite3_stmt *pStmt);
dvander@1203
  1396
dvander@1203
  1397
/*
dvander@1203
  1398
** CAPI3REF: Fundamental Datatypes
dvander@1203
  1399
**
dvander@1203
  1400
** Every value in SQLite has one of five fundamental datatypes:
dvander@1203
  1401
**
dvander@1203
  1402
** <ul>
dvander@1203
  1403
** <li> 64-bit signed integer
dvander@1203
  1404
** <li> 64-bit IEEE floating point number
dvander@1203
  1405
** <li> string
dvander@1203
  1406
** <li> BLOB
dvander@1203
  1407
** <li> NULL
dvander@1203
  1408
** </ul>
dvander@1203
  1409
**
dvander@1203
  1410
** These constants are codes for each of those types.
dvander@1203
  1411
**
dvander@1203
  1412
** Note that the SQLITE_TEXT constant was also used in SQLite version 2
dvander@1203
  1413
** for a completely different meaning.  Software that links against both
dvander@1203
  1414
** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not
dvander@1203
  1415
** SQLITE_TEXT.
dvander@1203
  1416
*/
dvander@1203
  1417
#define SQLITE_INTEGER  1
dvander@1203
  1418
#define SQLITE_FLOAT    2
dvander@1203
  1419
#define SQLITE_BLOB     4
dvander@1203
  1420
#define SQLITE_NULL     5
dvander@1203
  1421
#ifdef SQLITE_TEXT
dvander@1203
  1422
# undef SQLITE_TEXT
dvander@1203
  1423
#else
dvander@1203
  1424
# define SQLITE_TEXT     3
dvander@1203
  1425
#endif
dvander@1203
  1426
#define SQLITE3_TEXT     3
dvander@1203
  1427
dvander@1203
  1428
/*
dvander@1203
  1429
** CAPI3REF: Results Values From A Query
dvander@1203
  1430
**
dvander@1203
  1431
** These routines return information about the information
dvander@1203
  1432
** in a single column of the current result row of a query.  In every
dvander@1203
  1433
** case the first argument is a pointer to the 
dvander@1203
  1434
** [sqlite3_stmt | SQL statement] that is being
dvander@1203
  1435
** evaluate (the [sqlite_stmt*] that was returned from 
dvander@1203
  1436
** [sqlite3_prepare_v2()] or one of its variants) and
dvander@1203
  1437
** the second argument is the index of the column for which information 
dvander@1203
  1438
** should be returned.  The left-most column has an index of 0.
dvander@1203
  1439
**
dvander@1203
  1440
** If the SQL statement is not currently point to a valid row, or if the
dvander@1203
  1441
** the column index is out of range, the result is undefined.
dvander@1203
  1442
**
dvander@1203
  1443
** The sqlite3_column_type() routine returns 
dvander@1203
  1444
** [SQLITE_INTEGER | datatype code] for the initial data type
dvander@1203
  1445
** of the result column.  The returned value is one of [SQLITE_INTEGER],
dvander@1203
  1446
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
dvander@1203
  1447
** returned by sqlite3_column_type() is only meaningful if no type
dvander@1203
  1448
** conversions have occurred as described below.  After a type conversion,
dvander@1203
  1449
** the value returned by sqlite3_column_type() is undefined.  Future
dvander@1203
  1450
** versions of SQLite may change the behavior of sqlite3_column_type()
dvander@1203
  1451
** following a type conversion.
dvander@1203
  1452
**
dvander@1203
  1453
** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 
dvander@1203
  1454
** routine returns the number of bytes in that BLOB or string.
dvander@1203
  1455
** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
dvander@1203
  1456
** the string to UTF-8 and then returns the number of bytes.
dvander@1203
  1457
** If the result is a numeric value then sqlite3_column_bytes() uses
dvander@1203
  1458
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
dvander@1203
  1459
** the number of bytes in that string.
dvander@1203
  1460
** The value returned does not include the zero terminator at the end
dvander@1203
  1461
** of the string.  For clarity: the value returned is the number of
dvander@1203
  1462
** bytes in the string, not the number of characters.
dvander@1203
  1463
**
dvander@1203
  1464
** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
dvander@1203
  1465
** but leaves the result in UTF-16 instead of UTF-8.  
dvander@1203
  1466
** The zero terminator is not included in this count.
dvander@1203
  1467
**
dvander@1203
  1468
** These routines attempt to convert the value where appropriate.  For
dvander@1203
  1469
** example, if the internal representation is FLOAT and a text result
dvander@1203
  1470
** is requested, [sqlite3_snprintf()] is used internally to do the conversion
dvander@1203
  1471
** automatically.  The following table details the conversions that
dvander@1203
  1472
** are applied:
dvander@1203
  1473
**
dvander@1203
  1474
** <blockquote>
dvander@1203
  1475
** <table border="1">
dvander@1203
  1476
** <tr><th> Internal <th> Requested <th> 
dvander@1203
  1477
** <tr><th>  Type    <th>    Type   <th> Conversion
dvander@1203
  1478
**
dvander@1203
  1479
** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
dvander@1203
  1480
** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
dvander@1203
  1481
** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
dvander@1203
  1482
** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
dvander@1203
  1483
** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
dvander@1203
  1484
** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
dvander@1203
  1485
** <tr><td> INTEGER  <td>   BLOB    <td> Same as for INTEGER->TEXT
dvander@1203
  1486
** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
dvander@1203
  1487
** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
dvander@1203
  1488
** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
dvander@1203
  1489
** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
dvander@1203
  1490
** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
dvander@1203
  1491
** <tr><td>  TEXT    <td>   BLOB    <td> No change
dvander@1203
  1492
** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
dvander@1203
  1493
** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
dvander@1203
  1494
** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
dvander@1203
  1495
** </table>
dvander@1203
  1496
** </blockquote>
dvander@1203
  1497
**
dvander@1203
  1498
** The table above makes reference to standard C library functions atoi()
dvander@1203
  1499
** and atof().  SQLite does not really use these functions.  It has its
dvander@1203
  1500
** on equavalent internal routines.  The atoi() and atof() names are
dvander@1203
  1501
** used in the table for brevity and because they are familiar to most
dvander@1203
  1502
** C programmers.
dvander@1203
  1503
**
dvander@1203
  1504
** Note that when type conversions occur, pointers returned by prior
dvander@1203
  1505
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
dvander@1203
  1506
** sqlite3_column_text16() may be invalidated. 
dvander@1203
  1507
** Type conversions and pointer invalidations might occur
dvander@1203
  1508
** in the following cases:
dvander@1203
  1509
**
dvander@1203
  1510
** <ul>
dvander@1203
  1511
** <li><p>  The initial content is a BLOB and sqlite3_column_text() 
dvander@1203
  1512
**          or sqlite3_column_text16() is called.  A zero-terminator might
dvander@1203
  1513
**          need to be added to the string.</p></li>
dvander@1203
  1514
**
dvander@1203
  1515
** <li><p>  The initial content is UTF-8 text and sqlite3_column_bytes16() or
dvander@1203
  1516
**          sqlite3_column_text16() is called.  The content must be converted
dvander@1203
  1517
**          to UTF-16.</p></li>
dvander@1203
  1518
**
dvander@1203
  1519
** <li><p>  The initial content is UTF-16 text and sqlite3_column_bytes() or
dvander@1203
  1520
**          sqlite3_column_text() is called.  The content must be converted
dvander@1203
  1521
**          to UTF-8.</p></li>
dvander@1203
  1522
** </ul>
dvander@1203
  1523
**
dvander@1203
  1524
** Conversions between UTF-16be and UTF-16le are always done in place and do
dvander@1203
  1525
** not invalidate a prior pointer, though of course the content of the buffer
dvander@1203
  1526
** that the prior pointer points to will have been modified.  Other kinds
dvander@1203
  1527
** of conversion are done in place when it is possible, but sometime it is
dvander@1203
  1528
** not possible and in those cases prior pointers are invalidated.  
dvander@1203
  1529
**
dvander@1203
  1530
** The safest and easiest to remember policy is to invoke these routines
dvander@1203
  1531
** in one of the following ways:
dvander@1203
  1532
**
dvander@1203
  1533
**  <ul>
dvander@1203
  1534
**  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
dvander@1203
  1535
**  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
dvander@1203
  1536
**  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
dvander@1203
  1537
**  </ul>
dvander@1203
  1538
**
dvander@1203
  1539
** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(),
dvander@1203
  1540
** or sqlite3_column_text16() first to force the result into the desired
dvander@1203
  1541
** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to
dvander@1203
  1542
** find the size of the result.  Do not mix call to sqlite3_column_text() or
dvander@1203
  1543
** sqlite3_column_blob() with calls to sqlite3_column_bytes16().  And do not
dvander@1203
  1544
** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes().
dvander@1203
  1545
*/
dvander@1203
  1546
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
dvander@1203
  1547
int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
dvander@1203
  1548
int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
dvander@1203
  1549
double sqlite3_column_double(sqlite3_stmt*, int iCol);
dvander@1203
  1550
int sqlite3_column_int(sqlite3_stmt*, int iCol);
dvander@1203
  1551
sqlite_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
dvander@1203
  1552
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
dvander@1203
  1553
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
dvander@1203
  1554
int sqlite3_column_type(sqlite3_stmt*, int iCol);
dvander@1203
  1555
sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
dvander@1203
  1556
dvander@1203
  1557
/*
dvander@1203
  1558
** CAPI3REF: Destroy A Prepared Statement Object
dvander@1203
  1559
**
dvander@1203
  1560
** The sqlite3_finalize() function is called to delete a 
dvander@1203
  1561
** [sqlite3_stmt | compiled SQL statement]. If the statement was
dvander@1203
  1562
** executed successfully, or not executed at all, then SQLITE_OK is returned.
dvander@1203
  1563
** If execution of the statement failed then an 
dvander@1203
  1564
** [SQLITE_ERROR | error code] or [SQLITE_IOERR_READ | extended error code]
dvander@1203
  1565
** is returned. 
dvander@1203
  1566
**
dvander@1203
  1567
** This routine can be called at any point during the execution of the
dvander@1203
  1568
** [sqlite3_stmt | virtual machine].  If the virtual machine has not 
dvander@1203
  1569
** completed execution when this routine is called, that is like
dvander@1203
  1570
** encountering an error or an interrupt.  (See [sqlite3_interrupt()].) 
dvander@1203
  1571
** Incomplete updates may be rolled back and transactions cancelled,  
dvander@1203
  1572
** depending on the circumstances, and the 
dvander@1203
  1573
** [SQLITE_ERROR | result code] returned will be [SQLITE_ABORT].
dvander@1203
  1574
*/
dvander@1203
  1575
int sqlite3_finalize(sqlite3_stmt *pStmt);
dvander@1203
  1576
dvander@1203
  1577
/*
dvander@1203
  1578
** CAPI3REF: Reset A Prepared Statement Object
dvander@1203
  1579
**
dvander@1203
  1580
** The sqlite3_reset() function is called to reset a 
dvander@1203
  1581
** [sqlite_stmt | compiled SQL statement] object.
dvander@1203
  1582
** back to it's initial state, ready to be re-executed.
dvander@1203
  1583
** Any SQL statement variables that had values bound to them using
dvander@1203
  1584
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
dvander@1203
  1585
** Use [sqlite3_clear_bindings()] to reset the bindings.
dvander@1203
  1586
*/
dvander@1203
  1587
int sqlite3_reset(sqlite3_stmt *pStmt);
dvander@1203
  1588
dvander@1203
  1589
/*
dvander@1203
  1590
** CAPI3REF: Create Or Redefine SQL Functions
dvander@1203
  1591
**
dvander@1203
  1592
** The following two functions are used to add SQL functions or aggregates
dvander@1203
  1593
** or to redefine the behavior of existing SQL functions or aggregates.  The
dvander@1203
  1594
** difference only between the two is that the second parameter, the
dvander@1203
  1595
** name of the (scalar) function or aggregate, is encoded in UTF-8 for
dvander@1203
  1596
** sqlite3_create_function() and UTF-16 for sqlite3_create_function16().
dvander@1203
  1597
**
dvander@1203
  1598
** The first argument is the [sqlite3 | database handle] that holds the
dvander@1203
  1599
** SQL function or aggregate is to be added or redefined. If a single
dvander@1203
  1600
** program uses more than one database handle internally, then SQL
dvander@1203
  1601
** functions or aggregates must be added individually to each database
dvander@1203
  1602
** handle with which they will be used.
dvander@1203
  1603
**
dvander@1203
  1604
** The second parameter is the name of the SQL function to be created
dvander@1203
  1605
** or redefined.
dvander@1203
  1606
** The length of the name is limited to 255 bytes, exclusive of the 
dvander@1203
  1607
** zero-terminator.  Note that the name length limit is in bytes, not
dvander@1203
  1608
** characters.  Any attempt to create a function with a longer name
dvander@1203
  1609
** will result in an SQLITE_ERROR error.
dvander@1203
  1610
**
dvander@1203
  1611
** The third parameter is the number of arguments that the SQL function or
dvander@1203
  1612
** aggregate takes. If this parameter is negative, then the SQL function or
dvander@1203
  1613
** aggregate may take any number of arguments.
dvander@1203
  1614
**
dvander@1203
  1615
** The fourth parameter, eTextRep, specifies what 
dvander@1203
  1616
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
dvander@1203
  1617
** its parameters.  Any SQL function implementation should be able to work
dvander@1203
  1618
** work with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
dvander@1203
  1619
** more efficient with one encoding than another.  It is allowed to
dvander@1203
  1620
** invoke sqlite_create_function() or sqlite3_create_function16() multiple
dvander@1203
  1621
** times with the same function but with different values of eTextRep.
dvander@1203
  1622
** When multiple implementations of the same function are available, SQLite
dvander@1203
  1623
** will pick the one that involves the least amount of data conversion.
dvander@1203
  1624
** If there is only a single implementation which does not care what
dvander@1203
  1625
** text encoding is used, then the fourth argument should be
dvander@1203
  1626
** [SQLITE_ANY].
dvander@1203
  1627
**
dvander@1203
  1628
** The fifth parameter is an arbitrary pointer.  The implementation
dvander@1203
  1629
** of the function can gain access to this pointer using
dvander@1203
  1630
** [sqlite_user_data()].
dvander@1203
  1631
**
dvander@1203
  1632
** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
dvander@1203
  1633
** pointers to C-language functions that implement the SQL
dvander@1203
  1634
** function or aggregate. A scalar SQL function requires an implementation of
dvander@1203
  1635
** the xFunc callback only, NULL pointers should be passed as the xStep
dvander@1203
  1636
** and xFinal parameters. An aggregate SQL function requires an implementation
dvander@1203
  1637
** of xStep and xFinal and NULL should be passed for xFunc. To delete an
dvander@1203
  1638
** existing SQL function or aggregate, pass NULL for all three function
dvander@1203
  1639
** callback.
dvander@1203
  1640
**
dvander@1203
  1641
** It is permitted to register multiple implementations of the same
dvander@1203
  1642
** functions with the same name but with either differing numbers of
dvander@1203
  1643
** arguments or differing perferred text encodings.  SQLite will use
dvander@1203
  1644
** the implementation most closely matches the way in which the
dvander@1203
  1645
** SQL function is used.
dvander@1203
  1646
*/
dvander@1203
  1647
int sqlite3_create_function(
dvander@1203
  1648
  sqlite3 *,
dvander@1203
  1649
  const char *zFunctionName,
dvander@1203
  1650
  int nArg,
dvander@1203
  1651
  int eTextRep,
dvander@1203
  1652
  void*,
dvander@1203
  1653
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  1654
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  1655
  void (*xFinal)(sqlite3_context*)
dvander@1203
  1656
);
dvander@1203
  1657
int sqlite3_create_function16(
dvander@1203
  1658
  sqlite3*,
dvander@1203
  1659
  const void *zFunctionName,
dvander@1203
  1660
  int nArg,
dvander@1203
  1661
  int eTextRep,
dvander@1203
  1662
  void*,
dvander@1203
  1663
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  1664
  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  1665
  void (*xFinal)(sqlite3_context*)
dvander@1203
  1666
);
dvander@1203
  1667
dvander@1203
  1668
/*
dvander@1203
  1669
** CAPI3REF: Text Encodings
dvander@1203
  1670
**
dvander@1203
  1671
** These constant define integer codes that represent the various
dvander@1203
  1672
** text encodings supported by SQLite.
dvander@1203
  1673
*/
dvander@1203
  1674
#define SQLITE_UTF8           1
dvander@1203
  1675
#define SQLITE_UTF16LE        2
dvander@1203
  1676
#define SQLITE_UTF16BE        3
dvander@1203
  1677
#define SQLITE_UTF16          4    /* Use native byte order */
dvander@1203
  1678
#define SQLITE_ANY            5    /* sqlite3_create_function only */
dvander@1203
  1679
#define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
dvander@1203
  1680
dvander@1203
  1681
/*
dvander@1203
  1682
** CAPI3REF: Obsolete Functions
dvander@1203
  1683
**
dvander@1203
  1684
** These functions are all now obsolete.  In order to maintain
dvander@1203
  1685
** backwards compatibility with older code, we continue to support
dvander@1203
  1686
** these functions.  However, new development projects should avoid
dvander@1203
  1687
** the use of these functions.  To help encourage people to avoid
dvander@1203
  1688
** using these functions, we are not going to tell you want they do.
dvander@1203
  1689
*/
dvander@1203
  1690
int sqlite3_aggregate_count(sqlite3_context*);
dvander@1203
  1691
int sqlite3_expired(sqlite3_stmt*);
dvander@1203
  1692
int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
dvander@1203
  1693
int sqlite3_global_recover(void);
dvander@1203
  1694
dvander@1203
  1695
dvander@1203
  1696
/*
dvander@1203
  1697
** CAPI3REF: Obtaining SQL Function Parameter Values
dvander@1203
  1698
**
dvander@1203
  1699
** The C-language implementation of SQL functions and aggregates uses
dvander@1203
  1700
** this set of interface routines to access the parameter values on
dvander@1203
  1701
** the function or aggregate.
dvander@1203
  1702
**
dvander@1203
  1703
** The xFunc (for scalar functions) or xStep (for aggregates) parameters
dvander@1203
  1704
** to [sqlite3_create_function()] and [sqlite3_create_function16()]
dvander@1203
  1705
** define callbacks that implement the SQL functions and aggregates.
dvander@1203
  1706
** The 4th parameter to these callbacks is an array of pointers to
dvander@1203
  1707
** [sqlite3_value] objects.  There is one [sqlite3_value] object for
dvander@1203
  1708
** each parameter to the SQL function.  These routines are used to
dvander@1203
  1709
** extract values from the [sqlite3_value] objects.
dvander@1203
  1710
**
dvander@1203
  1711
** These routines work just like the corresponding 
dvander@1203
  1712
** [sqlite3_column_blob | sqlite3_column_* routines] except that 
dvander@1203
  1713
** these routines take a single [sqlite3_value*] pointer instead
dvander@1203
  1714
** of an [sqlite3_stmt*] pointer and an integer column number.
dvander@1203
  1715
**
dvander@1203
  1716
** The sqlite3_value_text16() interface extracts a UTF16 string
dvander@1203
  1717
** in the native byte-order of the host machine.  The
dvander@1203
  1718
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
dvander@1203
  1719
** extract UTF16 strings as big-endian and little-endian respectively.
dvander@1203
  1720
**
dvander@1203
  1721
** The sqlite3_value_numeric_type() interface attempts to apply
dvander@1203
  1722
** numeric affinity to the value.  This means that an attempt is
dvander@1203
  1723
** made to convert the value to an integer or floating point.  If
dvander@1203
  1724
** such a conversion is possible without loss of information (in order
dvander@1203
  1725
** words if the value is original a string that looks like a number)
dvander@1203
  1726
** then it is done.  Otherwise no conversion occurs.  The 
dvander@1203
  1727
** [SQLITE_INTEGER | datatype] after conversion is returned.
dvander@1203
  1728
**
dvander@1203
  1729
** Please pay particular attention to the fact that the pointer that
dvander@1203
  1730
** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or
dvander@1203
  1731
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
dvander@1203
  1732
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite_value_text()],
dvander@1203
  1733
** or [sqlite3_value_text16()].  
dvander@1203
  1734
*/
dvander@1203
  1735
const void *sqlite3_value_blob(sqlite3_value*);
dvander@1203
  1736
int sqlite3_value_bytes(sqlite3_value*);
dvander@1203
  1737
int sqlite3_value_bytes16(sqlite3_value*);
dvander@1203
  1738
double sqlite3_value_double(sqlite3_value*);
dvander@1203
  1739
int sqlite3_value_int(sqlite3_value*);
dvander@1203
  1740
sqlite_int64 sqlite3_value_int64(sqlite3_value*);
dvander@1203
  1741
const unsigned char *sqlite3_value_text(sqlite3_value*);
dvander@1203
  1742
const void *sqlite3_value_text16(sqlite3_value*);
dvander@1203
  1743
const void *sqlite3_value_text16le(sqlite3_value*);
dvander@1203
  1744
const void *sqlite3_value_text16be(sqlite3_value*);
dvander@1203
  1745
int sqlite3_value_type(sqlite3_value*);
dvander@1203
  1746
int sqlite3_value_numeric_type(sqlite3_value*);
dvander@1203
  1747
dvander@1203
  1748
/*
dvander@1203
  1749
** CAPI3REF: Obtain Aggregate Function Context
dvander@1203
  1750
**
dvander@1203
  1751
** The implementation of aggregate SQL functions use this routine to allocate
dvander@1203
  1752
** a structure for storing their state.  The first time this routine
dvander@1203
  1753
** is called for a particular aggregate, a new structure of size nBytes
dvander@1203
  1754
** is allocated, zeroed, and returned.  On subsequent calls (for the
dvander@1203
  1755
** same aggregate instance) the same buffer is returned.  The implementation
dvander@1203
  1756
** of the aggregate can use the returned buffer to accumulate data.
dvander@1203
  1757
**
dvander@1203
  1758
** The buffer allocated is freed automatically by SQLite whan the aggregate
dvander@1203
  1759
** query concludes.
dvander@1203
  1760
**
dvander@1203
  1761
** The first parameter should be a copy of the 
dvander@1203
  1762
** [sqlite3_context | SQL function context] that is the first
dvander@1203
  1763
** parameter to the callback routine that implements the aggregate
dvander@1203
  1764
** function.
dvander@1203
  1765
*/
dvander@1203
  1766
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
dvander@1203
  1767
dvander@1203
  1768
/*
dvander@1203
  1769
** CAPI3REF: User Data For Functions
dvander@1203
  1770
**
dvander@1203
  1771
** The pUserData parameter to the [sqlite3_create_function()]
dvander@1203
  1772
** and [sqlite3_create_function16()] routines
dvander@1203
  1773
** used to register user functions is available to
dvander@1203
  1774
** the implementation of the function using this call.
dvander@1203
  1775
*/
dvander@1203
  1776
void *sqlite3_user_data(sqlite3_context*);
dvander@1203
  1777
dvander@1203
  1778
/*
dvander@1203
  1779
** CAPI3REF: Function Auxiliary Data
dvander@1203
  1780
**
dvander@1203
  1781
** The following two functions may be used by scalar SQL functions to
dvander@1203
  1782
** associate meta-data with argument values. If the same value is passed to
dvander@1203
  1783
** multiple invocations of the same SQL function during query execution, under
dvander@1203
  1784
** some circumstances the associated meta-data may be preserved. This may
dvander@1203
  1785
** be used, for example, to add a regular-expression matching scalar
dvander@1203
  1786
** function. The compiled version of the regular expression is stored as
dvander@1203
  1787
** meta-data associated with the SQL value passed as the regular expression
dvander@1203
  1788
** pattern.  The compiled regular expression can be reused on multiple
dvander@1203
  1789
** invocations of the same function so that the original pattern string
dvander@1203
  1790
** does not need to be recompiled on each invocation.
dvander@1203
  1791
**
dvander@1203
  1792
** The sqlite3_get_auxdata() interface returns a pointer to the meta-data
dvander@1203
  1793
** associated with the Nth argument value to the current SQL function
dvander@1203
  1794
** call, where N is the second parameter. If no meta-data has been set for
dvander@1203
  1795
** that value, then a NULL pointer is returned.
dvander@1203
  1796
**
dvander@1203
  1797
** The sqlite3_set_auxdata() is used to associate meta-data with an SQL
dvander@1203
  1798
** function argument. The third parameter is a pointer to the meta-data
dvander@1203
  1799
** to be associated with the Nth user function argument value. The fourth
dvander@1203
  1800
** parameter specifies a destructor that will be called on the meta-
dvander@1203
  1801
** data pointer to release it when it is no longer required. If the 
dvander@1203
  1802
** destructor is NULL, it is not invoked.
dvander@1203
  1803
**
dvander@1203
  1804
** In practice, meta-data is preserved between function calls for
dvander@1203
  1805
** expressions that are constant at compile time. This includes literal
dvander@1203
  1806
** values and SQL variables.
dvander@1203
  1807
*/
dvander@1203
  1808
void *sqlite3_get_auxdata(sqlite3_context*, int);
dvander@1203
  1809
void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));
dvander@1203
  1810
dvander@1203
  1811
dvander@1203
  1812
/*
dvander@1203
  1813
** CAPI3REF: Constants Defining Special Destructor Behavior
dvander@1203
  1814
**
dvander@1203
  1815
** These are special value for the destructor that is passed in as the
dvander@1203
  1816
** final argument to routines like [sqlite3_result_blob()].  If the destructor
dvander@1203
  1817
** argument is SQLITE_STATIC, it means that the content pointer is constant
dvander@1203
  1818
** and will never change.  It does not need to be destroyed.  The 
dvander@1203
  1819
** SQLITE_TRANSIENT value means that the content will likely change in
dvander@1203
  1820
** the near future and that SQLite should make its own private copy of
dvander@1203
  1821
** the content before returning.
dvander@1203
  1822
**
dvander@1203
  1823
** The typedef is necessary to work around problems in certain
dvander@1203
  1824
** C++ compilers.  See ticket #2191.
dvander@1203
  1825
*/
dvander@1203
  1826
typedef void (*sqlite3_destructor_type)(void*);
dvander@1203
  1827
#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
dvander@1203
  1828
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
dvander@1203
  1829
dvander@1203
  1830
/*
dvander@1203
  1831
** CAPI3REF: Setting The Result Of An SQL Function
dvander@1203
  1832
**
dvander@1203
  1833
** These routines are used by the xFunc or xFinal callbacks that
dvander@1203
  1834
** implement SQL functions and aggregates.  See
dvander@1203
  1835
** [sqlite3_create_function()] and [sqlite3_create_function16()]
dvander@1203
  1836
** for additional information.
dvander@1203
  1837
**
dvander@1203
  1838
** These functions work very much like the 
dvander@1203
  1839
** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used
dvander@1203
  1840
** to bind values to host parameters in prepared statements.
dvander@1203
  1841
** Refer to the
dvander@1203
  1842
** [sqlite3_bind_blob | sqlite3_bind_* documentation] for
dvander@1203
  1843
** additional information.
dvander@1203
  1844
**
dvander@1203
  1845
** The sqlite3_result_error() and sqlite3_result_error16() functions
dvander@1203
  1846
** cause the implemented SQL function to throw an exception.  The
dvander@1203
  1847
** parameter to sqlite3_result_error() or sqlite3_result_error16()
dvander@1203
  1848
** is the text of an error message.
dvander@1203
  1849
**
dvander@1203
  1850
** The sqlite3_result_toobig() cause the function implementation
dvander@1203
  1851
** to throw and error indicating that a string or BLOB is to long
dvander@1203
  1852
** to represent.
dvander@1203
  1853
*/
dvander@1203
  1854
void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
dvander@1203
  1855
void sqlite3_result_double(sqlite3_context*, double);
dvander@1203
  1856
void sqlite3_result_error(sqlite3_context*, const char*, int);
dvander@1203
  1857
void sqlite3_result_error16(sqlite3_context*, const void*, int);
dvander@1203
  1858
void sqlite3_result_error_toobig(sqlite3_context*);
dvander@1203
  1859
void sqlite3_result_int(sqlite3_context*, int);
dvander@1203
  1860
void sqlite3_result_int64(sqlite3_context*, sqlite_int64);
dvander@1203
  1861
void sqlite3_result_null(sqlite3_context*);
dvander@1203
  1862
void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
dvander@1203
  1863
void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
dvander@1203
  1864
void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
dvander@1203
  1865
void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
dvander@1203
  1866
void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
dvander@1203
  1867
void sqlite3_result_zeroblob(sqlite3_context*, int n);
dvander@1203
  1868
dvander@1203
  1869
/*
dvander@1203
  1870
** CAPI3REF: Define New Collating Sequences
dvander@1203
  1871
**
dvander@1203
  1872
** These functions are used to add new collation sequences to the
dvander@1203
  1873
** [sqlite3*] handle specified as the first argument. 
dvander@1203
  1874
**
dvander@1203
  1875
** The name of the new collation sequence is specified as a UTF-8 string
dvander@1203
  1876
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
dvander@1203
  1877
** and a UTF-16 string for sqlite3_create_collation16().  In all cases
dvander@1203
  1878
** the name is passed as the second function argument.
dvander@1203
  1879
**
dvander@1203
  1880
** The third argument must be one of the constants [SQLITE_UTF8],
dvander@1203
  1881
** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied
dvander@1203
  1882
** routine expects to be passed pointers to strings encoded using UTF-8,
dvander@1203
  1883
** UTF-16 little-endian or UTF-16 big-endian respectively.
dvander@1203
  1884
**
dvander@1203
  1885
** A pointer to the user supplied routine must be passed as the fifth
dvander@1203
  1886
** argument. If it is NULL, this is the same as deleting the collation
dvander@1203
  1887
** sequence (so that SQLite cannot call it anymore). Each time the user
dvander@1203
  1888
** supplied function is invoked, it is passed a copy of the void* passed as
dvander@1203
  1889
** the fourth argument to sqlite3_create_collation() or
dvander@1203
  1890
** sqlite3_create_collation16() as its first parameter.
dvander@1203
  1891
**
dvander@1203
  1892
** The remaining arguments to the user-supplied routine are two strings,
dvander@1203
  1893
** each represented by a [length, data] pair and encoded in the encoding
dvander@1203
  1894
** that was passed as the third argument when the collation sequence was
dvander@1203
  1895
** registered. The user routine should return negative, zero or positive if
dvander@1203
  1896
** the first string is less than, equal to, or greater than the second
dvander@1203
  1897
** string. i.e. (STRING1 - STRING2).
dvander@1203
  1898
**
dvander@1203
  1899
** The sqlite3_create_collation_v2() works like sqlite3_create_collation()
dvander@1203
  1900
** excapt that it takes an extra argument which is a destructor for
dvander@1203
  1901
** the collation.  The destructor is called when the collation is
dvander@1203
  1902
** destroyed and is passed a copy of the fourth parameter void* pointer
dvander@1203
  1903
** of the sqlite3_create_collation_v2().  Collations are destroyed when
dvander@1203
  1904
** they are overridden by later calls to the collation creation functions
dvander@1203
  1905
** or when the [sqlite3*] database handle is closed using [sqlite3_close()].
dvander@1203
  1906
**
dvander@1203
  1907
** The sqlite3_create_collation_v2() interface is experimental and
dvander@1203
  1908
** subject to change in future releases.  The other collation creation
dvander@1203
  1909
** functions are stable.
dvander@1203
  1910
*/
dvander@1203
  1911
int sqlite3_create_collation(
dvander@1203
  1912
  sqlite3*, 
dvander@1203
  1913
  const char *zName, 
dvander@1203
  1914
  int eTextRep, 
dvander@1203
  1915
  void*,
dvander@1203
  1916
  int(*xCompare)(void*,int,const void*,int,const void*)
dvander@1203
  1917
);
dvander@1203
  1918
int sqlite3_create_collation_v2(
dvander@1203
  1919
  sqlite3*, 
dvander@1203
  1920
  const char *zName, 
dvander@1203
  1921
  int eTextRep, 
dvander@1203
  1922
  void*,
dvander@1203
  1923
  int(*xCompare)(void*,int,const void*,int,const void*),
dvander@1203
  1924
  void(*xDestroy)(void*)
dvander@1203
  1925
);
dvander@1203
  1926
int sqlite3_create_collation16(
dvander@1203
  1927
  sqlite3*, 
dvander@1203
  1928
  const char *zName, 
dvander@1203
  1929
  int eTextRep, 
dvander@1203
  1930
  void*,
dvander@1203
  1931
  int(*xCompare)(void*,int,const void*,int,const void*)
dvander@1203
  1932
);
dvander@1203
  1933
dvander@1203
  1934
/*
dvander@1203
  1935
** CAPI3REF: Collation Needed Callbacks
dvander@1203
  1936
**
dvander@1203
  1937
** To avoid having to register all collation sequences before a database
dvander@1203
  1938
** can be used, a single callback function may be registered with the
dvander@1203
  1939
** database handle to be called whenever an undefined collation sequence is
dvander@1203
  1940
** required.
dvander@1203
  1941
**
dvander@1203
  1942
** If the function is registered using the sqlite3_collation_needed() API,
dvander@1203
  1943
** then it is passed the names of undefined collation sequences as strings
dvander@1203
  1944
** encoded in UTF-8. If sqlite3_collation_needed16() is used, the names
dvander@1203
  1945
** are passed as UTF-16 in machine native byte order. A call to either
dvander@1203
  1946
** function replaces any existing callback.
dvander@1203
  1947
**
dvander@1203
  1948
** When the callback is invoked, the first argument passed is a copy
dvander@1203
  1949
** of the second argument to sqlite3_collation_needed() or
dvander@1203
  1950
** sqlite3_collation_needed16(). The second argument is the database
dvander@1203
  1951
** handle. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], or
dvander@1203
  1952
** [SQLITE_UTF16LE], indicating the most desirable form of the collation
dvander@1203
  1953
** sequence function required. The fourth parameter is the name of the
dvander@1203
  1954
** required collation sequence.
dvander@1203
  1955
**
dvander@1203
  1956
** The callback function should register the desired collation using
dvander@1203
  1957
** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
dvander@1203
  1958
** [sqlite3_create_collation_v2()].
dvander@1203
  1959
*/
dvander@1203
  1960
int sqlite3_collation_needed(
dvander@1203
  1961
  sqlite3*, 
dvander@1203
  1962
  void*, 
dvander@1203
  1963
  void(*)(void*,sqlite3*,int eTextRep,const char*)
dvander@1203
  1964
);
dvander@1203
  1965
int sqlite3_collation_needed16(
dvander@1203
  1966
  sqlite3*, 
dvander@1203
  1967
  void*,
dvander@1203
  1968
  void(*)(void*,sqlite3*,int eTextRep,const void*)
dvander@1203
  1969
);
dvander@1203
  1970
dvander@1203
  1971
/*
dvander@1203
  1972
** Specify the key for an encrypted database.  This routine should be
dvander@1203
  1973
** called right after sqlite3_open().
dvander@1203
  1974
**
dvander@1203
  1975
** The code to implement this API is not available in the public release
dvander@1203
  1976
** of SQLite.
dvander@1203
  1977
*/
dvander@1203
  1978
int sqlite3_key(
dvander@1203
  1979
  sqlite3 *db,                   /* Database to be rekeyed */
dvander@1203
  1980
  const void *pKey, int nKey     /* The key */
dvander@1203
  1981
);
dvander@1203
  1982
dvander@1203
  1983
/*
dvander@1203
  1984
** Change the key on an open database.  If the current database is not
dvander@1203
  1985
** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
dvander@1203
  1986
** database is decrypted.
dvander@1203
  1987
**
dvander@1203
  1988
** The code to implement this API is not available in the public release
dvander@1203
  1989
** of SQLite.
dvander@1203
  1990
*/
dvander@1203
  1991
int sqlite3_rekey(
dvander@1203
  1992
  sqlite3 *db,                   /* Database to be rekeyed */
dvander@1203
  1993
  const void *pKey, int nKey     /* The new key */
dvander@1203
  1994
);
dvander@1203
  1995
dvander@1203
  1996
/*
dvander@1203
  1997
** CAPI3REF:  Suspend Execution For A Short Time
dvander@1203
  1998
**
dvander@1203
  1999
** This function causes the current thread to suspend execution
dvander@1203
  2000
** a number of milliseconds specified in its parameter.
dvander@1203
  2001
**
dvander@1203
  2002
** If the operating system does not support sleep requests with 
dvander@1203
  2003
** millisecond time resolution, then the time will be rounded up to 
dvander@1203
  2004
** the nearest second. The number of milliseconds of sleep actually 
dvander@1203
  2005
** requested from the operating system is returned.
dvander@1203
  2006
*/
dvander@1203
  2007
int sqlite3_sleep(int);
dvander@1203
  2008
dvander@1203
  2009
/*
dvander@1203
  2010
** CAPI3REF:  Name Of The Folder Holding Temporary Files
dvander@1203
  2011
**
dvander@1203
  2012
** If this global variable is made to point to a string which is
dvander@1203
  2013
** the name of a folder (a.ka. directory), then all temporary files
dvander@1203
  2014
** created by SQLite will be placed in that directory.  If this variable
dvander@1203
  2015
** is NULL pointer, then SQLite does a search for an appropriate temporary
dvander@1203
  2016
** file directory.
dvander@1203
  2017
**
dvander@1203
  2018
** Once [sqlite3_open()] has been called, changing this variable will
dvander@1203
  2019
** invalidate the current temporary database, if any.  Generally speaking,
dvander@1203
  2020
** it is not safe to invoke this routine after [sqlite3_open()] has
dvander@1203
  2021
** been called.
dvander@1203
  2022
*/
dvander@1203
  2023
extern char *sqlite3_temp_directory;
dvander@1203
  2024
dvander@1203
  2025
/*
dvander@1203
  2026
** CAPI3REF:  Test To See If The Databse Is In Auto-Commit Mode
dvander@1203
  2027
**
dvander@1203
  2028
** Test to see whether or not the database connection is in autocommit
dvander@1203
  2029
** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
dvander@1203
  2030
** by default.  Autocommit is disabled by a BEGIN statement and reenabled
dvander@1203
  2031
** by the next COMMIT or ROLLBACK.
dvander@1203
  2032
*/
dvander@1203
  2033
int sqlite3_get_autocommit(sqlite3*);
dvander@1203
  2034
dvander@1203
  2035
/*
dvander@1203
  2036
** CAPI3REF:  Find The Database Handle Associated With A Prepared Statement
dvander@1203
  2037
**
dvander@1203
  2038
** Return the [sqlite3*] database handle to which a
dvander@1203
  2039
** [sqlite3_stmt | prepared statement] belongs.
dvander@1203
  2040
** This is the same database handle that was
dvander@1203
  2041
** the first argument to the [sqlite3_prepare_v2()] or its variants
dvander@1203
  2042
** that was used to create the statement in the first place.
dvander@1203
  2043
*/
dvander@1203
  2044
sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
dvander@1203
  2045
dvander@1203
  2046
dvander@1203
  2047
/*
dvander@1203
  2048
** CAPI3REF: Commit And Rollback Notification Callbacks
dvander@1203
  2049
**
dvander@1203
  2050
** These routines
dvander@1203
  2051
** register callback functions to be invoked whenever a transaction
dvander@1203
  2052
** is committed or rolled back.  The pArg argument is passed through
dvander@1203
  2053
** to the callback.  If the callback on a commit hook function 
dvander@1203
  2054
** returns non-zero, then the commit is converted into a rollback.
dvander@1203
  2055
**
dvander@1203
  2056
** If another function was previously registered, its pArg value is returned.
dvander@1203
  2057
** Otherwise NULL is returned.
dvander@1203
  2058
**
dvander@1203
  2059
** Registering a NULL function disables the callback.
dvander@1203
  2060
**
dvander@1203
  2061
** For the purposes of this API, a transaction is said to have been 
dvander@1203
  2062
** rolled back if an explicit "ROLLBACK" statement is executed, or
dvander@1203
  2063
** an error or constraint causes an implicit rollback to occur. The 
dvander@1203
  2064
** callback is not invoked if a transaction is automatically rolled
dvander@1203
  2065
** back because the database connection is closed.
dvander@1203
  2066
**
dvander@1203
  2067
** These are experimental interfaces and are subject to change.
dvander@1203
  2068
*/
dvander@1203
  2069
void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
dvander@1203
  2070
void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
dvander@1203
  2071
dvander@1203
  2072
/*
dvander@1203
  2073
** CAPI3REF: Data Change Notification Callbacks
dvander@1203
  2074
**
dvander@1203
  2075
** Register a callback function with the database connection identified by the 
dvander@1203
  2076
** first argument to be invoked whenever a row is updated, inserted or deleted.
dvander@1203
  2077
** Any callback set by a previous call to this function for the same 
dvander@1203
  2078
** database connection is overridden.
dvander@1203
  2079
**
dvander@1203
  2080
** The second argument is a pointer to the function to invoke when a 
dvander@1203
  2081
** row is updated, inserted or deleted. The first argument to the callback is
dvander@1203
  2082
** a copy of the third argument to sqlite3_update_hook(). The second callback 
dvander@1203
  2083
** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending
dvander@1203
  2084
** on the operation that caused the callback to be invoked. The third and 
dvander@1203
  2085
** fourth arguments to the callback contain pointers to the database and 
dvander@1203
  2086
** table name containing the affected row. The final callback parameter is 
dvander@1203
  2087
** the rowid of the row. In the case of an update, this is the rowid after 
dvander@1203
  2088
** the update takes place.
dvander@1203
  2089
**
dvander@1203
  2090
** The update hook is not invoked when internal system tables are
dvander@1203
  2091
** modified (i.e. sqlite_master and sqlite_sequence).
dvander@1203
  2092
**
dvander@1203
  2093
** If another function was previously registered, its pArg value is returned.
dvander@1203
  2094
** Otherwise NULL is returned.
dvander@1203
  2095
*/
dvander@1203
  2096
void *sqlite3_update_hook(
dvander@1203
  2097
  sqlite3*, 
dvander@1203
  2098
  void(*)(void *,int ,char const *,char const *,sqlite_int64),
dvander@1203
  2099
  void*
dvander@1203
  2100
);
dvander@1203
  2101
dvander@1203
  2102
/*
dvander@1203
  2103
** CAPI3REF:  Enable Or Disable Shared Pager Cache
dvander@1203
  2104
**
dvander@1203
  2105
** This routine enables or disables the sharing of the database cache
dvander@1203
  2106
** and schema data structures between connections to the same database.
dvander@1203
  2107
** Sharing is enabled if the argument is true and disabled if the argument
dvander@1203
  2108
** is false.
dvander@1203
  2109
**
dvander@1203
  2110
** Cache sharing is enabled and disabled on a thread-by-thread basis.
dvander@1203
  2111
** Each call to this routine enables or disables cache sharing only for
dvander@1203
  2112
** connections created in the same thread in which this routine is called.
dvander@1203
  2113
** There is no mechanism for sharing cache between database connections
dvander@1203
  2114
** running in different threads.
dvander@1203
  2115
**
dvander@1203
  2116
** Sharing must be disabled prior to shutting down a thread or else
dvander@1203
  2117
** the thread will leak memory.  Call this routine with an argument of
dvander@1203
  2118
** 0 to turn off sharing.  Or use the sqlite3_thread_cleanup() API.
dvander@1203
  2119
**
dvander@1203
  2120
** This routine must not be called when any database connections
dvander@1203
  2121
** are active in the current thread.  Enabling or disabling shared
dvander@1203
  2122
** cache while there are active database connections will result
dvander@1203
  2123
** in memory corruption.
dvander@1203
  2124
**
dvander@1203
  2125
** When the shared cache is enabled, the
dvander@1203
  2126
** following routines must always be called from the same thread:
dvander@1203
  2127
** [sqlite3_open()], [sqlite3_prepare_v2()], [sqlite3_step()],
dvander@1203
  2128
** [sqlite3_reset()], [sqlite3_finalize()], and [sqlite3_close()].
dvander@1203
  2129
** This is due to the fact that the shared cache makes use of
dvander@1203
  2130
** thread-specific storage so that it will be available for sharing
dvander@1203
  2131
** with other connections.
dvander@1203
  2132
**
dvander@1203
  2133
** Virtual tables cannot be used with a shared cache.  When shared
dvander@1203
  2134
** cache is enabled, the sqlite3_create_module() API used to register
dvander@1203
  2135
** virtual tables will always return an error.
dvander@1203
  2136
**
dvander@1203
  2137
** This routine returns [SQLITE_OK] if shared cache was
dvander@1203
  2138
** enabled or disabled successfully.  An [SQLITE_ERROR | error code]
dvander@1203
  2139
** is returned otherwise.
dvander@1203
  2140
**
dvander@1203
  2141
** Shared cache is disabled by default for backward compatibility.
dvander@1203
  2142
*/
dvander@1203
  2143
int sqlite3_enable_shared_cache(int);
dvander@1203
  2144
dvander@1203
  2145
/*
dvander@1203
  2146
** CAPI3REF:  Attempt To Free Heap Memory
dvander@1203
  2147
**
dvander@1203
  2148
** Attempt to free N bytes of heap memory by deallocating non-essential
dvander@1203
  2149
** memory allocations held by the database library (example: memory 
dvander@1203
  2150
** used to cache database pages to improve performance).
dvander@1203
  2151
**
dvander@1203
  2152
** This function is not a part of standard builds.  It is only created
dvander@1203
  2153
** if SQLite is compiled with the SQLITE_ENABLE_MEMORY_MANAGEMENT macro.
dvander@1203
  2154
*/
dvander@1203
  2155
int sqlite3_release_memory(int);
dvander@1203
  2156
dvander@1203
  2157
/*
dvander@1203
  2158
** CAPI3REF:  Impose A Limit On Heap Size
dvander@1203
  2159
**
dvander@1203
  2160
** Place a "soft" limit on the amount of heap memory that may be allocated by
dvander@1203
  2161
** SQLite within the current thread. If an internal allocation is requested 
dvander@1203
  2162
** that would exceed the specified limit, [sqlite3_release_memory()] is invoked
dvander@1203
  2163
** one or more times to free up some space before the allocation is made.
dvander@1203
  2164
**
dvander@1203
  2165
** The limit is called "soft", because if [sqlite3_release_memory()] cannot free
dvander@1203
  2166
** sufficient memory to prevent the limit from being exceeded, the memory is
dvander@1203
  2167
** allocated anyway and the current operation proceeds.
dvander@1203
  2168
**
dvander@1203
  2169
** Prior to shutting down a thread sqlite3_soft_heap_limit() must be set to 
dvander@1203
  2170
** zero (the default) or else the thread will leak memory. Alternatively, use
dvander@1203
  2171
** the [sqlite3_thread_cleanup()] API.
dvander@1203
  2172
**
dvander@1203
  2173
** A negative or zero value for N means that there is no soft heap limit and
dvander@1203
  2174
** [sqlite3_release_memory()] will only be called when memory is exhaused.
dvander@1203
  2175
** The default value for the soft heap limit is zero.
dvander@1203
  2176
**
dvander@1203
  2177
** SQLite makes a best effort to honor the soft heap limit.  But if it
dvander@1203
  2178
** is unable to reduce memory usage below the soft limit, execution will
dvander@1203
  2179
** continue without error or notification.  This is why the limit is 
dvander@1203
  2180
** called a "soft" limit.  It is advisory only.
dvander@1203
  2181
**
dvander@1203
  2182
** This function is only available if the library was compiled with the 
dvander@1203
  2183
** SQLITE_ENABLE_MEMORY_MANAGEMENT option set.
dvander@1203
  2184
** memory-management has been enabled.
dvander@1203
  2185
*/
dvander@1203
  2186
void sqlite3_soft_heap_limit(int);
dvander@1203
  2187
dvander@1203
  2188
/*
dvander@1203
  2189
** CAPI3REF:  Clean Up Thread Local Storage
dvander@1203
  2190
**
dvander@1203
  2191
** This routine makes sure that all thread-local storage has been
dvander@1203
  2192
** deallocated for the current thread.
dvander@1203
  2193
**
dvander@1203
  2194
** This routine is not technically necessary.  All thread-local storage
dvander@1203
  2195
** will be automatically deallocated once memory-management and
dvander@1203
  2196
** shared-cache are disabled and the soft heap limit has been set
dvander@1203
  2197
** to zero.  This routine is provided as a convenience for users who
dvander@1203
  2198
** want to make absolutely sure they have not forgotten something
dvander@1203
  2199
** prior to killing off a thread.
dvander@1203
  2200
*/
dvander@1203
  2201
void sqlite3_thread_cleanup(void);
dvander@1203
  2202
dvander@1203
  2203
/*
dvander@1203
  2204
** CAPI3REF:  Extract Metadata About A Column Of A Table
dvander@1203
  2205
**
dvander@1203
  2206
** This routine
dvander@1203
  2207
** returns meta-data about a specific column of a specific database
dvander@1203
  2208
** table accessible using the connection handle passed as the first function 
dvander@1203
  2209
** argument.
dvander@1203
  2210
**
dvander@1203
  2211
** The column is identified by the second, third and fourth parameters to 
dvander@1203
  2212
** this function. The second parameter is either the name of the database
dvander@1203
  2213
** (i.e. "main", "temp" or an attached database) containing the specified
dvander@1203
  2214
** table or NULL. If it is NULL, then all attached databases are searched
dvander@1203
  2215
** for the table using the same algorithm as the database engine uses to 
dvander@1203
  2216
** resolve unqualified table references.
dvander@1203
  2217
**
dvander@1203
  2218
** The third and fourth parameters to this function are the table and column 
dvander@1203
  2219
** name of the desired column, respectively. Neither of these parameters 
dvander@1203
  2220
** may be NULL.
dvander@1203
  2221
**
dvander@1203
  2222
** Meta information is returned by writing to the memory locations passed as
dvander@1203
  2223
** the 5th and subsequent parameters to this function. Any of these 
dvander@1203
  2224
** arguments may be NULL, in which case the corresponding element of meta 
dvander@1203
  2225
** information is ommitted.
dvander@1203
  2226
**
dvander@1203
  2227
** <pre>
dvander@1203
  2228
** Parameter     Output Type      Description
dvander@1203
  2229
** -----------------------------------
dvander@1203
  2230
**
dvander@1203
  2231
**   5th         const char*      Data type
dvander@1203
  2232
**   6th         const char*      Name of the default collation sequence 
dvander@1203
  2233
**   7th         int              True if the column has a NOT NULL constraint
dvander@1203
  2234
**   8th         int              True if the column is part of the PRIMARY KEY
dvander@1203
  2235
**   9th         int              True if the column is AUTOINCREMENT
dvander@1203
  2236
** </pre>
dvander@1203
  2237
**
dvander@1203
  2238
**
dvander@1203
  2239
** The memory pointed to by the character pointers returned for the 
dvander@1203
  2240
** declaration type and collation sequence is valid only until the next 
dvander@1203
  2241
** call to any sqlite API function.
dvander@1203
  2242
**
dvander@1203
  2243
** If the specified table is actually a view, then an error is returned.
dvander@1203
  2244
**
dvander@1203
  2245
** If the specified column is "rowid", "oid" or "_rowid_" and an 
dvander@1203
  2246
** INTEGER PRIMARY KEY column has been explicitly declared, then the output 
dvander@1203
  2247
** parameters are set for the explicitly declared column. If there is no
dvander@1203
  2248
** explicitly declared IPK column, then the output parameters are set as 
dvander@1203
  2249
** follows:
dvander@1203
  2250
**
dvander@1203
  2251
** <pre>
dvander@1203
  2252
**     data type: "INTEGER"
dvander@1203
  2253
**     collation sequence: "BINARY"
dvander@1203
  2254
**     not null: 0
dvander@1203
  2255
**     primary key: 1
dvander@1203
  2256
**     auto increment: 0
dvander@1203
  2257
** </pre>
dvander@1203
  2258
**
dvander@1203
  2259
** This function may load one or more schemas from database files. If an
dvander@1203
  2260
** error occurs during this process, or if the requested table or column
dvander@1203
  2261
** cannot be found, an SQLITE error code is returned and an error message
dvander@1203
  2262
** left in the database handle (to be retrieved using sqlite3_errmsg()).
dvander@1203
  2263
**
dvander@1203
  2264
** This API is only available if the library was compiled with the
dvander@1203
  2265
** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined.
dvander@1203
  2266
*/
dvander@1203
  2267
int sqlite3_table_column_metadata(
dvander@1203
  2268
  sqlite3 *db,                /* Connection handle */
dvander@1203
  2269
  const char *zDbName,        /* Database name or NULL */
dvander@1203
  2270
  const char *zTableName,     /* Table name */
dvander@1203
  2271
  const char *zColumnName,    /* Column name */
dvander@1203
  2272
  char const **pzDataType,    /* OUTPUT: Declared data type */
dvander@1203
  2273
  char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
dvander@1203
  2274
  int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
dvander@1203
  2275
  int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
dvander@1203
  2276
  int *pAutoinc               /* OUTPUT: True if colums is auto-increment */
dvander@1203
  2277
);
dvander@1203
  2278
dvander@1203
  2279
/*
dvander@1203
  2280
** CAPI3REF: Load An Extension
dvander@1203
  2281
**
dvander@1203
  2282
** Attempt to load an SQLite extension library contained in the file
dvander@1203
  2283
** zFile.  The entry point is zProc.  zProc may be 0 in which case the
dvander@1203
  2284
** name of the entry point defaults to "sqlite3_extension_init".
dvander@1203
  2285
**
dvander@1203
  2286
** Return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
dvander@1203
  2287
**
dvander@1203
  2288
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
dvander@1203
  2289
** error message text.  The calling function should free this memory
dvander@1203
  2290
** by calling [sqlite3_free()].
dvander@1203
  2291
**
dvander@1203
  2292
** Extension loading must be enabled using [sqlite3_enable_load_extension()]
dvander@1203
  2293
** prior to calling this API or an error will be returned.
dvander@1203
  2294
*/
dvander@1203
  2295
int sqlite3_load_extension(
dvander@1203
  2296
  sqlite3 *db,          /* Load the extension into this database connection */
dvander@1203
  2297
  const char *zFile,    /* Name of the shared library containing extension */
dvander@1203
  2298
  const char *zProc,    /* Entry point.  Derived from zFile if 0 */
dvander@1203
  2299
  char **pzErrMsg       /* Put error message here if not 0 */
dvander@1203
  2300
);
dvander@1203
  2301
dvander@1203
  2302
/*
dvander@1203
  2303
** CAPI3REF:  Enable Or Disable Extension Loading
dvander@1203
  2304
**
dvander@1203
  2305
** So as not to open security holes in older applications that are
dvander@1203
  2306
** unprepared to deal with extension loading, and as a means of disabling
dvander@1203
  2307
** extension loading while evaluating user-entered SQL, the following
dvander@1203
  2308
** API is provided to turn the [sqlite3_load_extension()] mechanism on and
dvander@1203
  2309
** off.  It is off by default.  See ticket #1863.
dvander@1203
  2310
**
dvander@1203
  2311
** Call this routine with onoff==1 to turn extension loading on
dvander@1203
  2312
** and call it with onoff==0 to turn it back off again.
dvander@1203
  2313
*/
dvander@1203
  2314
int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
dvander@1203
  2315
dvander@1203
  2316
/*
dvander@1203
  2317
** CAPI3REF: Make Arrangements To Automatically Load An Extension
dvander@1203
  2318
**
dvander@1203
  2319
** Register an extension entry point that is automatically invoked
dvander@1203
  2320
** whenever a new database connection is opened using
dvander@1203
  2321
** [sqlite3_open()] or [sqlite3_open16()].
dvander@1203
  2322
**
dvander@1203
  2323
** This API can be invoked at program startup in order to register
dvander@1203
  2324
** one or more statically linked extensions that will be available
dvander@1203
  2325
** to all new database connections.
dvander@1203
  2326
**
dvander@1203
  2327
** Duplicate extensions are detected so calling this routine multiple
dvander@1203
  2328
** times with the same extension is harmless.
dvander@1203
  2329
**
dvander@1203
  2330
** This routine stores a pointer to the extension in an array
dvander@1203
  2331
** that is obtained from malloc().  If you run a memory leak
dvander@1203
  2332
** checker on your program and it reports a leak because of this
dvander@1203
  2333
** array, then invoke [sqlite3_automatic_extension_reset()] prior
dvander@1203
  2334
** to shutdown to free the memory.
dvander@1203
  2335
**
dvander@1203
  2336
** Automatic extensions apply across all threads.
dvander@1203
  2337
**
dvander@1203
  2338
** This interface is experimental and is subject to change or
dvander@1203
  2339
** removal in future releases of SQLite.
dvander@1203
  2340
*/
dvander@1203
  2341
int sqlite3_auto_extension(void *xEntryPoint);
dvander@1203
  2342
dvander@1203
  2343
dvander@1203
  2344
/*
dvander@1203
  2345
** CAPI3REF: Reset Automatic Extension Loading
dvander@1203
  2346
**
dvander@1203
  2347
** Disable all previously registered automatic extensions.  This
dvander@1203
  2348
** routine undoes the effect of all prior [sqlite3_automatic_extension()]
dvander@1203
  2349
** calls.
dvander@1203
  2350
**
dvander@1203
  2351
** This call disabled automatic extensions in all threads.
dvander@1203
  2352
**
dvander@1203
  2353
** This interface is experimental and is subject to change or
dvander@1203
  2354
** removal in future releases of SQLite.
dvander@1203
  2355
*/
dvander@1203
  2356
void sqlite3_reset_auto_extension(void);
dvander@1203
  2357
dvander@1203
  2358
dvander@1203
  2359
/*
dvander@1203
  2360
****** EXPERIMENTAL - subject to change without notice **************
dvander@1203
  2361
**
dvander@1203
  2362
** The interface to the virtual-table mechanism is currently considered
dvander@1203
  2363
** to be experimental.  The interface might change in incompatible ways.
dvander@1203
  2364
** If this is a problem for you, do not use the interface at this time.
dvander@1203
  2365
**
dvander@1203
  2366
** When the virtual-table mechanism stablizes, we will declare the
dvander@1203
  2367
** interface fixed, support it indefinitely, and remove this comment.
dvander@1203
  2368
*/
dvander@1203
  2369
dvander@1203
  2370
/*
dvander@1203
  2371
** Structures used by the virtual table interface
dvander@1203
  2372
*/
dvander@1203
  2373
typedef struct sqlite3_vtab sqlite3_vtab;
dvander@1203
  2374
typedef struct sqlite3_index_info sqlite3_index_info;
dvander@1203
  2375
typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
dvander@1203
  2376
typedef struct sqlite3_module sqlite3_module;
dvander@1203
  2377
dvander@1203
  2378
/*
dvander@1203
  2379
** A module is a class of virtual tables.  Each module is defined
dvander@1203
  2380
** by an instance of the following structure.  This structure consists
dvander@1203
  2381
** mostly of methods for the module.
dvander@1203
  2382
*/
dvander@1203
  2383
struct sqlite3_module {
dvander@1203
  2384
  int iVersion;
dvander@1203
  2385
  int (*xCreate)(sqlite3*, void *pAux,
dvander@1203
  2386
               int argc, const char *const*argv,
dvander@1203
  2387
               sqlite3_vtab **ppVTab, char**);
dvander@1203
  2388
  int (*xConnect)(sqlite3*, void *pAux,
dvander@1203
  2389
               int argc, const char *const*argv,
dvander@1203
  2390
               sqlite3_vtab **ppVTab, char**);
dvander@1203
  2391
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
dvander@1203
  2392
  int (*xDisconnect)(sqlite3_vtab *pVTab);
dvander@1203
  2393
  int (*xDestroy)(sqlite3_vtab *pVTab);
dvander@1203
  2394
  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
dvander@1203
  2395
  int (*xClose)(sqlite3_vtab_cursor*);
dvander@1203
  2396
  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
dvander@1203
  2397
                int argc, sqlite3_value **argv);
dvander@1203
  2398
  int (*xNext)(sqlite3_vtab_cursor*);
dvander@1203
  2399
  int (*xEof)(sqlite3_vtab_cursor*);
dvander@1203
  2400
  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
dvander@1203
  2401
  int (*xRowid)(sqlite3_vtab_cursor*, sqlite_int64 *pRowid);
dvander@1203
  2402
  int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite_int64 *);
dvander@1203
  2403
  int (*xBegin)(sqlite3_vtab *pVTab);
dvander@1203
  2404
  int (*xSync)(sqlite3_vtab *pVTab);
dvander@1203
  2405
  int (*xCommit)(sqlite3_vtab *pVTab);
dvander@1203
  2406
  int (*xRollback)(sqlite3_vtab *pVTab);
dvander@1203
  2407
  int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
dvander@1203
  2408
                       void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
dvander@1203
  2409
                       void **ppArg);
dvander@1203
  2410
dvander@1203
  2411
  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
dvander@1203
  2412
};
dvander@1203
  2413
dvander@1203
  2414
/*
dvander@1203
  2415
** The sqlite3_index_info structure and its substructures is used to
dvander@1203
  2416
** pass information into and receive the reply from the xBestIndex
dvander@1203
  2417
** method of an sqlite3_module.  The fields under **Inputs** are the
dvander@1203
  2418
** inputs to xBestIndex and are read-only.  xBestIndex inserts its
dvander@1203
  2419
** results into the **Outputs** fields.
dvander@1203
  2420
**
dvander@1203
  2421
** The aConstraint[] array records WHERE clause constraints of the
dvander@1203
  2422
** form:
dvander@1203
  2423
**
dvander@1203
  2424
**         column OP expr
dvander@1203
  2425
**
dvander@1203
  2426
** Where OP is =, <, <=, >, or >=.  The particular operator is stored
dvander@1203
  2427
** in aConstraint[].op.  The index of the column is stored in 
dvander@1203
  2428
** aConstraint[].iColumn.  aConstraint[].usable is TRUE if the
dvander@1203
  2429
** expr on the right-hand side can be evaluated (and thus the constraint
dvander@1203
  2430
** is usable) and false if it cannot.
dvander@1203
  2431
**
dvander@1203
  2432
** The optimizer automatically inverts terms of the form "expr OP column"
dvander@1203
  2433
** and makes other simplificatinos to the WHERE clause in an attempt to
dvander@1203
  2434
** get as many WHERE clause terms into the form shown above as possible.
dvander@1203
  2435
** The aConstraint[] array only reports WHERE clause terms in the correct
dvander@1203
  2436
** form that refer to the particular virtual table being queried.
dvander@1203
  2437
**
dvander@1203
  2438
** Information about the ORDER BY clause is stored in aOrderBy[].
dvander@1203
  2439
** Each term of aOrderBy records a column of the ORDER BY clause.
dvander@1203
  2440
**
dvander@1203
  2441
** The xBestIndex method must fill aConstraintUsage[] with information
dvander@1203
  2442
** about what parameters to pass to xFilter.  If argvIndex>0 then
dvander@1203
  2443
** the right-hand side of the corresponding aConstraint[] is evaluated
dvander@1203
  2444
** and becomes the argvIndex-th entry in argv.  If aConstraintUsage[].omit
dvander@1203
  2445
** is true, then the constraint is assumed to be fully handled by the
dvander@1203
  2446
** virtual table and is not checked again by SQLite.
dvander@1203
  2447
**
dvander@1203
  2448
** The idxNum and idxPtr values are recorded and passed into xFilter.
dvander@1203
  2449
** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true.
dvander@1203
  2450
**
dvander@1203
  2451
** The orderByConsumed means that output from xFilter will occur in
dvander@1203
  2452
** the correct order to satisfy the ORDER BY clause so that no separate
dvander@1203
  2453
** sorting step is required.
dvander@1203
  2454
**
dvander@1203
  2455
** The estimatedCost value is an estimate of the cost of doing the
dvander@1203
  2456
** particular lookup.  A full scan of a table with N entries should have
dvander@1203
  2457
** a cost of N.  A binary search of a table of N entries should have a
dvander@1203
  2458
** cost of approximately log(N).
dvander@1203
  2459
*/
dvander@1203
  2460
struct sqlite3_index_info {
dvander@1203
  2461
  /* Inputs */
dvander@1203
  2462
  const int nConstraint;     /* Number of entries in aConstraint */
dvander@1203
  2463
  const struct sqlite3_index_constraint {
dvander@1203
  2464
     int iColumn;              /* Column on left-hand side of constraint */
dvander@1203
  2465
     unsigned char op;         /* Constraint operator */
dvander@1203
  2466
     unsigned char usable;     /* True if this constraint is usable */
dvander@1203
  2467
     int iTermOffset;          /* Used internally - xBestIndex should ignore */
dvander@1203
  2468
  } *const aConstraint;      /* Table of WHERE clause constraints */
dvander@1203
  2469
  const int nOrderBy;        /* Number of terms in the ORDER BY clause */
dvander@1203
  2470
  const struct sqlite3_index_orderby {
dvander@1203
  2471
     int iColumn;              /* Column number */
dvander@1203
  2472
     unsigned char desc;       /* True for DESC.  False for ASC. */
dvander@1203
  2473
  } *const aOrderBy;         /* The ORDER BY clause */
dvander@1203
  2474
dvander@1203
  2475
  /* Outputs */
dvander@1203
  2476
  struct sqlite3_index_constraint_usage {
dvander@1203
  2477
    int argvIndex;           /* if >0, constraint is part of argv to xFilter */
dvander@1203
  2478
    unsigned char omit;      /* Do not code a test for this constraint */
dvander@1203
  2479
  } *const aConstraintUsage;
dvander@1203
  2480
  int idxNum;                /* Number used to identify the index */
dvander@1203
  2481
  char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
dvander@1203
  2482
  int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
dvander@1203
  2483
  int orderByConsumed;       /* True if output is already ordered */
dvander@1203
  2484
  double estimatedCost;      /* Estimated cost of using this index */
dvander@1203
  2485
};
dvander@1203
  2486
#define SQLITE_INDEX_CONSTRAINT_EQ    2
dvander@1203
  2487
#define SQLITE_INDEX_CONSTRAINT_GT    4
dvander@1203
  2488
#define SQLITE_INDEX_CONSTRAINT_LE    8
dvander@1203
  2489
#define SQLITE_INDEX_CONSTRAINT_LT    16
dvander@1203
  2490
#define SQLITE_INDEX_CONSTRAINT_GE    32
dvander@1203
  2491
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
dvander@1203
  2492
dvander@1203
  2493
/*
dvander@1203
  2494
** This routine is used to register a new module name with an SQLite
dvander@1203
  2495
** connection.  Module names must be registered before creating new
dvander@1203
  2496
** virtual tables on the module, or before using preexisting virtual
dvander@1203
  2497
** tables of the module.
dvander@1203
  2498
*/
dvander@1203
  2499
int sqlite3_create_module(
dvander@1203
  2500
  sqlite3 *db,               /* SQLite connection to register module with */
dvander@1203
  2501
  const char *zName,         /* Name of the module */
dvander@1203
  2502
  const sqlite3_module *,    /* Methods for the module */
dvander@1203
  2503
  void *                     /* Client data for xCreate/xConnect */
dvander@1203
  2504
);
dvander@1203
  2505
dvander@1203
  2506
/*
dvander@1203
  2507
** This routine is identical to the sqlite3_create_module() method above,
dvander@1203
  2508
** except that it allows a destructor function to be specified. It is
dvander@1203
  2509
** even more experimental than the rest of the virtual tables API.
dvander@1203
  2510
*/
dvander@1203
  2511
int sqlite3_create_module_v2(
dvander@1203
  2512
  sqlite3 *db,               /* SQLite connection to register module with */
dvander@1203
  2513
  const char *zName,         /* Name of the module */
dvander@1203
  2514
  const sqlite3_module *,    /* Methods for the module */
dvander@1203
  2515
  void *,                    /* Client data for xCreate/xConnect */
dvander@1203
  2516
  void(*xDestroy)(void*)     /* Module destructor function */
dvander@1203
  2517
);
dvander@1203
  2518
dvander@1203
  2519
/*
dvander@1203
  2520
** Every module implementation uses a subclass of the following structure
dvander@1203
  2521
** to describe a particular instance of the module.  Each subclass will
dvander@1203
  2522
** be taylored to the specific needs of the module implementation.   The
dvander@1203
  2523
** purpose of this superclass is to define certain fields that are common
dvander@1203
  2524
** to all module implementations.
dvander@1203
  2525
**
dvander@1203
  2526
** Virtual tables methods can set an error message by assigning a
dvander@1203
  2527
** string obtained from sqlite3_mprintf() to zErrMsg.  The method should
dvander@1203
  2528
** take care that any prior string is freed by a call to sqlite3_free()
dvander@1203
  2529
** prior to assigning a new string to zErrMsg.  After the error message
dvander@1203
  2530
** is delivered up to the client application, the string will be automatically
dvander@1203
  2531
** freed by sqlite3_free() and the zErrMsg field will be zeroed.  Note
dvander@1203
  2532
** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field
dvander@1203
  2533
** since virtual tables are commonly implemented in loadable extensions which
dvander@1203
  2534
** do not have access to sqlite3MPrintf() or sqlite3Free().
dvander@1203
  2535
*/
dvander@1203
  2536
struct sqlite3_vtab {
dvander@1203
  2537
  const sqlite3_module *pModule;  /* The module for this virtual table */
dvander@1203
  2538
  int nRef;                       /* Used internally */
dvander@1203
  2539
  char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
dvander@1203
  2540
  /* Virtual table implementations will typically add additional fields */
dvander@1203
  2541
};
dvander@1203
  2542
dvander@1203
  2543
/* Every module implementation uses a subclass of the following structure
dvander@1203
  2544
** to describe cursors that point into the virtual table and are used
dvander@1203
  2545
** to loop through the virtual table.  Cursors are created using the
dvander@1203
  2546
** xOpen method of the module.  Each module implementation will define
dvander@1203
  2547
** the content of a cursor structure to suit its own needs.
dvander@1203
  2548
**
dvander@1203
  2549
** This superclass exists in order to define fields of the cursor that
dvander@1203
  2550
** are common to all implementations.
dvander@1203
  2551
*/
dvander@1203
  2552
struct sqlite3_vtab_cursor {
dvander@1203
  2553
  sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
dvander@1203
  2554
  /* Virtual table implementations will typically add additional fields */
dvander@1203
  2555
};
dvander@1203
  2556
dvander@1203
  2557
/*
dvander@1203
  2558
** The xCreate and xConnect methods of a module use the following API
dvander@1203
  2559
** to declare the format (the names and datatypes of the columns) of
dvander@1203
  2560
** the virtual tables they implement.
dvander@1203
  2561
*/
dvander@1203
  2562
int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable);
dvander@1203
  2563
dvander@1203
  2564
/*
dvander@1203
  2565
** Virtual tables can provide alternative implementations of functions
dvander@1203
  2566
** using the xFindFunction method.  But global versions of those functions
dvander@1203
  2567
** must exist in order to be overloaded.
dvander@1203
  2568
**
dvander@1203
  2569
** This API makes sure a global version of a function with a particular
dvander@1203
  2570
** name and number of parameters exists.  If no such function exists
dvander@1203
  2571
** before this API is called, a new function is created.  The implementation
dvander@1203
  2572
** of the new function always causes an exception to be thrown.  So
dvander@1203
  2573
** the new function is not good for anything by itself.  Its only
dvander@1203
  2574
** purpose is to be a place-holder function that can be overloaded
dvander@1203
  2575
** by virtual tables.
dvander@1203
  2576
**
dvander@1203
  2577
** This API should be considered part of the virtual table interface,
dvander@1203
  2578
** which is experimental and subject to change.
dvander@1203
  2579
*/
dvander@1203
  2580
int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
dvander@1203
  2581
dvander@1203
  2582
/*
dvander@1203
  2583
** The interface to the virtual-table mechanism defined above (back up
dvander@1203
  2584
** to a comment remarkably similar to this one) is currently considered
dvander@1203
  2585
** to be experimental.  The interface might change in incompatible ways.
dvander@1203
  2586
** If this is a problem for you, do not use the interface at this time.
dvander@1203
  2587
**
dvander@1203
  2588
** When the virtual-table mechanism stablizes, we will declare the
dvander@1203
  2589
** interface fixed, support it indefinitely, and remove this comment.
dvander@1203
  2590
**
dvander@1203
  2591
****** EXPERIMENTAL - subject to change without notice **************
dvander@1203
  2592
*/
dvander@1203
  2593
dvander@1203
  2594
/*
dvander@1203
  2595
** CAPI3REF: A Handle To An Open BLOB
dvander@1203
  2596
**
dvander@1203
  2597
** An instance of the following opaque structure is used to 
dvander@1203
  2598
** represent an blob-handle.  A blob-handle is created by
dvander@1203
  2599
** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()].
dvander@1203
  2600
** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
dvander@1203
  2601
** can be used to read or write small subsections of the blob.
dvander@1203
  2602
** The [sqltie3_blob_size()] interface returns the size of the
dvander@1203
  2603
** blob in bytes.
dvander@1203
  2604
*/
dvander@1203
  2605
typedef struct sqlite3_blob sqlite3_blob;
dvander@1203
  2606
dvander@1203
  2607
/*
dvander@1203
  2608
** CAPI3REF: Open A BLOB For Incremental I/O
dvander@1203
  2609
**
dvander@1203
  2610
** Open a handle to the blob located in row iRow,, column zColumn, 
dvander@1203
  2611
** table zTable in database zDb. i.e. the same blob that would
dvander@1203
  2612
** be selected by:
dvander@1203
  2613
**
dvander@1203
  2614
** <pre>
dvander@1203
  2615
**     SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
dvander@1203
  2616
** </pre>
dvander@1203
  2617
**
dvander@1203
  2618
** If the flags parameter is non-zero, the blob is opened for 
dvander@1203
  2619
** read and write access. If it is zero, the blob is opened for read 
dvander@1203
  2620
** access.
dvander@1203
  2621
**
dvander@1203
  2622
** On success, [SQLITE_OK] is returned and the new 
dvander@1203
  2623
** [sqlite3_blob | blob handle] is written to *ppBlob.
dvander@1203
  2624
** Otherwise an error code is returned and 
dvander@1203
  2625
** any value written to *ppBlob should not be used by the caller.
dvander@1203
  2626
** This function sets the database-handle error code and message
dvander@1203
  2627
** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()].
dvander@1203
  2628
*/
dvander@1203
  2629
int sqlite3_blob_open(
dvander@1203
  2630
  sqlite3*,
dvander@1203
  2631
  const char *zDb,
dvander@1203
  2632
  const char *zTable,
dvander@1203
  2633
  const char *zColumn,
dvander@1203
  2634
  sqlite_int64 iRow,
dvander@1203
  2635
  int flags,
dvander@1203
  2636
  sqlite3_blob **ppBlob
dvander@1203
  2637
);
dvander@1203
  2638
dvander@1203
  2639
/*
dvander@1203
  2640
** CAPI3REF:  Close A BLOB Handle
dvander@1203
  2641
**
dvander@1203
  2642
** Close an open [sqlite3_blob | blob handle].
dvander@1203
  2643
*/
dvander@1203
  2644
int sqlite3_blob_close(sqlite3_blob *);
dvander@1203
  2645
dvander@1203
  2646
/*
dvander@1203
  2647
** CAPI3REF:  Return The Size Of An Open BLOB
dvander@1203
  2648
**
dvander@1203
  2649
** Return the size in bytes of the blob accessible via the open 
dvander@1203
  2650
** [sqlite3_blob | blob-handle] passed as an argument.
dvander@1203
  2651
*/
dvander@1203
  2652
int sqlite3_blob_bytes(sqlite3_blob *);
dvander@1203
  2653
dvander@1203
  2654
/*
dvander@1203
  2655
** CAPI3REF:  Read Data From A BLOB Incrementally
dvander@1203
  2656
**
dvander@1203
  2657
** This function is used to read data from an open 
dvander@1203
  2658
** [sqlite3_blob | blob-handle] into a caller supplied buffer.
dvander@1203
  2659
** n bytes of data are copied into buffer
dvander@1203
  2660
** z from the open blob, starting at offset iOffset.
dvander@1203
  2661
**
dvander@1203
  2662
** On success, SQLITE_OK is returned. Otherwise, an 
dvander@1203
  2663
** [SQLITE_ERROR | SQLite error code] or an
dvander@1203
  2664
** [SQLITE_IOERR_READ | extended error code] is returned.
dvander@1203
  2665
*/
dvander@1203
  2666
int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset);
dvander@1203
  2667
dvander@1203
  2668
/*
dvander@1203
  2669
** CAPI3REF:  Write Data Into A BLOB Incrementally
dvander@1203
  2670
**
dvander@1203
  2671
** This function is used to write data into an open 
dvander@1203
  2672
** [sqlite3_blob | blob-handle] from a user supplied buffer.
dvander@1203
  2673
** n bytes of data are copied from the buffer
dvander@1203
  2674
** pointed to by z into the open blob, starting at offset iOffset.
dvander@1203
  2675
**
dvander@1203
  2676
** If the [sqlite3_blob | blob-handle] passed as the first argument
dvander@1203
  2677
** was not opened for writing (the flags parameter to [sqlite3_blob_open()]
dvander@1203
  2678
*** was zero), this function returns [SQLITE_READONLY].
dvander@1203
  2679
**
dvander@1203
  2680
** This function may only modify the contents of the blob, it is
dvander@1203
  2681
** not possible to increase the size of a blob using this API. If
dvander@1203
  2682
** offset iOffset is less than n bytes from the end of the blob, 
dvander@1203
  2683
** [SQLITE_ERROR] is returned and no data is written.
dvander@1203
  2684
**
dvander@1203
  2685
** On success, SQLITE_OK is returned. Otherwise, an 
dvander@1203
  2686
** [SQLITE_ERROR | SQLite error code] or an
dvander@1203
  2687
** [SQLITE_IOERR_READ | extended error code] is returned.
dvander@1203
  2688
*/
dvander@1203
  2689
int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
dvander@1203
  2690
dvander@1203
  2691
/*
dvander@1203
  2692
** Undo the hack that converts floating point types to integer for
dvander@1203
  2693
** builds on processors without floating point support.
dvander@1203
  2694
*/
dvander@1203
  2695
#ifdef SQLITE_OMIT_FLOATING_POINT
dvander@1203
  2696
# undef double
dvander@1203
  2697
#endif
dvander@1203
  2698
dvander@1203
  2699
#ifdef __cplusplus
dvander@1203
  2700
}  /* End of the 'extern "C"' block */
dvander@1203
  2701
#endif
dvander@1203
  2702
#endif