diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2012-06-04 09:01:56 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2012-06-04 09:01:56 +0000 |
commit | bc92864fa9d94b356859d1f7bded102e1065651b (patch) | |
tree | 9d25ed38aafa4ead3703014af21af6de82cab552 | |
parent | fae092837aa7c204801dedc712ae87ba91834caa (diff) |
minor update to 3.7.12.1
-rw-r--r-- | lib/libsqlite3/VERSION | 1 | ||||
-rw-r--r-- | lib/libsqlite3/src/build.c | 18 | ||||
-rw-r--r-- | lib/libsqlite3/src/expr.c | 8 | ||||
-rw-r--r-- | lib/libsqlite3/src/malloc.c | 4 | ||||
-rw-r--r-- | lib/libsqlite3/src/prepare.c | 1 | ||||
-rw-r--r-- | lib/libsqlite3/src/resolve.c | 36 | ||||
-rw-r--r-- | lib/libsqlite3/src/select.c | 3 | ||||
-rw-r--r-- | lib/libsqlite3/src/sqliteInt.h | 16 | ||||
-rw-r--r-- | lib/libsqlite3/src/test_quota.c | 112 | ||||
-rw-r--r-- | lib/libsqlite3/src/vdbetrace.c | 3 |
10 files changed, 118 insertions, 84 deletions
diff --git a/lib/libsqlite3/VERSION b/lib/libsqlite3/VERSION new file mode 100644 index 00000000000..74d3416de0a --- /dev/null +++ b/lib/libsqlite3/VERSION @@ -0,0 +1 @@ +3.7.12.1 diff --git a/lib/libsqlite3/src/build.c b/lib/libsqlite3/src/build.c index 6fc59dade40..31190f6fe76 100644 --- a/lib/libsqlite3/src/build.c +++ b/lib/libsqlite3/src/build.c @@ -502,9 +502,16 @@ static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){ ** the table data structure from the hash table. But it does destroy ** memory structures of the indices and foreign keys associated with ** the table. +** +** The db parameter is optional. It is needed if the Table object +** contains lookaside memory. (Table objects in the schema do not use +** lookaside memory, but some ephemeral Table objects do.) Or the +** db parameter can be used with db->pnBytesFreed to measure the memory +** used by the Table object. */ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ Index *pIndex, *pNext; + TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */ assert( !pTable || pTable->nRef>0 ); @@ -512,6 +519,12 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ if( !pTable ) return; if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return; + /* Record the number of outstanding lookaside allocations in schema Tables + ** prior to doing any free() operations. Since schema Tables do not use + ** lookaside, this number should not change. */ + TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ? + db->lookaside.nOut : 0 ); + /* Delete all indices associated with this table. */ for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){ pNext = pIndex->pNext; @@ -543,6 +556,9 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ sqlite3VtabClear(db, pTable); #endif sqlite3DbFree(db, pTable); + + /* Verify that no lookaside memory was used by schema tables */ + assert( nLookaside==0 || nLookaside==db->lookaside.nOut ); } /* @@ -1491,7 +1507,7 @@ void sqlite3EndTable( sSrc.a[0].iCursor = -1; sNC.pParse = pParse; sNC.pSrcList = &sSrc; - sNC.isCheck = 1; + sNC.ncFlags = NC_IsCheck; pList = p->pCheck; for(i=0; i<pList->nExpr; i++){ if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ diff --git a/lib/libsqlite3/src/expr.c b/lib/libsqlite3/src/expr.c index 10d9f775d9c..1e46596a2f1 100644 --- a/lib/libsqlite3/src/expr.c +++ b/lib/libsqlite3/src/expr.c @@ -3778,7 +3778,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB){ if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ return 2; } - }else if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ + }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ return 2; @@ -3965,7 +3965,9 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ return WRC_Prune; } case TK_AGG_FUNCTION: { - if( !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) ){ + if( (pNC->ncFlags & NC_InAggFunc)==0 + && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) + ){ /* Check to see if pExpr is a duplicate of another aggregate ** function that is already in the pAggInfo structure */ @@ -4002,8 +4004,8 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ ExprSetIrreducible(pExpr); pExpr->iAgg = (i16)i; pExpr->pAggInfo = pAggInfo; - return WRC_Prune; } + return WRC_Prune; } } return WRC_Continue; diff --git a/lib/libsqlite3/src/malloc.c b/lib/libsqlite3/src/malloc.c index 29c6b0dcd04..35a44e5f61c 100644 --- a/lib/libsqlite3/src/malloc.c +++ b/lib/libsqlite3/src/malloc.c @@ -491,6 +491,10 @@ void sqlite3DbFree(sqlite3 *db, void *p){ } if( isLookaside(db, p) ){ LookasideSlot *pBuf = (LookasideSlot*)p; +#if SQLITE_DEBUG + /* Trash all content in the buffer being freed */ + memset(p, 0xaa, db->lookaside.sz); +#endif pBuf->pNext = db->lookaside.pFree; db->lookaside.pFree = pBuf; db->lookaside.nOut--; diff --git a/lib/libsqlite3/src/prepare.c b/lib/libsqlite3/src/prepare.c index faeefa894f8..c46e55ed2c8 100644 --- a/lib/libsqlite3/src/prepare.c +++ b/lib/libsqlite3/src/prepare.c @@ -706,6 +706,7 @@ static int sqlite3LockAndPrepare( } sqlite3BtreeLeaveAll(db); sqlite3_mutex_leave(db->mutex); + assert( rc==SQLITE_OK || *ppStmt==0 ); return rc; } diff --git a/lib/libsqlite3/src/resolve.c b/lib/libsqlite3/src/resolve.c index 090fa79842f..a66f88fdc0d 100644 --- a/lib/libsqlite3/src/resolve.c +++ b/lib/libsqlite3/src/resolve.c @@ -311,7 +311,7 @@ static int lookupName( assert( pExpr->x.pList==0 ); assert( pExpr->x.pSelect==0 ); pOrig = pEList->a[j].pExpr; - if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){ + if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); return WRC_Abort; } @@ -556,7 +556,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ } } #endif - if( is_agg && !pNC->allowAgg ){ + if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); pNC->nErr++; is_agg = 0; @@ -570,11 +570,11 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ } if( is_agg ){ pExpr->op = TK_AGG_FUNCTION; - pNC->hasAgg = 1; + pNC->ncFlags |= NC_HasAgg; } - if( is_agg ) pNC->allowAgg = 0; + if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg; sqlite3WalkExprList(pWalker, pList); - if( is_agg ) pNC->allowAgg = 1; + if( is_agg ) pNC->ncFlags |= NC_AllowAgg; /* FIX ME: Compute pExpr->affinity based on the expected return ** type of the function */ @@ -589,7 +589,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ if( ExprHasProperty(pExpr, EP_xIsSelect) ){ int nRef = pNC->nRef; #ifndef SQLITE_OMIT_CHECK - if( pNC->isCheck ){ + if( (pNC->ncFlags & NC_IsCheck)!=0 ){ sqlite3ErrorMsg(pParse,"subqueries prohibited in CHECK constraints"); } #endif @@ -603,7 +603,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){ } #ifndef SQLITE_OMIT_CHECK case TK_VARIABLE: { - if( pNC->isCheck ){ + if( (pNC->ncFlags & NC_IsCheck)!=0 ){ sqlite3ErrorMsg(pParse,"parameters prohibited in CHECK constraints"); } break; @@ -685,7 +685,7 @@ static int resolveOrderByTermToExprList( nc.pParse = pParse; nc.pSrcList = pSelect->pSrc; nc.pEList = pEList; - nc.allowAgg = 1; + nc.ncFlags = NC_AllowAgg; nc.nErr = 0; db = pParse->db; savedSuppErr = db->suppressErr; @@ -987,7 +987,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ /* Set up the local name-context to pass to sqlite3ResolveExprNames() to ** resolve the result-set expression list. */ - sNC.allowAgg = 1; + sNC.ncFlags = NC_AllowAgg; sNC.pSrcList = p->pSrc; sNC.pNext = pOuterNC; @@ -1033,10 +1033,10 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ */ assert( (p->selFlags & SF_Aggregate)==0 ); pGroupBy = p->pGroupBy; - if( pGroupBy || sNC.hasAgg ){ + if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){ p->selFlags |= SF_Aggregate; }else{ - sNC.allowAgg = 0; + sNC.ncFlags &= ~NC_AllowAgg; } /* If a HAVING clause is present, then there must be a GROUP BY clause. @@ -1065,7 +1065,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** outer queries */ sNC.pNext = 0; - sNC.allowAgg = 1; + sNC.ncFlags |= NC_AllowAgg; /* Process the ORDER BY clause for singleton SELECT statements. ** The ORDER BY clause for compounds SELECT statements is handled @@ -1153,7 +1153,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** ** Function calls are checked to make sure that the function is ** defined and that the correct number of arguments are specified. -** If the function is an aggregate function, then the pNC->hasAgg is +** If the function is an aggregate function, then the NC_HasAgg flag is ** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION. ** If an expression contains aggregate functions then the EP_Agg ** property on the expression is set. @@ -1165,7 +1165,7 @@ int sqlite3ResolveExprNames( NameContext *pNC, /* Namespace to resolve expressions in. */ Expr *pExpr /* The expression to be analyzed. */ ){ - int savedHasAgg; + u8 savedHasAgg; Walker w; if( pExpr==0 ) return 0; @@ -1178,8 +1178,8 @@ int sqlite3ResolveExprNames( pParse->nHeight += pExpr->nHeight; } #endif - savedHasAgg = pNC->hasAgg; - pNC->hasAgg = 0; + savedHasAgg = pNC->ncFlags & NC_HasAgg; + pNC->ncFlags &= ~NC_HasAgg; w.xExprCallback = resolveExprStep; w.xSelectCallback = resolveSelectStep; w.pParse = pNC->pParse; @@ -1191,10 +1191,10 @@ int sqlite3ResolveExprNames( if( pNC->nErr>0 || w.pParse->nErr>0 ){ ExprSetProperty(pExpr, EP_Error); } - if( pNC->hasAgg ){ + if( pNC->ncFlags & NC_HasAgg ){ ExprSetProperty(pExpr, EP_Agg); }else if( savedHasAgg ){ - pNC->hasAgg = 1; + pNC->ncFlags |= NC_HasAgg; } return ExprHasProperty(pExpr, EP_Error); } diff --git a/lib/libsqlite3/src/select.c b/lib/libsqlite3/src/select.c index 835d9fd9ccb..d79a6112f72 100644 --- a/lib/libsqlite3/src/select.c +++ b/lib/libsqlite3/src/select.c @@ -3149,6 +3149,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){ if( IsVirtual(pTab) ) return 0; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; + if( pAggInfo->nFunc==0 ) return 0; if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0; if( pExpr->flags&EP_Distinct ) return 0; @@ -4139,7 +4140,9 @@ int sqlite3Select( sAggInfo.nAccumulator = sAggInfo.nColumn; for(i=0; i<sAggInfo.nFunc; i++){ assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); + sNC.ncFlags |= NC_InAggFunc; sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); + sNC.ncFlags &= ~NC_InAggFunc; } if( db->mallocFailed ) goto select_end; diff --git a/lib/libsqlite3/src/sqliteInt.h b/lib/libsqlite3/src/sqliteInt.h index cb178ff97cc..953850eee45 100644 --- a/lib/libsqlite3/src/sqliteInt.h +++ b/lib/libsqlite3/src/sqliteInt.h @@ -2006,16 +2006,22 @@ struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ ExprList *pEList; /* Optional list of named expressions */ - 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; /* True if aggregates are seen */ - u8 isCheck; /* True if resolving names in a CHECK constraint */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */ + int nRef; /* Number of names resolved by this context */ + int nErr; /* Number of errors encountered while resolving names */ + u8 ncFlags; /* Zero or more NC_* flags defined below */ }; /* +** Allowed values for the NameContext, ncFlags field. +*/ +#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */ +#define NC_HasAgg 0x02 /* One or more aggregate functions seen */ +#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */ +#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */ + +/* ** An instance of the following structure contains all information ** needed to generate code for a single SELECT statement. ** diff --git a/lib/libsqlite3/src/test_quota.c b/lib/libsqlite3/src/test_quota.c index 87bd1e91836..38dc36fdc23 100644 --- a/lib/libsqlite3/src/test_quota.c +++ b/lib/libsqlite3/src/test_quota.c @@ -45,6 +45,62 @@ #endif /* SQLITE_THREADSAFE==0 */ +/* +** Figure out if we are dealing with Unix, Windows, or some other +** operating system. After the following block of preprocess macros, +** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER +** will defined to either 1 or 0. One of the four will be 1. The other +** three will be 0. +*/ +#if defined(SQLITE_OS_OTHER) +# if SQLITE_OS_OTHER==1 +# undef SQLITE_OS_UNIX +# define SQLITE_OS_UNIX 0 +# undef SQLITE_OS_WIN +# define SQLITE_OS_WIN 0 +# undef SQLITE_OS_OS2 +# define SQLITE_OS_OS2 0 +# else +# undef SQLITE_OS_OTHER +# endif +#endif +#if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) +# define SQLITE_OS_OTHER 0 +# ifndef SQLITE_OS_WIN +# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) \ + || defined(__MINGW32__) || defined(__BORLANDC__) +# define SQLITE_OS_WIN 1 +# define SQLITE_OS_UNIX 0 +# define SQLITE_OS_OS2 0 +# elif defined(__EMX__) || defined(_OS2) || defined(OS2) \ + || defined(_OS2_) || defined(__OS2__) +# define SQLITE_OS_WIN 0 +# define SQLITE_OS_UNIX 0 +# define SQLITE_OS_OS2 1 +# else +# define SQLITE_OS_WIN 0 +# define SQLITE_OS_UNIX 1 +# define SQLITE_OS_OS2 0 +# endif +# else +# define SQLITE_OS_UNIX 0 +# define SQLITE_OS_OS2 0 +# endif +#else +# ifndef SQLITE_OS_WIN +# define SQLITE_OS_WIN 0 +# endif +#endif + +#if SQLITE_OS_UNIX +# include <unistd.h> +#endif +#if SQLITE_OS_WIN +# include <windows.h> +# include <io.h> +#endif + + /************************ Object Definitions ******************************/ /* Forward declaration of all object types */ @@ -359,62 +415,6 @@ static quotaFile *quotaFindFile( } return pFile; } - -/* -** Figure out if we are dealing with Unix, Windows, or some other -** operating system. After the following block of preprocess macros, -** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER -** will defined to either 1 or 0. One of the four will be 1. The other -** three will be 0. -*/ -#if defined(SQLITE_OS_OTHER) -# if SQLITE_OS_OTHER==1 -# undef SQLITE_OS_UNIX -# define SQLITE_OS_UNIX 0 -# undef SQLITE_OS_WIN -# define SQLITE_OS_WIN 0 -# undef SQLITE_OS_OS2 -# define SQLITE_OS_OS2 0 -# else -# undef SQLITE_OS_OTHER -# endif -#endif -#if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) -# define SQLITE_OS_OTHER 0 -# ifndef SQLITE_OS_WIN -# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) \ - || defined(__MINGW32__) || defined(__BORLANDC__) -# define SQLITE_OS_WIN 1 -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 0 -# elif defined(__EMX__) || defined(_OS2) || defined(OS2) \ - || defined(_OS2_) || defined(__OS2__) -# define SQLITE_OS_WIN 0 -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 1 -# else -# define SQLITE_OS_WIN 0 -# define SQLITE_OS_UNIX 1 -# define SQLITE_OS_OS2 0 -# endif -# else -# define SQLITE_OS_UNIX 0 -# define SQLITE_OS_OS2 0 -# endif -#else -# ifndef SQLITE_OS_WIN -# define SQLITE_OS_WIN 0 -# endif -#endif - -#if SQLITE_OS_UNIX -# include <unistd.h> -#endif -#if SQLITE_OS_WIN -# include <windows.h> -# include <io.h> -#endif - /* ** Translate UTF8 to MBCS for use in fopen() calls. Return a pointer to the ** translated text.. Call quota_mbcs_free() to deallocate any memory diff --git a/lib/libsqlite3/src/vdbetrace.c b/lib/libsqlite3/src/vdbetrace.c index 4c4be13737c..c71a7c41a43 100644 --- a/lib/libsqlite3/src/vdbetrace.c +++ b/lib/libsqlite3/src/vdbetrace.c @@ -167,8 +167,9 @@ char *sqlite3VdbeExpandSql( */ void sqlite3ExplainBegin(Vdbe *pVdbe){ if( pVdbe ){ + Explain *p; sqlite3BeginBenignMalloc(); - Explain *p = sqlite3_malloc( sizeof(Explain) ); + p = sqlite3_malloc( sizeof(Explain) ); if( p ){ memset(p, 0, sizeof(*p)); p->pVdbe = pVdbe; |