extensions/sqlite/sqlite-source/sqliteInt.h
author Asher Baker <asherkin@gmail.com>
Thu Apr 26 16:58:18 2012 +0100 (2012-04-26)
changeset 3488 bee90c8ef6c3
parent 1952 b7aa2b626807
permissions -rw-r--r--
Fixed client serials not being unique on Windows (bug 5285, r=psychonic).
ds@1952
     1
/*
ds@1952
     2
** 2001 September 15
ds@1952
     3
**
ds@1952
     4
** The author disclaims copyright to this source code.  In place of
ds@1952
     5
** a legal notice, here is a blessing:
ds@1952
     6
**
ds@1952
     7
**    May you do good and not evil.
ds@1952
     8
**    May you find forgiveness for yourself and forgive others.
ds@1952
     9
**    May you share freely, never taking more than you give.
ds@1952
    10
**
ds@1952
    11
*************************************************************************
ds@1952
    12
** Internal interface definitions for SQLite.
ds@1952
    13
**
ds@1952
    14
** @(#) $Id$
ds@1952
    15
*/
ds@1952
    16
#ifndef _SQLITEINT_H_
ds@1952
    17
#define _SQLITEINT_H_
ds@1952
    18
#include "sqliteLimit.h"
ds@1952
    19
ds@1952
    20
/*
ds@1952
    21
** For testing purposes, the various size limit constants are really
ds@1952
    22
** variables that we can modify in the testfixture.
ds@1952
    23
*/
ds@1952
    24
#ifdef SQLITE_TEST
ds@1952
    25
  #undef SQLITE_MAX_LENGTH
ds@1952
    26
  #undef SQLITE_MAX_COLUMN
ds@1952
    27
  #undef SQLITE_MAX_SQL_LENGTH
ds@1952
    28
  #undef SQLITE_MAX_EXPR_DEPTH
ds@1952
    29
  #undef SQLITE_MAX_COMPOUND_SELECT
ds@1952
    30
  #undef SQLITE_MAX_VDBE_OP
ds@1952
    31
  #undef SQLITE_MAX_FUNCTION_ARG
ds@1952
    32
  #undef SQLITE_MAX_VARIABLE_NUMBER
ds@1952
    33
  #undef SQLITE_MAX_PAGE_SIZE
ds@1952
    34
  #undef SQLITE_MAX_PAGE_COUNT
ds@1952
    35
  #undef SQLITE_MAX_LIKE_PATTERN_LENGTH
ds@1952
    36
ds@1952
    37
  #define SQLITE_MAX_LENGTH              sqlite3MAX_LENGTH
ds@1952
    38
  #define SQLITE_MAX_COLUMN              sqlite3MAX_COLUMN
ds@1952
    39
  #define SQLITE_MAX_SQL_LENGTH          sqlite3MAX_SQL_LENGTH
ds@1952
    40
  #define SQLITE_MAX_EXPR_DEPTH          sqlite3MAX_EXPR_DEPTH
ds@1952
    41
  #define SQLITE_MAX_COMPOUND_SELECT     sqlite3MAX_COMPOUND_SELECT
ds@1952
    42
  #define SQLITE_MAX_VDBE_OP             sqlite3MAX_VDBE_OP
ds@1952
    43
  #define SQLITE_MAX_FUNCTION_ARG        sqlite3MAX_FUNCTION_ARG
ds@1952
    44
  #define SQLITE_MAX_VARIABLE_NUMBER     sqlite3MAX_VARIABLE_NUMBER
ds@1952
    45
  #define SQLITE_MAX_PAGE_SIZE           sqlite3MAX_PAGE_SIZE
ds@1952
    46
  #define SQLITE_MAX_PAGE_COUNT          sqlite3MAX_PAGE_COUNT
ds@1952
    47
  #define SQLITE_MAX_LIKE_PATTERN_LENGTH sqlite3MAX_LIKE_PATTERN_LENGTH
ds@1952
    48
ds@1952
    49
  extern int sqlite3MAX_LENGTH;
ds@1952
    50
  extern int sqlite3MAX_COLUMN;
ds@1952
    51
  extern int sqlite3MAX_SQL_LENGTH;
ds@1952
    52
  extern int sqlite3MAX_EXPR_DEPTH;
ds@1952
    53
  extern int sqlite3MAX_COMPOUND_SELECT;
ds@1952
    54
  extern int sqlite3MAX_VDBE_OP;
ds@1952
    55
  extern int sqlite3MAX_FUNCTION_ARG;
ds@1952
    56
  extern int sqlite3MAX_VARIABLE_NUMBER;
ds@1952
    57
  extern int sqlite3MAX_PAGE_SIZE;
ds@1952
    58
  extern int sqlite3MAX_PAGE_COUNT;
ds@1952
    59
  extern int sqlite3MAX_LIKE_PATTERN_LENGTH;
ds@1952
    60
#endif
ds@1952
    61
ds@1952
    62
ds@1952
    63
/*
ds@1952
    64
** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
ds@1952
    65
** Older versions of SQLite used an optional THREADSAFE macro.
ds@1952
    66
** We support that for legacy
ds@1952
    67
*/
ds@1952
    68
#if !defined(SQLITE_THREADSAFE)
ds@1952
    69
#if defined(THREADSAFE)
ds@1952
    70
# define SQLITE_THREADSAFE THREADSAFE
ds@1952
    71
#else
ds@1952
    72
# define SQLITE_THREADSAFE 1
ds@1952
    73
#endif
ds@1952
    74
#endif
ds@1952
    75
ds@1952
    76
/*
ds@1952
    77
** We need to define _XOPEN_SOURCE as follows in order to enable
ds@1952
    78
** recursive mutexes on most unix systems.  But Mac OS X is different.
ds@1952
    79
** The _XOPEN_SOURCE define causes problems for Mac OS X we are told,
ds@1952
    80
** so it is omitted there.  See ticket #2673.
ds@1952
    81
**
ds@1952
    82
** Later we learn that _XOPEN_SOURCE is poorly or incorrectly
ds@1952
    83
** implemented on some systems.  So we avoid defining it at all
ds@1952
    84
** if it is already defined or if it is unneeded because we are
ds@1952
    85
** not doing a threadsafe build.  Ticket #2681.
ds@1952
    86
*/
ds@1952
    87
#if !defined(_XOPEN_SOURCE) && !defined(__MACOS__) && SQLITE_THREADSAFE
ds@1952
    88
#  define _XOPEN_SOURCE 500  /* Needed to enable pthread recursive mutexes */
ds@1952
    89
#endif
ds@1952
    90
ds@1952
    91
#if defined(SQLITE_TCL) || defined(TCLSH)
ds@1952
    92
# include <tcl.h>
ds@1952
    93
#endif
ds@1952
    94
ds@1952
    95
/*
ds@1952
    96
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
ds@1952
    97
** Setting NDEBUG makes the code smaller and run faster.  So the following
ds@1952
    98
** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1
ds@1952
    99
** option is set.  Thus NDEBUG becomes an opt-in rather than an opt-out
ds@1952
   100
** feature.
ds@1952
   101
*/
ds@1952
   102
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 
ds@1952
   103
# define NDEBUG 1
ds@1952
   104
#endif
ds@1952
   105
ds@1952
   106
/*
ds@1952
   107
** These #defines should enable >2GB file support on Posix if the
ds@1952
   108
** underlying operating system supports it.  If the OS lacks
ds@1952
   109
** large file support, or if the OS is windows, these should be no-ops.
ds@1952
   110
**
ds@1952
   111
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
ds@1952
   112
** on the compiler command line.  This is necessary if you are compiling
ds@1952
   113
** on a recent machine (ex: RedHat 7.2) but you want your code to work
ds@1952
   114
** on an older machine (ex: RedHat 6.0).  If you compile on RedHat 7.2
ds@1952
   115
** without this option, LFS is enable.  But LFS does not exist in the kernel
ds@1952
   116
** in RedHat 6.0, so the code won't work.  Hence, for maximum binary
ds@1952
   117
** portability you should omit LFS.
ds@1952
   118
**
ds@1952
   119
** Similar is true for MacOS.  LFS is only supported on MacOS 9 and later.
ds@1952
   120
*/
ds@1952
   121
#ifndef SQLITE_DISABLE_LFS
ds@1952
   122
# define _LARGE_FILE       1
ds@1952
   123
# ifndef _FILE_OFFSET_BITS
ds@1952
   124
#   define _FILE_OFFSET_BITS 64
ds@1952
   125
# endif
ds@1952
   126
# define _LARGEFILE_SOURCE 1
ds@1952
   127
#endif
ds@1952
   128
ds@1952
   129
#include "sqlite3.h"
ds@1952
   130
#include "hash.h"
ds@1952
   131
#include "parse.h"
ds@1952
   132
#include <stdio.h>
ds@1952
   133
#include <stdlib.h>
ds@1952
   134
#include <string.h>
ds@1952
   135
#include <assert.h>
ds@1952
   136
#include <stddef.h>
ds@1952
   137
ds@1952
   138
#define sqlite3_isnan(X)  ((X)!=(X))
ds@1952
   139
ds@1952
   140
/*
ds@1952
   141
** If compiling for a processor that lacks floating point support,
ds@1952
   142
** substitute integer for floating-point
ds@1952
   143
*/
ds@1952
   144
#ifdef SQLITE_OMIT_FLOATING_POINT
ds@1952
   145
# define double sqlite_int64
ds@1952
   146
# define LONGDOUBLE_TYPE sqlite_int64
ds@1952
   147
# ifndef SQLITE_BIG_DBL
ds@1952
   148
#   define SQLITE_BIG_DBL (0x7fffffffffffffff)
ds@1952
   149
# endif
ds@1952
   150
# define SQLITE_OMIT_DATETIME_FUNCS 1
ds@1952
   151
# define SQLITE_OMIT_TRACE 1
ds@1952
   152
# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
ds@1952
   153
#endif
ds@1952
   154
#ifndef SQLITE_BIG_DBL
ds@1952
   155
# define SQLITE_BIG_DBL (1e99)
ds@1952
   156
#endif
ds@1952
   157
ds@1952
   158
/*
ds@1952
   159
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
ds@1952
   160
** afterward. Having this macro allows us to cause the C compiler 
ds@1952
   161
** to omit code used by TEMP tables without messy #ifndef statements.
ds@1952
   162
*/
ds@1952
   163
#ifdef SQLITE_OMIT_TEMPDB
ds@1952
   164
#define OMIT_TEMPDB 1
ds@1952
   165
#else
ds@1952
   166
#define OMIT_TEMPDB 0
ds@1952
   167
#endif
ds@1952
   168
ds@1952
   169
/*
ds@1952
   170
** If the following macro is set to 1, then NULL values are considered
ds@1952
   171
** distinct when determining whether or not two entries are the same
ds@1952
   172
** in a UNIQUE index.  This is the way PostgreSQL, Oracle, DB2, MySQL,
ds@1952
   173
** OCELOT, and Firebird all work.  The SQL92 spec explicitly says this
ds@1952
   174
** is the way things are suppose to work.
ds@1952
   175
**
ds@1952
   176
** If the following macro is set to 0, the NULLs are indistinct for
ds@1952
   177
** a UNIQUE index.  In this mode, you can only have a single NULL entry
ds@1952
   178
** for a column declared UNIQUE.  This is the way Informix and SQL Server
ds@1952
   179
** work.
ds@1952
   180
*/
ds@1952
   181
#define NULL_DISTINCT_FOR_UNIQUE 1
ds@1952
   182
ds@1952
   183
/*
ds@1952
   184
** The "file format" number is an integer that is incremented whenever
ds@1952
   185
** the VDBE-level file format changes.  The following macros define the
ds@1952
   186
** the default file format for new databases and the maximum file format
ds@1952
   187
** that the library can read.
ds@1952
   188
*/
ds@1952
   189
#define SQLITE_MAX_FILE_FORMAT 4
ds@1952
   190
#ifndef SQLITE_DEFAULT_FILE_FORMAT
ds@1952
   191
# define SQLITE_DEFAULT_FILE_FORMAT 1
ds@1952
   192
#endif
ds@1952
   193
ds@1952
   194
/*
ds@1952
   195
** Provide a default value for TEMP_STORE in case it is not specified
ds@1952
   196
** on the command-line
ds@1952
   197
*/
ds@1952
   198
#ifndef TEMP_STORE
ds@1952
   199
# define TEMP_STORE 1
ds@1952
   200
#endif
ds@1952
   201
ds@1952
   202
/*
ds@1952
   203
** GCC does not define the offsetof() macro so we'll have to do it
ds@1952
   204
** ourselves.
ds@1952
   205
*/
ds@1952
   206
#ifndef offsetof
ds@1952
   207
#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
ds@1952
   208
#endif
ds@1952
   209
ds@1952
   210
/*
ds@1952
   211
** Check to see if this machine uses EBCDIC.  (Yes, believe it or
ds@1952
   212
** not, there are still machines out there that use EBCDIC.)
ds@1952
   213
*/
ds@1952
   214
#if 'A' == '\301'
ds@1952
   215
# define SQLITE_EBCDIC 1
ds@1952
   216
#else
ds@1952
   217
# define SQLITE_ASCII 1
ds@1952
   218
#endif
ds@1952
   219
ds@1952
   220
/*
ds@1952
   221
** Integers of known sizes.  These typedefs might change for architectures
ds@1952
   222
** where the sizes very.  Preprocessor macros are available so that the
ds@1952
   223
** types can be conveniently redefined at compile-type.  Like this:
ds@1952
   224
**
ds@1952
   225
**         cc '-DUINTPTR_TYPE=long long int' ...
ds@1952
   226
*/
ds@1952
   227
#ifndef UINT32_TYPE
ds@1952
   228
# define UINT32_TYPE unsigned int
ds@1952
   229
#endif
ds@1952
   230
#ifndef UINT16_TYPE
ds@1952
   231
# define UINT16_TYPE unsigned short int
ds@1952
   232
#endif
ds@1952
   233
#ifndef INT16_TYPE
ds@1952
   234
# define INT16_TYPE short int
ds@1952
   235
#endif
ds@1952
   236
#ifndef UINT8_TYPE
ds@1952
   237
# define UINT8_TYPE unsigned char
ds@1952
   238
#endif
ds@1952
   239
#ifndef INT8_TYPE
ds@1952
   240
# define INT8_TYPE signed char
ds@1952
   241
#endif
ds@1952
   242
#ifndef LONGDOUBLE_TYPE
ds@1952
   243
# define LONGDOUBLE_TYPE long double
ds@1952
   244
#endif
ds@1952
   245
typedef sqlite_int64 i64;          /* 8-byte signed integer */
ds@1952
   246
typedef sqlite_uint64 u64;         /* 8-byte unsigned integer */
ds@1952
   247
typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
ds@1952
   248
typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
ds@1952
   249
typedef INT16_TYPE i16;            /* 2-byte signed integer */
ds@1952
   250
typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
ds@1952
   251
typedef UINT8_TYPE i8;             /* 1-byte signed integer */
ds@1952
   252
ds@1952
   253
/*
ds@1952
   254
** Macros to determine whether the machine is big or little endian,
ds@1952
   255
** evaluated at runtime.
ds@1952
   256
*/
ds@1952
   257
#ifdef SQLITE_AMALGAMATION
ds@1952
   258
const int sqlite3One;
ds@1952
   259
#else
ds@1952
   260
extern const int sqlite3one;
ds@1952
   261
#endif
ds@1952
   262
#if defined(i386) || defined(__i386__) || defined(_M_IX86)
ds@1952
   263
# define SQLITE_BIGENDIAN    0
ds@1952
   264
