diff options
Diffstat (limited to 'ext/pdo_sqlite/sqlite/src/sqliteInt.h')
| -rw-r--r-- | ext/pdo_sqlite/sqlite/src/sqliteInt.h | 756 |
1 files changed, 484 insertions, 272 deletions
diff --git a/ext/pdo_sqlite/sqlite/src/sqliteInt.h b/ext/pdo_sqlite/sqlite/src/sqliteInt.h index 58e21c4f3c..4c9b98acc1 100644 --- a/ext/pdo_sqlite/sqlite/src/sqliteInt.h +++ b/ext/pdo_sqlite/sqlite/src/sqliteInt.h @@ -17,28 +17,29 @@ #define _SQLITEINT_H_ /* -** Extra interface definitions for those who need them -*/ -#ifdef SQLITE_EXTRA -# include "sqliteExtra.h" +** The macro unlikely() is a hint that surrounds a boolean +** expression that is usually false. Macro likely() surrounds +** a boolean expression that is usually true. GCC is able to +** use these hints to generate better code, sometimes. +*/ +#if defined(__GNUC__) && 0 +# define likely(X) __builtin_expect((X),1) +# define unlikely(X) __builtin_expect((X),0) +#else +# define likely(X) !!(X) +# define unlikely(X) !!(X) #endif -/* -** Many people are failing to set -DNDEBUG=1 when compiling SQLite. -** Setting NDEBUG makes the code smaller and run faster. So the following -** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 -** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out -** feature. -*/ -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) -# define NDEBUG 1 -#endif /* ** These #defines should enable >2GB file support on Posix if the ** underlying operating system supports it. If the OS lacks ** large file support, or if the OS is windows, these should be no-ops. ** +** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any +** system #includes. Hence, this block of code must be the very first +** code in all source files. +** ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch ** on the compiler command line. This is necessary if you are compiling ** on a recent machine (ex: RedHat 7.2) but you want your code to work @@ -57,6 +58,97 @@ # define _LARGEFILE_SOURCE 1 #endif + +#include "sqliteLimit.h" + +/* +** For testing purposes, the various size limit constants are really +** variables that we can modify in the testfixture. +*/ +#ifdef SQLITE_TEST + #undef SQLITE_MAX_LENGTH + #undef SQLITE_MAX_COLUMN + #undef SQLITE_MAX_SQL_LENGTH + #undef SQLITE_MAX_EXPR_DEPTH + #undef SQLITE_MAX_COMPOUND_SELECT + #undef SQLITE_MAX_VDBE_OP + #undef SQLITE_MAX_FUNCTION_ARG + #undef SQLITE_MAX_VARIABLE_NUMBER + #undef SQLITE_MAX_PAGE_SIZE + #undef SQLITE_MAX_PAGE_COUNT + #undef SQLITE_MAX_LIKE_PATTERN_LENGTH + + #define SQLITE_MAX_LENGTH sqlite3MAX_LENGTH + #define SQLITE_MAX_COLUMN sqlite3MAX_COLUMN + #define SQLITE_MAX_SQL_LENGTH sqlite3MAX_SQL_LENGTH + #define SQLITE_MAX_EXPR_DEPTH sqlite3MAX_EXPR_DEPTH + #define SQLITE_MAX_COMPOUND_SELECT sqlite3MAX_COMPOUND_SELECT + #define SQLITE_MAX_VDBE_OP sqlite3MAX_VDBE_OP + #define SQLITE_MAX_FUNCTION_ARG sqlite3MAX_FUNCTION_ARG + #define SQLITE_MAX_VARIABLE_NUMBER sqlite3MAX_VARIABLE_NUMBER + #define SQLITE_MAX_PAGE_SIZE sqlite3MAX_PAGE_SIZE + #define SQLITE_MAX_PAGE_COUNT sqlite3MAX_PAGE_COUNT + #define SQLITE_MAX_LIKE_PATTERN_LENGTH sqlite3MAX_LIKE_PATTERN_LENGTH + + extern int sqlite3MAX_LENGTH; + extern int sqlite3MAX_COLUMN; + extern int sqlite3MAX_SQL_LENGTH; + extern int sqlite3MAX_EXPR_DEPTH; + extern int sqlite3MAX_COMPOUND_SELECT; + extern int sqlite3MAX_VDBE_OP; + extern int sqlite3MAX_FUNCTION_ARG; + extern int sqlite3MAX_VARIABLE_NUMBER; + extern int sqlite3MAX_PAGE_SIZE; + extern int sqlite3MAX_PAGE_COUNT; + extern int sqlite3MAX_LIKE_PATTERN_LENGTH; +#endif + + +/* +** The SQLITE_THREADSAFE macro must be defined as either 0 or 1. +** Older versions of SQLite used an optional THREADSAFE macro. +** We support that for legacy +*/ +#if !defined(SQLITE_THREADSAFE) +#if defined(THREADSAFE) +# define SQLITE_THREADSAFE THREADSAFE +#else +# define SQLITE_THREADSAFE 1 +#endif +#endif + +/* +** We need to define _XOPEN_SOURCE as follows in order to enable +** recursive mutexes on most unix systems. But Mac OS X is different. +** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, +** so it is omitted there. See ticket #2673. +** +** Later we learn that _XOPEN_SOURCE is poorly or incorrectly +** implemented on some systems. So we avoid defining it at all +** if it is already defined or if it is unneeded because we are +** not doing a threadsafe build. Ticket #2681. +** +** See also ticket #2741. +*/ +#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE +# define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ +#endif + +#if defined(SQLITE_TCL) || defined(TCLSH) +# include <tcl.h> +#endif + +/* +** Many people are failing to set -DNDEBUG=1 when compiling SQLite. +** Setting NDEBUG makes the code smaller and run faster. So the following +** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 +** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out +** feature. +*/ +#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) +# define NDEBUG 1 +#endif + #include "sqlite3.h" #include "hash.h" #include "parse.h" @@ -66,6 +158,8 @@ #include <assert.h> #include <stddef.h> +#define sqlite3_isnan(X) ((X)!=(X)) + /* ** If compiling for a processor that lacks floating point support, ** substitute integer for floating-point @@ -78,30 +172,13 @@ # endif # define SQLITE_OMIT_DATETIME_FUNCS 1 # define SQLITE_OMIT_TRACE 1 +# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT #endif #ifndef SQLITE_BIG_DBL # define SQLITE_BIG_DBL (1e99) #endif /* -** The maximum number of in-memory pages to use for the main database -** table and for temporary tables. Internally, the MAX_PAGES and -** TEMP_PAGES macros are used. To override the default values at -** compilation time, the SQLITE_DEFAULT_CACHE_SIZE and -** SQLITE_DEFAULT_TEMP_CACHE_SIZE macros should be set. -*/ -#ifdef SQLITE_DEFAULT_CACHE_SIZE -# define MAX_PAGES SQLITE_DEFAULT_CACHE_SIZE -#else -# define MAX_PAGES 2000 -#endif -#ifdef SQLITE_DEFAULT_TEMP_CACHE_SIZE -# define TEMP_PAGES SQLITE_DEFAULT_TEMP_CACHE_SIZE -#else -# define TEMP_PAGES 500 -#endif - -/* ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 ** afterward. Having this macro allows us to cause the C compiler ** to omit code used by TEMP tables without messy #ifndef statements. @@ -127,20 +204,6 @@ #define NULL_DISTINCT_FOR_UNIQUE 1 /* -** The maximum number of attached databases. This must be at least 2 -** in order to support the main database file (0) and the file used to -** hold temporary tables (1). And it must be less than 32 because -** we use a bitmask of databases with a u32 in places (for example -** the Parse.cookieMask field). -*/ -#define MAX_ATTACHED 10 - -/* -** The maximum value of a ?nnn wildcard that the parser will accept. -*/ -#define SQLITE_MAX_VARIABLE_NUMBER 999 - -/* ** The "file format" number is an integer that is incremented whenever ** the VDBE-level file format changes. The following macros define the ** the default file format for new databases and the maximum file format @@ -214,9 +277,20 @@ typedef UINT8_TYPE i8; /* 1-byte signed integer */ ** Macros to determine whether the machine is big or little endian, ** evaluated at runtime. */ +#ifdef SQLITE_AMALGAMATION +const int sqlite3One; +#else extern const int sqlite3one; -#define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) -#define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) +#endif +#if defined(i386) || defined(__i386__) || defined(_M_IX86) +# define SQLITE_BIGENDIAN 0 +# define SQLITE_LITTLEENDIAN 1 +# define SQLITE_UTF16NATIVE SQLITE_UTF16LE +#else +# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) +# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) +# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) +#endif /* ** An instance of the following structure is used to store the busy-handler @@ -235,74 +309,6 @@ struct BusyHandler { }; /* -** Defer sourcing vdbe.h and btree.h until after the "u8" and -** "BusyHandler typedefs. -*/ -#include "vdbe.h" -#include "btree.h" -#include "pager.h" - -#ifdef SQLITE_MEMDEBUG -/* -** The following global variables are used for testing and debugging -** only. They only work if SQLITE_MEMDEBUG is defined. -*/ -extern int sqlite3_nMalloc; /* Number of sqliteMalloc() calls */ -extern int sqlite3_nFree; /* Number of sqliteFree() calls */ -extern int sqlite3_iMallocFail; /* Fail sqliteMalloc() after this many calls */ -extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */ - -extern void *sqlite3_pFirst; /* Pointer to linked list of allocations */ -extern int sqlite3_nMaxAlloc; /* High water mark of ThreadData.nAlloc */ -extern int sqlite3_mallocDisallowed; /* assert() in sqlite3Malloc() if set */ -extern int sqlite3_isFail; /* True if all malloc calls should fail */ -extern const char *sqlite3_zFile; /* Filename to associate debug info with */ -extern int sqlite3_iLine; /* Line number for debug info */ - -#define ENTER_MALLOC (sqlite3_zFile = __FILE__, sqlite3_iLine = __LINE__) -#define sqliteMalloc(x) (ENTER_MALLOC, sqlite3Malloc(x,1)) -#define sqliteMallocRaw(x) (ENTER_MALLOC, sqlite3MallocRaw(x,1)) -#define sqliteRealloc(x,y) (ENTER_MALLOC, sqlite3Realloc(x,y)) -#define sqliteStrDup(x) (ENTER_MALLOC, sqlite3StrDup(x)) -#define sqliteStrNDup(x,y) (ENTER_MALLOC, sqlite3StrNDup(x,y)) -#define sqliteReallocOrFree(x,y) (ENTER_MALLOC, sqlite3ReallocOrFree(x,y)) - -#else - -#define ENTER_MALLOC 0 -#define sqliteMalloc(x) sqlite3Malloc(x,1) -#define sqliteMallocRaw(x) sqlite3MallocRaw(x,1) -#define sqliteRealloc(x,y) sqlite3Realloc(x,y) -#define sqliteStrDup(x) sqlite3StrDup(x) -#define sqliteStrNDup(x,y) sqlite3StrNDup(x,y) -#define sqliteReallocOrFree(x,y) sqlite3ReallocOrFree(x,y) - -#endif - -#define sqliteFree(x) sqlite3FreeX(x) -#define sqliteAllocSize(x) sqlite3AllocSize(x) - - -/* -** An instance of this structure might be allocated to store information -** specific to a single thread. -*/ -struct ThreadData { - int dummy; /* So that this structure is never empty */ - -#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT - int nSoftHeapLimit; /* Suggested max mem allocation. No limit if <0 */ - int nAlloc; /* Number of bytes currently allocated */ - Pager *pPager; /* Linked list of all pagers in this thread */ -#endif - -#ifndef SQLITE_OMIT_SHARED_CACHE - u8 useSharedData; /* True if shared pagers and schemas are enabled */ - BtShared *pBtree; /* Linked list of all currently open BTrees */ -#endif -}; - -/* ** Name of the master database table. The master database table ** is a special table that holds the names and attributes of all ** user tables and indices. @@ -348,7 +354,7 @@ typedef struct NameContext NameContext; typedef struct Parse Parse; typedef struct Select Select; typedef struct SrcList SrcList; -typedef struct ThreadData ThreadData; +typedef struct StrAccum StrAccum; typedef struct Table Table; typedef struct TableLock TableLock; typedef struct Token Token; @@ -359,6 +365,18 @@ typedef struct WhereInfo WhereInfo; typedef struct WhereLevel WhereLevel; /* +** Defer sourcing vdbe.h and btree.h until after the "u8" and +** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque +** pointer types (i.e. FuncDef) defined above. +*/ +#include "btree.h" +#include "vdbe.h" +#include "pager.h" + +#include "os.h" +#include "mutex.h" + +/* ** Each database file to be accessed by the system is an instance ** of the following structure. There are normally two of these structures ** in the sqlite.aDb[] array. aDb[0] is the main database file and @@ -377,6 +395,14 @@ struct Db { /* ** An instance of the following structure stores a database schema. +** +** If there are no virtual tables configured in this schema, the +** Schema.db variable is set to NULL. After the first virtual table +** has been added, it is set to point to the database connection +** used to create the connection. Once a virtual table has been +** added to the Schema structure and the Schema.db variable populated, +** only that database connection may use the Schema to prepare +** statements. */ struct Schema { int schema_cookie; /* Database schema version number for this file */ @@ -389,6 +415,9 @@ struct Schema { u8 enc; /* Text encoding used by this database */ u16 flags; /* Flags associated with this schema */ int cache_size; /* Number of pages to use in the cache */ +#ifndef SQLITE_OMIT_VIRTUALTABLE + sqlite3 *db; /* "Owner" connection. See comment above */ +#endif }; /* @@ -414,7 +443,6 @@ struct Schema { #define DB_UnresetViews 0x0002 /* Some views have defined column names */ #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ -#define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) /* ** Each database is an instance of the following structure. @@ -443,12 +471,17 @@ struct Schema { ** consistently. */ struct sqlite3 { + sqlite3_vfs *pVfs; /* OS Interface */ int nDb; /* Number of backends currently in use */ Db *aDb; /* All backends */ int flags; /* Miscellanous flags. See below */ + int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ int errCode; /* Most recent error code (SQLITE_*) */ + int errMask; /* & result codes with this before returning */ u8 autoCommit; /* The auto-commit flag. */ u8 temp_store; /* 1: file 2: memory 0: default */ + u8 mallocFailed; /* True if we have seen a malloc failure */ + signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ int nTable; /* Number of tables in the database */ CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ i64 lastRowid; /* ROWID of most recent insert (see above) */ @@ -456,13 +489,14 @@ struct sqlite3 { int magic; /* Magic number for detect library misuse */ int nChange; /* Value returned by sqlite3_changes() */ int nTotalChange; /* Value returned by sqlite3_total_changes() */ + sqlite3_mutex *mutex; /* Connection mutex */ struct sqlite3InitInfo { /* Information used during initialization */ int iDb; /* When back is being initialized */ int newTnum; /* Rootpage of table being initialized */ u8 busy; /* TRUE if currently initializing */ } init; int nExtension; /* Number of loaded extensions */ - void *aExtension; /* Array of shared libraray handles */ + void **aExtension; /* Array of shared libraray handles */ struct Vdbe *pVdbe; /* List of active virtual machines */ int activeVdbeCnt; /* Number of vdbes currently executing */ void (*xTrace)(void*,const char*); /* Trace function */ @@ -509,6 +543,7 @@ struct sqlite3 { #ifdef SQLITE_SSE sqlite3_stmt *pFetch; /* Used by SSE to fetch stored statements */ #endif + u8 dfltLockMode; /* Default locking-mode for attached dbs */ }; /* @@ -544,6 +579,10 @@ struct sqlite3 { #define SQLITE_FullFSync 0x00010000 /* Use full fsync on the backend */ #define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */ +#define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */ +#define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */ +#define SQLITE_Vtab 0x00100000 /* There exists a virtual table */ + /* ** Possible values for the sqlite.magic field. ** The numbers are obtained at random and have no special meaning, other @@ -551,6 +590,7 @@ struct sqlite3 { */ #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */ #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */ +#define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */ #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */ #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */ @@ -582,6 +622,7 @@ struct Module { const sqlite3_module *pModule; /* Callback pointers */ const char *zName; /* Name passed to create_module() */ void *pAux; /* pAux passed to create_module() */ + void (*xDestroy)(void *); /* Module destructor function */ }; /* @@ -603,6 +644,9 @@ struct Column { u8 notNull; /* True if there is a NOT NULL constraint */ u8 isPrimKey; /* True if this column is part of the PRIMARY KEY */ char affinity; /* One of the SQLITE_AFF_... values */ +#ifndef SQLITE_OMIT_VIRTUALTABLE + u8 isHidden; /* True if this column is 'hidden' */ +#endif }; /* @@ -627,11 +671,12 @@ struct Column { ** collating sequence may not be read or written. */ struct CollSeq { - char *zName; /* Name of the collating sequence, UTF-8 encoded */ - u8 enc; /* Text encoding handled by xCmp() */ - u8 type; /* One of the SQLITE_COLL_... values below */ - void *pUser; /* First argument to xCmp() */ + char *zName; /* Name of the collating sequence, UTF-8 encoded */ + u8 enc; /* Text encoding handled by xCmp() */ + u8 type; /* One of the SQLITE_COLL_... values below */ + void *pUser; /* First argument to xCmp() */ int (*xCmp)(void*,int, const void*, int, const void*); + void (*xDel)(void*); /* Destructor for pUser */ }; /* @@ -657,7 +702,7 @@ struct CollSeq { ** ** But rather than start with 0 or 1, we begin with 'a'. That way, ** when multiple affinity types are concatenated into a string and -** used as the P3 operand, they will be more readable. +** used as the P4 operand, they will be more readable. ** ** Note also that the numeric types are grouped together so that testing ** for a numeric type is a single comparison. @@ -671,6 +716,20 @@ struct CollSeq { #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) /* +** The SQLITE_AFF_MASK values masks off the significant bits of an +** affinity value. +*/ +#define SQLITE_AFF_MASK 0x67 + +/* +** Additional bit values that can be ORed with an affinity without +** changing the affinity. +*/ +#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */ +#define SQLITE_NULLEQUAL 0x10 /* compare NULLs equal */ +#define SQLITE_STOREP2 0x80 /* Store result in reg[P2] rather than jump */ + +/* ** Each SQL table is represented in memory by an instance of the ** following structure. ** @@ -731,7 +790,7 @@ struct Table { int nModuleArg; /* Number of arguments to the module */ char **azModuleArg; /* Text of all module args. [0] is module name */ #endif - Schema *pSchema; + Schema *pSchema; /* Schema that contains this table */ }; /* @@ -740,9 +799,11 @@ struct Table { ** table support is omitted from the build. */ #ifndef SQLITE_OMIT_VIRTUALTABLE -# define IsVirtual(X) ((X)->isVirtual) +# define IsVirtual(X) ((X)->isVirtual) +# define IsHiddenColumn(X) ((X)->isHidden) #else -# define IsVirtual(X) 0 +# define IsVirtual(X) 0 +# define IsHiddenColumn(X) 0 #endif /* @@ -787,7 +848,7 @@ struct FKey { }; /* -** SQLite supports many different ways to resolve a contraint +** SQLite supports many different ways to resolve a constraint ** error. ROLLBACK processing means that a constraint violation ** causes the operation in process to fail and for the current transaction ** to be rolled back. ABORT processing means the operation in process @@ -836,8 +897,10 @@ struct FKey { ** were larger. */ struct KeyInfo { + sqlite3 *db; /* The database connection */ u8 enc; /* Text encoding - one of the TEXT_Utf* values */ u8 incrKey; /* Increase 2nd key by epsilon before comparison */ + u8 prefixIsEqual; /* Treat a prefix as equal */ int nField; /* Number of entries in aColl[] */ u8 *aSortOrder; /* If defined an aSortOrder[i] is true, sort DESC */ CollSeq *aColl[1]; /* Collating sequence for each term of the key */ @@ -921,6 +984,7 @@ struct AggInfo { ExprList *pGroupBy; /* The group by clause */ int nSortingColumn; /* Number of columns in the sorting index */ struct AggInfo_col { /* For each column used in source tables */ + Table *pTab; /* Source table */ int iTable; /* Cursor number of the source table */ int iColumn; /* Column number within the source table */ int iSorterColumn; /* Column number in the sorting index */ @@ -1006,7 +1070,10 @@ struct Expr { Select *pSelect; /* When the expression is a sub-select. Also the ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for OP_Column expressions. */ - Schema *pSchema; +/* Schema *pSchema; */ +#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0 + int nHeight; /* Height of the tree headed by this node */ +#endif }; /* @@ -1020,6 +1087,7 @@ struct Expr { #define EP_VarSelect 0x20 /* pSelect is correlated, not constant */ #define EP_Dequoted 0x40 /* True if the string has been dequoted */ #define EP_InfixFunc 0x80 /* True for an infix function: LIKE, GLOB, etc */ +#define EP_ExpCollate 0x100 /* Collating sequence specified explicitly */ /* ** These macros can be used to test, set, or clear bits in the @@ -1077,8 +1145,12 @@ struct IdList { /* ** The bitmask datatype defined below is used for various optimizations. +** +** Changing this from a 64-bit to a 32-bit type limits the number of +** tables in a join to 32 instead of 64. But it also reduces the size +** of the library by 738 bytes on ix86. */ -typedef unsigned int Bitmask; +typedef u64 Bitmask; /* ** The following structure describes the FROM clause of a SELECT statement. @@ -1090,6 +1162,11 @@ typedef unsigned int Bitmask; ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, ** such a table must be a simple name: ID. But in SQLite, the table can ** now be identified by a database name, a dot, then the table name: ID.ID. +** +** The jointype starts out showing the join type between the current table +** and the next table on the list. The parser builds the list this way. +** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each +** jointype expresses the join between the table and the previous table. */ struct SrcList { i16 nSrc; /* Number of tables or subqueries in the FROM clause */ @@ -1101,8 +1178,8 @@ struct SrcList { Table *pTab; /* An SQL table corresponding to zName */ Select *pSelect; /* A SELECT statement used in place of a table name */ u8 isPopulated; /* Temporary table associated with SELECT is populated */ - u8 jointype; /* Type of join between this table and the next */ - i16 iCursor; /* The VDBE cursor number used to access this table */ + u8 jointype; /* Type of join between this able and the previous */ + int iCursor; /* The VDBE cursor number used to access this table */ Expr *pOn; /* The ON clause of a join */ IdList *pUsing; /* The USING clause of a join */ Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */ @@ -1148,12 +1225,16 @@ struct WhereLevel { int iTabCur; /* The VDBE cursor used to access the table */ int iIdxCur; /* The VDBE cursor used to acesss pIdx */ int brk; /* Jump here to break out of the loop */ + int nxt; /* Jump here to start the next IN combination */ int cont; /* Jump here to continue with the next loop cycle */ int top; /* First instruction of interior of the loop */ int op, p1, p2; /* Opcode used to terminate the loop */ int nEq; /* Number of == or IN constraints on this loop */ int nIn; /* Number of IN operators constraining this loop */ - int *aInLoop; /* Loop terminators for IN operators */ + struct InLoop { + int iCur; /* The VDBE cursor used by this IN operator */ + int topAddr; /* Top of the IN loop */ + } *aInLoop; /* Information about each nested IN operator */ sqlite3_index_info *pBestIdx; /* Index information for this level */ /* The following field is really not part of the current level. But @@ -1163,6 +1244,10 @@ struct WhereLevel { sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */ }; +#define ORDERBY_NORMAL 0 +#define ORDERBY_MIN 1 +#define ORDERBY_MAX 2 + /* ** The WHERE clause processing routine has two halves. The ** first part does the start of the WHERE loop and the second @@ -1228,7 +1313,7 @@ struct NameContext { ** ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes. ** These addresses must be stored so that we can go back and fill in -** the P3_KEYINFO and P2 parameters later. Neither the KeyInfo nor +** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor ** the number of columns in P2 can be computed at the same time ** as the OP_OpenEphm instruction is coded because not ** enough information about the compound query is known at that point. @@ -1244,12 +1329,14 @@ struct Select { u8 isAgg; /* True if this is an aggregate query */ u8 usesEphm; /* True if uses an OpenEphemeral opcode */ u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */ + char affinity; /* MakeRecord with this affinity for SRT_Set */ SrcList *pSrc; /* The FROM clause */ Expr *pWhere; /* The WHERE clause */ ExprList *pGroupBy; /* The GROUP BY clause */ Expr *pHaving; /* The HAVING clause */ ExprList *pOrderBy; /* The ORDER BY clause */ Select *pPrior; /* Prior select in a compound select statement */ + Select *pNext; /* Next select to the left in a compound */ Select *pRightmost; /* Right-most select in a compound select statement */ Expr *pLimit; /* LIMIT expression. NULL means not used. */ Expr *pOffset; /* OFFSET expression. NULL means not used. */ @@ -1262,18 +1349,30 @@ struct Select { */ #define SRT_Union 1 /* Store result as keys in an index */ #define SRT_Except 2 /* Remove result from a UNION index */ -#define SRT_Discard 3 /* Do not save the results anywhere */ +#define SRT_Exists 3 /* Store 1 if the result is not empty */ +#define SRT_Discard 4 /* Do not save the results anywhere */ /* The ORDER BY clause is ignored for all of the above */ -#define IgnorableOrderby(X) (X<=SRT_Discard) +#define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard) -#define SRT_Callback 4 /* Invoke a callback with each row of result */ -#define SRT_Mem 5 /* Store result in a memory cell */ -#define SRT_Set 6 /* Store non-null results as keys in an index */ -#define SRT_Table 7 /* Store result as data with an automatic rowid */ -#define SRT_EphemTab 8 /* Create transient tab and store like SRT_Table */ -#define SRT_Subroutine 9 /* Call a subroutine to handle results */ -#define SRT_Exists 10 /* Store 1 if the result is not empty */ +#define SRT_Callback 5 /* Invoke a callback with each row of result */ +#define SRT_Mem 6 /* Store result in a memory cell */ +#define SRT_Set 7 /* Store non-null results as keys in an index */ +#define SRT_Table 8 /* Store result as data with an automatic rowid */ +#define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table */ +#define SRT_Subroutine 10 /* Call a subroutine to handle results */ + +/* +** A structure used to customize the behaviour of sqlite3Select(). See +** comments above sqlite3Select() for details. +*/ +typedef struct SelectDest SelectDest; +struct SelectDest { + u8 eDest; /* How to dispose of the results */ + u8 affinity; /* Affinity used when eDest==SRT_Set */ + int iParm; /* A parameter used by the eDest disposal method */ + int iMem; /* Base register where results are written */ +}; /* ** An SQL parser context. A copy of this structure is passed through @@ -1300,16 +1399,21 @@ struct Parse { u8 nameClash; /* A permanent table name clashes with temp table name */ u8 checkSchema; /* Causes schema cookie check after an error */ u8 nested; /* Number of nested calls to the parser/code generator */ - u8 parseError; /* True if a parsing error has been seen */ + u8 parseError; /* True after a parsing error. Ticket #1794 */ + u8 nTempReg; /* Number of temporary registers in aTempReg[] */ + u8 nTempInUse; /* Number of aTempReg[] currently checked out */ + int aTempReg[8]; /* Holding area for temporary registers */ + int nRangeReg; /* Size of the temporary register block */ + int iRangeReg; /* First register in temporary register block */ int nErr; /* Number of errors seen */ int nTab; /* Number of previously allocated VDBE cursors */ int nMem; /* Number of memory cells used so far */ int nSet; /* Number of sets used so far */ - int ckOffset; /* Stack offset to data used by CHECK constraints */ + int ckBase; /* Base register of data during check constraints */ u32 writeMask; /* Start a write transaction on these databases */ u32 cookieMask; /* Bitmask of schema verified databases */ int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ - int cookieValue[MAX_ATTACHED+2]; /* Values of cookies to verify */ + int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ #ifndef SQLITE_OMIT_SHARED_CACHE int nTableLock; /* Number of locks in aTableLock */ TableLock *aTableLock; /* Required table locks for shared-cache mode */ @@ -1318,6 +1422,8 @@ struct Parse { /* Above is constant between recursions. Below is reset before and after ** each recursion */ + int regRowid; /* Register holding rowid of CREATE TABLE entry */ + int regRoot; /* Register holding root page number for new objects */ int nVar; /* Number of '?' variables seen in the SQL so far */ int nVarExpr; /* Number of used slots in apVarExpr[] */ int nVarExprAlloc; /* Number of allocated slots in apVarExpr[] */ @@ -1337,6 +1443,9 @@ struct Parse { u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ Table *pVirtualLock; /* Require virtual table lock on this table */ #endif +#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0 + int nHeight; /* Expression tree height of current sub-select */ +#endif }; #ifdef SQLITE_OMIT_VIRTUALTABLE @@ -1360,6 +1469,7 @@ struct AuthContext { #define OPFLAG_NCHANGE 1 /* Set to update db->nChange */ #define OPFLAG_LASTROWID 2 /* Set to update db->lastRowid */ #define OPFLAG_ISUPDATE 4 /* This OP_Insert is an sql UPDATE */ +#define OPFLAG_APPEND 8 /* This is likely to be an append */ /* * Each trigger present in the database schema is stored as an instance of @@ -1384,7 +1494,6 @@ struct Trigger { Expr *pWhen; /* The WHEN clause of the expresion (may be NULL) */ IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, the <column-list> is stored here */ - int foreach; /* One of TK_ROW or TK_STATEMENT */ Token nameToken; /* Token containing zName. Use during parsing only */ Schema *pSchema; /* Schema containing the trigger */ Schema *pTabSchema; /* Schema containing the table */ @@ -1446,11 +1555,11 @@ struct TriggerStep { Trigger *pTrig; /* The trigger that this step is a part of */ Select *pSelect; /* Valid for SELECT and sometimes - INSERT steps (when pExprList == 0) */ + INSERT steps (when pExprList == 0) */ Token target; /* Valid for DELETE, UPDATE, INSERT steps */ Expr *pWhere; /* Valid for DELETE, UPDATE steps */ ExprList *pExprList; /* Valid for UPDATE statements and sometimes - INSERT steps (when pSelect == 0) */ + INSERT steps (when pSelect == 0) */ IdList *pIdList; /* Valid for INSERT statements only */ TriggerStep *pNext; /* Next in the link-list */ TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ @@ -1487,6 +1596,8 @@ struct TriggerStack { Table *pTab; /* Table that triggers are currently being coded on */ int newIdx; /* Index of vdbe cursor to "new" temp table */ int oldIdx; /* Index of vdbe cursor to "old" temp table */ + u32 newColMask; + u32 oldColMask; int orconf; /* Current orconf policy */ int ignoreJump; /* where to jump to for a RAISE(IGNORE) */ Trigger *pTrigger; /* The trigger currently being coded */ @@ -1507,21 +1618,39 @@ struct DbFixer { }; /* +** An objected used to accumulate the text of a string where we +** do not necessarily know how big the string will be in the end. +*/ +struct StrAccum { + char *zBase; /* A base allocation. Not from malloc. */ + char *zText; /* The string collected so far */ + int nChar; /* Length of the string so far */ + int nAlloc; /* Amount of space allocated in zText */ + u8 mallocFailed; /* Becomes true if any memory allocation fails */ + u8 useMalloc; /* True if zText is enlargable using realloc */ + u8 tooBig; /* Becomes true if string size exceeds limits */ +}; + +/* ** A pointer to this structure is used to communicate information ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. */ typedef struct { sqlite3 *db; /* The database being initialized */ + int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ char **pzErrMsg; /* Error message stored here */ int rc; /* Result code stored here */ } InitData; /* - * This global flag is set for performance testing of triggers. When it is set - * SQLite will perform the overhead of building new and old trigger references - * even when no triggers exist - */ -extern int sqlite3_always_code_trigger_setup; +** Assuming zIn points to the first byte of a UTF-8 character, +** advance zIn to point to the first byte of the next UTF-8 character. +*/ +#define SQLITE_SKIP_UTF8(zIn) { \ + if( (*(zIn++))>=0xc0 ){ \ + while( (*zIn & 0xc0)==0x80 ){ zIn++; } \ + } \ +} /* ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production @@ -1530,10 +1659,12 @@ extern int sqlite3_always_code_trigger_setup; ** corruption is first detected. */ #ifdef SQLITE_DEBUG - extern int sqlite3Corrupt(void); + int sqlite3Corrupt(void); # define SQLITE_CORRUPT_BKPT sqlite3Corrupt() +# define DEBUGONLY(X) X #else # define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT +# define DEBUGONLY(X) #endif /* @@ -1541,52 +1672,53 @@ extern int sqlite3_always_code_trigger_setup; */ int sqlite3StrICmp(const char *, const char *); int sqlite3StrNICmp(const char *, const char *, int); -int sqlite3HashNoCase(const char *, int); int sqlite3IsNumber(const char*, int*, u8); -int sqlite3Compare(const char *, const char *); -int sqlite3SortCompare(const char *, const char *); -void sqlite3RealToSortable(double r, char *); - -void *sqlite3Malloc(int,int); -void *sqlite3MallocRaw(int,int); -void sqlite3Free(void*); -void *sqlite3Realloc(void*,int); + +void *sqlite3MallocZero(unsigned); +void *sqlite3DbMallocZero(sqlite3*, unsigned); +void *sqlite3DbMallocRaw(sqlite3*, unsigned); char *sqlite3StrDup(const char*); char *sqlite3StrNDup(const char*, int); -# define sqlite3CheckMemory(a,b) -void sqlite3ReallocOrFree(void**,int); -void sqlite3FreeX(void*); -void *sqlite3MallocX(int); -int sqlite3AllocSize(void *); - -char *sqlite3MPrintf(const char*, ...); -char *sqlite3VMPrintf(const char*, va_list); -void sqlite3DebugPrintf(const char*, ...); -void *sqlite3TextToPtr(const char*); +char *sqlite3DbStrDup(sqlite3*,const char*); +char *sqlite3DbStrNDup(sqlite3*,const char*, int); +void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); +void *sqlite3DbRealloc(sqlite3 *, void *, int); + +char *sqlite3MPrintf(sqlite3*,const char*, ...); +char *sqlite3VMPrintf(sqlite3*,const char*, va_list); +#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) + void sqlite3DebugPrintf(const char*, ...); +#endif +#if defined(SQLITE_TEST) + void *sqlite3TextToPtr(const char*); +#endif void sqlite3SetString(char **, ...); void sqlite3ErrorMsg(Parse*, const char*, ...); void sqlite3ErrorClear(Parse*); void sqlite3Dequote(char*); -void sqlite3DequoteExpr(Expr*); +void sqlite3DequoteExpr(sqlite3*, Expr*); int sqlite3KeywordCode(const unsigned char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); -Expr *sqlite3Expr(int, Expr*, Expr*, const Token*); -Expr *sqlite3ExprOrFree(int, Expr*, Expr*, const Token*); +int sqlite3GetTempReg(Parse*); +void sqlite3ReleaseTempReg(Parse*,int); +int sqlite3GetTempRange(Parse*,int); +void sqlite3ReleaseTempRange(Parse*,int,int); +Expr *sqlite3Expr(sqlite3*, int, Expr*, Expr*, const Token*); +Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); Expr *sqlite3RegisterExpr(Parse*,Token*); -Expr *sqlite3ExprAnd(Expr*, Expr*); +Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); void sqlite3ExprSpan(Expr*,Token*,Token*); -Expr *sqlite3ExprFunction(ExprList*, Token*); +Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); void sqlite3ExprAssignVarNumber(Parse*, Expr*); void sqlite3ExprDelete(Expr*); -ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*); +ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*); void sqlite3ExprListDelete(ExprList*); int sqlite3Init(sqlite3*, char**); int sqlite3InitCallback(void*, int, char**, char**); void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); void sqlite3ResetInternalSchema(sqlite3*, int); void sqlite3BeginParse(Parse*,int); -void sqlite3RollbackInternalChanges(sqlite3*); void sqlite3CommitInternalChanges(sqlite3*); Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*); void sqlite3OpenMasterTable(Parse *, int); @@ -1597,10 +1729,10 @@ void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); void sqlite3AddCheckConstraint(Parse*, Expr*); void sqlite3AddColumnType(Parse*,Token*); void sqlite3AddDefaultValue(Parse*,Expr*); -void sqlite3AddCollateType(Parse*, const char*, int); +void sqlite3AddCollateType(Parse*, Token*); void sqlite3EndTable(Parse*,Token*,Token*,Select*); -void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int); +void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) int sqlite3ViewGetColumnNames(Parse*,Table*); @@ -1609,55 +1741,53 @@ void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int); #endif void sqlite3DropTable(Parse*, SrcList*, int, int); -void sqlite3DeleteTable(sqlite3*, Table*); +void sqlite3DeleteTable(Table*); void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); -int sqlite3ArrayAllocate(void**,int,int); -IdList *sqlite3IdListAppend(IdList*, Token*); +void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*); +IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); int sqlite3IdListIndex(IdList*,const char*); -SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*); -void sqlite3SrcListAddAlias(SrcList*, Token*); +SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*); +SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, Token*, + Select*, Expr*, IdList*); +void sqlite3SrcListShiftJoinType(SrcList*); void sqlite3SrcListAssignCursors(Parse*, SrcList*); void sqlite3IdListDelete(IdList*); void sqlite3SrcListDelete(SrcList*); void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, Token*, int, int); void sqlite3DropIndex(Parse*, SrcList*, int); -void sqlite3AddKeyType(Vdbe*, ExprList*); -void sqlite3AddIdxKeyType(Vdbe*, Index*); -int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff); -Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*, - int,Expr*,Expr*); +int sqlite3Select(Parse*, Select*, SelectDest*, Select*, int, int*, char *aff); +Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, + Expr*,ExprList*,int,Expr*,Expr*); void sqlite3SelectDelete(Select*); -void sqlite3SelectUnbind(Select*); Table *sqlite3SrcListLookup(Parse*, SrcList*); int sqlite3IsReadOnly(Parse*, Table*, int); void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); -WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**); +WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u8); void sqlite3WhereEnd(WhereInfo*); -void sqlite3ExprCode(Parse*, Expr*); -void sqlite3ExprCodeAndCache(Parse*, Expr*); -int sqlite3ExprCodeExprList(Parse*, ExprList*); +void sqlite3ExprCodeGetColumn(Vdbe*, Table*, int, int, int); +int sqlite3ExprCode(Parse*, Expr*, int); +int sqlite3ExprCodeTemp(Parse*, Expr*, int*); +int sqlite3ExprCodeAndCache(Parse*, Expr*, int); +int sqlite3ExprCodeExprList(Parse*, ExprList*, int); void sqlite3ExprIfTrue(Parse*, Expr*, int, int); void sqlite3ExprIfFalse(Parse*, Expr*, int, int); -void sqlite3NextedParse(Parse*, const char*, ...); Table *sqlite3FindTable(sqlite3*,const char*, const char*); -Table *sqlite3LocateTable(Parse*,const char*, const char*); +Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); Index *sqlite3FindIndex(sqlite3*,const char*, const char*); void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); void sqlite3Vacuum(Parse*); int sqlite3RunVacuum(char**, sqlite3*); -char *sqlite3NameFromToken(Token*); -int sqlite3ExprCheck(Parse*, Expr*, int, int*); +char *sqlite3NameFromToken(sqlite3*, Token*); int sqlite3ExprCompare(Expr*, Expr*); -int sqliteFuncId(Token*); int sqlite3ExprResolveNames(NameContext *, Expr *); -int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); -int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); +void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); +void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); Vdbe *sqlite3GetVdbe(Parse*); -Expr *sqlite3CreateIdExpr(const char*); +Expr *sqlite3CreateIdExpr(Parse *, const char*); void sqlite3Randomness(int, void*); void sqlite3RollbackAll(sqlite3*); void sqlite3CodeVerifySchema(Parse*, int); @@ -1665,65 +1795,76 @@ void sqlite3BeginTransaction(Parse*, int); void sqlite3CommitTransaction(Parse*); void sqlite3RollbackTransaction(Parse*); int sqlite3ExprIsConstant(Expr*); +int sqlite3ExprIsConstantNotJoin(Expr*); int sqlite3ExprIsConstantOrFunction(Expr*); int sqlite3ExprIsInteger(Expr*, int*); int sqlite3IsRowid(const char*); -void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int); -void sqlite3GenerateRowIndexDelete(Vdbe*, Table*, int, char*); -void sqlite3GenerateIndexKey(Vdbe*, Index*, int); -void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int); -void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int); -void sqlite3OpenTableAndIndices(Parse*, Table*, int, int); +void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int); +void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*); +int sqlite3GenerateIndexKey(Parse*, Index*, int, int); +void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int, + int*,int,int,int,int); +void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*,int,int,int,int); +int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); void sqlite3BeginWriteOperation(Parse*, int, int); -Expr *sqlite3ExprDup(Expr*); -void sqlite3TokenCopy(Token*, Token*); -ExprList *sqlite3ExprListDup(ExprList*); -SrcList *sqlite3SrcListDup(SrcList*); -IdList *sqlite3IdListDup(IdList*); -Select *sqlite3SelectDup(Select*); +Expr *sqlite3ExprDup(sqlite3*,Expr*); +void sqlite3TokenCopy(sqlite3*,Token*, Token*); +ExprList *sqlite3ExprListDup(sqlite3*,ExprList*); +SrcList *sqlite3SrcListDup(sqlite3*,SrcList*); +IdList *sqlite3IdListDup(sqlite3*,IdList*); +Select *sqlite3SelectDup(sqlite3*,Select*); FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int); void sqlite3RegisterBuiltinFunctions(sqlite3*); void sqlite3RegisterDateTimeFunctions(sqlite3*); -int sqlite3SafetyOn(sqlite3*); -int sqlite3SafetyOff(sqlite3*); -int sqlite3SafetyCheck(sqlite3*); -void sqlite3ChangeCookie(sqlite3*, Vdbe*, int); +#ifdef SQLITE_DEBUG + int sqlite3SafetyOn(sqlite3*); + int sqlite3SafetyOff(sqlite3*); +#else +# define sqlite3SafetyOn(A) 0 +# define sqlite3SafetyOff(A) 0 +#endif +int sqlite3SafetyCheckOk(sqlite3*); +int sqlite3SafetyCheckSickOrOk(sqlite3*); +void sqlite3ChangeCookie(Parse*, int); #ifndef SQLITE_OMIT_TRIGGER void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*, - int,Expr*,int); + Expr*,int, int); void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*); - void sqlite3DropTrigger(Parse*, SrcList*); + void sqlite3DropTrigger(Parse*, SrcList*, int); void sqlite3DropTriggerPtr(Parse*, Trigger*); int sqlite3TriggersExist(Parse*, Table*, int, ExprList*); int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, - int, int); + int, int, u32*, u32*); void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*); void sqlite3DeleteTriggerStep(TriggerStep*); - TriggerStep *sqlite3TriggerSelectStep(Select*); - TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*,Select*,int); - TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int); - TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*); + TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*); + TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*, + ExprList*,Select*,int); + TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, int); + TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*); void sqlite3DeleteTrigger(Trigger*); void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*); + void sqlite3SelectMask(Parse *, Select *, u32); #else # define sqlite3TriggersExist(A,B,C,D,E,F) 0 # define sqlite3DeleteTrigger(A) # define sqlite3DropTriggerPtr(A,B) # define sqlite3UnlinkAndDeleteTrigger(A,B,C) -# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 0 +# define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I,J,K) 0 +# define sqlite3SelectMask(A, B, C) #endif int sqlite3JoinType(Parse*, Token*, Token*, Token*); void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int); void sqlite3DeferForeignKey(Parse*, int); #ifndef SQLITE_OMIT_AUTHORIZATION - void sqlite3AuthRead(Parse*,Expr*,SrcList*); + void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*); int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*); void sqlite3AuthContextPush(Parse*, AuthContext*, const char*); void sqlite3AuthContextPop(AuthContext*); #else -# define sqlite3AuthRead(a,b,c) +# define sqlite3AuthRead(a,b,c,d) # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK # define sqlite3AuthContextPush(a,b,c) # define sqlite3AuthContextPop(a) ((void)(a)) @@ -1731,7 +1872,7 @@ void sqlite3DeferForeignKey(Parse*, int); void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); void sqlite3Detach(Parse*, Expr*); int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename, - int omitJournal, int nCache, Btree **ppBtree); + int omitJournal, int nCache, int flags, Btree **ppBtree); int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); int sqlite3FixSrcList(DbFixer*, SrcList*); int sqlite3FixSelect(DbFixer*, Select*); @@ -1741,10 +1882,10 @@ int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); int sqlite3AtoF(const char *z, double*); char *sqlite3_snprintf(int,char*,const char*,...); int sqlite3GetInt32(const char *, int*); -int sqlite3FitsIn64Bits(const char *); -int sqlite3utf16ByteLen(const void *pData, int nChar); -int sqlite3utf8CharLen(const char *pData, int nByte); -int sqlite3ReadUtf8(const unsigned char *); +int sqlite3FitsIn64Bits(const char *, int); +int sqlite3Utf16ByteLen(const void *pData, int nChar); +int sqlite3Utf8CharLen(const char *pData, int nByte); +int sqlite3Utf8Read(const u8*, const u8*, const u8**); int sqlite3PutVarint(unsigned char *, u64); int sqlite3GetVarint(const unsigned char *, u64 *); int sqlite3GetVarint32(const unsigned char *, u32 *); @@ -1754,31 +1895,32 @@ void sqlite3TableAffinityStr(Vdbe *, Table *); char sqlite3CompareAffinity(Expr *pExpr, char aff2); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); -int sqlite3atoi64(const char*, i64*); +int sqlite3Atoi64(const char*, i64*); void sqlite3Error(sqlite3*, int, const char*,...); -void *sqlite3HexToBlob(const char *z); +void *sqlite3HexToBlob(sqlite3*, const char *z, int n); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrStr(int); -int sqlite3ReadUniChar(const char *zStr, int *pOffset, u8 *pEnc, int fold); int sqlite3ReadSchema(Parse *pParse); CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int); CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName); CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); +Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *); int sqlite3CheckCollSeq(Parse *, CollSeq *); -int sqlite3CheckIndexCollSeq(Parse *, Index *); int sqlite3CheckObjectName(Parse *, const char *); void sqlite3VdbeSetChanges(sqlite3 *, int); -void sqlite3utf16Substr(sqlite3_context *,int,sqlite3_value **); const void *sqlite3ValueText(sqlite3_value*, u8); int sqlite3ValueBytes(sqlite3_value*, u8); -void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*)); +void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, + void(*)(void*)); void sqlite3ValueFree(sqlite3_value*); -sqlite3_value *sqlite3ValueNew(void); -char *sqlite3utf16to8(const void*, int); -int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **); +sqlite3_value *sqlite3ValueNew(sqlite3 *); +char *sqlite3Utf16to8(sqlite3 *, const void*, int); +int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); +#ifndef SQLITE_AMALGAMATION extern const unsigned char sqlite3UpperToLower[]; +#endif void sqlite3RootPageMoved(Db*, int, int); void sqlite3Reindex(Parse*, Token*, Token*); void sqlite3AlterFunctions(sqlite3*); @@ -1791,38 +1933,45 @@ int sqlite3SelectResolve(Parse *, Select *, NameContext *); void sqlite3ColumnDefault(Vdbe *, Table *, int); void sqlite3AlterFinishAddColumn(Parse *, Token *); void sqlite3AlterBeginAddColumn(Parse *, SrcList *); -const char *sqlite3TestErrorName(int); CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int); char sqlite3AffinityType(const Token*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); -void sqlite3AnalysisLoad(sqlite3*,int iDB); +int sqlite3AnalysisLoad(sqlite3*,int iDB); void sqlite3DefaultRowEst(Index*); void sqlite3RegisterLikeFunctions(sqlite3*, int); int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); -ThreadData *sqlite3ThreadData(void); -const ThreadData *sqlite3ThreadDataReadOnly(void); -void sqlite3ReleaseThreadData(void); void sqlite3AttachFunctions(sqlite3 *); void sqlite3MinimumFileFormat(Parse*, int, int); void sqlite3SchemaFree(void *); -Schema *sqlite3SchemaGet(Btree *); +Schema *sqlite3SchemaGet(sqlite3 *, Btree *); int sqlite3SchemaToIndex(sqlite3 *db, Schema *); KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*)); int sqlite3ApiExit(sqlite3 *db, int); -int sqlite3MallocFailed(void); -void sqlite3FailedMalloc(void); -void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *); int sqlite3OpenTempDatabase(Parse *); +void sqlite3StrAccumAppend(StrAccum*,const char*,int); +char *sqlite3StrAccumFinish(StrAccum*); +void sqlite3StrAccumReset(StrAccum*); +void sqlite3SelectDestInit(SelectDest*,int,int); + +/* +** The interface to the LEMON-generated parser +*/ +void *sqlite3ParserAlloc(void*(*)(size_t)); +void sqlite3ParserFree(void*, void(*)(void*)); +void sqlite3Parser(void*, int, Token, Parse*); + #ifndef SQLITE_OMIT_LOAD_EXTENSION void sqlite3CloseExtensions(sqlite3*); + int sqlite3AutoLoadExtensions(sqlite3*); #else # define sqlite3CloseExtensions(X) +# define sqlite3AutoLoadExtensions(X) SQLITE_OK #endif #ifndef SQLITE_OMIT_SHARED_CACHE @@ -1831,22 +1980,8 @@ int sqlite3OpenTempDatabase(Parse *); #define sqlite3TableLock(v,w,x,y,z) #endif -#ifdef SQLITE_MEMDEBUG - void sqlite3MallocDisallow(void); - void sqlite3MallocAllow(void); - int sqlite3TestMallocFail(void); -#else - #define sqlite3TestMallocFail() 0 - #define sqlite3MallocDisallow() - #define sqlite3MallocAllow() -#endif - -#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT - void *sqlite3ThreadSafeMalloc(int); - void sqlite3ThreadSafeFree(void *); -#else - #define sqlite3ThreadSafeMalloc sqlite3MallocX - #define sqlite3ThreadSafeFree sqlite3FreeX +#ifdef SQLITE_TEST + int sqlite3Utf8To8(unsigned char*); #endif #ifdef SQLITE_OMIT_VIRTUALTABLE @@ -1860,6 +1995,8 @@ int sqlite3OpenTempDatabase(Parse *); int sqlite3VtabRollback(sqlite3 *db); int sqlite3VtabCommit(sqlite3 *db); #endif +void sqlite3VtabLock(sqlite3_vtab*); +void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*); void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); void sqlite3VtabFinishParse(Parse*, Token*); void sqlite3VtabArgInit(Parse*); @@ -1868,10 +2005,85 @@ int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); int sqlite3VtabCallConnect(Parse*, Table*); int sqlite3VtabCallDestroy(sqlite3*, int, const char *); int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *); -FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*); +FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); +void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**); +int sqlite3Reprepare(Vdbe*); +void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*); +CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); + + +/* +** Available fault injectors. Should be numbered beginning with 0. +*/ +#define SQLITE_FAULTINJECTOR_MALLOC 0 +#define SQLITE_FAULTINJECTOR_COUNT 1 + +/* +** The interface to the fault injector subsystem. If the fault injector +** mechanism is disabled at compile-time then set up macros so that no +** unnecessary code is generated. +*/ +#ifndef SQLITE_OMIT_FAULTINJECTOR + void sqlite3FaultConfig(int,int,int); + int sqlite3FaultFailures(int); + int sqlite3FaultBenignFailures(int); + int sqlite3FaultPending(int); + void sqlite3FaultBenign(int,int); + int sqlite3FaultStep(int); +#else +# define sqlite3FaultConfig(A,B,C) +# define sqlite3FaultFailures(A) 0 +# define sqlite3FaultBenignFailures(A) 0 +# define sqlite3FaultPending(A) (-1) +# define sqlite3FaultBenign(A,B) +# define sqlite3FaultStep(A) 0 +#endif + + + +#define IN_INDEX_ROWID 1 +#define IN_INDEX_EPH 2 +#define IN_INDEX_INDEX 3 +int sqlite3FindInIndex(Parse *, Expr *, int); + +#ifdef SQLITE_ENABLE_ATOMIC_WRITE + int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); + int sqlite3JournalSize(sqlite3_vfs *); + int sqlite3JournalCreate(sqlite3_file *); +#else + #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile) +#endif + +#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0 + void sqlite3ExprSetHeight(Expr *); + int sqlite3SelectExprHeight(Select *); +#else + #define sqlite3ExprSetHeight(x) +#endif + +u32 sqlite3Get4byte(const u8*); +void sqlite3Put4byte(u8*, u32); #ifdef SQLITE_SSE #include "sseInt.h" #endif +#ifdef SQLITE_DEBUG + void sqlite3ParserTrace(FILE*, char *); +#endif + +/* +** If the SQLITE_ENABLE IOTRACE exists then the global variable +** sqlite3_io_trace is a pointer to a printf-like routine used to +** print I/O tracing messages. +*/ +#ifdef SQLITE_ENABLE_IOTRACE +# define IOTRACE(A) if( sqlite3_io_trace ){ sqlite3_io_trace A; } + void sqlite3VdbeIOTraceSql(Vdbe*); +#else +# define IOTRACE(A) +# define sqlite3VdbeIOTraceSql(X) +#endif +SQLITE_EXTERN void (*sqlite3_io_trace)(const char*,...); + #endif |
