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