# define SQLITE_LITTLEENDIAN 1
ds@1952
   265
# define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
ds@1952
   266
#else
ds@1952
   267
# define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
ds@1952
   268
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
ds@1952
   269
# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
ds@1952
   270
#endif
ds@1952
   271
ds@1952
   272
/*
ds@1952
   273
** An instance of the following structure is used to store the busy-handler
ds@1952
   274
** callback for a given sqlite handle. 
ds@1952
   275
**
ds@1952
   276
** The sqlite.busyHandler member of the sqlite struct contains the busy
ds@1952
   277
** callback for the database handle. Each pager opened via the sqlite
ds@1952
   278
** handle is passed a pointer to sqlite.busyHandler. The busy-handler
ds@1952
   279
** callback is currently invoked only from within pager.c.
ds@1952
   280
*/
ds@1952
   281
typedef struct BusyHandler BusyHandler;
ds@1952
   282
struct BusyHandler {
ds@1952
   283
  int (*xFunc)(void *,int);  /* The busy callback */
ds@1952
   284
  void *pArg;                /* First arg to busy callback */
ds@1952
   285
  int nBusy;                 /* Incremented with each busy call */
ds@1952
   286
};
ds@1952
   287
ds@1952
   288
/*
ds@1952
   289
** Defer sourcing vdbe.h and btree.h until after the "u8" and 
ds@1952
   290
** "BusyHandler typedefs.
ds@1952
   291
*/
ds@1952
   292
#include "btree.h"
ds@1952
   293
#include "vdbe.h"
ds@1952
   294
#include "pager.h"
ds@1952
   295
ds@1952
   296
ds@1952
   297
/*
ds@1952
   298
** Name of the master database table.  The master database table
ds@1952
   299
** is a special table that holds the names and attributes of all
ds@1952
   300
** user tables and indices.
ds@1952
   301
*/
ds@1952
   302
#define MASTER_NAME       "sqlite_master"
ds@1952
   303
#define TEMP_MASTER_NAME  "sqlite_temp_master"
ds@1952
   304
ds@1952
   305
/*
ds@1952
   306
** The root-page of the master database table.
ds@1952
   307
*/
ds@1952
   308
#define MASTER_ROOT       1
ds@1952
   309
ds@1952
   310
/*
ds@1952
   311
** The name of the schema table.
ds@1952
   312
*/
ds@1952
   313
#define SCHEMA_TABLE(x)  ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
ds@1952
   314
ds@1952
   315
/*
ds@1952
   316
** A convenience macro that returns the number of elements in
ds@1952
   317
** an array.
ds@1952
   318
*/
ds@1952
   319
#define ArraySize(X)    (sizeof(X)/sizeof(X[0]))
ds@1952
   320
ds@1952
   321
/*
ds@1952
   322
** Forward references to structures
ds@1952
   323
*/
ds@1952
   324
typedef struct AggInfo AggInfo;
ds@1952
   325
typedef struct AuthContext AuthContext;
ds@1952
   326
typedef struct CollSeq CollSeq;
ds@1952
   327
typedef struct Column Column;
ds@1952
   328
typedef struct Db Db;
ds@1952
   329
typedef struct Schema Schema;
ds@1952
   330
typedef struct Expr Expr;
ds@1952
   331
typedef struct ExprList ExprList;
ds@1952
   332
typedef struct FKey FKey;
ds@1952
   333
typedef struct FuncDef FuncDef;
ds@1952
   334
typedef struct IdList IdList;
ds@1952
   335
typedef struct Index Index;
ds@1952
   336
typedef struct KeyClass KeyClass;
ds@1952
   337
typedef struct KeyInfo KeyInfo;
ds@1952
   338
typedef struct Module Module;
ds@1952
   339
typedef struct NameContext NameContext;
ds@1952
   340
typedef struct Parse Parse;
ds@1952
   341
typedef struct Select Select;
ds@1952
   342
typedef struct SrcList SrcList;
ds@1952
   343
typedef struct Table Table;
ds@1952
   344
typedef struct TableLock TableLock;
ds@1952
   345
typedef struct Token Token;
ds@1952
   346
typedef struct TriggerStack TriggerStack;
ds@1952
   347
typedef struct TriggerStep TriggerStep;
ds@1952
   348
typedef struct Trigger Trigger;
ds@1952
   349
typedef struct WhereInfo WhereInfo;
ds@1952
   350
typedef struct WhereLevel WhereLevel;
ds@1952
   351
ds@1952
   352
#include "os.h"
ds@1952
   353
#include "mutex.h"
ds@1952
   354
ds@1952
   355
/*
ds@1952
   356
** Each database file to be accessed by the system is an instance
ds@1952
   357
** of the following structure.  There are normally two of these structures
ds@1952
   358
** in the sqlite.aDb[] array.  aDb[0] is the main database file and
ds@1952
   359
** aDb[1] is the database file used to hold temporary tables.  Additional
ds@1952
   360
** databases may be attached.
ds@1952
   361
*/
ds@1952
   362
struct Db {
ds@1952
   363
  char *zName;         /* Name of this database */
ds@1952
   364
  Btree *pBt;          /* The B*Tree structure for this database file */
ds@1952
   365
  u8 inTrans;          /* 0: not writable.  1: Transaction.  2: Checkpoint */
ds@1952
   366
  u8 safety_level;     /* How aggressive at synching data to disk */
ds@1952
   367
  void *pAux;               /* Auxiliary data.  Usually NULL */
ds@1952
   368
  void (*xFreeAux)(void*);  /* Routine to free pAux */
ds@1952
   369
  Schema *pSchema;     /* Pointer to database schema (possibly shared) */
ds@1952
   370
};
ds@1952
   371
ds@1952
   372
/*
ds@1952
   373
** An instance of the following structure stores a database schema.
ds@1952
   374
**
ds@1952
   375
** If there are no virtual tables configured in this schema, the
ds@1952
   376
** Schema.db variable is set to NULL. After the first virtual table
ds@1952
   377
** has been added, it is set to point to the database connection 
ds@1952
   378
** used to create the connection. Once a virtual table has been
ds@1952
   379
** added to the Schema structure and the Schema.db variable populated, 
ds@1952
   380
** only that database connection may use the Schema to prepare 
ds@1952
   381
** statements.
ds@1952
   382
*/
ds@1952
   383
struct Schema {
ds@1952
   384
  int schema_cookie;   /* Database schema version number for this file */
ds@1952
   385
  Hash tblHash;        /* All tables indexed by name */
ds@1952
   386
  Hash idxHash;        /* All (named) indices indexed by name */
ds@1952
   387
  Hash trigHash;       /* All triggers indexed by name */
ds@1952
   388
  Hash aFKey;          /* Foreign keys indexed by to-table */
ds@1952
   389
  Table *pSeqTab;      /* The sqlite_sequence table used by AUTOINCREMENT */
ds@1952
   390
  u8 file_format;      /* Schema format version for this file */
ds@1952
   391
  u8 enc;              /* Text encoding used by this database */
ds@1952
   392
  u16 flags;           /* Flags associated with this schema */
ds@1952
   393
  int cache_size;      /* Number of pages to use in the cache */
ds@1952
   394
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
   395
  sqlite3 *db;         /* "Owner" connection. See comment above */
ds@1952
   396
#endif
ds@1952
   397
};
ds@1952
   398
ds@1952
   399
/*
ds@1952
   400
** These macros can be used to test, set, or clear bits in the 
ds@1952
   401
** Db.flags field.
ds@1952
   402
*/
ds@1952
   403
#define DbHasProperty(D,I,P)     (((D)->aDb[I].pSchema->flags&(P))==(P))
ds@1952
   404
#define DbHasAnyProperty(D,I,P)  (((D)->aDb[I].pSchema->flags&(P))!=0)
ds@1952
   405
#define DbSetProperty(D,I,P)     (D)->aDb[I].pSchema->flags|=(P)
ds@1952
   406
#define DbClearProperty(D,I,P)   (D)->aDb[I].pSchema->flags&=~(P)
ds@1952
   407
ds@1952
   408
/*
ds@1952
   409
** Allowed values for the DB.flags field.
ds@1952
   410
**
ds@1952
   411
** The DB_SchemaLoaded flag is set after the database schema has been
ds@1952
   412
** read into internal hash tables.
ds@1952
   413
**
ds@1952
   414
** DB_UnresetViews means that one or more views have column names that
ds@1952
   415
** have been filled out.  If the schema changes, these column names might
ds@1952
   416
** changes and so the view will need to be reset.
ds@1952
   417
*/
ds@1952
   418
#define DB_SchemaLoaded    0x0001  /* The schema has been loaded */
ds@1952
   419
#define DB_UnresetViews    0x0002  /* Some views have defined column names */
ds@1952
   420
#define DB_Empty           0x0004  /* The file is empty (length 0 bytes) */
ds@1952
   421
ds@1952
   422
ds@1952
   423
/*
ds@1952
   424
** Each database is an instance of the following structure.
ds@1952
   425
**
ds@1952
   426
** The sqlite.lastRowid records the last insert rowid generated by an
ds@1952
   427
** insert statement.  Inserts on views do not affect its value.  Each
ds@1952
   428
** trigger has its own context, so that lastRowid can be updated inside
ds@1952
   429
** triggers as usual.  The previous value will be restored once the trigger
ds@1952
   430
** exits.  Upon entering a before or instead of trigger, lastRowid is no
ds@1952
   431
** longer (since after version 2.8.12) reset to -1.
ds@1952
   432
**
ds@1952
   433
** The sqlite.nChange does not count changes within triggers and keeps no
ds@1952
   434
** context.  It is reset at start of sqlite3_exec.
ds@1952
   435
** The sqlite.lsChange represents the number of changes made by the last
ds@1952
   436
** insert, update, or delete statement.  It remains constant throughout the
ds@1952
   437
** length of a statement and is then updated by OP_SetCounts.  It keeps a
ds@1952
   438
** context stack just like lastRowid so that the count of changes
ds@1952
   439
** within a trigger is not seen outside the trigger.  Changes to views do not
ds@1952
   440
** affect the value of lsChange.
ds@1952
   441
** The sqlite.csChange keeps track of the number of current changes (since
ds@1952
   442
** the last statement) and is used to update sqlite_lsChange.
ds@1952
   443
**
ds@1952
   444
** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16
ds@1952
   445
** store the most recent error code and, if applicable, string. The
ds@1952
   446
** internal function sqlite3Error() is used to set these variables
ds@1952
   447
** consistently.
ds@1952
   448
*/
ds@1952
   449
struct sqlite3 {
ds@1952
   450
  sqlite3_vfs *pVfs;            /* OS Interface */
ds@1952
   451
  int nDb;                      /* Number of backends currently in use */
ds@1952
   452
  Db *aDb;                      /* All backends */
ds@1952
   453
  int flags;                    /* Miscellanous flags. See below */
ds@1952
   454
  int openFlags;                /* Flags passed to sqlite3_vfs.xOpen() */
ds@1952
   455
  int errCode;                  /* Most recent error code (SQLITE_*) */
ds@1952
   456
  int errMask;                  /* & result codes with this before returning */
ds@1952
   457
  u8 autoCommit;                /* The auto-commit flag. */
ds@1952
   458
  u8 temp_store;                /* 1: file 2: memory 0: default */
ds@1952
   459
  u8 mallocFailed;              /* True if we have seen a malloc failure */
ds@1952
   460
  int nTable;                   /* Number of tables in the database */
ds@1952
   461
  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
ds@1952
   462
  i64 lastRowid;                /* ROWID of most recent insert (see above) */
ds@1952
   463
  i64 priorNewRowid;            /* Last randomly generated ROWID */
ds@1952
   464
  int magic;                    /* Magic number for detect library misuse */
ds@1952
   465
  int nChange;                  /* Value returned by sqlite3_changes() */
ds@1952
   466
  int nTotalChange;             /* Value returned by sqlite3_total_changes() */
ds@1952
   467
  sqlite3_mutex *mutex;         /* Connection mutex */
ds@1952
   468
  struct sqlite3InitInfo {      /* Information used during initialization */
ds@1952
   469
    int iDb;                    /* When back is being initialized */
ds@1952
   470
    int newTnum;                /* Rootpage of table being initialized */
ds@1952
   471
    u8 busy;                    /* TRUE if currently initializing */
ds@1952
   472
  } init;
ds@1952
   473
  int nExtension;               /* Number of loaded extensions */
ds@1952
   474
  void **aExtension;            /* Array of shared libraray handles */
ds@1952
   475
  struct Vdbe *pVdbe;           /* List of active virtual machines */
ds@1952
   476
  int activeVdbeCnt;            /* Number of vdbes currently executing */
ds@1952
   477
  void (*xTrace)(void*,const char*);        /* Trace function */
ds@1952
   478
  void *pTraceArg;                          /* Argument to the trace function */
ds@1952
   479
  void (*xProfile)(void*,const char*,u64);  /* Profiling function */
ds@1952
   480
  void *pProfileArg;                        /* Argument to profile function */
ds@1952
   481
  void *pCommitArg;                 /* Argument to xCommitCallback() */   
ds@1952
   482
  int (*xCommitCallback)(void*);    /* Invoked at every commit. */
ds@1952
   483
  void *pRollbackArg;               /* Argument to xRollbackCallback() */   
ds@1952
   484
  void (*xRollbackCallback)(void*); /* Invoked at every commit. */
ds@1952
   485
  void *pUpdateArg;
ds@1952
   486
  void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
ds@1952
   487
  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
ds@1952
   488
  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
ds@1952
   489
  void *pCollNeededArg;
ds@1952
   490
  sqlite3_value *pErr;          /* Most recent error message */
ds@1952
   491
  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
ds@1952
   492
  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
ds@1952
   493
  union {
ds@1952
   494
    int isInterrupted;          /* True if sqlite3_interrupt has been called */
ds@1952
   495
    double notUsed1;            /* Spacer */
ds@1952
   496
  } u1;
ds@1952
   497
#ifndef SQLITE_OMIT_AUTHORIZATION
ds@1952
   498
  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
ds@1952
   499
                                /* Access authorization function */
ds@1952
   500
  void *pAuthArg;               /* 1st argument to the access auth function */
ds@1952
   501
#endif
ds@1952
   502
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
ds@1952
   503
  int (*xProgress)(void *);     /* The progress callback */
ds@1952
   504
  void *pProgressArg;           /* Argument to the progress callback */
ds@1952
   505
  int nProgressOps;             /* Number of opcodes for progress callback */
ds@1952
   506
#endif
ds@1952
   507
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
   508
  Hash aModule;                 /* populated by sqlite3_create_module() */
ds@1952
   509
  Table *pVTab;                 /* vtab with active Connect/Create method */
ds@1952
   510
  sqlite3_vtab **aVTrans;       /* Virtual tables with open transactions */
ds@1952
   511
  int nVTrans;                  /* Allocated size of aVTrans */
ds@1952
   512
#endif
ds@1952
   513
  Hash aFunc;                   /* All functions that can be in SQL exprs */
ds@1952
   514
  Hash aCollSeq;                /* All collating sequences */
ds@1952
   515
  BusyHandler busyHandler;      /* Busy callback */
ds@1952
   516
  int busyTimeout;              /* Busy handler timeout, in msec */
ds@1952
   517
  Db aDbStatic[2];              /* Static space for the 2 default backends */
ds@1952
   518
#ifdef SQLITE_SSE
ds@1952
   519
  sqlite3_stmt *pFetch;         /* Used by SSE to fetch stored statements */
ds@1952
   520
#endif
ds@1952
   521
  u8 dfltLockMode;              /* Default locking-mode for attached dbs */
ds@1952
   522
};
ds@1952
   523
ds@1952
   524
/*
ds@1952
   525
** A macro to discover the encoding of a database.
ds@1952
   526
*/
ds@1952
   527
#define ENC(db) ((db)->aDb[0].pSchema->enc)
ds@1952
   528
ds@1952
   529
/*
ds@1952
   530
** Possible values for the sqlite.flags and or Db.flags fields.
ds@1952
   531
**
ds@1952
   532
** On sqlite.flags, the SQLITE_InTrans value means that we have
ds@1952
   533
** executed a BEGIN.  On Db.flags, SQLITE_InTrans means a statement
ds@1952
   534
** transaction is active on that particular database file.
ds@1952
   535
*/
ds@1952
   536
#define SQLITE_VdbeTrace      0x00000001  /* True to trace VDBE execution */
ds@1952
   537
#define SQLITE_InTrans        0x00000008  /* True if in a transaction */
ds@1952
   538
#define SQLITE_InternChanges  0x00000010  /* Uncommitted Hash table changes */
ds@1952
   539
#define SQLITE_FullColNames   0x00000020  /* Show full column names on SELECT */
ds@1952
   540
#define SQLITE_ShortColNames  0x00000040  /* Show short columns names */
ds@1952
   541
#define SQLITE_CountRows      0x00000080  /* Count rows changed by INSERT, */
ds@1952
   542
                                          /*   DELETE, or UPDATE and return */
ds@1952
   543
                                          /*   the count using a callback. */
ds@1952
   544
#define SQLITE_NullCallback   0x00000100  /* Invoke the callback once if the */
ds@1952
   545
                                          /*   result set is empty */
ds@1952
   546
#define SQLITE_SqlTrace       0x00000200  /* Debug print SQL as it executes */
ds@1952
   547
#define SQLITE_VdbeListing    0x00000400  /* Debug listings of VDBE programs */
ds@1952
   548
#define SQLITE_WriteSchema    0x00000800  /* OK to update SQLITE_MASTER */
ds@1952
   549
#define SQLITE_NoReadlock     0x00001000  /* Readlocks are omitted when 
ds@1952
   550
                                          ** accessing read-only databases */
ds@1952
   551
#define SQLITE_IgnoreChecks   0x00002000  /* Do not enforce check constraints */
ds@1952
   552
#define SQLITE_ReadUncommitted 0x00004000 /* For shared-cache mode */
ds@1952
   553
#define SQLITE_LegacyFileFmt  0x00008000  /* Create new databases in format 1 */
ds@1952
   554
#define SQLITE_FullFSync      0x00010000  /* Use full fsync on the backend */
ds@1952
   555
#define SQLITE_LoadExtension  0x00020000  /* Enable load_extension */
ds@1952
   556
ds@1952
   557
#define SQLITE_RecoveryMode   0x00040000  /* Ignore schema errors */
ds@1952
   558
#define SQLITE_SharedCache    0x00080000  /* Cache sharing is enabled */
ds@1952
   559
#define SQLITE_Vtab           0x00100000  /* There exists a virtual table */
ds@1952
   560
ds@1952
   561
/*
ds@1952
   562
** Possible values for the sqlite.magic field.
ds@1952
   563
** The numbers are obtained at random and have no special meaning, other
ds@1952
   564
** than being distinct from one another.
ds@1952
   565
*/
ds@1952
   566
#define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */
ds@1952
   567
#define SQLITE_MAGIC_CLOSED   0x9f3c2d33  /* Database is closed */
ds@1952
   568
#define SQLITE_MAGIC_BUSY     0xf03b7906  /* Database currently in use */
ds@1952
   569
#define SQLITE_MAGIC_ERROR    0xb5357930  /* An SQLITE_MISUSE error occurred */
ds@1952
   570
ds@1952
   571
/*
ds@1952
   572
** Each SQL function is defined by an instance of the following
ds@1952
   573
** structure.  A pointer to this structure is stored in the sqlite.aFunc
ds@1952
   574
** hash table.  When multiple functions have the same name, the hash table
ds@1952
   575
** points to a linked list of these structures.
ds@1952
   576
*/
ds@1952
   577
struct FuncDef {
ds@1952
   578
  i16 nArg;            /* Number of arguments.  -1 means unlimited */
ds@1952
   579
  u8 iPrefEnc;         /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
ds@1952
   580
  u8 needCollSeq;      /* True if sqlite3GetFuncCollSeq() might be called */
ds@1952
   581
  u8 flags;            /* Some combination of SQLITE_FUNC_* */
ds@1952
   582
  void *pUserData;     /* User data parameter */
ds@1952
   583
  FuncDef *pNext;      /* Next function with same name */
ds@1952
   584
  void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
ds@1952
   585
  void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
ds@1952
   586
  void (*xFinalize)(sqlite3_context*);                /* Aggregate finializer */
ds@1952
   587
  char zName[1];       /* SQL name of the function.  MUST BE LAST */
ds@1952
   588
};
ds@1952
   589
ds@1952
   590
/*
ds@1952
   591
** Each SQLite module (virtual table definition) is defined by an
ds@1952
   592
** instance of the following structure, stored in the sqlite3.aModule
ds@1952
   593
** hash table.
ds@1952
   594
*/
ds@1952
   595
struct Module {
ds@1952
   596
  const sqlite3_module *pModule;       /* Callback pointers */
ds@1952
   597
  const char *zName;                   /* Name passed to create_module() */
ds@1952
   598
  void *pAux;                          /* pAux passed to create_module() */
ds@1952
   599
  void (*xDestroy)(void *);            /* Module destructor function */
ds@1952
   600
};
ds@1952
   601
ds@1952
   602
/*
ds@1952
   603
** Possible values for FuncDef.flags
ds@1952
   604
*/
ds@1952
   605
#define SQLITE_FUNC_LIKE   0x01  /* Candidate for the LIKE optimization */
ds@1952
   606
#define SQLITE_FUNC_CASE   0x02  /* Case-sensitive LIKE-type function */
ds@1952
   607
#define SQLITE_FUNC_EPHEM  0x04  /* Ephermeral.  Delete with VDBE */
ds@1952
   608
ds@1952
   609
/*
ds@1952
   610
** information about each column of an SQL table is held in an instance
ds@1952
   611
** of this structure.
ds@1952
   612
*/
ds@1952
   613
struct Column {
ds@1952
   614
  char *zName;     /* Name of this column */
ds@1952
   615
  Expr *pDflt;     /* Default value of this column */
ds@1952
   616
  char *zType;     /* Data type for this column */
ds@1952
   617
  char *zColl;     /* Collating sequence.  If NULL, use the default */
ds@1952
   618
  u8 notNull;      /* True if there is a NOT NULL constraint */
ds@1952
   619
  u8 isPrimKey;    /* True if this column is part of the PRIMARY KEY */
ds@1952
   620
  char affinity;   /* One of the SQLITE_AFF_... values */
ds@1952
   621
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
   622
  u8 isHidden;     /* True if this column is 'hidden' */
ds@1952
   623
#endif
ds@1952
   624
};
ds@1952
   625
ds@1952
   626
/*
ds@1952
   627
** A "Collating Sequence" is defined by an instance of the following
ds@1952
   628
** structure. Conceptually, a collating sequence consists of a name and
ds@1952
   629
** a comparison routine that defines the order of that sequence.
ds@1952
   630
**
ds@1952
   631
** There may two seperate implementations of the collation function, one
ds@1952
   632
** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that
ds@1952
   633
** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine
ds@1952
   634
** native byte order. When a collation sequence is invoked, SQLite selects
ds@1952
   635
** the version that will require the least expensive encoding
ds@1952
   636
** translations, if any.
ds@1952
   637
**
ds@1952
   638
** The CollSeq.pUser member variable is an extra parameter that passed in
ds@1952
   639
** as the first argument to the UTF-8 comparison function, xCmp.
ds@1952
   640
** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function,
ds@1952
   641
** xCmp16.
ds@1952
   642
**
ds@1952
   643
** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
ds@1952
   644
** collating sequence is undefined.  Indices built on an undefined
ds@1952
   645
** collating sequence may not be read or written.
ds@1952
   646
*/
ds@1952
   647
struct CollSeq {
ds@1952
   648
  char *zName;          /* Name of the collating sequence, UTF-8 encoded */
ds@1952
   649
  u8 enc;               /* Text encoding handled by xCmp() */
ds@1952
   650
  u8 type;              /* One of the SQLITE_COLL_... values below */
ds@1952
   651
  void *pUser;          /* First argument to xCmp() */
ds@1952
   652
  int (*xCmp)(void*,int, const void*, int, const void*);
ds@1952
   653
  void (*xDel)(void*);  /* Destructor for pUser */
ds@1952
   654
};
ds@1952
   655
ds@1952
   656
/*
ds@1952
   657
** Allowed values of CollSeq flags:
ds@1952
   658
*/
ds@1952
   659
#define SQLITE_COLL_BINARY  1  /* The default memcmp() collating sequence */
ds@1952
   660
#define SQLITE_COLL_NOCASE  2  /* The built-in NOCASE collating sequence */
ds@1952
   661
#define SQLITE_COLL_REVERSE 3  /* The built-in REVERSE collating sequence */
ds@1952
   662
#define SQLITE_COLL_USER    0  /* Any other user-defined collating sequence */
ds@1952
   663
ds@1952
   664
/*
ds@1952
   665
** A sort order can be either ASC or DESC.
ds@1952
   666
*/
ds@1952
   667
#define SQLITE_SO_ASC       0  /* Sort in ascending order */
ds@1952
   668
#define SQLITE_SO_DESC      1  /* Sort in ascending order */
ds@1952
   669
ds@1952
   670
/*
ds@1952
   671
** Column affinity types.
ds@1952
   672
**
ds@1952
   673
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
ds@1952
   674
** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve
ds@1952
   675
** the speed a little by number the values consecutively.  
ds@1952
   676
**
ds@1952
   677
** But rather than start with 0 or 1, we begin with 'a'.  That way,
ds@1952
   678
** when multiple affinity types are concatenated into a string and
ds@1952
   679
** used as the P3 operand, they will be more readable.
ds@1952
   680
**
ds@1952
   681
** Note also that the numeric types are grouped together so that testing
ds@1952
   682
** for a numeric type is a single comparison.
ds@1952
   683
*/
ds@1952
   684
#define SQLITE_AFF_TEXT     'a'
ds@1952
   685
#define SQLITE_AFF_NONE     'b'
ds@1952
   686
#define SQLITE_AFF_NUMERIC  'c'
ds@1952
   687
#define SQLITE_AFF_INTEGER  'd'
ds@1952
   688
#define SQLITE_AFF_REAL     'e'
ds@1952
   689
ds@1952
   690
#define sqlite3IsNumericAffinity(X)  ((X)>=SQLITE_AFF_NUMERIC)
ds@1952
   691
ds@1952
   692
/*
ds@1952
   693
** Each SQL table is represented in memory by an instance of the
ds@1952
   694
** following structure.
ds@1952
   695
**
ds@1952
   696
** Table.zName is the name of the table.  The case of the original
ds@1952
   697
** CREATE TABLE statement is stored, but case is not significant for
ds@1952
   698
** comparisons.
ds@1952
   699
**
ds@1952
   700
** Table.nCol is the number of columns in this table.  Table.aCol is a
ds@1952
   701
** pointer to an array of Column structures, one for each column.
ds@1952
   702
**
ds@1952
   703
** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
ds@1952
   704
** the column that is that key.   Otherwise Table.iPKey is negative.  Note
ds@1952
   705
** that the datatype of the PRIMARY KEY must be INTEGER for this field to
ds@1952
   706
** be set.  An INTEGER PRIMARY KEY is used as the rowid for each row of
ds@1952
   707
** the table.  If a table has no INTEGER PRIMARY KEY, then a random rowid
ds@1952
   708
** is generated for each row of the table.  Table.hasPrimKey is true if
ds@1952
   709
** the table has any PRIMARY KEY, INTEGER or otherwise.
ds@1952
   710
**
ds@1952
   711
** Table.tnum is the page number for the root BTree page of the table in the
ds@1952
   712
** database file.  If Table.iDb is the index of the database table backend
ds@1952
   713
** in sqlite.aDb[].  0 is for the main database and 1 is for the file that
ds@1952
   714
** holds temporary tables and indices.  If Table.isEphem
ds@1952
   715
** is true, then the table is stored in a file that is automatically deleted
ds@1952
   716
** when the VDBE cursor to the table is closed.  In this case Table.tnum 
ds@1952
   717
** refers VDBE cursor number that holds the table open, not to the root
ds@1952
   718
** page number.  Transient tables are used to hold the results of a
ds@1952
   719
** sub-query that appears instead of a real table name in the FROM clause 
ds@1952
   720
** of a SELECT statement.
ds@1952
   721
*/
ds@1952
   722
struct Table {
ds@1952
   723
  char *zName;     /* Name of the table */
ds@1952
   724
  int nCol;        /* Number of columns in this table */
ds@1952
   725
  Column *aCol;    /* Information about each column */
ds@1952
   726
  int iPKey;       /* If not less then 0, use aCol[iPKey] as the primary key */
ds@1952
   727
  Index *pIndex;   /* List of SQL indexes on this table. */
ds@1952
   728
  int tnum;        /* Root BTree node for this table (see note above) */
ds@1952
   729
  Select *pSelect; /* NULL for tables.  Points to definition if a view. */
ds@1952
   730
  int nRef;          /* Number of pointers to this Table */
ds@1952
   731
  Trigger *pTrigger; /* List of SQL triggers on this table */
ds@1952
   732
  FKey *pFKey;       /* Linked list of all foreign keys in this table */
ds@1952
   733
  char *zColAff;     /* String defining the affinity of each column */
ds@1952
   734
#ifndef SQLITE_OMIT_CHECK
ds@1952
   735
  Expr *pCheck;      /* The AND of all CHECK constraints */
ds@1952
   736
#endif
ds@1952
   737
#ifndef SQLITE_OMIT_ALTERTABLE
ds@1952
   738
  int addColOffset;  /* Offset in CREATE TABLE statement to add a new column */
ds@1952
   739
#endif
ds@1952
   740
  u8 readOnly;     /* True if this table should not be written by the user */
ds@1952
   741
  u8 isEphem;      /* True if created using OP_OpenEphermeral */
ds@1952
   742
  u8 hasPrimKey;   /* True if there exists a primary key */
ds@1952
   743
  u8 keyConf;      /* What to do in case of uniqueness conflict on iPKey */
ds@1952
   744
  u8 autoInc;      /* True if the integer primary key is autoincrement */
ds@1952
   745
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
   746
  u8 isVirtual;             /* True if this is a virtual table */
ds@1952
   747
  u8 isCommit;              /* True once the CREATE TABLE has been committed */
ds@1952
   748
  Module *pMod;             /* Pointer to the implementation of the module */
ds@1952
   749
  sqlite3_vtab *pVtab;      /* Pointer to the module instance */
ds@1952
   750
  int nModuleArg;           /* Number of arguments to the module */
ds@1952
   751
  char **azModuleArg;       /* Text of all module args. [0] is module name */
ds@1952
   752
#endif
ds@1952
   753
  Schema *pSchema;          /* Schema that contains this table */
ds@1952
   754
};
ds@1952
   755
ds@1952
   756
/*
ds@1952
   757
** Test to see whether or not a table is a virtual table.  This is
ds@1952
   758
** done as a macro so that it will be optimized out when virtual
ds@1952
   759
** table support is omitted from the build.
ds@1952
   760
*/
ds@1952
   761
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
   762
#  define IsVirtual(X)      ((X)->isVirtual)
ds@1952
   763
