mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
MFH: upgraded bundled libsqlite3 to version 3.2.7
This commit is contained in:
parent
15c9f414a6
commit
846b0826ab
42 changed files with 4885 additions and 4209 deletions
|
|
@ -16,6 +16,17 @@
|
|||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
|
||||
/*
|
||||
** 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
|
||||
|
|
@ -298,7 +309,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
|
|||
/*
|
||||
** Forward references to structures
|
||||
*/
|
||||
typedef struct AggExpr AggExpr;
|
||||
typedef struct AggInfo AggInfo;
|
||||
typedef struct AuthContext AuthContext;
|
||||
typedef struct CollSeq CollSeq;
|
||||
typedef struct Column Column;
|
||||
|
|
@ -420,8 +431,10 @@ struct sqlite3 {
|
|||
} init;
|
||||
struct Vdbe *pVdbe; /* List of active virtual machines */
|
||||
int activeVdbeCnt; /* Number of vdbes currently executing */
|
||||
void (*xTrace)(void*,const char*); /* Trace function */
|
||||
void *pTraceArg; /* Argument to the trace function */
|
||||
void (*xTrace)(void*,const char*); /* Trace function */
|
||||
void *pTraceArg; /* Argument to the trace function */
|
||||
void (*xProfile)(void*,const char*,u64); /* Profiling function */
|
||||
void *pProfileArg; /* Argument to profile function */
|
||||
void *pCommitArg; /* Argument to xCommitCallback() */
|
||||
int (*xCommitCallback)(void*);/* Invoked at every commit. */
|
||||
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
|
||||
|
|
@ -511,7 +524,8 @@ struct FuncDef {
|
|||
/*
|
||||
** Possible values for FuncDef.flags
|
||||
*/
|
||||
#define SQLITE_FUNC_LIKEOPT 0x01 /* Candidate for the LIKE optimization */
|
||||
#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
|
||||
#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
|
||||
|
||||
/*
|
||||
** information about each column of an SQL table is held in an instance
|
||||
|
|
@ -551,10 +565,19 @@ struct Column {
|
|||
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() */
|
||||
int (*xCmp)(void*,int, const void*, int, const void*);
|
||||
};
|
||||
|
||||
/*
|
||||
** Allowed values of CollSeq flags:
|
||||
*/
|
||||
#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */
|
||||
#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */
|
||||
#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */
|
||||
#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */
|
||||
|
||||
/*
|
||||
** A sort order can be either ASC or DESC.
|
||||
*/
|
||||
|
|
@ -776,6 +799,49 @@ struct Token {
|
|||
unsigned n : 31; /* Number of characters in this token */
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of this structure contains information needed to generate
|
||||
** code for a SELECT that contains aggregate functions.
|
||||
**
|
||||
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
|
||||
** pointer to this structure. The Expr.iColumn field is the index in
|
||||
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
|
||||
** code for that node.
|
||||
**
|
||||
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
|
||||
** original Select structure that describes the SELECT statement. These
|
||||
** fields do not need to be freed when deallocating the AggInfo structure.
|
||||
*/
|
||||
struct AggInfo {
|
||||
u8 directMode; /* Direct rendering mode means take data directly
|
||||
** from source tables rather than from accumulators */
|
||||
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
|
||||
** than the source table */
|
||||
int sortingIdx; /* Cursor number of the sorting index */
|
||||
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 */
|
||||
int iTable; /* Cursor number of the source table */
|
||||
int iColumn; /* Column number within the source table */
|
||||
int iSorterColumn; /* Column number in the sorting index */
|
||||
int iMem; /* Memory location that acts as accumulator */
|
||||
Expr *pExpr; /* The original expression */
|
||||
} *aCol;
|
||||
int nColumn; /* Number of used entries in aCol[] */
|
||||
int nColumnAlloc; /* Number of slots allocated for aCol[] */
|
||||
int nAccumulator; /* Number of columns that show through to the output.
|
||||
** Additional columns are used only as parameters to
|
||||
** aggregate functions */
|
||||
struct AggInfo_func { /* For each aggregate function */
|
||||
Expr *pExpr; /* Expression encoding the function */
|
||||
FuncDef *pFunc; /* The aggregate function implementation */
|
||||
int iMem; /* Memory location that acts as accumulator */
|
||||
int iDistinct; /* Virtual table used to enforce DISTINCT */
|
||||
} *aFunc;
|
||||
int nFunc; /* Number of entries in aFunc[] */
|
||||
int nFuncAlloc; /* Number of slots allocated for aFunc[] */
|
||||
};
|
||||
|
||||
/*
|
||||
** Each node of an expression in the parse tree is an instance
|
||||
** of this structure.
|
||||
|
|
@ -835,9 +901,9 @@ struct Expr {
|
|||
Token span; /* Complete text of the expression */
|
||||
int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the
|
||||
** iColumn-th field of the iTable-th table. */
|
||||
int iAgg; /* When op==TK_COLUMN and pParse->fillAgg==FALSE, pull
|
||||
** result from the iAgg-th element of the aggregator */
|
||||
int iAggCtx; /* The value to pass as P1 of OP_AggGet. */
|
||||
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
|
||||
int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
|
||||
int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
|
||||
Select *pSelect; /* When the expression is a sub-select. Also the
|
||||
** right side of "<expr> IN (<select>)" */
|
||||
Table *pTab; /* Table for OP_Column expressions. */
|
||||
|
|
@ -850,7 +916,7 @@ struct Expr {
|
|||
#define EP_Agg 0x02 /* Contains one or more aggregate functions */
|
||||
#define EP_Resolved 0x04 /* IDs have been resolved to COLUMNs */
|
||||
#define EP_Error 0x08 /* Expression contains one or more errors */
|
||||
#define EP_Not 0x10 /* Operator preceeded by NOT */
|
||||
#define EP_Distinct 0x10 /* Aggregate function with DISTINCT keyword */
|
||||
#define EP_VarSelect 0x20 /* pSelect is correlated, not constant */
|
||||
#define EP_Dequoted 0x40 /* True if the string has been dequoted */
|
||||
|
||||
|
|
@ -874,6 +940,7 @@ struct Expr {
|
|||
struct ExprList {
|
||||
int nExpr; /* Number of expressions on the list */
|
||||
int nAlloc; /* Number of entries allocated below */
|
||||
int iECursor; /* VDBE Cursor associated with this ExprList */
|
||||
struct ExprList_item {
|
||||
Expr *pExpr; /* The list of expressions */
|
||||
char *zName; /* Token associated with this expression */
|
||||
|
|
@ -899,12 +966,12 @@ struct ExprList {
|
|||
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
|
||||
*/
|
||||
struct IdList {
|
||||
int nId; /* Number of identifiers on the list */
|
||||
int nAlloc; /* Number of entries allocated for a[] below */
|
||||
struct IdList_item {
|
||||
char *zName; /* Name of the identifier */
|
||||
int idx; /* Index in some Table.aCol[] of a column named zName */
|
||||
} *a;
|
||||
int nId; /* Number of identifiers on the list */
|
||||
int nAlloc; /* Number of entries allocated for a[] below */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -944,11 +1011,12 @@ struct SrcList {
|
|||
** Permitted values of the SrcList.a.jointype field
|
||||
*/
|
||||
#define JT_INNER 0x0001 /* Any kind of inner or cross join */
|
||||
#define JT_NATURAL 0x0002 /* True for a "natural" join */
|
||||
#define JT_LEFT 0x0004 /* Left outer join */
|
||||
#define JT_RIGHT 0x0008 /* Right outer join */
|
||||
#define JT_OUTER 0x0010 /* The "OUTER" keyword is present */
|
||||
#define JT_ERROR 0x0020 /* unknown or unsupported join type */
|
||||
#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
|
||||
#define JT_NATURAL 0x0004 /* True for a "natural" join */
|
||||
#define JT_LEFT 0x0008 /* Left outer join */
|
||||
#define JT_RIGHT 0x0010 /* Right outer join */
|
||||
#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
|
||||
#define JT_ERROR 0x0040 /* unknown or unsupported join type */
|
||||
|
||||
/*
|
||||
** For each nested loop in a WHERE clause implementation, the WhereInfo
|
||||
|
|
@ -1018,8 +1086,9 @@ struct NameContext {
|
|||
int nRef; /* Number of names resolved by this context */
|
||||
int nErr; /* Number of errors encountered while resolving names */
|
||||
u8 allowAgg; /* Aggregate functions allowed here */
|
||||
u8 hasAgg;
|
||||
u8 hasAgg; /* True if aggregates are seen */
|
||||
int nDepth; /* Depth of subquery recursion. 1 for no recursion */
|
||||
AggInfo *pAggInfo; /* Information about aggregates at this level */
|
||||
NameContext *pNext; /* Next outer name context. NULL for outermost */
|
||||
};
|
||||
|
||||
|
|
@ -1032,64 +1101,55 @@ struct NameContext {
|
|||
** limit and nOffset to the value of the offset (or 0 if there is not
|
||||
** offset). But later on, nLimit and nOffset become the memory locations
|
||||
** in the VDBE that record the limit and offset counters.
|
||||
**
|
||||
** addrOpenVirt[] entries contain the address of OP_OpenVirtual 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 number of columns in P2 can be computed at the same time
|
||||
** as the OP_OpenVirtual instruction is coded because not
|
||||
** enough information about the compound query is known at that point.
|
||||
** The KeyInfo for addrOpenVirt[0] and [1] contains collating sequences
|
||||
** for the result set. The KeyInfo for addrOpenVirt[2] contains collating
|
||||
** sequences for the ORDER BY clause.
|
||||
*/
|
||||
struct Select {
|
||||
ExprList *pEList; /* The fields of the result */
|
||||
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
|
||||
u8 isDistinct; /* True if the DISTINCT keyword is present */
|
||||
u8 isResolved; /* True once sqlite3SelectResolve() has run. */
|
||||
u8 isAgg; /* True if this is an aggregate query */
|
||||
u8 usesVirt; /* True if uses an OpenVirtual opcode */
|
||||
u8 disallowOrderBy; /* Do not allow an ORDER BY to be attached if TRUE */
|
||||
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 *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. */
|
||||
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
|
||||
IdList **ppOpenVirtual;/* OP_OpenVirtual addresses used by multi-selects */
|
||||
u8 isResolved; /* True once sqlite3SelectResolve() has run. */
|
||||
u8 isAgg; /* True if this is an aggregate query */
|
||||
int addrOpenVirt[3]; /* OP_OpenVirtual opcodes related to this select */
|
||||
};
|
||||
|
||||
/*
|
||||
** The results of a select can be distributed in several ways.
|
||||
*/
|
||||
#define SRT_Callback 1 /* Invoke a callback with each row of result */
|
||||
#define SRT_Mem 2 /* Store result in a memory cell */
|
||||
#define SRT_Set 3 /* Store result as unique keys in a table */
|
||||
#define SRT_Union 5 /* Store result as keys in a table */
|
||||
#define SRT_Except 6 /* Remove result from a UNION table */
|
||||
#define SRT_Table 7 /* Store result as data with a unique key */
|
||||
#define SRT_TempTable 8 /* Store result in a trasient table */
|
||||
#define SRT_Discard 9 /* Do not save the results anywhere */
|
||||
#define SRT_Sorter 10 /* Store results in the sorter */
|
||||
#define SRT_Subroutine 11 /* Call a subroutine to handle results */
|
||||
#define SRT_Exists 12 /* Put 0 or 1 in a memory cell */
|
||||
#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 */
|
||||
|
||||
/*
|
||||
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
|
||||
** we have to do some additional analysis of expressions. An instance
|
||||
** of the following structure holds information about a single subexpression
|
||||
** somewhere in the SELECT statement. An array of these structures holds
|
||||
** all the information we need to generate code for aggregate
|
||||
** expressions.
|
||||
**
|
||||
** Note that when analyzing a SELECT containing aggregates, both
|
||||
** non-aggregate field variables and aggregate functions are stored
|
||||
** in the AggExpr array of the Parser structure.
|
||||
**
|
||||
** The pExpr field points to an expression that is part of either the
|
||||
** field list, the GROUP BY clause, the HAVING clause or the ORDER BY
|
||||
** clause. The expression will be freed when those clauses are cleaned
|
||||
** up. Do not try to delete the expression attached to AggExpr.pExpr.
|
||||
**
|
||||
** If AggExpr.pExpr==0, that means the expression is "count(*)".
|
||||
*/
|
||||
struct AggExpr {
|
||||
int isAgg; /* if TRUE contains an aggregate function */
|
||||
Expr *pExpr; /* The expression */
|
||||
FuncDef *pFunc; /* Information about the aggregate function */
|
||||
};
|
||||
/* The ORDER BY clause is ignored for all of the above */
|
||||
#define IgnorableOrderby(X) (X<=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_VirtualTab 8 /* Create virtual table and store like SRT_Table */
|
||||
#define SRT_Subroutine 9 /* Call a subroutine to handle results */
|
||||
#define SRT_Exists 10 /* Put 0 or 1 in a memory cell */
|
||||
|
||||
/*
|
||||
** An SQL parser context. A copy of this structure is passed through
|
||||
|
|
@ -1110,7 +1170,6 @@ 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 fillAgg; /* If true, ignore the Expr.iAgg field. Normally false */
|
||||
int nErr; /* Number of errors seen */
|
||||
int nTab; /* Number of previously allocated VDBE cursors */
|
||||
int nMem; /* Number of memory cells used so far */
|
||||
|
|
@ -1137,9 +1196,6 @@ struct Parse {
|
|||
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
|
||||
TriggerStack *trigStack; /* Trigger actions being coded */
|
||||
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
|
||||
int nAgg; /* Number of aggregate expressions */
|
||||
AggExpr *aAgg; /* An array of aggregate expressions */
|
||||
int nMaxDepth; /* Maximum depth of subquery recursion */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -1319,6 +1375,19 @@ typedef struct {
|
|||
*/
|
||||
extern int sqlite3_always_code_trigger_setup;
|
||||
|
||||
/*
|
||||
** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
|
||||
** builds) or a function call (for debugging). If it is a function call,
|
||||
** it allows the operator to set a breakpoint at the spot where database
|
||||
** corruption is first detected.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
extern int sqlite3Corrupt(void);
|
||||
# define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
|
||||
#else
|
||||
# define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Internal function prototypes
|
||||
*/
|
||||
|
|
@ -1346,6 +1415,7 @@ void sqlite3RealToSortable(double r, char *);
|
|||
# define sqlite3CheckMemory(a,b)
|
||||
# define sqlite3MallocX sqlite3Malloc
|
||||
#endif
|
||||
void sqlite3ReallocOrFree(void**,int);
|
||||
void sqlite3FreeX(void*);
|
||||
void *sqlite3MallocX(int);
|
||||
char *sqlite3MPrintf(const char*, ...);
|
||||
|
|
@ -1396,6 +1466,7 @@ void sqlite3EndTable(Parse*,Token*,Token*,Select*);
|
|||
void sqlite3DropTable(Parse*, SrcList*, int);
|
||||
void sqlite3DeleteTable(sqlite3*, Table*);
|
||||
void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
|
||||
int sqlite3ArrayAllocate(void**,int,int);
|
||||
IdList *sqlite3IdListAppend(IdList*, Token*);
|
||||
int sqlite3IdListIndex(IdList*,const char*);
|
||||
SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
|
||||
|
|
@ -1440,6 +1511,7 @@ int sqlite3ExprCompare(Expr*, Expr*);
|
|||
int sqliteFuncId(Token*);
|
||||
int sqlite3ExprResolveNames(NameContext *, Expr *);
|
||||
int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
|
||||
int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
|
||||
Vdbe *sqlite3GetVdbe(Parse*);
|
||||
void sqlite3Randomness(int, void*);
|
||||
void sqlite3RollbackAll(sqlite3*);
|
||||
|
|
@ -1557,7 +1629,7 @@ const void *sqlite3ValueText(sqlite3_value*, u8);
|
|||
int sqlite3ValueBytes(sqlite3_value*, u8);
|
||||
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
|
||||
void sqlite3ValueFree(sqlite3_value*);
|
||||
sqlite3_value *sqlite3ValueNew();
|
||||
sqlite3_value *sqlite3ValueNew(void);
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
|
||||
int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
|
||||
void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
|
||||
|
|
@ -1583,7 +1655,7 @@ int sqlite3FindDb(sqlite3*, Token*);
|
|||
void sqlite3AnalysisLoad(sqlite3*,int iDB);
|
||||
void sqlite3DefaultRowEst(Index*);
|
||||
void sqlite3RegisterLikeFunctions(sqlite3*, int);
|
||||
int sqlite3IsLikeFunction(sqlite3*,Expr*,char*);
|
||||
int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
|
||||
|
||||
#ifdef SQLITE_SSE
|
||||
#include "sseInt.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue