extensions/sqlite/sqlite-source/sqliteInt.h
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/extensions/sqlite/sqlite-source/sqliteInt.h	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1972 +0,0 @@
     1.4 -/*
     1.5 -** 2001 September 15
     1.6 -**
     1.7 -** The author disclaims copyright to this source code.  In place of
     1.8 -** a legal notice, here is a blessing:
     1.9 -**
    1.10 -**    May you do good and not evil.
    1.11 -**    May you find forgiveness for yourself and forgive others.
    1.12 -**    May you share freely, never taking more than you give.
    1.13 -**
    1.14 -*************************************************************************
    1.15 -** Internal interface definitions for SQLite.
    1.16 -**
    1.17 -** @(#) $Id$
    1.18 -*/
    1.19 -#ifndef _SQLITEINT_H_
    1.20 -#define _SQLITEINT_H_
    1.21 -#include "sqliteLimit.h"
    1.22 -
    1.23 -/*
    1.24 -** For testing purposes, the various size limit constants are really
    1.25 -** variables that we can modify in the testfixture.
    1.26 -*/
    1.27 -#ifdef SQLITE_TEST
    1.28 -  #undef SQLITE_MAX_LENGTH
    1.29 -  #undef SQLITE_MAX_COLUMN
    1.30 -  #undef SQLITE_MAX_SQL_LENGTH
    1.31 -  #undef SQLITE_MAX_EXPR_DEPTH
    1.32 -  #undef SQLITE_MAX_COMPOUND_SELECT
    1.33 -  #undef SQLITE_MAX_VDBE_OP
    1.34 -  #undef SQLITE_MAX_FUNCTION_ARG
    1.35 -  #undef SQLITE_MAX_VARIABLE_NUMBER
    1.36 -  #undef SQLITE_MAX_PAGE_SIZE
    1.37 -  #undef SQLITE_MAX_PAGE_COUNT
    1.38 -  #undef SQLITE_MAX_LIKE_PATTERN_LENGTH
    1.39 -
    1.40 -  #define SQLITE_MAX_LENGTH              sqlite3MAX_LENGTH
    1.41 -  #define SQLITE_MAX_COLUMN              sqlite3MAX_COLUMN
    1.42 -  #define SQLITE_MAX_SQL_LENGTH          sqlite3MAX_SQL_LENGTH
    1.43 -  #define SQLITE_MAX_EXPR_DEPTH          sqlite3MAX_EXPR_DEPTH
    1.44 -  #define SQLITE_MAX_COMPOUND_SELECT     sqlite3MAX_COMPOUND_SELECT
    1.45 -  #define SQLITE_MAX_VDBE_OP             sqlite3MAX_VDBE_OP
    1.46 -  #define SQLITE_MAX_FUNCTION_ARG        sqlite3MAX_FUNCTION_ARG
    1.47 -  #define SQLITE_MAX_VARIABLE_NUMBER     sqlite3MAX_VARIABLE_NUMBER
    1.48 -  #define SQLITE_MAX_PAGE_SIZE           sqlite3MAX_PAGE_SIZE
    1.49 -  #define SQLITE_MAX_PAGE_COUNT          sqlite3MAX_PAGE_COUNT
    1.50 -  #define SQLITE_MAX_LIKE_PATTERN_LENGTH sqlite3MAX_LIKE_PATTERN_LENGTH
    1.51 -
    1.52 -  extern int sqlite3MAX_LENGTH;
    1.53 -  extern int sqlite3MAX_COLUMN;
    1.54 -  extern int sqlite3MAX_SQL_LENGTH;
    1.55 -  extern int sqlite3MAX_EXPR_DEPTH;
    1.56 -  extern int sqlite3MAX_COMPOUND_SELECT;
    1.57 -  extern int sqlite3MAX_VDBE_OP;
    1.58 -  extern int sqlite3MAX_FUNCTION_ARG;
    1.59 -  extern int sqlite3MAX_VARIABLE_NUMBER;
    1.60 -  extern int sqlite3MAX_PAGE_SIZE;
    1.61 -  extern int sqlite3MAX_PAGE_COUNT;
    1.62 -  extern int sqlite3MAX_LIKE_PATTERN_LENGTH;
    1.63 -#endif
    1.64 -
    1.65 -
    1.66 -/*
    1.67 -** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
    1.68 -** Older versions of SQLite used an optional THREADSAFE macro.
    1.69 -** We support that for legacy
    1.70 -*/
    1.71 -#if !defined(SQLITE_THREADSAFE)
    1.72 -#if defined(THREADSAFE)
    1.73 -# define SQLITE_THREADSAFE THREADSAFE
    1.74 -#else
    1.75 -# define SQLITE_THREADSAFE 1
    1.76 -#endif
    1.77 -#endif
    1.78 -
    1.79 -/*
    1.80 -** We need to define _XOPEN_SOURCE as follows in order to enable
    1.81 -** recursive mutexes on most unix systems.  But Mac OS X is different.
    1.82 -** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
    1.83 -** so it is omitted there.  See ticket #2673.
    1.84 -**
    1.85 -** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
    1.86 -** implemented on some systems.  So we avoid defining it at all
    1.87 -** if it is already defined or if it is unneeded because we are
    1.88 -** not doing a threadsafe build.  Ticket #2681.
    1.89 -*/
    1.90 -#if !defined(_XOPEN_SOURCE) && !defined(__MACOS__) && SQLITE_THREADSAFE
    1.91 -#  define _XOPEN_SOURCE 500  /* Needed to enable pthread recursive mutexes */
    1.92 -#endif
    1.93 -
    1.94 -#if defined(SQLITE_TCL) || defined(TCLSH)
    1.95 -# include <tcl.h>
    1.96 -#endif
    1.97 -
    1.98 -/*
    1.99 -** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
   1.100 -** Setting NDEBUG makes the code smaller and run faster.  So the following
   1.101 -** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
   1.102 -** option is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
   1.103 -** feature.
   1.104 -*/
   1.105 -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 
   1.106 -# define NDEBUG 1
   1.107 -#endif
   1.108 -
   1.109 -/*
   1.110 -** These #defines should enable >2GB file support on Posix if the
   1.111 -** underlying operating system supports it.  If the OS lacks
   1.112 -** large file support, or if the OS is windows, these should be no-ops.
   1.113 -**
   1.114 -** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
   1.115 -** on the compiler command line.  This is necessary if you are compiling
   1.116 -** on a recent machine (ex: RedHat 7.2) but you want your code to work
   1.117 -** on an older machine (ex: RedHat 6.0).  If you compile on RedHat 7.2
   1.118 -** without this option, LFS is enable.  But LFS does not exist in the kernel
   1.119 -** in RedHat 6.0, so the code won't work.  Hence, for maximum binary
   1.120 -** portability you should omit LFS.
   1.121 -**
   1.122 -** Similar is true for MacOS.  LFS is only supported on MacOS 9 and later.
   1.123 -*/
   1.124 -#ifndef SQLITE_DISABLE_LFS
   1.125 -# define _LARGE_FILE       1
   1.126 -# ifndef _FILE_OFFSET_BITS
   1.127 -#   define _FILE_OFFSET_BITS 64
   1.128 -# endif
   1.129 -# define _LARGEFILE_SOURCE 1
   1.130 -#endif
   1.131 -
   1.132 -#include "sqlite3.h"
   1.133 -#include "hash.h"
   1.134 -#include "parse.h"
   1.135 -#include <stdio.h>
   1.136 -#include <stdlib.h>
   1.137 -#include <string.h>
   1.138 -#include <assert.h>
   1.139 -#include <stddef.h>
   1.140 -
   1.141 -#define sqlite3_isnan(X)  ((X)!=(X))
   1.142 -
   1.143 -/*
   1.144 -** If compiling for a processor that lacks floating point support,
   1.145 -** substitute integer for floating-point
   1.146 -*/
   1.147 -#ifdef SQLITE_OMIT_FLOATING_POINT
   1.148 -# define double sqlite_int64
   1.149 -# define LONGDOUBLE_TYPE sqlite_int64
   1.150 -# ifndef SQLITE_BIG_DBL
   1.151 -#   define SQLITE_BIG_DBL (0x7fffffffffffffff)
   1.152 -# endif
   1.153 -# define SQLITE_OMIT_DATETIME_FUNCS 1
   1.154 -# define SQLITE_OMIT_TRACE 1
   1.155 -# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
   1.156 -#endif
   1.157 -#ifndef SQLITE_BIG_DBL
   1.158 -# define SQLITE_BIG_DBL (1e99)
   1.159 -#endif
   1.160 -
   1.161 -/*
   1.162 -** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
   1.163 -** afterward. Having this macro allows us to cause the C compiler 
   1.164 -** to omit code used by TEMP tables without messy #ifndef statements.
   1.165 -*/
   1.166 -#ifdef SQLITE_OMIT_TEMPDB
   1.167 -#define OMIT_TEMPDB 1
   1.168 -#else
   1.169 -#define OMIT_TEMPDB 0
   1.170 -#endif
   1.171 -
   1.172 -/*
   1.173 -** If the following macro is set to 1, then NULL values are considered
   1.174 -** distinct when determining whether or not two entries are the same
   1.175 -** in a UNIQUE index.  This is the way PostgreSQL, Oracle, DB2, MySQL,
   1.176 -** OCELOT, and Firebird all work.  The SQL92 spec explicitly says this
   1.177 -** is the way things are suppose to work.
   1.178 -**
   1.179 -** If the following macro is set to 0, the NULLs are indistinct for
   1.180 -** a UNIQUE index.  In this mode, you can only have a single NULL entry
   1.181 -** for a column declared UNIQUE.  This is the way Informix and SQL Server
   1.182 -** work.
   1.183 -*/
   1.184 -#define NULL_DISTINCT_FOR_UNIQUE 1
   1.185 -
   1.186 -/*
   1.187 -** The "file format" number is an integer that is incremented whenever
   1.188 -** the VDBE-level file format changes.  The following macros define the
   1.189 -** the default file format for new databases and the maximum file format
   1.190 -** that the library can read.
   1.191 -*/
   1.192 -#define SQLITE_MAX_FILE_FORMAT 4
   1.193 -#ifndef SQLITE_DEFAULT_FILE_FORMAT
   1.194 -# define SQLITE_DEFAULT_FILE_FORMAT 1
   1.195 -#endif
   1.196 -
   1.197 -/*
   1.198 -** Provide a default value for TEMP_STORE in case it is not specified
   1.199 -** on the command-line
   1.200 -*/
   1.201 -#ifndef TEMP_STORE
   1.202 -# define TEMP_STORE 1
   1.203 -#endif
   1.204 -
   1.205 -/*
   1.206 -** GCC does not define the offsetof() macro so we'll have to do it
   1.207 -** ourselves.
   1.208 -*/
   1.209 -#ifndef offsetof
   1.210 -#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
   1.211 -#endif
   1.212 -
   1.213 -/*
   1.214 -** Check to see if this machine uses EBCDIC.  (Yes, believe it or
   1.215 -** not, there are still machines out there that use EBCDIC.)
   1.216 -*/
   1.217 -#if 'A' == '\301'
   1.218 -# define SQLITE_EBCDIC 1
   1.219 -#else
   1.220 -# define SQLITE_ASCII 1
   1.221 -#endif
   1.222 -
   1.223 -/*
   1.224 -** Integers of known sizes.  These typedefs might change for architectures
   1.225 -** where the sizes very.  Preprocessor macros are available so that the
   1.226 -** types can be conveniently redefined at compile-type.  Like this:
   1.227 -**
   1.228 -**         cc '-DUINTPTR_TYPE=long long int' ...
   1.229 -*/
   1.230 -#ifndef UINT32_TYPE
   1.231 -# define UINT32_TYPE unsigned int
   1.232 -#endif
   1.233 -#ifndef UINT16_TYPE
   1.234 -# define UINT16_TYPE unsigned short int
   1.235 -#endif
   1.236 -#ifndef INT16_TYPE
   1.237 -# define INT16_TYPE short int
   1.238 -#endif
   1.239 -#ifndef UINT8_TYPE
   1.240 -# define UINT8_TYPE unsigned char
   1.241 -#endif
   1.242 -#ifndef INT8_TYPE
   1.243 -# define INT8_TYPE signed char
   1.244 -#endif
   1.245 -#ifndef LONGDOUBLE_TYPE
   1.246 -# define LONGDOUBLE_TYPE long double
   1.247 -#endif
   1.248 -typedef sqlite_int64 i64;          /* 8-byte signed integer */
   1.249 -typedef sqlite_uint64 u64;         /* 8-byte unsigned integer */
   1.250 -typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
   1.251 -typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
   1.252 -typedef INT16_TYPE i16;            /* 2-byte signed integer */
   1.253 -typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
   1.254 -typedef UINT8_TYPE i8;             /* 1-byte signed integer */
   1.255 -
   1.256 -/*
   1.257 -** Macros to determine whether the machine is big or little endian,
   1.258 -** evaluated at runtime.
   1.259 -*/
   1.260 -#ifdef SQLITE_AMALGAMATION
   1.261 -const int sqlite3One;
   1.262 -#else
   1.263 -extern const int sqlite3one;
   1.264 -#endif
   1.265 -#if defined(i386) || defined(__i386__) || defined(_M_IX86)
   1.266 -# define SQLITE_BIGENDIAN    0
   1.267 -# define SQLITE_LITTLEENDIAN 1
   1.268 -# define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
   1.269 -#else
   1.270 -# define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
   1.271 -# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
   1.272 -# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
   1.273 -#endif
   1.274 -
   1.275 -/*
   1.276 -** An instance of the following structure is used to store the busy-handler
   1.277 -** callback for a given sqlite handle. 
   1.278 -**
   1.279 -** The sqlite.busyHandler member of the sqlite struct contains the busy
   1.280 -** callback for the database handle. Each pager opened via the sqlite
   1.281 -** handle is passed a pointer to sqlite.busyHandler. The busy-handler
   1.282 -** callback is currently invoked only from within pager.c.
   1.283 -*/
   1.284 -typedef struct BusyHandler BusyHandler;
   1.285 -struct BusyHandler {
   1.286 -  int (*xFunc)(void *,int);  /* The busy callback */
   1.287 -  void *pArg;                /* First arg to busy callback */
   1.288 -  int nBusy;                 /* Incremented with each busy call */
   1.289 -};
   1.290 -
   1.291 -/*
   1.292 -** Defer sourcing vdbe.h and btree.h until after the "u8" and 
   1.293 -** "BusyHandler typedefs.
   1.294 -*/
   1.295 -#include "btree.h"
   1.296 -#include "vdbe.h"
   1.297 -#include "pager.h"
   1.298 -
   1.299 -
   1.300 -/*
   1.301 -** Name of the master database table.  The master database table
   1.302 -** is a special table that holds the names and attributes of all
   1.303 -** user tables and indices.
   1.304 -*/
   1.305 -#define MASTER_NAME       "sqlite_master"
   1.306 -#define TEMP_MASTER_NAME  "sqlite_temp_master"
   1.307 -
   1.308 -/*
   1.309 -** The root-page of the master database table.
   1.310 -*/
   1.311 -#define MASTER_ROOT       1
   1.312 -
   1.313 -/*
   1.314 -** The name of the schema table.
   1.315 -*/
   1.316 -#define SCHEMA_TABLE(x)  ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
   1.317 -
   1.318 -/*
   1.319 -** A convenience macro that returns the number of elements in
   1.320 -** an array.
   1.321 -*/
   1.322 -#define ArraySize(X)    (sizeof(X)/sizeof(X[0]))
   1.323 -
   1.324 -/*
   1.325 -** Forward references to structures
   1.326 -*/
   1.327 -typedef struct AggInfo AggInfo;
   1.328 -typedef struct AuthContext AuthContext;
   1.329 -typedef struct CollSeq CollSeq;
   1.330 -typedef struct Column Column;
   1.331 -typedef struct Db Db;
   1.332 -typedef struct Schema Schema;
   1.333 -typedef struct Expr Expr;
   1.334 -typedef struct ExprList ExprList;
   1.335 -typedef struct FKey FKey;
   1.336 -typedef struct FuncDef FuncDef;
   1.337 -typedef struct IdList IdList;
   1.338 -typedef struct Index Index;
   1.339 -typedef struct KeyClass KeyClass;
   1.340 -typedef struct KeyInfo KeyInfo;
   1.341 -typedef struct Module Module;
   1.342 -typedef struct NameContext NameContext;
   1.343 -typedef struct Parse Parse;
   1.344 -typedef struct Select Select;
   1.345 -typedef struct SrcList SrcList;
   1.346 -typedef struct Table Table;
   1.347 -typedef struct TableLock TableLock;
   1.348 -typedef struct Token Token;
   1.349 -typedef struct TriggerStack TriggerStack;
   1.350 -typedef struct TriggerStep TriggerStep;
   1.351 -typedef struct Trigger Trigger;
   1.352 -typedef struct WhereInfo WhereInfo;
   1.353 -typedef struct WhereLevel WhereLevel;
   1.354 -
   1.355 -#include "os.h"
   1.356 -#include "mutex.h"
   1.357 -
   1.358 -/*
   1.359 -** Each database file to be accessed by the system is an instance
   1.360 -** of the following structure.  There are normally two of these structures
   1.361 -** in the sqlite.aDb[] array.  aDb[0] is the main database file and
   1.362 -** aDb[1] is the database file used to hold temporary tables.  Additional
   1.363 -** databases may be attached.
   1.364 -*/
   1.365 -struct Db {
   1.366 -  char *zName;         /* Name of this database */
   1.367 -  Btree *pBt;          /* The B*Tree structure for this database file */
   1.368 -  u8 inTrans;          /* 0: not writable.  1: Transaction.  2: Checkpoint */
   1.369 -  u8 safety_level;     /* How aggressive at synching data to disk */
   1.370 -  void *pAux;               /* Auxiliary data.  Usually NULL */
   1.371 -  void (*xFreeAux)(void*);  /* Routine to free pAux */
   1.372 -  Schema *pSchema;     /* Pointer to database schema (possibly shared) */
   1.373 -};
   1.374 -
   1.375 -/*
   1.376 -** An instance of the following structure stores a database schema.
   1.377 -**
   1.378 -** If there are no virtual tables configured in this schema, the
   1.379 -** Schema.db variable is set to NULL. After the first virtual table
   1.380 -** has been added, it is set to point to the database connection 
   1.381 -** used to create the connection. Once a virtual table has been
   1.382 -** added to the Schema structure and the Schema.db variable populated, 
   1.383 -** only that database connection may use the Schema to prepare 
   1.384 -** statements.
   1.385 -*/
   1.386 -struct Schema {
   1.387 -  int schema_cookie;   /* Database schema version number for this file */
   1.388 -  Hash tblHash;        /* All tables indexed by name */
   1.389 -  Hash idxHash;        /* All (named) indices indexed by name */
   1.390 -  Hash trigHash;       /* All triggers indexed by name */
   1.391 -  Hash aFKey;          /* Foreign keys indexed by to-table */
   1.392 -  Table *pSeqTab;      /* The sqlite_sequence table used by AUTOINCREMENT */
   1.393 -  u8 file_format;      /* Schema format version for this file */
   1.394 -  u8 enc;              /* Text encoding used by this database */
   1.395 -  u16 flags;           /* Flags associated with this schema */
   1.396 -  int cache_size;      /* Number of pages to use in the cache */
   1.397 -#ifndef SQLITE_OMIT_VIRTUALTABLE
   1.398 -  sqlite3 *db;         /* "Owner" connection. See comment above */
   1.399 -#endif
   1.400 -};
   1.401 -
   1.402 -/*
   1.403 -** These macros can be used to test, set, or clear bits in the 
   1.404 -** Db.flags field.
   1.405 -*/
   1.406 -#define DbHasProperty(D,I,P)     (((D)->aDb[I].pSchema->flags&(P))==(P))
   1.407 -#define DbHasAnyProperty(D,I,P)  (((D)->aDb[I].pSchema->flags&(P))!=0)
   1.408 -#define DbSetProperty(D,I,P)     (D)->aDb[I].pSchema->flags|=(P)
   1.409 -#define DbClearProperty(D,I,P)   (D)->aDb[I].pSchema->flags&=~(P)
   1.410 -
   1.411 -/*
   1.412 -** Allowed values for the DB.flags field.
   1.413 -**
   1.414 -** The DB_SchemaLoaded flag is set after the database schema has been
   1.415 -** read into internal hash tables.
   1.416 -**
   1.417 -** DB_UnresetViews means that one or more views have column names that
   1.418 -** have been filled out.  If the schema changes, these column names might
   1.419 -** changes and so the view will need to be reset.
   1.420 -*/
   1.421 -#define DB_SchemaLoaded    0x0001  /* The schema has been loaded */
   1.422 -#define DB_UnresetViews    0x0002  /* Some views have defined column names */
   1.423 -#define DB_Empty           0x0004  /* The file is empty (length 0 bytes) */
   1.424 -
   1.425 -
   1.426 -/*
   1.427 -** Each database is an instance of the following structure.
   1.428 -**
   1.429 -** The sqlite.lastRowid records the last insert rowid generated by an
   1.430 -** insert statement.  Inserts on views do not affect its value.  Each
   1.431 -** trigger has its own context, so that lastRowid can be updated inside
   1.432 -** triggers as usual.  The previous value will be restored once the trigger
   1.433 -** exits.  Upon entering a before or instead of trigger, lastRowid is no
   1.434 -** longer (since after version 2.8.12) reset to -1.
   1.435 -**
   1.436 -** The sqlite.nChange does not count changes within triggers and keeps no
   1.437 -** context.  It is reset at start of sqlite3_exec.
   1.438 -** The sqlite.lsChange represents the number of changes made by the last
   1.439 -** insert, update, or delete statement.  It remains constant throughout the
   1.440 -** length of a statement and is then updated by OP_SetCounts.  It keeps a
   1.441 -** context stack just like lastRowid so that the count of changes
   1.442 -** within a trigger is not seen outside the trigger.  Changes to views do not
   1.443 -** affect the value of lsChange.
   1.444 -** The sqlite.csChange keeps track of the number of current changes (since
   1.445 -** the last statement) and is used to update sqlite_lsChange.
   1.446 -**
   1.447 -** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
   1.448 -** store the most recent error code and, if applicable, string. The
   1.449 -** internal function sqlite3Error() is used to set these variables
   1.450 -** consistently.
   1.451 -*/
   1.452 -struct sqlite3 {
   1.453 -  sqlite3_vfs *pVfs;            /* OS Interface */
   1.454 -  int nDb;                      /* Number of backends currently in use */
   1.455 -  Db *aDb;                      /* All backends */
   1.456 -  int flags;                    /* Miscellanous flags. See below */
   1.457 -  int openFlags;                /* Flags passed to sqlite3_vfs.xOpen() */
   1.458 -  int errCode;                  /* Most recent error code (SQLITE_*) */
   1.459 -  int errMask;                  /* & result codes with this before returning */
   1.460 -  u8 autoCommit;                /* The auto-commit flag. */
   1.461 -  u8 temp_store;                /* 1: file 2: memory 0: default */
   1.462 -  u8 mallocFailed;              /* True if we have seen a malloc failure */
   1.463 -  int nTable;                   /* Number of tables in the database */
   1.464 -  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
   1.465 -  i64 lastRowid;                /* ROWID of most recent insert (see above) */
   1.466 -  i64 priorNewRowid;            /* Last randomly generated ROWID */
   1.467 -  int magic;                    /* Magic number for detect library misuse */
   1.468 -  int nChange;                  /* Value returned by sqlite3_changes() */
   1.469 -  int nTotalChange;             /* Value returned by sqlite3_total_changes() */
   1.470 -  sqlite3_mutex *mutex;         /* Connection mutex */
   1.471 -  struct sqlite3InitInfo {      /* Information used during initialization */
   1.472 -    int iDb;                    /* When back is being initialized */
   1.473 -    int newTnum;                /* Rootpage of table being initialized */
   1.474 -    u8 busy;                    /* TRUE if currently initializing */
   1.475 -  } init;
   1.476 -  int nExtension;               /* Number of loaded extensions */
   1.477 -  void **aExtension;            /* Array of shared libraray handles */
   1.478 -  struct Vdbe *pVdbe;           /* List of active virtual machines */
   1.479 -  int activeVdbeCnt;            /* Number of vdbes currently executing */
   1.480 -  void (*xTrace)(void*,const char*);        /* Trace function */
   1.481 -  void *pTraceArg;                          /* Argument to the trace function */
   1.482 -  void (*xProfile)(void*,const char*,u64);  /* Profiling function */
   1.483 -  void *pProfileArg;                        /* Argument to profile function */
   1.484 -  void *pCommitArg;                 /* Argument to xCommitCallback() */   
   1.485 -  int (*xCommitCallback)(void*);    /* Invoked at every commit. */
   1.486 -  void *pRollbackArg;               /* Argument to xRollbackCallback() */   
   1.487 -  void (*xRollbackCallback)(void*); /* Invoked at every commit. */
   1.488 -  void *pUpdateArg;
   1.489 -  void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
   1.490 -  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
   1.491 -  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
   1.492 -  void *pCollNeededArg;
   1.493 -  sqlite3_value *pErr;          /* Most recent error message */
   1.494 -  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
   1.495 -  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
   1.496 -  union {
   1.497 -    int isInterrupted;          /* True if sqlite3_interrupt has been called */
   1.498 -    double notUsed1;            /* Spacer */
   1.499 -  } u1;
   1.500 -#ifndef SQLITE_OMIT_AUTHORIZATION
   1.501 -  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
   1.502 -                                /* Access authorization function */
   1.503 -  void *pAuthArg;               /* 1st argument to the access auth function */
   1.504 -#endif
   1.505 -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   1.506 -  int (*xProgress)(void *);     /* The progress callback */
   1.507 -  void *pProgressArg;           /* Argument to the progress callback */
   1.508 -  int nProgressOps;             /* Number of opcodes for progress callback */
   1.509 -#endif
   1.510 -#ifndef SQLITE_OMIT_VIRTUALTABLE
   1.511 -  Hash aModule;                 /* populated by sqlite3_create_module() */
   1.512 -  Table *pVTab;                 /* vtab with active Connect/Create method */
   1.513 -  sqlite3_vtab **aVTrans;       /* Virtual tables with open transactions */
   1.514 -  int nVTrans;                  /* Allocated size of aVTrans */
   1.515 -#endif
   1.516 -  Hash aFunc;                   /* All functions that can be in SQL exprs */
   1.517 -  Hash aCollSeq;                /* All collating sequences */
   1.518 -  BusyHandler busyHandler;      /* Busy callback */
   1.519 -  int busyTimeout;              /* Busy handler timeout, in msec */
   1.520 -  Db aDbStatic[2];              /* Static space for the 2 default backends */
   1.521 -#ifdef SQLITE_SSE
   1.522 -  sqlite3_stmt *pFetch;         /* Used by SSE to fetch stored statements */
   1.523 -#endif
   1.524 -  u8 dfltLockMode;              /* Default locking-mode for attached dbs */
   1.525 -};
   1.526 -
   1.527 -/*
   1.528 -** A macro to discover the encoding of a database.
   1.529 -*/
   1.530 -#define ENC(db) ((db)->aDb[0].pSchema->enc)
   1.531 -
   1.532 -/*
   1.533 -** Possible values for the sqlite.flags and or Db.flags fields.
   1.534 -**
   1.535 -** On sqlite.flags, the SQLITE_InTrans value means that we have
   1.536 -** executed a BEGIN.  On Db.flags, SQLITE_InTrans means a statement
   1.537 -** transaction is active on that particular database file.
   1.538 -*/
   1.539 -#define SQLITE_VdbeTrace      0x00000001  /* True to trace VDBE execution */
   1.540 -#define SQLITE_InTrans        0x00000008  /* True if in a transaction */
   1.541 -#define SQLITE_InternChanges  0x00000010  /* Uncommitted Hash table changes */
   1.542 -#define SQLITE_FullColNames   0x00000020  /* Show full column names on SELECT */
   1.543 -#define SQLITE_ShortColNames  0x00000040  /* Show short columns names */
   1.544 -#define SQLITE_CountRows      0x00000080  /* Count rows changed by INSERT, */
   1.545 -                                          /*   DELETE, or UPDATE and return */
   1.546 -                                          /*   the count using a callback. */
   1.547 -#define SQLITE_NullCallback   0x00000100  /* Invoke the callback once if the */
   1.548 -                                          /*   result set is empty */
   1.549 -#define SQLITE_SqlTrace       0x00000200  /* Debug print SQL as it executes */
   1.550 -#define SQLITE_VdbeListing    0x00000400  /* Debug listings of VDBE programs */
   1.551 -#define SQLITE_WriteSchema    0x00000800  /* OK to update SQLITE_MASTER */
   1.552 -#define SQLITE_NoReadlock     0x00001000  /* Readlocks are omitted when 
   1.553 -                                          ** accessing read-only databases */
   1.554 -#define SQLITE_IgnoreChecks   0x00002000  /* Do not enforce check constraints */
   1.555 -#define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */
   1.556 -#define SQLITE_LegacyFileFmt  0x00008000  /* Create new databases in format 1 */
   1.557 -#define SQLITE_FullFSync      0x00010000  /* Use full fsync on the backend */
   1.558 -#define SQLITE_LoadExtension  0x00020000  /* Enable load_extension */
   1.559 -
   1.560 -#define SQLITE_RecoveryMode   0x00040000  /* Ignore schema errors */
   1.561 -#define SQLITE_SharedCache    0x00080000  /* Cache sharing is enabled */
   1.562 -#define SQLITE_Vtab           0x00100000  /* There exists a virtual table */
   1.563 -
   1.564 -/*
   1.565 -** Possible values for the sqlite.magic field.
   1.566 -** The numbers are obtained at random and have no special meaning, other
   1.567 -** than being distinct from one another.
   1.568 -*/
   1.569 -#define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */
   1.570 -#define SQLITE_MAGIC_CLOSED   0x9f3c2d33  /* Database is closed */
   1.571 -#define SQLITE_MAGIC_BUSY     0xf03b7906  /* Database currently in use */
   1.572 -#define SQLITE_MAGIC_ERROR    0xb5357930  /* An SQLITE_MISUSE error occurred */
   1.573 -
   1.574 -/*
   1.575 -** Each SQL function is defined by an instance of the following
   1.576 -** structure.  A pointer to this structure is stored in the sqlite.aFunc
   1.577 -** hash table.  When multiple functions have the same name, the hash table
   1.578 -** points to a linked list of these structures.
   1.579 -*/
   1.580 -struct FuncDef {
   1.581 -  i16 nArg;            /* Number of arguments.  -1 means unlimited */
   1.582 -  u8 iPrefEnc;         /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
   1.583 -  u8 needCollSeq;      /* True if sqlite3GetFuncCollSeq() might be called */
   1.584 -  u8 flags;            /* Some combination of SQLITE_FUNC_* */
   1.585 -  void *pUserData;     /* User data parameter */
   1.586 -  FuncDef *pNext;      /* Next function with same name */
   1.587 -  void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
   1.588 -  void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
   1.589 -  void (*xFinalize)(sqlite3_context*);                /* Aggregate finializer */
   1.590 -  char zName[1];       /* SQL name of the function.  MUST BE LAST */
   1.591 -};
   1.592 -
   1.593 -/*
   1.594 -** Each SQLite module (virtual table definition) is defined by an
   1.595 -** instance of the following structure, stored in the sqlite3.aModule
   1.596 -** hash table.
   1.597 -*/
   1.598 -struct Module {
   1.599 -  const sqlite3_module *pModule;       /* Callback pointers */
   1.600 -  const char *zName;                   /* Name passed to create_module() */
   1.601 -  void *pAux;                          /* pAux passed to create_module() */
   1.602 -  void (*xDestroy)(void *);            /* Module destructor function */
   1.603 -};
   1.604 -
   1.605 -/*
   1.606 -** Possible values for FuncDef.flags
   1.607 -*/
   1.608 -#define SQLITE_FUNC_LIKE   0x01  /* Candidate for the LIKE optimization */
   1.609 -#define SQLITE_FUNC_CASE   0x02  /* Case-sensitive LIKE-type function */
   1.610 -#define SQLITE_FUNC_EPHEM  0x04  /* Ephermeral.  Delete with VDBE */
   1.611 -
   1.612 -/*
   1.613 -** information about each column of an SQL table is held in an instance
   1.614 -** of this structure.
   1.615 -*/
   1.616 -struct Column {
   1.617 -  char *zName;     /* Name of this column */
   1.618 -  Expr *pDflt;     /* Default value of this column */
   1.619 -  char *zType;     /* Data type for this column */
   1.620 -  char *zColl;     /* Collating sequence.  If NULL, use the default */
   1.621 -  u8 notNull;      /* True if there is a NOT NULL constraint */
   1.622 -  u8 isPrimKey;    /* True if this column is part of the PRIMARY KEY */
   1.623 -  char affinity;   /* One of the SQLITE_AFF_... values */
   1.624 -#ifndef SQLITE_OMIT_VIRTUALTABLE
   1.625 -  u8 isHidden;     /* True if this column is 'hidden' */
   1.626 -#endif
   1.627 -};
   1.628 -
   1.629 -/*
   1.630 -** A "Collating Sequence" is defined by an instance of the following
   1.631 -** structure. Conceptually, a collating sequence consists of a name and
   1.632 -** a comparison routine that defines the order of that sequence.
   1.633 -**
   1.634 -** There may two seperate implementations of the collation function, one
   1.635 -** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
   1.636 -** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
   1.637 -** native byte order. When a collation sequence is invoked, SQLite selects
   1.638 -** the version that will require the least expensive encoding
   1.639 -** translations, if any.
   1.640 -**
   1.641 -** The CollSeq.pUser member variable is an extra parameter that passed in
   1.642 -** as the first argument to the UTF-8 comparison function, xCmp.
   1.643 -** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
   1.644 -** xCmp16.
   1.645 -**
   1.646 -** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
   1.647 -** collating sequence is undefined.  Indices built on an undefined
   1.648 -** collating sequence may not be read or written.
   1.649 -*/
   1.650 -struct CollSeq {
   1.651 -  char *zName;          /* Name of the collating sequence, UTF-8 encoded */
   1.652 -  u8 enc;               /* Text encoding handled by xCmp() */
   1.653 -  u8 type;              /* One of the SQLITE_COLL_... values below */
   1.654 -  void *pUser;          /* First argument to xCmp() */
   1.655 -  int (*xCmp)(void*,int, const void*, int, const void*);
   1.656 -  void (*xDel)(void*);  /* Destructor for pUser */
   1.657 -};
   1.658 -
   1.659 -/*
   1.660 -** Allowed values of CollSeq flags:
   1.661 -*/
   1.662 -#define SQLITE_COLL_BINARY  1  /* The default memcmp() collating sequence */
   1.663 -#define SQLITE_COLL_NOCASE  2  /* The built-in NOCASE collating sequence */
   1.664 -#define SQLITE_COLL_REVERSE 3  /* The built-in REVERSE collating sequence */
   1.665 -#define SQLITE_COLL_USER    0  /* Any other user-defined collating sequence */
   1.666 -
   1.667 -/*
   1.668 -** A sort order can be either ASC or DESC.
   1.669 -*/
   1.670 -#define SQLITE_SO_ASC       0  /* Sort in ascending order */
   1.671 -#define SQLITE_SO_DESC      1  /* Sort in ascending order */
   1.672 -
   1.673 -/*
   1.674 -** Column affinity types.
   1.675 -**
   1.676 -** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
   1.677 -** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve
   1.678 -** the speed a little by number the values consecutively.  
   1.679 -**
   1.680 -** But rather than start with 0 or 1, we begin with 'a'.  That way,
   1.681 -** when multiple affinity types are concatenated into a string and
   1.682 -** used as the P3 operand, they will be more readable.
   1.683 -**
   1.684 -** Note also that the numeric types are grouped together so that testing
   1.685 -** for a numeric type is a single comparison.
   1.686 -*/
   1.687 -#define SQLITE_AFF_TEXT     'a'
   1.688 -#define SQLITE_AFF_NONE     'b'
   1.689 -#define SQLITE_AFF_NUMERIC  'c'
   1.690 -#define SQLITE_AFF_INTEGER  'd'
   1.691 -#define SQLITE_AFF_REAL     'e'
   1.692 -
   1.693 -#define sqlite3IsNumericAffinity(X)  ((X)>=SQLITE_AFF_NUMERIC)
   1.694 -
   1.695 -/*
   1.696 -** Each SQL table is represented in memory by an instance of the
   1.697 -** following structure.
   1.698 -**
   1.699 -** Table.zName is the name of the table.  The case of the original
   1.700 -** CREATE TABLE statement is stored, but case is not significant for
   1.701 -** comparisons.
   1.702 -**
   1.703 -** Table.nCol is the number of columns in this table.  Table.aCol is a
   1.704 -** pointer to an array of Column structures, one for each column.
   1.705 -**
   1.706 -** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
   1.707 -** the column that is that key.   Otherwise Table.iPKey is negative.  Note
   1.708 -** that the datatype of the PRIMARY KEY must be INTEGER for this field to
   1.709 -** be set.  An INTEGER PRIMARY KEY is used as the rowid for each row of
   1.710 -** the table.  If a table has no INTEGER PRIMARY KEY, then a random rowid
   1.711 -** is generated for each row of the table.  Table.hasPrimKey is true if
   1.712 -** the table has any PRIMARY KEY, INTEGER or otherwise.
   1.713 -**
   1.714 -** Table.tnum is the page number for the root BTree page of the table in the
   1.715 -** database file.  If Table.iDb is the index of the database table backend
   1.716 -** in sqlite.aDb[].  0 is for the main database and 1 is for the file that
   1.717 -** holds temporary tables and indices.  If Table.isEphem
   1.718 -** is true, then the table is stored in a file that is automatically deleted
   1.719 -** when the VDBE cursor to the table is closed.  In this case Table.tnum 
   1.720 -** refers VDBE cursor number that holds the table open, not to the root
   1.721 -** page number.  Transient tables are used to hold the results of a
   1.722 -** sub-query that appears instead of a real table name in the FROM clause 
   1.723 -** of a SELECT statement.
   1.724 -*/
   1.725 -struct Table {
   1.726 -  char *zName;     /* Name of the table */
   1.727 -  int nCol;        /* Number of columns in this table */
   1.728 -  Column *aCol;    /* Information about each column */
   1.729 -  int iPKey;       /* If not less then 0, use aCol[iPKey] as the primary key */
   1.730 -  Index *pIndex;   /* List of SQL indexes on this table. */
   1.731 -  int tnum;        /* Root BTree node for this table (see note above) */
   1.732 -  Select *pSelect; /* NULL for tables.  Points to definition if a view. */
   1.733 -  int nRef;          /* Number of pointers to this Table */
   1.734 -  Trigger *pTrigger; /* List of SQL triggers on this table */
   1.735 -  FKey *pFKey;       /* Linked list of all foreign keys in this table */
   1.736 -  char *zColAff;     /* String defining the affinity of each column */
   1.737 -#ifndef SQLITE_OMIT_CHECK
   1.738 -  Expr *pCheck;      /* The AND of all CHECK constraints */
   1.739 -#endif
   1.740 -#ifndef SQLITE_OMIT_ALTERTABLE
   1.741 -  int addColOffset;  /* Offset in CREATE TABLE statement to add a new column */
   1.742 -#endif
   1.743 -  u8 readOnly;     /* True if this table should not be written by the user */
   1.744 -  u8 isEphem;      /* True if created using OP_OpenEphermeral */
   1.745 -  u8 hasPrimKey;   /* True if there exists a primary key */
   1.746 -  u8 keyConf;      /* What to do in case of uniqueness conflict on iPKey */
   1.747 -  u8 autoInc;      /* True if the integer primary key is autoincrement */
   1.748 -#ifndef SQLITE_OMIT_VIRTUALTABLE
   1.749 -  u8 isVirtual;             /* True if this is a virtual table */
   1.750 -  u8 isCommit;              /* True once the CREATE TABLE has been committed */
   1.751 -  Module *pMod;             /* Pointer to the implementation of the module */
   1.752 -  sqlite3_vtab *pVtab;      /* Pointer to the module instance */
   1.753 -  int nModuleArg;           /* Number of arguments to the module */
   1.754 -  char **azModuleArg;       /* Text of all module args. [0] is module name */
   1.755 -#endif
   1.756 -  Schema *pSchema;          /* Schema that contains this table */
   1.757 -};
   1.758 -
   1.759 -/*
   1.760 -** Test to see whether or not a table is a virtual table.  This is
   1.761 -** done as a macro so that it will be optimized out when virtual
   1.762 -** table support is omitted from the build.
   1.763 -*/
   1.764 -#ifndef SQLITE_OMIT_VIRTUALTABLE
   1.765 -#  define IsVirtual(X)      ((X)->isVirtual)
   1.766 -#  define IsHiddenColumn(X) ((X)->isHidden)
   1.767 -#else
   1.768 -#  define IsVirtual(X)      0
   1.769 -#  define IsHiddenColumn(X) 0
   1.770 -#endif
   1.771 -
   1.772 -/*
   1.773 -** Each foreign key constraint is an instance of the following structure.
   1.774 -**
   1.775 -** A foreign key is associated with two tables.  The "from" table is
   1.776 -** the table that contains the REFERENCES clause that creates the foreign
   1.777 -** key.  The "to" table is the table that is named in the REFERENCES clause.
   1.778 -** Consider this example:
   1.779 -**
   1.780 -**     CREATE TABLE ex1(
   1.781 -**       a INTEGER PRIMARY KEY,
   1.782 -**       b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
   1.783 -**     );
   1.784 -**
   1.785 -** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
   1.786 -**
   1.787 -** Each REFERENCES clause generates an instance of the following structure
   1.788 -** which is attached to the from-table.  The to-table need not exist when
   1.789 -** the from-table is created.  The existance of the to-table is not checked
   1.790 -** until an attempt is made to insert data into the from-table.
   1.791 -**
   1.792 -** The sqlite.aFKey hash table stores pointers to this structure
   1.793 -** given the name of a to-table.  For each to-table, all foreign keys
   1.794 -** associated with that table are on a linked list using the FKey.pNextTo
   1.795 -** field.
   1.796 -*/
   1.797 -struct FKey {
   1.798 -  Table *pFrom;     /* The table that constains the REFERENCES clause */
   1.799 -  FKey *pNextFrom;  /* Next foreign key in pFrom */
   1.800 -  char *zTo;        /* Name of table that the key points to */
   1.801 -  FKey *pNextTo;    /* Next foreign key that points to zTo */
   1.802 -  int nCol;         /* Number of columns in this key */
   1.803 -  struct sColMap {  /* Mapping of columns in pFrom to columns in zTo */
   1.804 -    int iFrom;         /* Index of column in pFrom */
   1.805 -    char *zCol;        /* Name of column in zTo.  If 0 use PRIMARY KEY */
   1.806 -  } *aCol;          /* One entry for each of nCol column s */
   1.807 -  u8 isDeferred;    /* True if constraint checking is deferred till COMMIT */
   1.808 -  u8 updateConf;    /* How to resolve conflicts that occur on UPDATE */
   1.809 -  u8 deleteConf;    /* How to resolve conflicts that occur on DELETE */
   1.810 -  u8 insertConf;    /* How to resolve conflicts that occur on INSERT */
   1.811 -};
   1.812 -
   1.813 -/*
   1.814 -** SQLite supports many different ways to resolve a constraint
   1.815 -** error.  ROLLBACK processing means that a constraint violation
   1.816 -** causes the operation in process to fail and for the current transaction
   1.817 -** to be rolled back.  ABORT processing means the operation in process
   1.818 -** fails and any prior changes from that one operation are backed out,
   1.819 -** but the transaction is not rolled back.  FAIL processing means that
   1.820 -** the operation in progress stops and returns an error code.  But prior
   1.821 -** changes due to the same operation are not backed out and no rollback
   1.822 -** occurs.  IGNORE means that the particular row that caused the constraint
   1.823 -** error is not inserted or updated.  Processing continues and no error
   1.824 -** is returned.  REPLACE means that preexisting database rows that caused
   1.825 -** a UNIQUE constraint violation are removed so that the new insert or
   1.826 -** update can proceed.  Processing continues and no error is reported.
   1.827 -**
   1.828 -** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
   1.829 -** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
   1.830 -** same as ROLLBACK for DEFERRED keys.  SETNULL means that the foreign
   1.831 -** key is set to NULL.  CASCADE means that a DELETE or UPDATE of the
   1.832 -** referenced table row is propagated into the row that holds the
   1.833 -** foreign key.
   1.834 -** 
   1.835 -** The following symbolic values are used to record which type
   1.836 -** of action to take.
   1.837 -*/
   1.838 -#define OE_None     0   /* There is no constraint to check */
   1.839 -#define OE_Rollback 1   /* Fail the operation and rollback the transaction */
   1.840 -#define OE_Abort    2   /* Back out changes but do no rollback transaction */
   1.841 -#define OE_Fail     3   /* Stop the operation but leave all prior changes */
   1.842 -#define OE_Ignore   4   /* Ignore the error. Do not do the INSERT or UPDATE */
   1.843 -#define OE_Replace  5   /* Delete existing record, then do INSERT or UPDATE */
   1.844 -
   1.845 -#define OE_Restrict 6   /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
   1.846 -#define OE_SetNull  7   /* Set the foreign key value to NULL */
   1.847 -#define OE_SetDflt  8   /* Set the foreign key value to its default */
   1.848 -#define OE_Cascade  9   /* Cascade the changes */
   1.849 -
   1.850 -#define OE_Default  99  /* Do whatever the default action is */
   1.851 -
   1.852 -
   1.853 -/*
   1.854 -** An instance of the following structure is passed as the first
   1.855 -** argument to sqlite3VdbeKeyCompare and is used to control the 
   1.856 -** comparison of the two index keys.
   1.857 -**
   1.858 -** If the KeyInfo.incrKey value is true and the comparison would
   1.859 -** otherwise be equal, then return a result as if the second key
   1.860 -** were larger.
   1.861 -*/
   1.862 -struct KeyInfo {
   1.863 -  sqlite3 *db;        /* The database connection */
   1.864 -  u8 enc;             /* Text encoding - one of the TEXT_Utf* values */
   1.865 -  u8 incrKey;         /* Increase 2nd key by epsilon before comparison */
   1.866 -  int nField;         /* Number of entries in aColl[] */
   1.867 -  u8 *aSortOrder;     /* If defined an aSortOrder[i] is true, sort DESC */
   1.868 -  CollSeq *aColl[1];  /* Collating sequence for each term of the key */
   1.869 -};
   1.870 -
   1.871 -/*
   1.872 -** Each SQL index is represented in memory by an
   1.873 -** instance of the following structure.
   1.874 -**
   1.875 -** The columns of the table that are to be indexed are described
   1.876 -** by the aiColumn[] field of this structure.  For example, suppose
   1.877 -** we have the following table and index:
   1.878 -**
   1.879 -**     CREATE TABLE Ex1(c1 int, c2 int, c3 text);
   1.880 -**     CREATE INDEX Ex2 ON Ex1(c3,c1);
   1.881 -**
   1.882 -** In the Table structure describing Ex1, nCol==3 because there are
   1.883 -** three columns in the table.  In the Index structure describing
   1.884 -** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
   1.885 -** The value of aiColumn is {2, 0}.  aiColumn[0]==2 because the 
   1.886 -** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
   1.887 -** The second column to be indexed (c1) has an index of 0 in
   1.888 -** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
   1.889 -**
   1.890 -** The Index.onError field determines whether or not the indexed columns
   1.891 -** must be unique and what to do if they are not.  When Index.onError=OE_None,
   1.892 -** it means this is not a unique index.  Otherwise it is a unique index
   1.893 -** and the value of Index.onError indicate the which conflict resolution 
   1.894 -** algorithm to employ whenever an attempt is made to insert a non-unique
   1.895 -** element.
   1.896 -*/
   1.897 -struct Index {
   1.898 -  char *zName;     /* Name of this index */
   1.899 -  int nColumn;     /* Number of columns in the table used by this index */
   1.900 -  int *aiColumn;   /* Which columns are used by this index.  1st is 0 */
   1.901 -  unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
   1.902 -  Table *pTable;   /* The SQL table being indexed */
   1.903 -  int tnum;        /* Page containing root of this index in database file */
   1.904 -  u8 onError;      /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
   1.905 -  u8 autoIndex;    /* True if is automatically created (ex: by UNIQUE) */
   1.906 -  char *zColAff;   /* String defining the affinity of each column */
   1.907 -  Index *pNext;    /* The next index associated with the same table */
   1.908 -  Schema *pSchema; /* Schema containing this index */
   1.909 -  u8 *aSortOrder;  /* Array of size Index.nColumn. True==DESC, False==ASC */
   1.910 -  char **azColl;   /* Array of collation sequence names for index */
   1.911 -};
   1.912 -
   1.913 -/*
   1.914 -** Each token coming out of the lexer is an instance of
   1.915 -** this structure.  Tokens are also used as part of an expression.
   1.916 -**
   1.917 -** Note if Token.z==0 then Token.dyn and Token.n are undefined and
   1.918 -** may contain random values.  Do not make any assuptions about Token.dyn
   1.919 -** and Token.n when Token.z==0.
   1.920 -*/
   1.921 -struct Token {
   1.922 -  const unsigned char *z; /* Text of the token.  Not NULL-terminated! */
   1.923 -  unsigned dyn  : 1;      /* True for malloced memory, false for static */
   1.924 -  unsigned n    : 31;     /* Number of characters in this token */
   1.925 -};
   1.926 -
   1.927 -/*
   1.928 -** An instance of this structure contains information needed to generate
   1.929 -** code for a SELECT that contains aggregate functions.
   1.930 -**
   1.931 -** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
   1.932 -** pointer to this structure.  The Expr.iColumn field is the index in
   1.933 -** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
   1.934 -** code for that node.
   1.935 -**
   1.936 -** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
   1.937 -** original Select structure that describes the SELECT statement.  These
   1.938 -** fields do not need to be freed when deallocating the AggInfo structure.
   1.939 -*/
   1.940 -struct AggInfo {
   1.941 -  u8 directMode;          /* Direct rendering mode means take data directly
   1.942 -                          ** from source tables rather than from accumulators */
   1.943 -  u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
   1.944 -                          ** than the source table */
   1.945 -  int sortingIdx;         /* Cursor number of the sorting index */
   1.946 -  ExprList *pGroupBy;     /* The group by clause */
   1.947 -  int nSortingColumn;     /* Number of columns in the sorting index */
   1.948 -  struct AggInfo_col {    /* For each column used in source tables */
   1.949 -    Table *pTab;             /* Source table */
   1.950 -    int iTable;              /* Cursor number of the source table */
   1.951 -    int iColumn;             /* Column number within the source table */
   1.952 -    int iSorterColumn;       /* Column number in the sorting index */
   1.953 -    int iMem;                /* Memory location that acts as accumulator */
   1.954 -    Expr *pExpr;             /* The original expression */
   1.955 -  } *aCol;
   1.956 -  int nColumn;            /* Number of used entries in aCol[] */
   1.957 -  int nColumnAlloc;       /* Number of slots allocated for aCol[] */
   1.958 -  int nAccumulator;       /* Number of columns that show through to the output.
   1.959 -                          ** Additional columns are used only as parameters to
   1.960 -                          ** aggregate functions */
   1.961 -  struct AggInfo_func {   /* For each aggregate function */
   1.962 -    Expr *pExpr;             /* Expression encoding the function */
   1.963 -    FuncDef *pFunc;          /* The aggregate function implementation */
   1.964 -    int iMem;                /* Memory location that acts as accumulator */
   1.965 -    int iDistinct;           /* Ephermeral table used to enforce DISTINCT */
   1.966 -  } *aFunc;
   1.967 -  int nFunc;              /* Number of entries in aFunc[] */
   1.968 -  int nFuncAlloc;         /* Number of slots allocated for aFunc[] */
   1.969 -};
   1.970 -
   1.971 -/*
   1.972 -** Each node of an expression in the parse tree is an instance
   1.973 -** of this structure.
   1.974 -**
   1.975 -** Expr.op is the opcode.  The integer parser token codes are reused
   1.976 -** as opcodes here.  For example, the parser defines TK_GE to be an integer
   1.977 -** code representing the ">=" operator.  This same integer code is reused
   1.978 -** to represent the greater-than-or-equal-to operator in the expression
   1.979 -** tree.
   1.980 -**
   1.981 -** Expr.pRight and Expr.pLeft are subexpressions.  Expr.pList is a list
   1.982 -** of argument if the expression is a function.
   1.983 -**
   1.984 -** Expr.token is the operator token for this node.  For some expressions
   1.985 -** that have subexpressions, Expr.token can be the complete text that gave
   1.986 -** rise to the Expr.  In the latter case, the token is marked as being
   1.987 -** a compound token.
   1.988 -**
   1.989 -** An expression of the form ID or ID.ID refers to a column in a table.
   1.990 -** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
   1.991 -** the integer cursor number of a VDBE cursor pointing to that table and
   1.992 -** Expr.iColumn is the column number for the specific column.  If the
   1.993 -** expression is used as a result in an aggregate SELECT, then the
   1.994 -** value is also stored in the Expr.iAgg column in the aggregate so that
   1.995 -** it can be accessed after all aggregates are computed.
   1.996 -**
   1.997 -** If the expression is a function, the Expr.iTable is an integer code
   1.998 -** representing which function.  If the expression is an unbound variable
   1.999 -** marker (a question mark character '?' in the original SQL) then the
  1.1000 -** Expr.iTable holds the index number for that variable.
  1.1001 -**
  1.1002 -** If the expression is a subquery then Expr.iColumn holds an integer
  1.1003 -** register number containing the result of the subquery.  If the
  1.1004 -** subquery gives a constant result, then iTable is -1.  If the subquery
  1.1005 -** gives a different answer at different times during statement processing
  1.1006 -** then iTable is the address of a subroutine that computes the subquery.
  1.1007 -**
  1.1008 -** The Expr.pSelect field points to a SELECT statement.  The SELECT might
  1.1009 -** be the right operand of an IN operator.  Or, if a scalar SELECT appears
  1.1010 -** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
  1.1011 -** operand.
  1.1012 -**
  1.1013 -** If the Expr is of type OP_Column, and the table it is selecting from
  1.1014 -** is a disk table or the "old.*" pseudo-table, then pTab points to the
  1.1015 -** corresponding table definition.
  1.1016 -*/
  1.1017 -struct Expr {
  1.1018 -  u8 op;                 /* Operation performed by this node */
  1.1019 -  char affinity;         /* The affinity of the column or 0 if not a column */
  1.1020 -  u16 flags;             /* Various flags.  See below */
  1.1021 -  CollSeq *pColl;        /* The collation type of the column or 0 */
  1.1022 -  Expr *pLeft, *pRight;  /* Left and right subnodes */
  1.1023 -  ExprList *pList;       /* A list of expressions used as function arguments
  1.1024 -                         ** or in "<expr> IN (<expr-list)" */
  1.1025 -  Token token;           /* An operand token */
  1.1026 -  Token span;            /* Complete text of the expression */
  1.1027 -  int iTable, iColumn;   /* When op==TK_COLUMN, then this expr node means the
  1.1028 -                         ** iColumn-th field of the iTable-th table. */
  1.1029 -  AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  1.1030 -  int iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  1.1031 -  int iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  1.1032 -  Select *pSelect;       /* When the expression is a sub-select.  Also the
  1.1033 -                         ** right side of "<expr> IN (<select>)" */
  1.1034 -  Table *pTab;           /* Table for OP_Column expressions. */
  1.1035 -/*  Schema *pSchema; */
  1.1036 -#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
  1.1037 -  int nHeight;           /* Height of the tree headed by this node */
  1.1038 -#endif
  1.1039 -};
  1.1040 -
  1.1041 -/*
  1.1042 -** The following are the meanings of bits in the Expr.flags field.
  1.1043 -*/
  1.1044 -#define EP_FromJoin     0x01  /* Originated in ON or USING clause of a join */
  1.1045 -#define EP_Agg          0x02  /* Contains one or more aggregate functions */
  1.1046 -#define EP_Resolved     0x04  /* IDs have been resolved to COLUMNs */
  1.1047 -#define EP_Error        0x08  /* Expression contains one or more errors */
  1.1048 -#define EP_Distinct     0x10  /* Aggregate function with DISTINCT keyword */
  1.1049 -#define EP_VarSelect    0x20  /* pSelect is correlated, not constant */
  1.1050 -#define EP_Dequoted     0x40  /* True if the string has been dequoted */
  1.1051 -#define EP_InfixFunc    0x80  /* True for an infix function: LIKE, GLOB, etc */
  1.1052 -#define EP_ExpCollate  0x100  /* Collating sequence specified explicitly */
  1.1053 -
  1.1054 -/*
  1.1055 -** These macros can be used to test, set, or clear bits in the 
  1.1056 -** Expr.flags field.
  1.1057 -*/
  1.1058 -#define ExprHasProperty(E,P)     (((E)->flags&(P))==(P))
  1.1059 -#define ExprHasAnyProperty(E,P)  (((E)->flags&(P))!=0)
  1.1060 -#define ExprSetProperty(E,P)     (E)->flags|=(P)
  1.1061 -#define ExprClearProperty(E,P)   (E)->flags&=~(P)
  1.1062 -
  1.1063 -/*
  1.1064 -** A list of expressions.  Each expression may optionally have a
  1.1065 -** name.  An expr/name combination can be used in several ways, such
  1.1066 -** as the list of "expr AS ID" fields following a "SELECT" or in the
  1.1067 -** list of "ID = expr" items in an UPDATE.  A list of expressions can
  1.1068 -** also be used as the argument to a function, in which case the a.zName
  1.1069 -** field is not used.
  1.1070 -*/
  1.1071 -struct ExprList {
  1.1072 -  int nExpr;             /* Number of expressions on the list */
  1.1073 -  int nAlloc;            /* Number of entries allocated below */
  1.1074 -  int iECursor;          /* VDBE Cursor associated with this ExprList */
  1.1075 -  struct ExprList_item {
  1.1076 -    Expr *pExpr;           /* The list of expressions */
  1.1077 -    char *zName;           /* Token associated with this expression */
  1.1078 -    u8 sortOrder;          /* 1 for DESC or 0 for ASC */
  1.1079 -    u8 isAgg;              /* True if this is an aggregate like count(*) */
  1.1080 -    u8 done;               /* A flag to indicate when processing is finished */
  1.1081 -  } *a;                  /* One entry for each expression */
  1.1082 -};
  1.1083 -
  1.1084 -/*
  1.1085 -** An instance of this structure can hold a simple list of identifiers,
  1.1086 -** such as the list "a,b,c" in the following statements:
  1.1087 -**
  1.1088 -**      INSERT INTO t(a,b,c) VALUES ...;
  1.1089 -**      CREATE INDEX idx ON t(a,b,c);
  1.1090 -**      CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
  1.1091 -**
  1.1092 -** The IdList.a.idx field is used when the IdList represents the list of
  1.1093 -** column names after a table name in an INSERT statement.  In the statement
  1.1094 -**
  1.1095 -**     INSERT INTO t(a,b,c) ...
  1.1096 -**
  1.1097 -** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
  1.1098 -*/
  1.1099 -struct IdList {
  1.1100 -  struct IdList_item {
  1.1101 -    char *zName;      /* Name of the identifier */
  1.1102 -    int idx;          /* Index in some Table.aCol[] of a column named zName */
  1.1103 -  } *a;
  1.1104 -  int nId;         /* Number of identifiers on the list */
  1.1105 -  int nAlloc;      /* Number of entries allocated for a[] below */
  1.1106 -};
  1.1107 -
  1.1108 -/*
  1.1109 -** The bitmask datatype defined below is used for various optimizations.
  1.1110 -**
  1.1111 -** Changing this from a 64-bit to a 32-bit type limits the number of
  1.1112 -** tables in a join to 32 instead of 64.  But it also reduces the size
  1.1113 -** of the library by 738 bytes on ix86.
  1.1114 -*/
  1.1115 -typedef u64 Bitmask;
  1.1116 -
  1.1117 -/*
  1.1118 -** The following structure describes the FROM clause of a SELECT statement.
  1.1119 -** Each table or subquery in the FROM clause is a separate element of
  1.1120 -** the SrcList.a[] array.
  1.1121 -**
  1.1122 -** With the addition of multiple database support, the following structure
  1.1123 -** can also be used to describe a particular table such as the table that
  1.1124 -** is modified by an INSERT, DELETE, or UPDATE statement.  In standard SQL,
  1.1125 -** such a table must be a simple name: ID.  But in SQLite, the table can
  1.1126 -** now be identified by a database name, a dot, then the table name: ID.ID.
  1.1127 -**
  1.1128 -** The jointype starts out showing the join type between the current table
  1.1129 -** and the next table on the list.  The parser builds the list this way.
  1.1130 -** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
  1.1131 -** jointype expresses the join between the table and the previous table.
  1.1132 -*/
  1.1133 -struct SrcList {
  1.1134 -  i16 nSrc;        /* Number of tables or subqueries in the FROM clause */
  1.1135 -  i16 nAlloc;      /* Number of entries allocated in a[] below */
  1.1136 -  struct SrcList_item {
  1.1137 -    char *zDatabase;  /* Name of database holding this table */
  1.1138 -    char *zName;      /* Name of the table */
  1.1139 -    char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
  1.1140 -    Table *pTab;      /* An SQL table corresponding to zName */
  1.1141 -    Select *pSelect;  /* A SELECT statement used in place of a table name */
  1.1142 -    u8 isPopulated;   /* Temporary table associated with SELECT is populated */
  1.1143 -    u8 jointype;      /* Type of join between this able and the previous */
  1.1144 -    int iCursor;      /* The VDBE cursor number used to access this table */
  1.1145 -    Expr *pOn;        /* The ON clause of a join */
  1.1146 -    IdList *pUsing;   /* The USING clause of a join */
  1.1147 -    Bitmask colUsed;  /* Bit N (1<<N) set if column N or pTab is used */
  1.1148 -  } a[1];             /* One entry for each identifier on the list */
  1.1149 -};
  1.1150 -
  1.1151 -/*
  1.1152 -** Permitted values of the SrcList.a.jointype field
  1.1153 -*/
  1.1154 -#define JT_INNER     0x0001    /* Any kind of inner or cross join */
  1.1155 -#define JT_CROSS     0x0002    /* Explicit use of the CROSS keyword */
  1.1156 -#define JT_NATURAL   0x0004    /* True for a "natural" join */
  1.1157 -#define JT_LEFT      0x0008    /* Left outer join */
  1.1158 -#define JT_RIGHT     0x0010    /* Right outer join */
  1.1159 -#define JT_OUTER     0x0020    /* The "OUTER" keyword is present */
  1.1160 -#define JT_ERROR     0x0040    /* unknown or unsupported join type */
  1.1161 -
  1.1162 -/*
  1.1163 -** For each nested loop in a WHERE clause implementation, the WhereInfo
  1.1164 -** structure contains a single instance of this structure.  This structure
  1.1165 -** is intended to be private the the where.c module and should not be
  1.1166 -** access or modified by other modules.
  1.1167 -**
  1.1168 -** The pIdxInfo and pBestIdx fields are used to help pick the best
  1.1169 -** index on a virtual table.  The pIdxInfo pointer contains indexing
  1.1170 -** information for the i-th table in the FROM clause before reordering.
  1.1171 -** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
  1.1172 -** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after
  1.1173 -** FROM clause ordering.  This is a little confusing so I will repeat
  1.1174 -** it in different words.  WhereInfo.a[i].pIdxInfo is index information 
  1.1175 -** for WhereInfo.pTabList.a[i].  WhereInfo.a[i].pBestInfo is the
  1.1176 -** index information for the i-th loop of the join.  pBestInfo is always
  1.1177 -** either NULL or a copy of some pIdxInfo.  So for cleanup it is 
  1.1178 -** sufficient to free all of the pIdxInfo pointers.
  1.1179 -** 
  1.1180 -*/
  1.1181 -struct WhereLevel {
  1.1182 -  int iFrom;            /* Which entry in the FROM clause */
  1.1183 -  int flags;            /* Flags associated with this level */
  1.1184 -  int iMem;             /* First memory cell used by this level */
  1.1185 -  int iLeftJoin;        /* Memory cell used to implement LEFT OUTER JOIN */
  1.1186 -  Index *pIdx;          /* Index used.  NULL if no index */
  1.1187 -  int iTabCur;          /* The VDBE cursor used to access the table */
  1.1188 -  int iIdxCur;          /* The VDBE cursor used to acesss pIdx */
  1.1189 -  int brk;              /* Jump here to break out of the loop */
  1.1190 -  int nxt;              /* Jump here to start the next IN combination */
  1.1191 -  int cont;             /* Jump here to continue with the next loop cycle */
  1.1192 -  int top;              /* First instruction of interior of the loop */
  1.1193 -  int op, p1, p2;       /* Opcode used to terminate the loop */
  1.1194 -  int nEq;              /* Number of == or IN constraints on this loop */
  1.1195 -  int nIn;              /* Number of IN operators constraining this loop */
  1.1196 -  struct InLoop {
  1.1197 -    int iCur;              /* The VDBE cursor used by this IN operator */
  1.1198 -    int topAddr;           /* Top of the IN loop */
  1.1199 -  } *aInLoop;           /* Information about each nested IN operator */
  1.1200 -  sqlite3_index_info *pBestIdx;  /* Index information for this level */
  1.1201 -
  1.1202 -  /* The following field is really not part of the current level.  But
  1.1203 -  ** we need a place to cache index information for each table in the
  1.1204 -  ** FROM clause and the WhereLevel structure is a convenient place.
  1.1205 -  */
  1.1206 -  sqlite3_index_info *pIdxInfo;  /* Index info for n-th source table */
  1.1207 -};
  1.1208 -
  1.1209 -/*
  1.1210 -** The WHERE clause processing routine has two halves.  The
  1.1211 -** first part does the start of the WHERE loop and the second
  1.1212 -** half does the tail of the WHERE loop.  An instance of
  1.1213 -** this structure is returned by the first half and passed
  1.1214 -** into the second half to give some continuity.
  1.1215 -*/
  1.1216 -struct WhereInfo {
  1.1217 -  Parse *pParse;
  1.1218 -  SrcList *pTabList;   /* List of tables in the join */
  1.1219 -  int iTop;            /* The very beginning of the WHERE loop */
  1.1220 -  int iContinue;       /* Jump here to continue with next record */
  1.1221 -  int iBreak;          /* Jump here to break out of the loop */
  1.1222 -  int nLevel;          /* Number of nested loop */
  1.1223 -  sqlite3_index_info **apInfo;  /* Array of pointers to index info structures */
  1.1224 -  WhereLevel a[1];     /* Information about each nest loop in the WHERE */
  1.1225 -};
  1.1226 -
  1.1227 -/*
  1.1228 -** A NameContext defines a context in which to resolve table and column
  1.1229 -** names.  The context consists of a list of tables (the pSrcList) field and
  1.1230 -** a list of named expression (pEList).  The named expression list may
  1.1231 -** be NULL.  The pSrc corresponds to the FROM clause of a SELECT or
  1.1232 -** to the table being operated on by INSERT, UPDATE, or DELETE.  The
  1.1233 -** pEList corresponds to the result set of a SELECT and is NULL for
  1.1234 -** other statements.
  1.1235 -**
  1.1236 -** NameContexts can be nested.  When resolving names, the inner-most 
  1.1237 -** context is searched first.  If no match is found, the next outer
  1.1238 -** context is checked.  If there is still no match, the next context
  1.1239 -** is checked.  This process continues until either a match is found
  1.1240 -** or all contexts are check.  When a match is found, the nRef member of
  1.1241 -** the context containing the match is incremented. 
  1.1242 -**
  1.1243 -** Each subquery gets a new NameContext.  The pNext field points to the
  1.1244 -** NameContext in the parent query.  Thus the process of scanning the
  1.1245 -** NameContext list corresponds to searching through successively outer
  1.1246 -** subqueries looking for a match.
  1.1247 -*/
  1.1248 -struct NameContext {
  1.1249 -  Parse *pParse;       /* The parser */
  1.1250 -  SrcList *pSrcList;   /* One or more tables used to resolve names */
  1.1251 -  ExprList *pEList;    /* Optional list of named expressions */
  1.1252 -  int nRef;            /* Number of names resolved by this context */
  1.1253 -  int nErr;            /* Number of errors encountered while resolving names */
  1.1254 -  u8 allowAgg;         /* Aggregate functions allowed here */
  1.1255 -  u8 hasAgg;           /* True if aggregates are seen */
  1.1256 -  u8 isCheck;          /* True if resolving names in a CHECK constraint */
  1.1257 -  int nDepth;          /* Depth of subquery recursion. 1 for no recursion */
  1.1258 -  AggInfo *pAggInfo;   /* Information about aggregates at this level */
  1.1259 -  NameContext *pNext;  /* Next outer name context.  NULL for outermost */
  1.1260 -};
  1.1261 -
  1.1262 -/*
  1.1263 -** An instance of the following structure contains all information
  1.1264 -** needed to generate code for a single SELECT statement.
  1.1265 -**
  1.1266 -** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
  1.1267 -** If there is a LIMIT clause, the parser sets nLimit to the value of the
  1.1268 -** limit and nOffset to the value of the offset (or 0 if there is not
  1.1269 -** offset).  But later on, nLimit and nOffset become the memory locations
  1.1270 -** in the VDBE that record the limit and offset counters.
  1.1271 -**
  1.1272 -** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
  1.1273 -** These addresses must be stored so that we can go back and fill in
  1.1274 -** the P3_KEYINFO and P2 parameters later.  Neither the KeyInfo nor
  1.1275 -** the number of columns in P2 can be computed at the same time
  1.1276 -** as the OP_OpenEphm instruction is coded because not
  1.1277 -** enough information about the compound query is known at that point.
  1.1278 -** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
  1.1279 -** for the result set.  The KeyInfo for addrOpenTran[2] contains collating
  1.1280 -** sequences for the ORDER BY clause.
  1.1281 -*/
  1.1282 -struct Select {
  1.1283 -  ExprList *pEList;      /* The fields of the result */
  1.1284 -  u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
  1.1285 -  u8 isDistinct;         /* True if the DISTINCT keyword is present */
  1.1286 -  u8 isResolved;         /* True once sqlite3SelectResolve() has run. */
  1.1287 -  u8 isAgg;              /* True if this is an aggregate query */
  1.1288 -  u8 usesEphm;           /* True if uses an OpenEphemeral opcode */
  1.1289 -  u8 disallowOrderBy;    /* Do not allow an ORDER BY to be attached if TRUE */
  1.1290 -  char affinity;         /* MakeRecord with this affinity for SRT_Set */
  1.1291 -  SrcList *pSrc;         /* The FROM clause */
  1.1292 -  Expr *pWhere;          /* The WHERE clause */
  1.1293 -  ExprList *pGroupBy;    /* The GROUP BY clause */
  1.1294 -  Expr *pHaving;         /* The HAVING clause */
  1.1295 -  ExprList *pOrderBy;    /* The ORDER BY clause */
  1.1296 -  Select *pPrior;        /* Prior select in a compound select statement */
  1.1297 -  Select *pRightmost;    /* Right-most select in a compound select statement */
  1.1298 -  Expr *pLimit;          /* LIMIT expression. NULL means not used. */
  1.1299 -  Expr *pOffset;         /* OFFSET expression. NULL means not used. */
  1.1300 -  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
  1.1301 -  int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */
  1.1302 -};
  1.1303 -
  1.1304 -/*
  1.1305 -** The results of a select can be distributed in several ways.
  1.1306 -*/
  1.1307 -#define SRT_Union        1  /* Store result as keys in an index */
  1.1308 -#define SRT_Except       2  /* Remove result from a UNION index */
  1.1309 -#define SRT_Discard      3  /* Do not save the results anywhere */
  1.1310 -
  1.1311 -/* The ORDER BY clause is ignored for all of the above */
  1.1312 -#define IgnorableOrderby(X) (X<=SRT_Discard)
  1.1313 -
  1.1314 -#define SRT_Callback     4  /* Invoke a callback with each row of result */
  1.1315 -#define SRT_Mem          5  /* Store result in a memory cell */
  1.1316 -#define SRT_Set          6  /* Store non-null results as keys in an index */
  1.1317 -#define SRT_Table        7  /* Store result as data with an automatic rowid */
  1.1318 -#define SRT_EphemTab     8  /* Create transient tab and store like SRT_Table */
  1.1319 -#define SRT_Subroutine   9  /* Call a subroutine to handle results */
  1.1320 -#define SRT_Exists      10  /* Store 1 if the result is not empty */
  1.1321 -
  1.1322 -/*
  1.1323 -** An SQL parser context.  A copy of this structure is passed through
  1.1324 -** the parser and down into all the parser action routine in order to
  1.1325 -** carry around information that is global to the entire parse.
  1.1326 -**
  1.1327 -** The structure is divided into two parts.  When the parser and code
  1.1328 -** generate call themselves recursively, the first part of the structure
  1.1329 -** is constant but the second part is reset at the beginning and end of
  1.1330 -** each recursion.
  1.1331 -**
  1.1332 -** The nTableLock and aTableLock variables are only used if the shared-cache 
  1.1333 -** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
  1.1334 -** used to store the set of table-locks required by the statement being
  1.1335 -** compiled. Function sqlite3TableLock() is used to add entries to the
  1.1336 -** list.
  1.1337 -*/
  1.1338 -struct Parse {
  1.1339 -  sqlite3 *db;         /* The main database structure */
  1.1340 -  int rc;              /* Return code from execution */
  1.1341 -  char *zErrMsg;       /* An error message */
  1.1342 -  Vdbe *pVdbe;         /* An engine for executing database bytecode */
  1.1343 -  u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
  1.1344 -  u8 nameClash;        /* A permanent table name clashes with temp table name */
  1.1345 -  u8 checkSchema;      /* Causes schema cookie check after an error */
  1.1346 -  u8 nested;           /* Number of nested calls to the parser/code generator */
  1.1347 -  u8 parseError;       /* True after a parsing error.  Ticket #1794 */
  1.1348 -  int nErr;            /* Number of errors seen */
  1.1349 -  int nTab;            /* Number of previously allocated VDBE cursors */
  1.1350 -  int nMem;            /* Number of memory cells used so far */
  1.1351 -  int nSet;            /* Number of sets used so far */
  1.1352 -  int ckOffset;        /* Stack offset to data used by CHECK constraints */
  1.1353 -  u32 writeMask;       /* Start a write transaction on these databases */
  1.1354 -  u32 cookieMask;      /* Bitmask of schema verified databases */
  1.1355 -  int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
  1.1356 -  int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
  1.1357 -#ifndef SQLITE_OMIT_SHARED_CACHE
  1.1358 -  int nTableLock;        /* Number of locks in aTableLock */
  1.1359 -  TableLock *aTableLock; /* Required table locks for shared-cache mode */
  1.1360 -#endif
  1.1361 -
  1.1362 -  /* Above is constant between recursions.  Below is reset before and after
  1.1363 -  ** each recursion */
  1.1364 -
  1.1365 -  int nVar;            /* Number of '?' variables seen in the SQL so far */
  1.1366 -  int nVarExpr;        /* Number of used slots in apVarExpr[] */
  1.1367 -  int nVarExprAlloc;   /* Number of allocated slots in apVarExpr[] */
  1.1368 -  Expr **apVarExpr;    /* Pointers to :aaa and $aaaa wildcard expressions */
  1.1369 -  u8 explain;          /* True if the EXPLAIN flag is found on the query */
  1.1370 -  Token sErrToken;     /* The token at which the error occurred */
  1.1371 -  Token sNameToken;    /* Token with unqualified schema object name */
  1.1372 -  Token sLastToken;    /* The last token parsed */
  1.1373 -  const char *zSql;    /* All SQL text */
  1.1374 -  const char *zTail;   /* All SQL text past the last semicolon parsed */
  1.1375 -  Table *pNewTable;    /* A table being constructed by CREATE TABLE */
  1.1376 -  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
  1.1377 -  TriggerStack *trigStack;  /* Trigger actions being coded */
  1.1378 -  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
  1.1379 -#ifndef SQLITE_OMIT_VIRTUALTABLE
  1.1380 -  Token sArg;                /* Complete text of a module argument */
  1.1381 -  u8 declareVtab;            /* True if inside sqlite3_declare_vtab() */
  1.1382 -  Table *pVirtualLock;       /* Require virtual table lock on this table */
  1.1383 -#endif
  1.1384 -#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
  1.1385 -  int nHeight;            /* Expression tree height of current sub-select */
  1.1386 -#endif
  1.1387 -};
  1.1388 -
  1.1389 -#ifdef SQLITE_OMIT_VIRTUALTABLE
  1.1390 -  #define IN_DECLARE_VTAB 0
  1.1391 -#else
  1.1392 -  #define IN_DECLARE_VTAB (pParse->declareVtab)
  1.1393 -#endif
  1.1394 -
  1.1395 -/*
  1.1396 -** An instance of the following structure can be declared on a stack and used
  1.1397 -** to save the Parse.zAuthContext value so that it can be restored later.
  1.1398 -*/
  1.1399 -struct AuthContext {
  1.1400 -  const char *zAuthContext;   /* Put saved Parse.zAuthContext here */
  1.1401 -  Parse *pParse;              /* The Parse structure */
  1.1402 -};
  1.1403 -
  1.1404 -/*
  1.1405 -** Bitfield flags for P2 value in OP_Insert and OP_Delete
  1.1406 -*/
  1.1407 -#define OPFLAG_NCHANGE   1    /* Set to update db->nChange */
  1.1408 -#define OPFLAG_LASTROWID 2    /* Set to update db->lastRowid */
  1.1409 -#define OPFLAG_ISUPDATE  4    /* This OP_Insert is an sql UPDATE */
  1.1410 -#define OPFLAG_APPEND    8    /* This is likely to be an append */
  1.1411 -
  1.1412 -/*
  1.1413 - * Each trigger present in the database schema is stored as an instance of
  1.1414 - * struct Trigger. 
  1.1415 - *
  1.1416 - * Pointers to instances of struct Trigger are stored in two ways.
  1.1417 - * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 
  1.1418 - *    database). This allows Trigger structures to be retrieved by name.
  1.1419 - * 2. All triggers associated with a single table form a linked list, using the
  1.1420 - *    pNext member of struct Trigger. A pointer to the first element of the
  1.1421 - *    linked list is stored as the "pTrigger" member of the associated
  1.1422 - *    struct Table.
  1.1423 - *
  1.1424 - * The "step_list" member points to the first element of a linked list
  1.1425 - * containing the SQL statements specified as the trigger program.
  1.1426 - */
  1.1427 -struct Trigger {
  1.1428 -  char *name;             /* The name of the trigger                        */
  1.1429 -  char *table;            /* The table or view to which the trigger applies */
  1.1430 -  u8 op;                  /* One of TK_DELETE, TK_UPDATE, TK_INSERT         */
  1.1431 -  u8 tr_tm;               /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
  1.1432 -  Expr *pWhen;            /* The WHEN clause of the expresion (may be NULL) */
  1.1433 -  IdList *pColumns;       /* If this is an UPDATE OF <column-list> trigger,
  1.1434 -                             the <column-list> is stored here */
  1.1435 -  Token nameToken;        /* Token containing zName. Use during parsing only */
  1.1436 -  Schema *pSchema;        /* Schema containing the trigger */
  1.1437 -  Schema *pTabSchema;     /* Schema containing the table */
  1.1438 -  TriggerStep *step_list; /* Link list of trigger program steps             */
  1.1439 -  Trigger *pNext;         /* Next trigger associated with the table */
  1.1440 -};
  1.1441 -
  1.1442 -/*
  1.1443 -** A trigger is either a BEFORE or an AFTER trigger.  The following constants
  1.1444 -** determine which. 
  1.1445 -**
  1.1446 -** If there are multiple triggers, you might of some BEFORE and some AFTER.
  1.1447 -** In that cases, the constants below can be ORed together.
  1.1448 -*/
  1.1449 -#define TRIGGER_BEFORE  1
  1.1450 -#define TRIGGER_AFTER   2
  1.1451 -
  1.1452 -/*
  1.1453 - * An instance of struct TriggerStep is used to store a single SQL statement
  1.1454 - * that is a part of a trigger-program. 
  1.1455 - *
  1.1456 - * Instances of struct TriggerStep are stored in a singly linked list (linked
  1.1457 - * using the "pNext" member) referenced by the "step_list" member of the 
  1.1458 - * associated struct Trigger instance. The first element of the linked list is
  1.1459 - * the first step of the trigger-program.
  1.1460 - * 
  1.1461 - * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
  1.1462 - * "SELECT" statement. The meanings of the other members is determined by the 
  1.1463 - * value of "op" as follows:
  1.1464 - *
  1.1465 - * (op == TK_INSERT)
  1.1466 - * orconf    -> stores the ON CONFLICT algorithm
  1.1467 - * pSelect   -> If this is an INSERT INTO ... SELECT ... statement, then
  1.1468 - *              this stores a pointer to the SELECT statement. Otherwise NULL.
  1.1469 - * target    -> A token holding the name of the table to insert into.
  1.1470 - * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
  1.1471 - *              this stores values to be inserted. Otherwise NULL.
  1.1472 - * pIdList   -> If this is an INSERT INTO ... (<column-names>) VALUES ... 
  1.1473 - *              statement, then this stores the column-names to be
  1.1474 - *              inserted into.
  1.1475 - *
  1.1476 - * (op == TK_DELETE)
  1.1477 - * target    -> A token holding the name of the table to delete from.
  1.1478 - * pWhere    -> The WHERE clause of the DELETE statement if one is specified.
  1.1479 - *              Otherwise NULL.
  1.1480 - * 
  1.1481 - * (op == TK_UPDATE)
  1.1482 - * target    -> A token holding the name of the table to update rows of.
  1.1483 - * pWhere    -> The WHERE clause of the UPDATE statement if one is specified.
  1.1484 - *              Otherwise NULL.
  1.1485 - * pExprList -> A list of the columns to update and the expressions to update
  1.1486 - *              them to. See sqlite3Update() documentation of "pChanges"
  1.1487 - *              argument.
  1.1488 - * 
  1.1489 - */
  1.1490 -struct TriggerStep {
  1.1491 -  int op;              /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
  1.1492 -  int orconf;          /* OE_Rollback etc. */
  1.1493 -  Trigger *pTrig;      /* The trigger that this step is a part of */
  1.1494 -
  1.1495 -  Select *pSelect;     /* Valid for SELECT and sometimes 
  1.1496 -                          INSERT steps (when pExprList == 0) */
  1.1497 -  Token target;        /* Valid for DELETE, UPDATE, INSERT steps */
  1.1498 -  Expr *pWhere;        /* Valid for DELETE, UPDATE steps */
  1.1499 -  ExprList *pExprList; /* Valid for UPDATE statements and sometimes 
  1.1500 -                           INSERT steps (when pSelect == 0)         */
  1.1501 -  IdList *pIdList;     /* Valid for INSERT statements only */
  1.1502 -  TriggerStep *pNext;  /* Next in the link-list */
  1.1503 -  TriggerStep *pLast;  /* Last element in link-list. Valid for 1st elem only */
  1.1504 -};
  1.1505 -
  1.1506 -/*
  1.1507 - * An instance of struct TriggerStack stores information required during code
  1.1508 - * generation of a single trigger program. While the trigger program is being
  1.1509 - * coded, its associated TriggerStack instance is pointed to by the
  1.1510 - * "pTriggerStack" member of the Parse structure.
  1.1511 - *
  1.1512 - * The pTab member points to the table that triggers are being coded on. The 
  1.1513 - * newIdx member contains the index of the vdbe cursor that points at the temp
  1.1514 - * table that stores the new.* references. If new.* references are not valid
  1.1515 - * for the trigger being coded (for example an ON DELETE trigger), then newIdx
  1.1516 - * is set to -1. The oldIdx member is analogous to newIdx, for old.* references.
  1.1517 - *
  1.1518 - * The ON CONFLICT policy to be used for the trigger program steps is stored 
  1.1519 - * as the orconf member. If this is OE_Default, then the ON CONFLICT clause 
  1.1520 - * specified for individual triggers steps is used.
  1.1521 - *
  1.1522 - * struct TriggerStack has a "pNext" member, to allow linked lists to be
  1.1523 - * constructed. When coding nested triggers (triggers fired by other triggers)
  1.1524 - * each nested trigger stores its parent trigger's TriggerStack as the "pNext" 
  1.1525 - * pointer. Once the nested trigger has been coded, the pNext value is restored
  1.1526 - * to the pTriggerStack member of the Parse stucture and coding of the parent
  1.1527 - * trigger continues.
  1.1528 - *
  1.1529 - * Before a nested trigger is coded, the linked list pointed to by the 
  1.1530 - * pTriggerStack is scanned to ensure that the trigger is not about to be coded
  1.1531 - * recursively. If this condition is detected, the nested trigger is not coded.
  1.1532 - */
  1.1533 -struct TriggerStack {
  1.1534 -  Table *pTab;         /* Table that triggers are currently being coded on */
  1.1535 -  int newIdx;          /* Index of vdbe cursor to "new" temp table */
  1.1536 -  int oldIdx;          /* Index of vdbe cursor to "old" temp table */
  1.1537 -  int orconf;          /* Current orconf policy */
  1.1538 -  int ignoreJump;      /* where to jump to for a RAISE(IGNORE) */
  1.1539 -  Trigger *pTrigger;   /* The trigger currently being coded */
  1.1540 -  TriggerStack *pNext; /* Next trigger down on the trigger stack */
  1.1541 -};
  1.1542 -
  1.1543 -/*
  1.1544 -** The following structure contains information used by the sqliteFix...
  1.1545 -** routines as they walk the parse tree to make database references
  1.1546 -** explicit.  
  1.1547 -*/
  1.1548 -typedef struct DbFixer DbFixer;
  1.1549 -struct DbFixer {
  1.1550 -  Parse *pParse;      /* The parsing context.  Error messages written here */
  1.1551 -  const char *zDb;    /* Make sure all objects are contained in this database */
  1.1552 -  const char *zType;  /* Type of the container - used for error messages */
  1.1553 -  const Token *pName; /* Name of the container - used for error messages */
  1.1554 -};
  1.1555 -
  1.1556 -/*
  1.1557 -** A pointer to this structure is used to communicate information
  1.1558 -** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
  1.1559 -*/
  1.1560 -typedef struct {
  1.1561 -  sqlite3 *db;        /* The database being initialized */
  1.1562 -  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
  1.1563 -  char **pzErrMsg;    /* Error message stored here */
  1.1564 -  int rc;             /* Result code stored here */
  1.1565 -} InitData;
  1.1566 -
  1.1567 -/*
  1.1568 -** Assuming zIn points to the first byte of a UTF-8 character,
  1.1569 -** advance zIn to point to the first byte of the next UTF-8 character.
  1.1570 -*/
  1.1571 -#define SQLITE_SKIP_UTF8(zIn) {                        \
  1.1572 -  if( (*(zIn++))>=0xc0 ){                              \
  1.1573 -    while( (*zIn & 0xc0)==0x80 ){ zIn++; }             \
  1.1574 -  }                                                    \
  1.1575 -}
  1.1576 -
  1.1577 -/*
  1.1578 -** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
  1.1579 -** builds) or a function call (for debugging).  If it is a function call,
  1.1580 -** it allows the operator to set a breakpoint at the spot where database
  1.1581 -** corruption is first detected.
  1.1582 -*/
  1.1583 -#ifdef SQLITE_DEBUG
  1.1584 -  int sqlite3Corrupt(void);
  1.1585 -# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
  1.1586 -#else
  1.1587 -# define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
  1.1588 -#endif
  1.1589 -
  1.1590 -/*
  1.1591 -** Internal function prototypes
  1.1592 -*/
  1.1593 -int sqlite3StrICmp(const char *, const char *);
  1.1594 -int sqlite3StrNICmp(const char *, const char *, int);
  1.1595 -int sqlite3IsNumber(const char*, int*, u8);
  1.1596 -
  1.1597 -void *sqlite3MallocZero(unsigned);
  1.1598 -void *sqlite3DbMallocZero(sqlite3*, unsigned);
  1.1599 -void *sqlite3DbMallocRaw(sqlite3*, unsigned);
  1.1600 -char *sqlite3StrDup(const char*);
  1.1601 -char *sqlite3StrNDup(const char*, int);
  1.1602 -char *sqlite3DbStrDup(sqlite3*,const char*);
  1.1603 -char *sqlite3DbStrNDup(sqlite3*,const char*, int);
  1.1604 -void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
  1.1605 -void *sqlite3DbRealloc(sqlite3 *, void *, int);
  1.1606 -
  1.1607 -char *sqlite3MPrintf(sqlite3*,const char*, ...);
  1.1608 -char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  1.1609 -#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  1.1610 -  void sqlite3DebugPrintf(const char*, ...);
  1.1611 -  void *sqlite3TextToPtr(const char*);
  1.1612 -#endif
  1.1613 -void sqlite3SetString(char **, ...);
  1.1614 -void sqlite3ErrorMsg(Parse*, const char*, ...);
  1.1615 -void sqlite3ErrorClear(Parse*);
  1.1616 -void sqlite3Dequote(char*);
  1.1617 -void sqlite3DequoteExpr(sqlite3*, Expr*);
  1.1618 -int sqlite3KeywordCode(const unsigned char*, int);
  1.1619 -int sqlite3RunParser(Parse*, const char*, char **);
  1.1620 -void sqlite3FinishCoding(Parse*);
  1.1621 -Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*);
  1.1622 -Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  1.1623 -Expr *sqlite3RegisterExpr(Parse*,Token*);
  1.1624 -Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  1.1625 -void sqlite3ExprSpan(Expr*,Token*,Token*);
  1.1626 -Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  1.1627 -void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  1.1628 -void sqlite3ExprDelete(Expr*);
  1.1629 -ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
  1.1630 -void sqlite3ExprListDelete(ExprList*);
  1.1631 -int sqlite3Init(sqlite3*, char**);
  1.1632 -int sqlite3InitCallback(void*, int, char**, char**);
  1.1633 -void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  1.1634 -void sqlite3ResetInternalSchema(sqlite3*, int);
  1.1635 -void sqlite3BeginParse(Parse*,int);
  1.1636 -void sqlite3CommitInternalChanges(sqlite3*);
  1.1637 -Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
  1.1638 -void sqlite3OpenMasterTable(Parse *, int);
  1.1639 -void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  1.1640 -void sqlite3AddColumn(Parse*,Token*);
  1.1641 -void sqlite3AddNotNull(Parse*, int);
  1.1642 -void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  1.1643 -void sqlite3AddCheckConstraint(Parse*, Expr*);
  1.1644 -void sqlite3AddColumnType(Parse*,Token*);
  1.1645 -void sqlite3AddDefaultValue(Parse*,Expr*);
  1.1646 -void sqlite3AddCollateType(Parse*, const char*, int);
  1.1647 -void sqlite3EndTable(Parse*,Token*,Token*,Select*);
  1.1648 -
  1.1649 -void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  1.1650 -
  1.1651 -#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  1.1652 -  int sqlite3ViewGetColumnNames(Parse*,Table*);
  1.1653 -#else
  1.1654 -# define sqlite3ViewGetColumnNames(A,B) 0
  1.1655 -#endif
  1.1656 -
  1.1657 -void sqlite3DropTable(Parse*, SrcList*, int, int);
  1.1658 -void sqlite3DeleteTable(Table*);
  1.1659 -void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  1.1660 -void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
  1.1661 -IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
  1.1662 -int sqlite3IdListIndex(IdList*,const char*);
  1.1663 -SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
  1.1664 -SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*,
  1.1665 -                                      Select*, Expr*, IdList*);
  1.1666 -void sqlite3SrcListShiftJoinType(SrcList*);
  1.1667 -void sqlite3SrcListAssignCursors(Parse*, SrcList*);
  1.1668 -void sqlite3IdListDelete(IdList*);
  1.1669 -void sqlite3SrcListDelete(SrcList*);
  1.1670 -void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  1.1671 -                        Token*, int, int);
  1.1672 -void sqlite3DropIndex(Parse*, SrcList*, int);
  1.1673 -int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
  1.1674 -Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  1.1675 -                         Expr*,ExprList*,int,Expr*,Expr*);
  1.1676 -void sqlite3SelectDelete(Select*);
  1.1677 -Table *sqlite3SrcListLookup(Parse*, SrcList*);
  1.1678 -int sqlite3IsReadOnly(Parse*, Table*, int);
  1.1679 -void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  1.1680 -void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
  1.1681 -void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  1.1682 -WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
  1.1683 -void sqlite3WhereEnd(WhereInfo*);
  1.1684 -void sqlite3ExprCodeGetColumn(Vdbe*, Table*, int, int);
  1.1685 -void sqlite3ExprCode(Parse*, Expr*);
  1.1686 -void sqlite3ExprCodeAndCache(Parse*, Expr*);
  1.1687 -int sqlite3ExprCodeExprList(Parse*, ExprList*);
  1.1688 -void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  1.1689 -void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  1.1690 -Table *sqlite3FindTable(sqlite3*,const char*, const char*);
  1.1691 -Table *sqlite3LocateTable(Parse*,const char*, const char*);
  1.1692 -Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
  1.1693 -void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
  1.1694 -void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
  1.1695 -void sqlite3Vacuum(Parse*);
  1.1696 -int sqlite3RunVacuum(char**, sqlite3*);
  1.1697 -char *sqlite3NameFromToken(sqlite3*, Token*);
  1.1698 -int sqlite3ExprCompare(Expr*, Expr*);
  1.1699 -int sqlite3ExprResolveNames(NameContext *, Expr *);
  1.1700 -int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  1.1701 -int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  1.1702 -Vdbe *sqlite3GetVdbe(Parse*);
  1.1703 -Expr *sqlite3CreateIdExpr(Parse *, const char*);
  1.1704 -void sqlite3Randomness(int, void*);
  1.1705 -void sqlite3RollbackAll(sqlite3*);
  1.1706 -void sqlite3CodeVerifySchema(Parse*, int);
  1.1707 -void sqlite3BeginTransaction(Parse*, int);
  1.1708 -void sqlite3CommitTransaction(Parse*);
  1.1709 -void sqlite3RollbackTransaction(Parse*);
  1.1710 -int sqlite3ExprIsConstant(Expr*);
  1.1711 -int sqlite3ExprIsConstantNotJoin(Expr*);
  1.1712 -int sqlite3ExprIsConstantOrFunction(Expr*);
  1.1713 -int sqlite3ExprIsInteger(Expr*, int*);
  1.1714 -int sqlite3IsRowid(const char*);
  1.1715 -void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
  1.1716 -void sqlite3GenerateRowIndexDelete(Vdbe*, Table*, int, char*);
  1.1717 -void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
  1.1718 -void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
  1.1719 -void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int, int);
  1.1720 -void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
  1.1721 -void sqlite3BeginWriteOperation(Parse*, int, int);
  1.1722 -Expr *sqlite3ExprDup(sqlite3*,Expr*);
  1.1723 -void sqlite3TokenCopy(sqlite3*,Token*, Token*);
  1.1724 -ExprList *sqlite3ExprListDup(sqlite3*,ExprList*);
  1.1725 -SrcList *sqlite3SrcListDup(sqlite3*,SrcList*);
  1.1726 -IdList *sqlite3IdListDup(sqlite3*,IdList*);
  1.1727 -Select *sqlite3SelectDup(sqlite3*,Select*);
  1.1728 -FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
  1.1729 -void sqlite3RegisterBuiltinFunctions(sqlite3*);
  1.1730 -void sqlite3RegisterDateTimeFunctions(sqlite3*);
  1.1731 -int sqlite3SafetyOn(sqlite3*);
  1.1732 -int sqlite3SafetyOff(sqlite3*);
  1.1733 -int sqlite3SafetyCheck(sqlite3*);
  1.1734 -void sqlite3ChangeCookie(sqlite3*, Vdbe*, int);
  1.1735 -
  1.1736 -#ifndef SQLITE_OMIT_TRIGGER
  1.1737 -  void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
  1.1738 -                           Expr*,int, int);
  1.1739 -  void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
  1.1740 -  void sqlite3DropTrigger(Parse*, SrcList*, int);
  1.1741 -  void sqlite3DropTriggerPtr(Parse*, Trigger*);
  1.1742 -  int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
  1.1743 -  int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, 
  1.1744 -                           int, int);
  1.1745 -  void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
  1.1746 -  void sqlite3DeleteTriggerStep(TriggerStep*);
  1.1747 -  TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
  1.1748 -  TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
  1.1749 -                                        ExprList*,Select*,int);
  1.1750 -  TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int);
  1.1751 -  TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
  1.1752 -  void sqlite3DeleteTrigger(Trigger*);
  1.1753 -  void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
  1.1754 -#else
  1.1755 -# define sqlite3TriggersExist(A,B,C,D,E,F) 0
  1.1756 -# define sqlite3DeleteTrigger(A)
  1.1757 -# define sqlite3DropTriggerPtr(A,B)
  1.1758 -# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
  1.1759 -# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 0
  1.1760 -#endif
  1.1761 -
  1.1762 -int sqlite3JoinType(Parse*, Token*, Token*, Token*);
  1.1763 -void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
  1.1764 -void sqlite3DeferForeignKey(Parse*, int);
  1.1765 -#ifndef SQLITE_OMIT_AUTHORIZATION
  1.1766 -  void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*);
  1.1767 -  int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
  1.1768 -  void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
  1.1769 -  void sqlite3AuthContextPop(AuthContext*);
  1.1770 -#else
  1.1771 -# define sqlite3AuthRead(a,b,c)
  1.1772 -# define sqlite3AuthCheck(a,b,c,d,e)    SQLITE_OK
  1.1773 -# define sqlite3AuthContextPush(a,b,c)
  1.1774 -# define sqlite3AuthContextPop(a)  ((void)(a))
  1.1775 -#endif
  1.1776 -void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
  1.1777 -void sqlite3Detach(Parse*, Expr*);
  1.1778 -int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
  1.1779 -                       int omitJournal, int nCache, int flags, Btree **ppBtree);
  1.1780 -int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
  1.1781 -int sqlite3FixSrcList(DbFixer*, SrcList*);
  1.1782 -int sqlite3FixSelect(DbFixer*, Select*);
  1.1783 -int sqlite3FixExpr(DbFixer*, Expr*);
  1.1784 -int sqlite3FixExprList(DbFixer*, ExprList*);
  1.1785 -int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  1.1786 -int sqlite3AtoF(const char *z, double*);
  1.1787 -char *sqlite3_snprintf(int,char*,const char*,...);
  1.1788 -int sqlite3GetInt32(const char *, int*);
  1.1789 -int sqlite3FitsIn64Bits(const char *);
  1.1790 -int sqlite3Utf16ByteLen(const void *pData, int nChar);
  1.1791 -int sqlite3Utf8CharLen(const char *pData, int nByte);
  1.1792 -int sqlite3Utf8Read(const u8*, const u8*, const u8**);
  1.1793 -int sqlite3PutVarint(unsigned char *, u64);
  1.1794 -int sqlite3GetVarint(const unsigned char *, u64 *);
  1.1795 -int sqlite3GetVarint32(const unsigned char *, u32 *);
  1.1796 -int sqlite3VarintLen(u64 v);
  1.1797 -void sqlite3IndexAffinityStr(Vdbe *, Index *);
  1.1798 -void sqlite3TableAffinityStr(Vdbe *, Table *);
  1.1799 -char sqlite3CompareAffinity(Expr *pExpr, char aff2);
  1.1800 -int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  1.1801 -char sqlite3ExprAffinity(Expr *pExpr);
  1.1802 -int sqlite3Atoi64(const char*, i64*);
  1.1803 -void sqlite3Error(sqlite3*, int, const char*,...);
  1.1804 -void *sqlite3HexToBlob(sqlite3*, const char *z);
  1.1805 -int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
  1.1806 -const char *sqlite3ErrStr(int);
  1.1807 -int sqlite3ReadSchema(Parse *pParse);
  1.1808 -CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
  1.1809 -CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
  1.1810 -CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  1.1811 -Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
  1.1812 -int sqlite3CheckCollSeq(Parse *, CollSeq *);
  1.1813 -int sqlite3CheckObjectName(Parse *, const char *);
  1.1814 -void sqlite3VdbeSetChanges(sqlite3 *, int);
  1.1815 -
  1.1816 -const void *sqlite3ValueText(sqlite3_value*, u8);
  1.1817 -int sqlite3ValueBytes(sqlite3_value*, u8);
  1.1818 -void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 
  1.1819 -                        void(*)(void*));
  1.1820 -void sqlite3ValueFree(sqlite3_value*);
  1.1821 -sqlite3_value *sqlite3ValueNew(sqlite3 *);
  1.1822 -char *sqlite3Utf16to8(sqlite3 *, const void*, int);
  1.1823 -int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
  1.1824 -void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  1.1825 -#ifndef SQLITE_AMALGAMATION
  1.1826 -extern const unsigned char sqlite3UpperToLower[];
  1.1827 -#endif
  1.1828 -void sqlite3RootPageMoved(Db*, int, int);
  1.1829 -void sqlite3Reindex(Parse*, Token*, Token*);
  1.1830 -void sqlite3AlterFunctions(sqlite3*);
  1.1831 -void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  1.1832 -int sqlite3GetToken(const unsigned char *, int *);
  1.1833 -void sqlite3NestedParse(Parse*, const char*, ...);
  1.1834 -void sqlite3ExpirePreparedStatements(sqlite3*);
  1.1835 -void sqlite3CodeSubselect(Parse *, Expr *);
  1.1836 -int sqlite3SelectResolve(Parse *, Select *, NameContext *);
  1.1837 -void sqlite3ColumnDefault(Vdbe *, Table *, int);
  1.1838 -void sqlite3AlterFinishAddColumn(Parse *, Token *);
  1.1839 -void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  1.1840 -CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
  1.1841 -char sqlite3AffinityType(const Token*);
  1.1842 -void sqlite3Analyze(Parse*, Token*, Token*);
  1.1843 -int sqlite3InvokeBusyHandler(BusyHandler*);
  1.1844 -int sqlite3FindDb(sqlite3*, Token*);
  1.1845 -int sqlite3AnalysisLoad(sqlite3*,int iDB);
  1.1846 -void sqlite3DefaultRowEst(Index*);
  1.1847 -void sqlite3RegisterLikeFunctions(sqlite3*, int);
  1.1848 -int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
  1.1849 -void sqlite3AttachFunctions(sqlite3 *);
  1.1850 -void sqlite3MinimumFileFormat(Parse*, int, int);
  1.1851 -void sqlite3SchemaFree(void *);
  1.1852 -Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
  1.1853 -int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
  1.1854 -KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
  1.1855 -int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 
  1.1856 -  void (*)(sqlite3_context*,int,sqlite3_value **),
  1.1857 -  void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
  1.1858 -int sqlite3ApiExit(sqlite3 *db, int);
  1.1859 -void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
  1.1860 -int sqlite3OpenTempDatabase(Parse *);
  1.1861 -
  1.1862 -
  1.1863 -/*
  1.1864 -** The interface to the LEMON-generated parser
  1.1865 -*/
  1.1866 -void *sqlite3ParserAlloc(void*(*)(size_t));
  1.1867 -void sqlite3ParserFree(void*, void(*)(void*));
  1.1868 -void sqlite3Parser(void*, int, Token, Parse*);
  1.1869 -
  1.1870 -#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1.1871 -  void sqlite3CloseExtensions(sqlite3*);
  1.1872 -  int sqlite3AutoLoadExtensions(sqlite3*);
  1.1873 -#else
  1.1874 -# define sqlite3CloseExtensions(X)
  1.1875 -# define sqlite3AutoLoadExtensions(X)  SQLITE_OK
  1.1876 -#endif
  1.1877 -
  1.1878 -#ifndef SQLITE_OMIT_SHARED_CACHE
  1.1879 -  void sqlite3TableLock(Parse *, int, int, u8, const char *);
  1.1880 -#else
  1.1881 -  #define sqlite3TableLock(v,w,x,y,z)
  1.1882 -#endif
  1.1883 -
  1.1884 -#ifdef SQLITE_TEST
  1.1885 -  int sqlite3Utf8To8(unsigned char*);
  1.1886 -#endif
  1.1887 -
  1.1888 -/*
  1.1889 -** The MallocDisallow() and MallocAllow() routines are like asserts.
  1.1890 -** Call them around a section of code that you do not expect to do
  1.1891 -** any memory allocation.
  1.1892 -*/
  1.1893 -#ifdef SQLITE_MEMDEBUG
  1.1894 -  void sqlite3MallocDisallow(void);
  1.1895 -  void sqlite3MallocAllow(void);
  1.1896 -  void sqlite3MallocBenignFailure(int);
  1.1897 -  void sqlite3MallocEnterBenignBlock(int isBenign);
  1.1898 -  void sqlite3MallocLeaveBenignBlock();
  1.1899 -#else
  1.1900 -# define sqlite3MallocDisallow()
  1.1901 -# define sqlite3MallocAllow()
  1.1902 -# define sqlite3MallocBenignFailure(x)
  1.1903 -# define sqlite3MallocEnterBenignBlock(x);
  1.1904 -# define sqlite3MallocLeaveBenignBlock();
  1.1905 -#endif
  1.1906 -
  1.1907 -
  1.1908 -#ifdef SQLITE_OMIT_VIRTUALTABLE
  1.1909 -#  define sqlite3VtabClear(X)
  1.1910 -#  define sqlite3VtabSync(X,Y) (Y)
  1.1911 -#  define sqlite3VtabRollback(X)
  1.1912 -#  define sqlite3VtabCommit(X)
  1.1913 -#else
  1.1914 -   void sqlite3VtabClear(Table*);
  1.1915 -   int sqlite3VtabSync(sqlite3 *db, int rc);
  1.1916 -   int sqlite3VtabRollback(sqlite3 *db);
  1.1917 -   int sqlite3VtabCommit(sqlite3 *db);
  1.1918 -#endif
  1.1919 -void sqlite3VtabLock(sqlite3_vtab*);
  1.1920 -void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*);
  1.1921 -void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
  1.1922 -void sqlite3VtabFinishParse(Parse*, Token*);
  1.1923 -void sqlite3VtabArgInit(Parse*);
  1.1924 -void sqlite3VtabArgExtend(Parse*, Token*);
  1.1925 -int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
  1.1926 -int sqlite3VtabCallConnect(Parse*, Table*);
  1.1927 -int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  1.1928 -int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
  1.1929 -FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
  1.1930 -void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
  1.1931 -int sqlite3Reprepare(Vdbe*);
  1.1932 -void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
  1.1933 -CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
  1.1934 -
  1.1935 -#ifdef SQLITE_ENABLE_ATOMIC_WRITE
  1.1936 -  int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  1.1937 -  int sqlite3JournalSize(sqlite3_vfs *);
  1.1938 -  int sqlite3JournalCreate(sqlite3_file *);
  1.1939 -#else
  1.1940 -  #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
  1.1941 -#endif
  1.1942 -
  1.1943 -#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
  1.1944 -  void sqlite3ExprSetHeight(Expr *);
  1.1945 -  int sqlite3SelectExprHeight(Select *);
  1.1946 -#else
  1.1947 -  #define sqlite3ExprSetHeight(x)
  1.1948 -#endif
  1.1949 -
  1.1950 -u32 sqlite3Get4byte(const u8*);
  1.1951 -void sqlite3Put4byte(u8*, u32);
  1.1952 -
  1.1953 -#ifdef SQLITE_SSE
  1.1954 -#include "sseInt.h"
  1.1955 -#endif
  1.1956 -
  1.1957 -#ifdef SQLITE_DEBUG
  1.1958 -  void sqlite3ParserTrace(FILE*, char *);
  1.1959 -#endif
  1.1960 -
  1.1961 -/*
  1.1962 -** If the SQLITE_ENABLE IOTRACE exists then the global variable
  1.1963 -** sqlite3_io_trace is a pointer to a printf-like routine used to
  1.1964 -** print I/O tracing messages. 
  1.1965 -*/
  1.1966 -#ifdef SQLITE_ENABLE_IOTRACE
  1.1967 -# define IOTRACE(A)  if( sqlite3_io_trace ){ sqlite3_io_trace A; }
  1.1968 -  void sqlite3VdbeIOTraceSql(Vdbe*);
  1.1969 -#else
  1.1970 -# define IOTRACE(A)
  1.1971 -# define sqlite3VdbeIOTraceSql(X)
  1.1972 -#endif
  1.1973 -SQLITE_EXTERN void (*sqlite3_io_trace)(const char*,...);
  1.1974 -
  1.1975 -#endif