#  define IsHiddenColumn(X) ((X)->isHidden)
ds@1952
   764
#else
ds@1952
   765
#  define IsVirtual(X)      0
ds@1952
   766
#  define IsHiddenColumn(X) 0
ds@1952
   767
#endif
ds@1952
   768
ds@1952
   769
/*
ds@1952
   770
** Each foreign key constraint is an instance of the following structure.
ds@1952
   771
**
ds@1952
   772
** A foreign key is associated with two tables.  The "from" table is
ds@1952
   773
** the table that contains the REFERENCES clause that creates the foreign
ds@1952
   774
** key.  The "to" table is the table that is named in the REFERENCES clause.
ds@1952
   775
** Consider this example:
ds@1952
   776
**
ds@1952
   777
**     CREATE TABLE ex1(
ds@1952
   778
**       a INTEGER PRIMARY KEY,
ds@1952
   779
**       b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
ds@1952
   780
**     );
ds@1952
   781
**
ds@1952
   782
** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
ds@1952
   783
**
ds@1952
   784
** Each REFERENCES clause generates an instance of the following structure
ds@1952
   785
** which is attached to the from-table.  The to-table need not exist when
ds@1952
   786
** the from-table is created.  The existance of the to-table is not checked
ds@1952
   787
** until an attempt is made to insert data into the from-table.
ds@1952
   788
**
ds@1952
   789
** The sqlite.aFKey hash table stores pointers to this structure
ds@1952
   790
** given the name of a to-table.  For each to-table, all foreign keys
ds@1952
   791
** associated with that table are on a linked list using the FKey.pNextTo
ds@1952
   792
** field.
ds@1952
   793
*/
ds@1952
   794
struct FKey {
ds@1952
   795
  Table *pFrom;     /* The table that constains the REFERENCES clause */
ds@1952
   796
  FKey *pNextFrom;  /* Next foreign key in pFrom */
ds@1952
   797
  char *zTo;        /* Name of table that the key points to */
ds@1952
   798
  FKey *pNextTo;    /* Next foreign key that points to zTo */
ds@1952
   799
  int nCol;         /* Number of columns in this key */
ds@1952
   800
  struct sColMap {  /* Mapping of columns in pFrom to columns in zTo */
ds@1952
   801
    int iFrom;         /* Index of column in pFrom */
ds@1952
   802
    char *zCol;        /* Name of column in zTo.  If 0 use PRIMARY KEY */
ds@1952
   803
  } *aCol;          /* One entry for each of nCol column s */
ds@1952
   804
  u8 isDeferred;    /* True if constraint checking is deferred till COMMIT */
ds@1952
   805
  u8 updateConf;    /* How to resolve conflicts that occur on UPDATE */
ds@1952
   806
  u8 deleteConf;    /* How to resolve conflicts that occur on DELETE */
ds@1952
   807
  u8 insertConf;    /* How to resolve conflicts that occur on INSERT */
ds@1952
   808
};
ds@1952
   809
ds@1952
   810
/*
ds@1952
   811
** SQLite supports many different ways to resolve a constraint
ds@1952
   812
** error.  ROLLBACK processing means that a constraint violation
ds@1952
   813
** causes the operation in process to fail and for the current transaction
ds@1952
   814
** to be rolled back.  ABORT processing means the operation in process
ds@1952
   815
** fails and any prior changes from that one operation are backed out,
ds@1952
   816
** but the transaction is not rolled back.  FAIL processing means that
ds@1952
   817
** the operation in progress stops and returns an error code.  But prior
ds@1952
   818
** changes due to the same operation are not backed out and no rollback
ds@1952
   819
** occurs.  IGNORE means that the particular row that caused the constraint
ds@1952
   820
** error is not inserted or updated.  Processing continues and no error
ds@1952
   821
** is returned.  REPLACE means that preexisting database rows that caused
ds@1952
   822
** a UNIQUE constraint violation are removed so that the new insert or
ds@1952
   823
** update can proceed.  Processing continues and no error is reported.
ds@1952
   824
**
ds@1952
   825
** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
ds@1952
   826
** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
ds@1952
   827
** same as ROLLBACK for DEFERRED keys.  SETNULL means that the foreign
ds@1952
   828
** key is set to NULL.  CASCADE means that a DELETE or UPDATE of the
ds@1952
   829
** referenced table row is propagated into the row that holds the
ds@1952
   830
** foreign key.
ds@1952
   831
** 
ds@1952
   832
** The following symbolic values are used to record which type
ds@1952
   833
** of action to take.
ds@1952
   834
*/
ds@1952
   835
#define OE_None     0   /* There is no constraint to check */
ds@1952
   836
#define OE_Rollback 1   /* Fail the operation and rollback the transaction */
ds@1952
   837
#define OE_Abort    2   /* Back out changes but do no rollback transaction */
ds@1952
   838
#define OE_Fail     3   /* Stop the operation but leave all prior changes */
ds@1952
   839
#define OE_Ignore   4   /* Ignore the error. Do not do the INSERT or UPDATE */
ds@1952
   840
#define OE_Replace  5   /* Delete existing record, then do INSERT or UPDATE */
ds@1952
   841
ds@1952
   842
#define OE_Restrict 6   /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
ds@1952
   843
#define OE_SetNull  7   /* Set the foreign key value to NULL */
ds@1952
   844
#define OE_SetDflt  8   /* Set the foreign key value to its default */
ds@1952
   845
#define OE_Cascade  9   /* Cascade the changes */
ds@1952
   846
ds@1952
   847
#define OE_Default  99  /* Do whatever the default action is */
ds@1952
   848
ds@1952
   849
ds@1952
   850
/*
ds@1952
   851
** An instance of the following structure is passed as the first
ds@1952
   852
** argument to sqlite3VdbeKeyCompare and is used to control the 
ds@1952
   853
** comparison of the two index keys.
ds@1952
   854
**
ds@1952
   855
** If the KeyInfo.incrKey value is true and the comparison would
ds@1952
   856
** otherwise be equal, then return a result as if the second key
ds@1952
   857
** were larger.
ds@1952
   858
*/
ds@1952
   859
struct KeyInfo {
ds@1952
   860
  sqlite3 *db;        /* The database connection */
ds@1952
   861
  u8 enc;             /* Text encoding - one of the TEXT_Utf* values */
ds@1952
   862
  u8 incrKey;         /* Increase 2nd key by epsilon before comparison */
ds@1952
   863
  int nField;         /* Number of entries in aColl[] */
ds@1952
   864
  u8 *aSortOrder;     /* If defined an aSortOrder[i] is true, sort DESC */
ds@1952
   865
  CollSeq *aColl[1];  /* Collating sequence for each term of the key */
ds@1952
   866
};
ds@1952
   867
ds@1952
   868
/*
ds@1952
   869
** Each SQL index is represented in memory by an
ds@1952
   870
** instance of the following structure.
ds@1952
   871
**
ds@1952
   872
** The columns of the table that are to be indexed are described
ds@1952
   873
** by the aiColumn[] field of this structure.  For example, suppose
ds@1952
   874
** we have the following table and index:
ds@1952
   875
**
ds@1952
   876
**     CREATE TABLE Ex1(c1 int, c2 int, c3 text);
ds@1952
   877
**     CREATE INDEX Ex2 ON Ex1(c3,c1);
ds@1952
   878
**
ds@1952
   879
** In the Table structure describing Ex1, nCol==3 because there are
ds@1952
   880
** three columns in the table.  In the Index structure describing
ds@1952
   881
** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
ds@1952
   882
** The value of aiColumn is {2, 0}.  aiColumn[0]==2 because the 
ds@1952
   883
** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
ds@1952
   884
** The second column to be indexed (c1) has an index of 0 in
ds@1952
   885
** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
ds@1952
   886
**
ds@1952
   887
** The Index.onError field determines whether or not the indexed columns
ds@1952
   888
** must be unique and what to do if they are not.  When Index.onError=OE_None,
ds@1952
   889
** it means this is not a unique index.  Otherwise it is a unique index
ds@1952
   890
** and the value of Index.onError indicate the which conflict resolution 
ds@1952
   891
** algorithm to employ whenever an attempt is made to insert a non-unique
ds@1952
   892
** element.
ds@1952
   893
*/
ds@1952
   894
struct Index {
ds@1952
   895
  char *zName;     /* Name of this index */
ds@1952
   896
  int nColumn;     /* Number of columns in the table used by this index */
ds@1952
   897
  int *aiColumn;   /* Which columns are used by this index.  1st is 0 */
ds@1952
   898
  unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
ds@1952
   899
  Table *pTable;   /* The SQL table being indexed */
ds@1952
   900
  int tnum;        /* Page containing root of this index in database file */
ds@1952
   901
  u8 onError;      /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
ds@1952
   902
  u8 autoIndex;    /* True if is automatically created (ex: by UNIQUE) */
ds@1952
   903
  char *zColAff;   /* String defining the affinity of each column */
ds@1952
   904
  Index *pNext;    /* The next index associated with the same table */
ds@1952
   905
  Schema *pSchema; /* Schema containing this index */
ds@1952
   906
  u8 *aSortOrder;  /* Array of size Index.nColumn. True==DESC, False==ASC */
ds@1952
   907
  char **azColl;   /* Array of collation sequence names for index */
ds@1952
   908
};
ds@1952
   909
ds@1952
   910
/*
ds@1952
   911
** Each token coming out of the lexer is an instance of
ds@1952
   912
** this structure.  Tokens are also used as part of an expression.
ds@1952
   913
**
ds@1952
   914
** Note if Token.z==0 then Token.dyn and Token.n are undefined and
ds@1952
   915
** may contain random values.  Do not make any assuptions about Token.dyn
ds@1952
   916
** and Token.n when Token.z==0.
ds@1952
   917
*/
ds@1952
   918
struct Token {
ds@1952
   919
  const unsigned char *z; /* Text of the token.  Not NULL-terminated! */
ds@1952
   920
  unsigned dyn  : 1;      /* True for malloced memory, false for static */
ds@1952
   921
  unsigned n    : 31;     /* Number of characters in this token */
ds@1952
   922
};
ds@1952
   923
ds@1952
   924
/*
ds@1952
   925
** An instance of this structure contains information needed to generate
ds@1952
   926
** code for a SELECT that contains aggregate functions.
ds@1952
   927
**
ds@1952
   928
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
ds@1952
   929
** pointer to this structure.  The Expr.iColumn field is the index in
ds@1952
   930
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
ds@1952
   931
** code for that node.
ds@1952
   932
**
ds@1952
   933
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
ds@1952
   934
** original Select structure that describes the SELECT statement.  These
ds@1952
   935
** fields do not need to be freed when deallocating the AggInfo structure.
ds@1952
   936
*/
ds@1952
   937
struct AggInfo {
ds@1952
   938
  u8 directMode;          /* Direct rendering mode means take data directly
ds@1952
   939
                          ** from source tables rather than from accumulators */
ds@1952
   940
  u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
ds@1952
   941
                          ** than the source table */
ds@1952
   942
  int sortingIdx;         /* Cursor number of the sorting index */
ds@1952
   943
  ExprList *pGroupBy;     /* The group by clause */
ds@1952
   944
  int nSortingColumn;     /* Number of columns in the sorting index */
ds@1952
   945
  struct AggInfo_col {    /* For each column used in source tables */
ds@1952
   946
    Table *pTab;             /* Source table */
ds@1952
   947
    int iTable;              /* Cursor number of the source table */
ds@1952
   948
    int iColumn;             /* Column number within the source table */
ds@1952
   949
    int iSorterColumn;       /* Column number in the sorting index */
ds@1952
   950
    int iMem;                /* Memory location that acts as accumulator */
ds@1952
   951
    Expr *pExpr;             /* The original expression */
ds@1952
   952
  } *aCol;
ds@1952
   953
  int nColumn;            /* Number of used entries in aCol[] */
ds@1952
   954
  int nColumnAlloc;       /* Number of slots allocated for aCol[] */
ds@1952
   955
  int nAccumulator;       /* Number of columns that show through to the output.
ds@1952
   956
                          ** Additional columns are used only as parameters to
ds@1952
   957
                          ** aggregate functions */
ds@1952
   958
  struct AggInfo_func {   /* For each aggregate function */
ds@1952
   959
    Expr *pExpr;             /* Expression encoding the function */
ds@1952
   960
    FuncDef *pFunc;          /* The aggregate function implementation */
ds@1952
   961
    int iMem;                /* Memory location that acts as accumulator */
ds@1952
   962
    int iDistinct;           /* Ephermeral table used to enforce DISTINCT */
ds@1952
   963
  } *aFunc;
ds@1952
   964
  int nFunc;              /* Number of entries in aFunc[] */
ds@1952
   965
  int nFuncAlloc;         /* Number of slots allocated for aFunc[] */
ds@1952
   966
};
ds@1952
   967
ds@1952
   968
/*
ds@1952
   969
** Each node of an expression in the parse tree is an instance
ds@1952
   970
** of this structure.
ds@1952
   971
**
ds@1952
   972
** Expr.op is the opcode.  The integer parser token codes are reused
ds@1952
   973
** as opcodes here.  For example, the parser defines TK_GE to be an integer
ds@1952
   974
** code representing the ">=" operator.  This same integer code is reused
ds@1952
   975
** to represent the greater-than-or-equal-to operator in the expression
ds@1952
   976
** tree.
ds@1952
   977
**
ds@1952
   978
** Expr.pRight and Expr.pLeft are subexpressions.  Expr.pList is a list
ds@1952
   979
** of argument if the expression is a function.
ds@1952
   980
**
ds@1952
   981
** Expr.token is the operator token for this node.  For some expressions
ds@1952
   982
** that have subexpressions, Expr.token can be the complete text that gave
ds@1952
   983
** rise to the Expr.  In the latter case, the token is marked as being
ds@1952
   984
** a compound token.
ds@1952
   985
**
ds@1952
   986
** An expression of the form ID or ID.ID refers to a column in a table.
ds@1952
   987
** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
ds@1952
   988
** the integer cursor number of a VDBE cursor pointing to that table and
ds@1952
   989
** Expr.iColumn is the column number for the specific column.  If the
ds@1952
   990
** expression is used as a result in an aggregate SELECT, then the
ds@1952
   991
** value is also stored in the Expr.iAgg column in the aggregate so that
ds@1952
   992
** it can be accessed after all aggregates are computed.
ds@1952
   993
**
ds@1952
   994
** If the expression is a function, the Expr.iTable is an integer code
ds@1952
   995
** representing which function.  If the expression is an unbound variable
ds@1952
   996
** marker (a question mark character '?' in the original SQL) then the
ds@1952
   997
** Expr.iTable holds the index number for that variable.
ds@1952
   998
**
ds@1952
   999
** If the expression is a subquery then Expr.iColumn holds an integer
ds@1952
  1000
** register number containing the result of the subquery.  If the
ds@1952
  1001
** subquery gives a constant result, then iTable is -1.  If the subquery
ds@1952
  1002
** gives a different answer at different times during statement processing
ds@1952
  1003
** then iTable is the address of a subroutine that computes the subquery.
ds@1952
  1004
**
ds@1952
  1005
** The Expr.pSelect field points to a SELECT statement.  The SELECT might
ds@1952
  1006
** be the right operand of an IN operator.  Or, if a scalar SELECT appears
ds@1952
  1007
** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
ds@1952
  1008
** operand.
ds@1952
  1009
**
ds@1952
  1010
** If the Expr is of type OP_Column, and the table it is selecting from
ds@1952
  1011
** is a disk table or the "old.*" pseudo-table, then pTab points to the
ds@1952
  1012
** corresponding table definition.
ds@1952
  1013
*/
ds@1952
  1014
struct Expr {
ds@1952
  1015
  u8 op;                 /* Operation performed by this node */
ds@1952
  1016
  char affinity;         /* The affinity of the column or 0 if not a column */
ds@1952
  1017
  u16 flags;             /* Various flags.  See below */
ds@1952
  1018
  CollSeq *pColl;        /* The collation type of the column or 0 */
ds@1952
  1019
  Expr *pLeft, *pRight;  /* Left and right subnodes */
ds@1952
  1020
  ExprList *pList;       /* A list of expressions used as function arguments
ds@1952
  1021
                         ** or in "<expr> IN (<expr-list)" */
ds@1952
  1022
  Token token;           /* An operand token */
ds@1952
  1023
  Token span;            /* Complete text of the expression */
ds@1952
  1024
  int iTable, iColumn;   /* When op==TK_COLUMN, then this expr node means the
ds@1952
  1025
                         ** iColumn-th field of the iTable-th table. */
ds@1952
  1026
  AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
ds@1952
  1027
  int iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
ds@1952
  1028
  int iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
ds@1952
  1029
  Select *pSelect;       /* When the expression is a sub-select.  Also the
ds@1952
  1030
                         ** right side of "<expr> IN (<select>)" */
ds@1952
  1031
  Table *pTab;           /* Table for OP_Column expressions. */
ds@1952
  1032
/*  Schema *pSchema; */
ds@1952
  1033
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
ds@1952
  1034
  int nHeight;           /* Height of the tree headed by this node */
ds@1952
  1035
#endif
ds@1952
  1036
};
ds@1952
  1037
ds@1952
  1038
/*
ds@1952
  1039
** The following are the meanings of bits in the Expr.flags field.
ds@1952
  1040
*/
ds@1952
  1041
#define EP_FromJoin     0x01  /* Originated in ON or USING clause of a join */
ds@1952
  1042
#define EP_Agg          0x02  /* Contains one or more aggregate functions */
ds@1952
  1043
#define EP_Resolved     0x04  /* IDs have been resolved to COLUMNs */
ds@1952
  1044
#define EP_Error        0x08  /* Expression contains one or more errors */
ds@1952
  1045
#define EP_Distinct     0x10  /* Aggregate function with DISTINCT keyword */
ds@1952
  1046
#define EP_VarSelect    0x20  /* pSelect is correlated, not constant */
ds@1952
  1047
#define EP_Dequoted     0x40  /* True if the string has been dequoted */
ds@1952
  1048
#define EP_InfixFunc    0x80  /* True for an infix function: LIKE, GLOB, etc */
ds@1952
  1049
#define EP_ExpCollate  0x100  /* Collating sequence specified explicitly */
ds@1952
  1050
ds@1952
  1051
/*
ds@1952
  1052
** These macros can be used to test, set, or clear bits in the 
ds@1952
  1053
** Expr.flags field.
ds@1952
  1054
*/
ds@1952
  1055
#define ExprHasProperty(E,P)     (((E)->flags&(P))==(P))
ds@1952
  1056
#define ExprHasAnyProperty(E,P)  (((E)->flags&(P))!=0)
ds@1952
  1057
#define ExprSetProperty(E,P)     (E)->flags|=(P)
ds@1952
  1058
#define ExprClearProperty(E,P)   (E)->flags&=~(P)
ds@1952
  1059
ds@1952
  1060
/*
ds@1952
  1061
** A list of expressions.  Each expression may optionally have a
ds@1952
  1062
** name.  An expr/name combination can be used in several ways, such
ds@1952
  1063
** as the list of "expr AS ID" fields following a "SELECT" or in the
ds@1952
  1064
** list of "ID = expr" items in an UPDATE.  A list of expressions can
ds@1952
  1065
** also be used as the argument to a function, in which case the a.zName
ds@1952
  1066
** field is not used.
ds@1952
  1067
*/
ds@1952
  1068
struct ExprList {
ds@1952
  1069
  int nExpr;             /* Number of expressions on the list */
ds@1952
  1070
  int nAlloc;            /* Number of entries allocated below */
ds@1952
  1071
  int iECursor;          /* VDBE Cursor associated with this ExprList */
ds@1952
  1072
  struct ExprList_item {
ds@1952
  1073
    Expr *pExpr;           /* The list of expressions */
ds@1952
  1074
    char *zName;           /* Token associated with this expression */
ds@1952
  1075
    u8 sortOrder;          /* 1 for DESC or 0 for ASC */
ds@1952
  1076
    u8 isAgg;              /* True if this is an aggregate like count(*) */
ds@1952
  1077
    u8 done;               /* A flag to indicate when processing is finished */
ds@1952
  1078
  } *a;                  /* One entry for each expression */
ds@1952
  1079
};
ds@1952
  1080
ds@1952
  1081
/*
ds@1952
  1082
** An instance of this structure can hold a simple list of identifiers,
ds@1952
  1083
** such as the list "a,b,c" in the following statements:
ds@1952
  1084
**
ds@1952
  1085
**      INSERT INTO t(a,b,c) VALUES ...;
ds@1952
  1086
**      CREATE INDEX idx ON t(a,b,c);
ds@1952
  1087
**      CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
ds@1952
  1088
**
ds@1952
  1089
** The IdList.a.idx field is used when the IdList represents the list of
ds@1952
  1090
** column names after a table name in an INSERT statement.  In the statement
ds@1952
  1091
**
ds@1952
  1092
**     INSERT INTO t(a,b,c) ...
ds@1952
  1093
**
ds@1952
  1094
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
ds@1952
  1095
*/
ds@1952
  1096
struct IdList {
ds@1952
  1097
  struct IdList_item {
ds@1952
  1098
    char *zName;      /* Name of the identifier */
ds@1952
  1099
    int idx;          /* Index in some Table.aCol[] of a column named zName */
ds@1952
  1100
  } *a;
ds@1952
  1101
  int nId;         /* Number of identifiers on the list */
ds@1952
  1102
  int nAlloc;      /* Number of entries allocated for a[] below */
ds@1952
  1103
};
ds@1952
  1104
ds@1952
  1105
/*
ds@1952
  1106
** The bitmask datatype defined below is used for various optimizations.
ds@1952
  1107
**
ds@1952
  1108
** Changing this from a 64-bit to a 32-bit type limits the number of
ds@1952
  1109
** tables in a join to 32 instead of 64.  But it also reduces the size
ds@1952
  1110
** of the library by 738 bytes on ix86.
ds@1952
  1111
*/
ds@1952
  1112
typedef u64 Bitmask;
ds@1952
  1113
ds@1952
  1114
/*
ds@1952
  1115
** The following structure describes the FROM clause of a SELECT statement.
ds@1952
  1116
** Each table or subquery in the FROM clause is a separate element of
ds@1952
  1117
** the SrcList.a[] array.
ds@1952
  1118
**
ds@1952
  1119
** With the addition of multiple database support, the following structure
ds@1952
  1120
** can also be used to describe a particular table such as the table that
ds@1952
  1121
** is modified by an INSERT, DELETE, or UPDATE statement.  In standard SQL,
ds@1952
  1122
** such a table must be a simple name: ID.  But in SQLite, the table can
ds@1952
  1123
** now be identified by a database name, a dot, then the table name: ID.ID.
ds@1952
  1124
**
ds@1952
  1125
** The jointype starts out showing the join type between the current table
ds@1952
  1126
** and the next table on the list.  The parser builds the list this way.
ds@1952
  1127
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
ds@1952
  1128
** jointype expresses the join between the table and the previous table.
ds@1952
  1129
*/
ds@1952
  1130
struct SrcList {
ds@1952
  1131
  i16 nSrc;        /* Number of tables or subqueries in the FROM clause */
ds@1952
  1132
  i16 nAlloc;      /* Number of entries allocated in a[] below */
ds@1952
  1133
  struct SrcList_item {
ds@1952
  1134
    char *zDatabase;  /* Name of database holding this table */
ds@1952
  1135
    char *zName;      /* Name of the table */
ds@1952
  1136
    char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
ds@1952
  1137
    Table *pTab;      /* An SQL table corresponding to zName */
ds@1952
  1138
    Select *pSelect;  /* A SELECT statement used in place of a table name */
ds@1952
  1139
    u8 isPopulated;   /* Temporary table associated with SELECT is populated */
ds@1952
  1140
    u8 jointype;      /* Type of join between this able and the previous */
ds@1952
  1141
    int iCursor;      /* The VDBE cursor number used to access this table */
ds@1952
  1142
    Expr *pOn;        /* The ON clause of a join */
ds@1952
  1143
    IdList *pUsing;   /* The USING clause of a join */
ds@1952
  1144
    Bitmask colUsed;  /* Bit N (1<<N) set if column N or pTab is used */
ds@1952
  1145
  } a[1];             /* One entry for each identifier on the list */
ds@1952
  1146
};
ds@1952
  1147
ds@1952
  1148
/*
ds@1952
  1149
** Permitted values of the SrcList.a.jointype field
ds@1952
  1150
*/
ds@1952
  1151
#define JT_INNER     0x0001    /* Any kind of inner or cross join */
ds@1952
  1152
#define JT_CROSS     0x0002    /* Explicit use of the CROSS keyword */
ds@1952
  1153
#define JT_NATURAL   0x0004    /* True for a "natural" join */
ds@1952
  1154
#define JT_LEFT      0x0008    /* Left outer join */
ds@1952
  1155
#define JT_RIGHT     0x0010    /* Right outer join */
ds@1952
  1156
#define JT_OUTER     0x0020    /* The "OUTER" keyword is present */
ds@1952
  1157
#define JT_ERROR     0x0040    /* unknown or unsupported join type */
ds@1952
  1158
ds@1952
  1159
/*
ds@1952
  1160
** For each nested loop in a WHERE clause implementation, the WhereInfo
ds@1952
  1161
** structure contains a single instance of this structure.  This structure
ds@1952
  1162
** is intended to be private the the where.c module and should not be
ds@1952
  1163
** access or modified by other modules.
ds@1952
  1164
**
ds@1952
  1165
** The pIdxInfo and pBestIdx fields are used to help pick the best
ds@1952
  1166
** index on a virtual table.  The pIdxInfo pointer contains indexing
ds@1952
  1167
** information for the i-th table in the FROM clause before reordering.
ds@1952
  1168
** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.
ds@1952
  1169
** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after
ds@1952
  1170
** FROM clause ordering.  This is a little confusing so I will repeat
ds@1952
  1171
** it in different words.  WhereInfo.a[i].pIdxInfo is index information 
ds@1952
  1172
** for WhereInfo.pTabList.a[i].  WhereInfo.a[i].pBestInfo is the
ds@1952
  1173
** index information for the i-th loop of the join.  pBestInfo is always
ds@1952
  1174
** either NULL or a copy of some pIdxInfo.  So for cleanup it is 
ds@1952
  1175
** sufficient to free all of the pIdxInfo pointers.
ds@1952
  1176
** 
ds@1952
  1177
*/
ds@1952
  1178
struct WhereLevel {
ds@1952
  1179
  int iFrom;            /* Which entry in the FROM clause */
ds@1952
  1180
  int flags;            /* Flags associated with this level */
ds@1952
  1181
  int iMem;             /* First memory cell used by this level */
ds@1952
  1182
  int iLeftJoin;        /* Memory cell used to implement LEFT OUTER JOIN */
ds@1952
  1183
  Index *pIdx;          /* Index used.  NULL if no index */
ds@1952
  1184
  int iTabCur;          /* The VDBE cursor used to access the table */
ds@1952
  1185
  int iIdxCur;          /* The VDBE cursor used to acesss pIdx */
ds@1952
  1186
  int brk;              /* Jump here to break out of the loop */
ds@1952
  1187
  int nxt;              /* Jump here to start the next IN combination */
ds@1952
  1188
  int cont;             /* Jump here to continue with the next loop cycle */
ds@1952
  1189
  int top;              /* First instruction of interior of the loop */
ds@1952
  1190
  int op, p1, p2;       /* Opcode used to terminate the loop */
ds@1952
  1191
  int nEq;              /* Number of == or IN constraints on this loop */
ds@1952
  1192
  int nIn;              /* Number of IN operators constraining this loop */
ds@1952
  1193
  struct InLoop {
ds@1952
  1194
    int iCur;              /* The VDBE cursor used by this IN operator */
ds@1952
  1195
    int topAddr;           /* Top of the IN loop */
ds@1952
  1196
  } *aInLoop;           /* Information about each nested IN operator */
ds@1952
  1197
  sqlite3_index_info *pBestIdx;  /* Index information for this level */
ds@1952
  1198
ds@1952
  1199
  /* The following field is really not part of the current level.  But
ds@1952
  1200
  ** we need a place to cache index information for each table in the
ds@1952
  1201
  ** FROM clause and the WhereLevel structure is a convenient place.
ds@1952
  1202
  */
ds@1952
  1203
  sqlite3_index_info *pIdxInfo;  /* Index info for n-th source table */
ds@1952
  1204
};
ds@1952
  1205
ds@1952
  1206
/*
ds@1952
  1207
** The WHERE clause processing routine has two halves.  The
ds@1952
  1208
** first part does the start of the WHERE loop and the second
ds@1952
  1209
** half does the tail of the WHERE loop.  An instance of
ds@1952
  1210
** this structure is returned by the first half and passed
ds@1952
  1211
** into the second half to give some continuity.
ds@1952
  1212
*/
ds@1952
  1213
struct WhereInfo {
ds@1952
  1214
  Parse *pParse;
ds@1952
  1215
  SrcList *pTabList;   /* List of tables in the join */
ds@1952
  1216
  int iTop;            /* The very beginning of the WHERE loop */
ds@1952
  1217
  int iContinue;       /* Jump here to continue with next record */
ds@1952
  1218
  int iBreak;          /* Jump here to break out of the loop */
ds@1952
  1219
  int nLevel;          /* Number of nested loop */
ds@1952
  1220
  sqlite3_index_info **apInfo;  /* Array of pointers to index info structures */
ds@1952
  1221
  WhereLevel a[1];     /* Information about each nest loop in the WHERE */
ds@1952
  1222
};
ds@1952
  1223
ds@1952
  1224
/*
ds@1952
  1225
** A NameContext defines a context in which to resolve table and column
ds@1952
  1226
** names.  The context consists of a list of tables (the pSrcList) field and
ds@1952
  1227
** a list of named expression (pEList).  The named expression list may
ds@1952
  1228
** be NULL.  The pSrc corresponds to the FROM clause of a SELECT or
ds@1952
  1229
** to the table being operated on by INSERT, UPDATE, or DELETE.  The
ds@1952
  1230
** pEList corresponds to the result set of a SELECT and is NULL for
ds@1952
  1231
** other statements.
ds@1952
  1232
**
ds@1952
  1233
** NameContexts can be nested.  When resolving names, the inner-most 
ds@1952
  1234
** context is searched first.  If no match is found, the next outer
ds@1952
  1235
** context is checked.  If there is still no match, the next context
ds@1952
  1236
** is checked.  This process continues until either a match is found
ds@1952
  1237
** or all contexts are check.  When a match is found, the nRef member of
ds@1952
  1238
** the context containing the match is incremented. 
ds@1952
  1239
**
ds@1952
  1240
** Each subquery gets a new NameContext.  The pNext field points to the
ds@1952
  1241
** NameContext in the parent query.  Thus the process of scanning the
ds@1952
  1242
** NameContext list corresponds to searching through successively outer
ds@1952
  1243
** subqueries looking for a match.
ds@1952
  1244
*/
ds@1952
  1245
struct NameContext {
ds@1952
  1246
  Parse *pParse;       /* The parser */
ds@1952
  1247
  SrcList *pSrcList;   /* One or more tables used to resolve names */
ds@1952
  1248
  ExprList *pEList;    /* Optional list of named expressions */
ds@1952
  1249
  int nRef;            /* Number of names resolved by this context */
ds@1952
  1250
  int nErr;            /* Number of errors encountered while resolving names */
ds@1952
  1251
  u8 allowAgg;         /* Aggregate functions allowed here */
ds@1952
  1252
  u8 hasAgg;           /* True if aggregates are seen */
ds@1952
  1253
  u8 isCheck;          /* True if resolving names in a CHECK constraint */
ds@1952
  1254
  int nDepth;          /* Depth of subquery recursion. 1 for no recursion */
ds@1952
  1255
  AggInfo *pAggInfo;   /* Information about aggregates at this level */
ds@1952
  1256
  NameContext *pNext;  /* Next outer name context.  NULL for outermost */
ds@1952
  1257
};
ds@1952
  1258
ds@1952
  1259
/*
ds@1952
  1260
** An instance of the following structure contains all information
ds@1952
  1261
** needed to generate code for a single SELECT statement.
ds@1952
  1262
**
ds@1952
  1263
** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
ds@1952
  1264
** If there is a LIMIT clause, the parser sets nLimit to the value of the
ds@1952
  1265
** limit and nOffset to the value of the offset (or 0 if there is not
ds@1952
  1266
** offset).  But later on, nLimit and nOffset become the memory locations
ds@1952
  1267
** in the VDBE that record the limit and offset counters.
ds@1952
  1268
**
ds@1952
  1269
** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
ds@1952
  1270
** These addresses must be stored so that we can go back and fill in
ds@1952
  1271
** the P3_KEYINFO and P2 parameters later.  Neither the KeyInfo nor
ds@1952
  1272
** the number of columns in P2 can be computed at the same time
ds@1952
  1273
** as the OP_OpenEphm instruction is coded because not
ds@1952
  1274
** enough information about the compound query is known at that point.
ds@1952
  1275
** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
ds@1952
  1276
** for the result set.  The KeyInfo for addrOpenTran[2] contains collating
ds@1952
  1277
** sequences for the ORDER BY clause.
ds@1952
  1278
*/
ds@1952
  1279
struct Select {
ds@1952
  1280
  ExprList *pEList;      /* The fields of the result */
ds@1952
  1281
  u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
ds@1952
  1282
  u8 isDistinct;         /* True if the DISTINCT keyword is present */
ds@1952
  1283
  u8 isResolved;         /* True once sqlite3SelectResolve() has run. */
ds@1952
  1284
  u8 isAgg;              /* True if this is an aggregate query */
ds@1952
  1285
  u8 usesEphm;           /* True if uses an OpenEphemeral opcode */
ds@1952
  1286
  u8 disallowOrderBy;    /* Do not allow an ORDER BY to be attached if TRUE */
ds@1952
  1287
  char affinity;         /* MakeRecord with this affinity for SRT_Set */
ds@1952
  1288
  SrcList *pSrc;         /* The FROM clause */
ds@1952
  1289
  Expr *pWhere;          /* The WHERE clause */
ds@1952
  1290
  ExprList *pGroupBy;    /* The GROUP BY clause */
ds@1952
  1291
  Expr *pHaving;         /* The HAVING clause */
ds@1952
  1292
  ExprList *pOrderBy;    /* The ORDER BY clause */
ds@1952
  1293
  Select *pPrior;        /* Prior select in a compound select statement */
ds@1952
  1294
  Select *pRightmost;    /* Right-most select in a compound select statement */
ds@1952
  1295
  Expr *pLimit;          /* LIMIT expression. NULL means not used. */
ds@1952
  1296
  Expr *pOffset;         /* OFFSET expression. NULL means not used. */
ds@1952
  1297
  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
ds@1952
  1298
  int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */
ds@1952
  1299
};
ds@1952
  1300
ds@1952
  1301
/*
ds@1952
  1302
** The results of a select can be distributed in several ways.
ds@1952
  1303
*/
ds@1952
  1304
#define SRT_Union        1  /* Store result as keys in an index */
ds@1952
  1305
#define SRT_Except       2  /* Remove result from a UNION index */
ds@1952
  1306
#define SRT_Discard      3  /* Do not save the results anywhere */
ds@1952
  1307
ds@1952
  1308
/* The ORDER BY clause is ignored for all of the above */
ds@1952
  1309
#define IgnorableOrderby(X) (X<=SRT_Discard)
ds@1952
  1310
ds@1952
  1311
#define SRT_Callback     4  /* Invoke a callback with each row of result */
ds@1952
  1312
#define SRT_Mem          5  /* Store result in a memory cell */
ds@1952
  1313
#define SRT_Set          6  /* Store non-null results as keys in an index */
ds@1952
  1314
#define SRT_Table        7  /* Store result as data with an automatic rowid */
ds@1952
  1315
#define SRT_EphemTab     8  /* Create transient tab and store like SRT_Table */
ds@1952
  1316
#define SRT_Subroutine   9  /* Call a subroutine to handle results */
ds@1952
  1317
#define SRT_Exists      10  /* Store 1 if the result is not empty */
ds@1952
  1318
ds@1952
  1319
/*
ds@1952
  1320
** An SQL parser context.  A copy of this structure is passed through
ds@1952
  1321
** the parser and down into all the parser action routine in order to
ds@1952
  1322
** carry around information that is global to the entire parse.
ds@1952
  1323
**
ds@1952
  1324
** The structure is divided into two parts.  When the parser and code
ds@1952
  1325
** generate call themselves recursively, the first part of the structure
ds@1952
  1326
** is constant but the second part is reset at the beginning and end of
ds@1952
  1327
** each recursion.
ds@1952
  1328
**
ds@1952
  1329
** The nTableLock and aTableLock variables are only used if the shared-cache 
ds@1952
  1330
** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
ds@1952
  1331
** used to store the set of table-locks required by the statement being
ds@1952
  1332
** compiled. Function sqlite3TableLock() is used to add entries to the
ds@1952
  1333
** list.
ds@1952
  1334
*/
ds@1952
  1335
struct Parse {
ds@1952
  1336
  sqlite3 *db;         /* The main database structure */
ds@1952
  1337
  int rc;              /* Return code from execution */
ds@1952
  1338
  char *zErrMsg;       /* An error message */
ds@1952
  1339
  Vdbe *pVdbe;         /* An engine for executing database bytecode */
ds@1952
  1340
  u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
ds@1952
  1341
  u8 nameClash;        /* A permanent table name clashes with temp table name */
ds@1952
  1342
  u8 checkSchema;      /* Causes schema cookie check after an error */
ds@1952
  1343
  u8 nested;           /* Number of nested calls to the parser/code generator */
ds@1952
  1344
  u8 parseError;       /* True after a parsing error.  Ticket #1794 */
ds@1952
  1345
  int nErr;            /* Number of errors seen */
ds@1952
  1346
  int nTab;            /* Number of previously allocated VDBE cursors */
ds@1952
  1347
  int nMem;            /* Number of memory cells used so far */
ds@1952
  1348
  int nSet;            /* Number of sets used so far */
ds@1952
  1349
  int ckOffset;        /* Stack offset to data used by CHECK constraints */
ds@1952
  1350
  u32 writeMask;       /* Start a write transaction on these databases */
ds@1952
  1351
  u32 cookieMask;      /* Bitmask of schema verified databases */
ds@1952
  1352
  int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
ds@1952
  1353
  int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
ds@1952
  1354
#ifndef SQLITE_OMIT_SHARED_CACHE
ds@1952
  1355
  int nTableLock;        /* Number of locks in aTableLock */
ds@1952
  1356
  TableLock *aTableLock; /* Required table locks for shared-cache mode */
ds@1952
  1357
#endif
ds@1952
  1358
ds@1952
  1359
  /* Above is constant between recursions.  Below is reset before and after
ds@1952
  1360
  ** each recursion */
ds@1952
  1361
ds@1952
  1362
  int nVar;            /* Number of '?' variables seen in the SQL so far */
ds@1952
  1363
  int nVarExpr;        /* Number of used slots in apVarExpr[] */
ds@1952
  1364
  int nVarExprAlloc;   /* Number of allocated slots in apVarExpr[] */
ds@1952
  1365
  Expr **apVarExpr;    /* Pointers to :aaa and $aaaa wildcard expressions */
ds@1952
  1366
  u8 explain;          /* True if the EXPLAIN flag is found on the query */
ds@1952
  1367
  Token sErrToken;     /* The token at which the error occurred */
ds@1952
  1368
  Token sNameToken;    /* Token with unqualified schema object name */
ds@1952
  1369
  Token sLastToken;    /* The last token parsed */
ds@1952
  1370
  const char *zSql;    /* All SQL text */
ds@1952
  1371
  const char *zTail;   /* All SQL text past the last semicolon parsed */
ds@1952
  1372
  Table *pNewTable;    /* A table being constructed by CREATE TABLE */
ds@1952
  1373
  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
ds@1952
  1374
  TriggerStack *trigStack;  /* Trigger actions being coded */
ds@1952
  1375
  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
ds@1952
  1376
#ifndef SQLITE_OMIT_VIRTUALTABLE
ds@1952
  1377
  Token sArg;                /* Complete text of a module argument */
ds@1952
  1378
  u8 declareVtab;            /* True if inside sqlite3_declare_vtab() */
ds@1952
  1379
  Table *pVirtualLock;       /* Require virtual table lock on this table */
ds@1952
  1380
#endif
ds@1952
  1381
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
ds@1952
  1382
  int nHeight;            /* Expression tree height of current sub-select */
ds@1952
  1383
#endif
ds@1952
  1384
};
ds@1952
  1385
ds@1952
  1386
#ifdef SQLITE_OMIT_VIRTUALTABLE
ds@1952
  1387
  #define IN_DECLARE_VTAB 0
ds@1952
  1388
#else
ds@1952
  1389
  #define IN_DECLARE_VTAB (pParse->declareVtab)
ds@1952
  1390
#endif
ds@1952
  1391
ds@1952
  1392
/*
ds@1952
  1393
** An instance of the following structure can be declared on a stack and used
ds@1952
  1394
** to save the Parse.zAuthContext value so that it can be restored later.
ds@1952
  1395
*/
ds@1952
  1396
struct AuthContext {
ds@1952
  1397
  const char *zAuthContext;   /* Put saved Parse.zAuthContext here */
ds@1952
  1398
  Parse *pParse;              /* The Parse structure */
ds@1952
  1399
};
ds@1952
  1400
ds@1952
  1401
/*
ds@1952
  1402
** Bitfield flags for P2 value in OP_Insert and OP_Delete
ds@1952
  1403
*/
ds@1952
  1404
#define OPFLAG_NCHANGE   1    /* Set to update db->nChange */
ds@1952
  1405
#define OPFLAG_LASTROWID 2    /* Set to update db->lastRowid */
ds@1952
  1406
#define OPFLAG_ISUPDATE  4    /* This OP_Insert is an sql UPDATE */
ds@1952
  1407
#define OPFLAG_APPEND    8    /* This is likely to be an append */
ds@1952
  1408
ds@1952
  1409
/*
ds@1952
  1410
 * Each trigger present in the database schema is stored as an instance of
ds@1952
  1411
 * struct Trigger. 
ds@1952
  1412
 *
ds@1952
  1413
 * Pointers to instances of struct Trigger are stored in two ways.
ds@1952
  1414
 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 
ds@1952
  1415
 *    database). This allows Trigger structures to be retrieved by name.
ds@1952
  1416
 * 2. All triggers associated with a single table form a linked list, using the
ds@1952
  1417
 *    pNext member of struct Trigger. A pointer to the first element of the
ds@1952
  1418
 *    linked list is stored as the "pTrigger" member of the associated
ds@1952
  1419
 *    struct Table.
ds@1952
  1420
 *
ds@1952
  1421
 * The "step_list" member points to the first element of a linked list
ds@1952
  1422
 * containing the SQL statements specified as the trigger program.
ds@1952
  1423
 */
ds@1952
  1424
struct Trigger {
ds@1952
  1425
  char *name;             /* The name of the trigger                        */
ds@1952
  1426
  char *table;            /* The table or view to which the trigger applies */
ds@1952
  1427
  u8 op;                  /* One of TK_DELETE, TK_UPDATE, TK_INSERT         */
ds@1952
  1428
  u8 tr_tm;               /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
ds@1952
  1429
  Expr *pWhen;            /* The WHEN clause of the expresion (may be NULL) */
ds@1952
  1430
  IdList *pColumns;       /* If this is an UPDATE OF <column-list> trigger,
ds@1952
  1431
                             the <column-list> is stored here */
ds@1952
  1432
  Token nameToken;        /* Token containing zName. Use during parsing only */
ds@1952
  1433
  Schema *pSchema;        /* Schema containing the trigger */
ds@1952
  1434
  Schema *pTabSchema;     /* Schema containing the table */
ds@1952
  1435
  TriggerStep *step_list; /* Link list of trigger program steps             */
ds@1952
  1436
  Trigger *pNext;         /* Next trigger associated with the table */
ds@1952
  1437
};
ds@1952
  1438
ds@1952
  1439
/*
ds@1952
  1440
** A trigger is either a BEFORE or an AFTER trigger.  The following constants
ds@1952
  1441
** determine which. 
ds@1952
  1442
**
ds@1952
  1443
** If there are multiple triggers, you might of some BEFORE and some AFTER.
ds@1952
  1444
** In that cases, the constants below can be ORed together.
ds@1952
  1445
*/
ds@1952
  1446
#define TRIGGER_BEFORE  1
ds@1952
  1447
#define TRIGGER_AFTER   2
ds@1952
  1448
ds@1952
  1449
/*
ds@1952
  1450
 * An instance of struct TriggerStep is used to store a single SQL statement
ds@1952
  1451
 * that is a part of a trigger-program. 
ds@1952
  1452
 *
ds@1952
  1453
 * Instances of struct TriggerStep are stored in a singly linked list (linked
ds@1952
  1454
 * using the "pNext" member) referenced by the "step_list" member of the 
ds@1952
  1455
 * associated struct Trigger instance. The first element of the linked list is
ds@1952
  1456
 * the first step of the trigger-program.
ds@1952
  1457
 * 
ds@1952
  1458
 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
ds@1952
  1459
 * "SELECT" statement. The meanings of the other members is determined by the 
ds@1952
  1460
 * value of "op" as follows:
ds@1952
  1461
 *
ds@1952
  1462
 * (op == TK_INSERT)
ds@1952
  1463
 * orconf    -> stores the ON CONFLICT algorithm
ds@1952
  1464
 * pSelect   -> If this is an INSERT INTO ... SELECT ... statement, then
ds@1952
  1465
 *              this stores a pointer to the SELECT statement. Otherwise NULL.
ds@1952
  1466
 * target    -> A token holding the name of the table to insert into.
ds@1952
  1467
 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
ds@1952
  1468
 *              this stores values to be inserted. Otherwise NULL.
ds@1952
  1469
 * pIdList   -> If this is an INSERT INTO ... (<column-names>) VALUES ... 
ds@1952
  1470
 *              statement, then this stores the column-names to be
ds@1952
  1471
 *              inserted into.
ds@1952
  1472
 *
ds@1952
  1473
 * (op == TK_DELETE)
ds@1952
  1474
 * target    -> A token holding the name of the table to delete from.
ds@1952
  1475
 * pWhere    -> The WHERE clause of the DELETE statement if one is specified.
ds@1952
  1476
 *              Otherwise NULL.
ds@1952
  1477
 * 
ds@1952
  1478
 * (op == TK_UPDATE)
ds@1952
  1479
 * target    -> A token holding the name of the table to update rows of.
ds@1952
  1480
 * pWhere    -> The WHERE clause of the UPDATE statement if one is specified.
ds@1952
  1481
 *              Otherwise NULL.
ds@1952
  1482
 * pExprList -> A list of the columns to update and the expressions to update
ds@1952
  1483
 *              them to. See sqlite3Update() documentation of "pChanges"
ds@1952
  1484
 *              argument.
ds@1952
  1485
 * 
ds@1952
  1486
 */
ds@1952
  1487
struct TriggerStep {
ds@1952
  1488
  int op;              /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
ds@1952
  1489
  int orconf;          /* OE_Rollback etc. */
ds@1952
  1490
  Trigger *pTrig;      /* The trigger that this step is a part of */
ds@1952
  1491
ds@1952
  1492
  Select *pSelect;     /* Valid for SELECT and sometimes 
ds@1952
  1493
                          INSERT steps (when pExprList == 0) */
ds@1952
  1494
  Token target;        /* Valid for DELETE, UPDATE, INSERT steps */
ds@1952
  1495
  Expr *pWhere;        /* Valid for DELETE, UPDATE steps */
ds@1952
  1496
  ExprList *pExprList; /* Valid for UPDATE statements and sometimes 
ds@1952
  1497
                           INSERT steps (when pSelect == 0)         */
ds@1952
  1498
  IdList *pIdList;     /* Valid for INSERT statements only */
ds@1952
  1499
  TriggerStep *pNext;  /* Next in the link-list */
ds@1952
  1500
  TriggerStep *pLast;  /* Last element in link-list. Valid for 1st elem only */
ds@1952
  1501
};
ds@1952
  1502
ds@1952
  1503
/*
ds@1952
  1504
 * An instance of struct TriggerStack stores information required during code
ds@1952
  1505
 * generation of a single trigger program. While the trigger program is being
ds@1952
  1506
 * coded, its associated TriggerStack instance is pointed to by the
ds@1952
  1507
 * "pTriggerStack" member of the Parse structure.
ds@1952
  1508
 *
ds@1952
  1509
 * The pTab member points to the table that triggers are being coded on. The 
ds@1952
  1510
 * newIdx member contains the index of the vdbe cursor that points at the temp
ds@1952
  1511
 * table that stores the new.* references. If new.* references are not valid
ds@1952
  1512
 * for the trigger being coded (for example an ON DELETE trigger), then newIdx
ds@1952
  1513
 * is set to -1. The oldIdx member is analogous to newIdx, for old.* references.
ds@1952
  1514
 *
ds@1952
  1515
 * The ON CONFLICT policy to be used for the trigger program steps is stored 
ds@1952
  1516
 * as the orconf member. If this is OE_Default, then the ON CONFLICT clause 
ds@1952
  1517
 * specified for individual triggers steps is used.
ds@1952
  1518
 *
ds@1952
  1519
 * struct TriggerStack has a "pNext" member, to allow linked lists to be
ds@1952
  1520
 * constructed. When coding nested triggers (triggers fired by other triggers)
ds@1952
  1521
 * each nested trigger stores its parent trigger's TriggerStack as the "pNext" 
ds@1952
  1522
 * pointer. Once the nested trigger has been coded, the pNext value is restored
ds@1952
  1523
 * to the pTriggerStack member of the Parse stucture and coding of the parent
ds@1952
  1524
 * trigger continues.
ds@1952
  1525
 *
ds@1952
  1526
 * Before a nested trigger is coded, the linked list pointed to by the 
ds@1952
  1527
 * pTriggerStack is scanned to ensure that the trigger is not about to be coded
ds@1952
  1528
 * recursively. If this condition is detected, the nested trigger is not coded.
ds@1952
  1529
 */
ds@1952
  1530
struct TriggerStack {
ds@1952
  1531
  Table *pTab;         /* Table that triggers are currently being coded on */
ds@1952
  1532
  int newIdx;          /* Index of vdbe cursor to "new" temp table */
ds@1952
  1533
  int oldIdx;          /* Index of vdbe cursor to "old" temp table */
ds@1952
  1534
  int orconf;          /* Current orconf policy */
ds@1952
  1535
  int ignoreJump;      /* where to jump to for a RAISE(IGNORE) */
ds@1952
  1536
  Trigger *pTrigger;   /* The trigger currently being coded */
ds@1952
  1537
  TriggerStack *pNext; /* Next trigger down on the trigger stack */
ds@1952
  1538
};
ds@1952
  1539
ds@1952
  1540
/*
ds@1952
  1541
** The following structure contains information used by the sqliteFix...
ds@1952
  1542
** routines as they walk the parse tree to make database references
ds@1952
  1543
** explicit.  
ds@1952
  1544
*/
ds@1952
  1545
typedef struct DbFixer DbFixer;
ds@1952
  1546
struct DbFixer {
ds@1952
  1547
  Parse *pParse;      /* The parsing context.  Error messages written here */
ds@1952
  1548
  const char *zDb;    /* Make sure all objects are contained in this database */
ds@1952
  1549
  const char *zType;  /* Type of the container - used for error messages */
ds@1952
  1550
  const Token *pName; /* Name of the container - used for error messages */
ds@1952
  1551
};
ds@1952
  1552
ds@1952
  1553
/*
ds@1952
  1554
** A pointer to this structure is used to communicate information
ds@1952
  1555
** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
ds@1952
  1556
*/
ds@1952
  1557
typedef struct {
ds@1952
  1558
  sqlite3 *db;        /* The database being initialized */
ds@1952
  1559
  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
ds@1952
  1560
  char **pzErrMsg;    /* Error message stored here */
ds@1952
  1561
  int rc;             /* Result code stored here */
ds@1952
  1562
} InitData;
ds@1952
  1563
ds@1952
  1564
/*
ds@1952
  1565
** Assuming zIn points to the first byte of a UTF-8 character,
ds@1952
  1566
** advance zIn to point to the first byte of the next UTF-8 character.
ds@1952
  1567
*/
ds@1952
  1568
#define SQLITE_SKIP_UTF8(zIn) {                        \
ds@1952
  1569
  if( (*(zIn++))>=0xc0 ){                              \
ds@1952
  1570
    while( (*zIn & 0xc0)==0x80 ){ zIn++; }             \
ds@1952
  1571
  }                                                    \
ds@1952
  1572
}
ds@1952
  1573
ds@1952
  1574
/*
ds@1952
  1575
** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
ds@1952
  1576
** builds) or a function call (for debugging).  If it is a function call,
ds@1952
  1577
** it allows the operator to set a breakpoint at the spot where database
ds@1952
  1578
** corruption is first detected.
ds@1952
  1579
*/
ds@1952
  1580
#ifdef SQLITE_DEBUG
ds@1952
  1581
  int sqlite3Corrupt(void);
ds@1952
  1582
# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
ds@1952
  1583
#else
ds@1952
  1584
# define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
ds@1952
  1585
#endif
ds@1952
  1586
ds@1952
  1587
/*
ds@1952
  1588
** Internal function prototypes
ds@1952
  1589
*/
ds@1952
  1590
int sqlite3StrICmp(const char *, const char *);
ds@1952
  1591
int sqlite3StrNICmp(const char *, const char *, int);
ds@1952
  1592
int sqlite3IsNumber(const char*, int*, u8);
ds@1952
  1593
ds@1952
  1594
void *sqlite3MallocZero(unsigned);
ds@1952
  1595
void *sqlite3DbMallocZero(sqlite3*, unsigned);
ds@1952
  1596
void *sqlite3DbMallocRaw(sqlite3*, unsigned);
ds@1952
  1597
char *sqlite3StrDup(const char*);
ds@1952
  1598
char *sqlite3StrNDup(const char*, int);
ds@1952
  1599
char *sqlite3DbStrDup(sqlite3*,const char*);
ds@1952
  1600
char *sqlite3DbStrNDup(sqlite3*,const char*, int);
ds@1952
  1601
void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
ds@1952
  1602
void *sqlite3DbRealloc(sqlite3 *, void *, int);
ds@1952
  1603
ds@1952
  1604
char *sqlite3MPrintf(sqlite3*,const char*, ...);
ds@1952
  1605
char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
ds@1952
  1606
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
ds@1952
  1607
  void sqlite3DebugPrintf(const char*, ...);
ds@1952
  1608
  void *sqlite3TextToPtr(const char*);
ds@1952
  1609
#endif
ds@1952
  1610
void sqlite3SetString(char **, ...);
ds@1952
  1611
void sqlite3ErrorMsg(Parse*, const char*, ...);
ds@1952
  1612
void sqlite3ErrorClear(Parse*);
ds@1952
  1613
void sqlite3Dequote(char*);
ds@1952
  1614
void sqlite3DequoteExpr(sqlite3*, Expr*);
ds@1952
  1615
int sqlite3KeywordCode(const unsigned char*, int);
ds@1952
  1616
int sqlite3RunParser(Parse*, const char*, char **);
ds@1952
  1617
void sqlite3FinishCoding(Parse*);
ds@1952
  1618
Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*);
ds@1952
  1619
Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
ds@1952
  1620
Expr *sqlite3RegisterExpr(Parse*,Token*);
ds@1952
  1621
Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
ds@1952
  1622
void sqlite3ExprSpan(Expr*,Token*,Token*);
ds@1952
  1623
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
ds@1952
  1624
void sqlite3ExprAssignVarNumber(Parse*, Expr*);
ds@1952
  1625
void sqlite3ExprDelete(Expr*);
ds@1952
  1626
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
ds@1952
  1627
void sqlite3ExprListDelete(ExprList*);
ds@1952
  1628
int sqlite3Init(sqlite3*, char**);
ds@1952
  1629
int sqlite3InitCallback(void*, int, char**, char**);
ds@1952
  1630
void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
ds@1952
  1631
void sqlite3ResetInternalSchema(sqlite3*, int);
ds@1952
  1632
void sqlite3BeginParse(Parse*,int);
ds@1952
  1633
void sqlite3CommitInternalChanges(sqlite3*);
ds@1952
  1634
Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
ds@1952
  1635
void sqlite3OpenMasterTable(Parse *, int);
ds@1952
  1636
void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
ds@1952
  1637
void sqlite3AddColumn(Parse*,Token*);
ds@1952
  1638
void sqlite3AddNotNull(Parse*, int);
ds@1952
  1639
void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
ds@1952
  1640
void sqlite3AddCheckConstraint(Parse*, Expr*);
ds@1952
  1641
void sqlite3AddColumnType(Parse*,Token*);
ds@1952
  1642
void sqlite3AddDefaultValue(Parse*,Expr*);
ds@1952
  1643
void sqlite3AddCollateType(Parse*, const char*, int);
ds@1952
  1644
void sqlite3EndTable(Parse*,Token*,Token*,Select*);
ds@1952
  1645
ds@1952
  1646
void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
ds@1952
  1647
ds@1952
  1648
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
ds@1952
  1649
  int sqlite3ViewGetColumnNames(Parse*,Table*);
ds@1952
  1650
#else
ds@1952
  1651
# define sqlite3ViewGetColumnNames(A,B) 0
ds@1952
  1652
#endif
ds@1952
  1653
ds@1952
  1654
void sqlite3DropTable(Parse*, SrcList*, int, int);
ds@1952
  1655
void sqlite3DeleteTable(Table*);
ds@1952
  1656
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
ds@1952
  1657
void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*);
ds@1952
  1658
IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
ds@1952
  1659
int sqlite3IdListIndex(IdList*,const char*);
ds@1952
  1660
SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
ds@1952
  1661
SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*,
ds@1952
  1662
                                      Select*, Expr*, IdList*);
ds@1952
  1663
void sqlite3SrcListShiftJoinType(SrcList*);
ds@1952
  1664
void sqlite3SrcListAssignCursors(Parse*, SrcList*);
ds@1952
  1665
void sqlite3IdListDelete(IdList*);
ds@1952
  1666
void sqlite3SrcListDelete(SrcList*);
ds@1952
  1667
void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
ds@1952
  1668
                        Token*, int, int);
ds@1952
  1669
void sqlite3DropIndex(Parse*, SrcList*, int);
ds@1952
  1670
int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
ds@1952
  1671
Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
ds@1952
  1672
                         Expr*,ExprList*,int,Expr*,Expr*);
ds@1952
  1673
void sqlite3SelectDelete(Select*);
ds@1952
  1674
Table *sqlite3SrcListLookup(Parse*, SrcList*);
ds@1952
  1675
int sqlite3IsReadOnly(Parse*, Table*, int);
ds@1952
  1676
void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
ds@1952
  1677
void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
ds@1952
  1678
void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
ds@1952
  1679
WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
ds@1952
  1680
void sqlite3WhereEnd(WhereInfo*);
ds@1952
  1681
void sqlite3ExprCodeGetColumn(Vdbe*, Table*, int, int);
ds@1952
  1682
void sqlite3ExprCode(Parse*, Expr*);
ds@1952
  1683
void sqlite3ExprCodeAndCache(Parse*, Expr*);
ds@1952
  1684
int sqlite3ExprCodeExprList(Parse*, ExprList*);
ds@1952
  1685
void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
ds@1952
  1686
void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
ds@1952
  1687
Table *sqlite3FindTable(sqlite3*,const char*, const char*);
ds@1952
  1688
Table *sqlite3LocateTable(Parse*,const char*, const char*);
ds@1952
  1689
Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
ds@1952
  1690
void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
ds@1952
  1691
void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
ds@1952
  1692
void sqlite3Vacuum(Parse*);
ds@1952
  1693
int sqlite3RunVacuum(char**, sqlite3*);
ds@1952
  1694
char *sqlite3NameFromToken(sqlite3*, Token*);
ds@1952
  1695
int sqlite3ExprCompare(Expr*, Expr*);
ds@1952
  1696
int sqlite3ExprResolveNames(NameContext *, Expr *);
ds@1952
  1697
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
ds@1952
  1698
int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
ds@1952
  1699
Vdbe *sqlite3GetVdbe(Parse*);
ds@1952
  1700
Expr *sqlite3CreateIdExpr(Parse *, const char*);
ds@1952
  1701
void sqlite3Randomness(int, void*);
ds@1952
  1702
void sqlite3RollbackAll(sqlite3*);
ds@1952
  1703
void sqlite3CodeVerifySchema(Parse*, int);
ds@1952
  1704
void sqlite3BeginTransaction(Parse*, int);
ds@1952
  1705
void sqlite3CommitTransaction(Parse*);
ds@1952
  1706
void sqlite3RollbackTransaction(Parse*);
ds@1952
  1707
int sqlite3ExprIsConstant(Expr*);
ds@1952
  1708
int sqlite3ExprIsConstantNotJoin(Expr*);
ds@1952
  1709
int sqlite3ExprIsConstantOrFunction(Expr*);
ds@1952
  1710
int sqlite3ExprIsInteger(Expr*, int*);
ds@1952
  1711
int sqlite3IsRowid(const char*);
ds@1952
  1712
void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
ds@1952
  1713
void sqlite3GenerateRowIndexDelete(Vdbe*, Table*, int, char*);
ds@1952
  1714
void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
ds@1952
  1715
void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
ds@1952
  1716
void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int, int);
ds@1952
  1717
void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
ds@1952
  1718
void sqlite3BeginWriteOperation(Parse*, int, int);
ds@1952
  1719
Expr *sqlite3ExprDup(sqlite3*,Expr*);
ds@1952
  1720
void sqlite3TokenCopy(sqlite3*,Token*, Token*);
ds@1952
  1721
ExprList *sqlite3ExprListDup(sqlite3*,ExprList*);
ds@1952
  1722
SrcList *sqlite3SrcListDup(sqlite3*,SrcList*);
ds@1952
  1723
IdList *sqlite3IdListDup(sqlite3*,IdList*);
ds@1952
  1724
Select *sqlite3SelectDup(sqlite3*,Select*);
ds@1952
  1725
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
ds@1952
  1726
void sqlite3RegisterBuiltinFunctions(sqlite3*);
ds@1952
  1727
void sqlite3RegisterDateTimeFunctions(sqlite3*);
ds@1952
  1728
int sqlite3SafetyOn(sqlite3*);
ds@1952
  1729
int sqlite3SafetyOff(sqlite3*);
ds@1952
  1730
int sqlite3SafetyCheck(sqlite3*);
ds@1952
  1731
void sqlite3ChangeCookie(sqlite3*, Vdbe*, int);
ds@1952
  1732
ds@1952
  1733
#ifndef SQLITE_OMIT_TRIGGER
ds@1952
  1734
  void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
ds@1952
  1735
                           Expr*,int, int);
ds@1952
  1736
  void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
ds@1952
  1737
  void sqlite3DropTrigger(Parse*, SrcList*, int);
ds@1952
  1738
  void sqlite3DropTriggerPtr(Parse*, Trigger*);
ds@1952
  1739
  int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
ds@1952
  1740
  int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, 
ds@1952
  1741
                           int, int);
ds@1952
  1742
  void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
ds@1952
  1743
  void sqlite3DeleteTriggerStep(TriggerStep*);
ds@1952
  1744
  TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
ds@1952
  1745
  TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
ds@1952
  1746
                                        ExprList*,Select*,int);
ds@1952
  1747
  TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int);
ds@1952
  1748
  TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
ds@1952
  1749
  void sqlite3DeleteTrigger(Trigger*);
ds@1952
  1750
  void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
ds@1952
  1751
#else
ds@1952
  1752
# define sqlite3TriggersExist(A,B,C,D,E,F) 0
ds@1952
  1753
# define sqlite3DeleteTrigger(A)
ds@1952
  1754
# define sqlite3DropTriggerPtr(A,B)
ds@1952
  1755
# define sqlite3UnlinkAndDeleteTrigger(A,B,C)
ds@1952
  1756
# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 0
ds@1952
  1757
#endif
ds@1952
  1758
ds@1952
  1759
int sqlite3JoinType(Parse*, Token*, Token*, Token*);
ds@1952
  1760
void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
ds@1952
  1761
void sqlite3DeferForeignKey(Parse*, int);
ds@1952
  1762
#ifndef SQLITE_OMIT_AUTHORIZATION
ds@1952
  1763
  void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*);
ds@1952
  1764
  int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
ds@1952
  1765
  void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
ds@1952
  1766
  void sqlite3AuthContextPop(AuthContext*);
ds@1952
  1767
#else
ds@1952
  1768
# define sqlite3AuthRead(a,b,c)
ds@1952
  1769
# define sqlite3AuthCheck(a,b,c,d,e)    SQLITE_OK
ds@1952
  1770
# define sqlite3AuthContextPush(a,b,c)
ds@1952
  1771
# define sqlite3AuthContextPop(a)  ((void)(a))
ds@1952
  1772
#endif
ds@1952
  1773
void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
ds@1952
  1774
void sqlite3Detach(Parse*, Expr*);
ds@1952
  1775
int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
ds@1952
  1776
                       int omitJournal, int nCache, int flags, Btree **ppBtree);
ds@1952
  1777
int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
ds@1952
  1778
int sqlite3FixSrcList(DbFixer*, SrcList*);
ds@1952
  1779
int sqlite3FixSelect(DbFixer*, Select*);
ds@1952
  1780
int sqlite3FixExpr(DbFixer*, Expr*);
ds@1952
  1781
int sqlite3FixExprList(DbFixer*, ExprList*);
ds@1952
  1782
int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
ds@1952
  1783
int sqlite3AtoF(const char *z, double*);
ds@1952
  1784
char *sqlite3_snprintf(int,char*,const char*,...);
ds@1952
  1785
int sqlite3GetInt32(const char *, int*);
ds@1952
  1786
int sqlite3FitsIn64Bits(const char *);
ds@1952
  1787
int sqlite3Utf16ByteLen(const void *pData, int nChar);
ds@1952
  1788
int sqlite3Utf8CharLen(const char *pData, int nByte);
ds@1952
  1789
int sqlite3Utf8Read(const u8*, const u8*, const u8**);
ds@1952
  1790
int sqlite3PutVarint(unsigned char *, u64);
ds@1952
  1791
int sqlite3GetVarint(const unsigned char *, u64 *);
ds@1952
  1792
int sqlite3GetVarint32(const unsigned char *, u32 *);
ds@1952
  1793
int sqlite3VarintLen(u64 v);
ds@1952
  1794
void sqlite3IndexAffinityStr(Vdbe *, Index *);
ds@1952
  1795
void sqlite3TableAffinityStr(Vdbe *, Table *);
ds@1952
  1796
char sqlite3CompareAffinity(Expr *pExpr, char aff2);
ds@1952
  1797
int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
ds@1952
  1798
char sqlite3ExprAffinity(Expr *pExpr);
ds@1952
  1799
int sqlite3Atoi64(const char*, i64*);
ds@1952
  1800
void sqlite3Error(sqlite3*, int, const char*,...);
ds@1952
  1801
void *sqlite3HexToBlob(sqlite3*, const char *z);
ds@1952
  1802
int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
ds@1952
  1803
const char *sqlite3ErrStr(int);
ds@1952
  1804
int sqlite3ReadSchema(Parse *pParse);
ds@1952
  1805
CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
ds@1952
  1806
CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
ds@1952
  1807
CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
ds@1952
  1808
Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
ds@1952
  1809
int sqlite3CheckCollSeq(Parse *, CollSeq *);
ds@1952
  1810
int sqlite3CheckObjectName(Parse *, const char *);
ds@1952
  1811
void sqlite3VdbeSetChanges(sqlite3 *, int);
ds@1952
  1812
ds@1952
  1813
const void *sqlite3ValueText(sqlite3_value*, u8);
ds@1952
  1814
int sqlite3ValueBytes(sqlite3_value*, u8);
ds@1952
  1815
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, 
ds@1952
  1816
                        void(*)(void*));
ds@1952
  1817
void sqlite3ValueFree(sqlite3_value*);
ds@1952
  1818
sqlite3_value *sqlite3ValueNew(sqlite3 *);
ds@1952
  1819
char *sqlite3Utf16to8(sqlite3 *, const void*, int);
ds@1952
  1820
int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
ds@1952
  1821
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
ds@1952
  1822
#ifndef SQLITE_AMALGAMATION
ds@1952
  1823
extern const unsigned char sqlite3UpperToLower[];
ds@1952
  1824
#endif
ds@1952
  1825
void sqlite3RootPageMoved(Db*, int, int);
ds@1952
  1826
void sqlite3Reindex(Parse*, Token*, Token*);
ds@1952
  1827
void sqlite3AlterFunctions(sqlite3*);
ds@1952
  1828
void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
ds@1952
  1829
int sqlite3GetToken(const unsigned char *, int *);
ds@1952
  1830
void sqlite3NestedParse(Parse*, const char*, ...);
ds@1952
  1831
void sqlite3ExpirePreparedStatements(sqlite3*);
ds@1952
  1832
void sqlite3CodeSubselect(Parse *, Expr *);
ds@1952
  1833
int sqlite3SelectResolve(Parse *, Select *, NameContext *);
ds@1952
  1834
void sqlite3ColumnDefault(Vdbe *, Table *, int);
ds@1952
  1835
void sqlite3AlterFinishAddColumn(Parse *, Token *);
ds@1952
  1836
void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
ds@1952
  1837
CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
ds@1952
  1838
char sqlite3AffinityType(const Token*);
ds@1952
  1839
void sqlite3Analyze(Parse*, Token*, Token*);
ds@1952
  1840
int sqlite3InvokeBusyHandler(BusyHandler*);
ds@1952
  1841
int sqlite3FindDb(sqlite3*, Token*);
ds@1952
  1842
int sqlite3AnalysisLoad(sqlite3*,int iDB);
ds@1952
  1843
void sqlite3DefaultRowEst(Index*);
ds@1952
  1844
void sqlite3RegisterLikeFunctions(sqlite3*, int);
ds@1952
  1845
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
ds@1952
  1846
void sqlite3AttachFunctions(sqlite3 *);
ds@1952
  1847
void sqlite3MinimumFileFormat(Parse*, int, int);
ds@1952
  1848
void sqlite3SchemaFree(void *);
ds@1952
  1849
Schema *sqlite3SchemaGet(sqlite3 *, Btree *);
ds@1952
  1850
int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
ds@1952
  1851
KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
ds@1952
  1852
int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 
ds@1952
  1853
  void (*)(sqlite3_context*,int,sqlite3_value **),
ds@1952
  1854
  void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
ds@1952
  1855
int sqlite3ApiExit(sqlite3 *db, int);
ds@1952
  1856
void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
ds@1952
  1857
int sqlite3OpenTempDatabase(Parse *);
ds@1952
  1858
ds@1952
  1859
ds@1952
  1860
/*
ds@1952
  1861
** The interface to the LEMON-generated parser
ds@1952
  1862
*/
ds@1952
  1863
void *sqlite3ParserAlloc(void*(*)(size_t));
ds@1952
  1864
void sqlite3ParserFree(void*, void(*)(void*));
ds@1952
  1865
void sqlite3Parser(void*, int, Token, Parse*);
ds@1952
  1866
ds@1952
  1867
#ifndef SQLITE_OMIT_LOAD_EXTENSION
ds@1952
  1868
  void sqlite3CloseExtensions(sqlite3*);
ds@1952
  1869
  int sqlite3AutoLoadExtensions(sqlite3*);
ds@1952
  1870
#else
ds@1952
  1871
# define sqlite3CloseExtensions(X)
ds@1952
  1872
# define sqlite3AutoLoadExtensions(X)  SQLITE_OK
ds@1952
  1873
#endif
ds@1952
  1874
ds@1952
  1875
#ifndef SQLITE_OMIT_SHARED_CACHE
ds@1952
  1876
  void sqlite3TableLock(Parse *, int, int, u8, const char *);
ds@1952
  1877
#else
ds@1952
  1878
  #define sqlite3TableLock(v,w,x,y,z)
ds@1952
  1879
#endif
ds@1952
  1880
ds@1952
  1881
#ifdef SQLITE_TEST
ds@1952
  1882
  int sqlite3Utf8To8(unsigned char*);
ds@1952
  1883
#endif
ds@1952
  1884
ds@1952
  1885
/*
ds@1952
  1886
** The MallocDisallow() and MallocAllow() routines are like asserts.
ds@1952
  1887
** Call them around a section of code that you do not expect to do
ds@1952
  1888
** any memory allocation.
ds@1952
  1889
*/
ds@1952
  1890
#ifdef SQLITE_MEMDEBUG
ds@1952
  1891
  void sqlite3MallocDisallow(void);
ds@1952
  1892
  void sqlite3MallocAllow(void);
ds@1952
  1893
  void sqlite3MallocBenignFailure(int);
ds@1952
  1894
  void sqlite3MallocEnterBenignBlock(int isBenign);
ds@1952
  1895
  void sqlite3MallocLeaveBenignBlock();
ds@1952
  1896
#else
ds@1952
  1897
# define sqlite3MallocDisallow()
ds@1952
  1898
# define sqlite3MallocAllow()
ds@1952
  1899
# define sqlite3MallocBenignFailure(x)
ds@1952
  1900
# define sqlite3MallocEnterBenignBlock(x);
ds@1952
  1901
# define sqlite3MallocLeaveBenignBlock();
ds@1952
  1902
#endif
ds@1952
  1903
ds@1952
  1904
ds@1952
  1905
#ifdef SQLITE_OMIT_VIRTUALTABLE
ds@1952
  1906
#  define sqlite3VtabClear(X)
ds@1952
  1907
#  define sqlite3VtabSync(X,Y) (Y)
ds@1952
  1908
#  define sqlite3VtabRollback(X)
ds@1952
  1909
#  define sqlite3VtabCommit(X)
ds@1952
  1910
#else
ds@1952
  1911
   void sqlite3VtabClear(Table*);
ds@1952
  1912
   int sqlite3VtabSync(sqlite3 *db, int rc);
ds@1952
  1913
   int sqlite3VtabRollback(sqlite3 *db);
ds@1952
  1914
   int sqlite3VtabCommit(sqlite3 *db);
ds@1952
  1915
#endif
ds@1952
  1916
void sqlite3VtabLock(sqlite3_vtab*);
ds@1952
  1917
void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*);
ds@1952
  1918
void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
ds@1952
  1919
void sqlite3VtabFinishParse(Parse*, Token*);
ds@1952
  1920
void sqlite3VtabArgInit(Parse*);
ds@1952
  1921
void sqlite3VtabArgExtend(Parse*, Token*);
ds@1952
  1922
int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
ds@1952
  1923
int sqlite3VtabCallConnect(Parse*, Table*);
ds@1952
  1924
int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
ds@1952
  1925
int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
ds@1952
  1926
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
ds@1952
  1927
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
ds@1952
  1928
int sqlite3Reprepare(Vdbe*);
ds@1952
  1929
void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
ds@1952
  1930
CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
ds@1952
  1931
ds@1952
  1932
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
ds@1952
  1933
  int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
ds@1952
  1934
  int sqlite3JournalSize(sqlite3_vfs *);
ds@1952
  1935
  int sqlite3JournalCreate(sqlite3_file *);
ds@1952
  1936
#else
ds@1952
  1937
  #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile)
ds@1952
  1938
#endif
ds@1952
  1939
ds@1952
  1940
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
ds@1952
  1941
  void sqlite3ExprSetHeight(Expr *);
ds@1952
  1942
  int sqlite3SelectExprHeight(Select *);
ds@1952
  1943
#else
ds@1952
  1944
  #define sqlite3ExprSetHeight(x)
ds@1952
  1945
#endif
ds@1952
  1946
ds@1952
  1947
u32 sqlite3Get4byte(const u8*);
ds@1952
  1948
void sqlite3Put4byte(u8*, u32);
ds@1952
  1949
ds@1952
  1950
#ifdef SQLITE_SSE
ds@1952
  1951
#include "sseInt.h"
ds@1952
  1952
#endif
ds@1952
  1953
ds@1952
  1954
#ifdef SQLITE_DEBUG
ds@1952
  1955
  void sqlite3ParserTrace(FILE*, char *);
ds@1952
  1956
#endif
ds@1952
  1957
ds@1952
  1958
/*
ds@1952
  1959
** If the SQLITE_ENABLE IOTRACE exists then the global variable
ds@1952
  1960
** sqlite3_io_trace is a pointer to a printf-like routine used to
ds@1952
  1961
** print I/O tracing messages. 
ds@1952
  1962
*/
ds@1952
  1963
#ifdef SQLITE_ENABLE_IOTRACE
ds@1952
  1964
# define IOTRACE(A)  if( sqlite3_io_trace ){ sqlite3_io_trace A; }
ds@1952
  1965
  void sqlite3VdbeIOTraceSql(Vdbe*);
ds@1952
  1966
#else
ds@1952
  1967
# define IOTRACE(A)
ds@1952
  1968
# define sqlite3VdbeIOTraceSql(X)
ds@1952
  1969
#endif
ds@1952
  1970
SQLITE_EXTERN void (*sqlite3_io_trace)(const char*,...);
ds@1952
  1971
ds@1952
  1972
#endif