# # # patch "sqlite/btree.c" # from [c1cc6660b01d9e9f4329a9ab559d6a991c2be638] # to [be3f7d6d20f65c997f2f67d5b31d63aa74de6845] # # patch "sqlite/expr.c" # from [de9f55b1baed00199466028ad96967208d487798] # to [9bc05ed44feb04b585c72162fbb30d89b268feb6] # # patch "sqlite/func.c" # from [6b45261aa2c514f642201b90493af68469c04af6] # to [28daebcddce30030f167afb3a7ed881a043b98b0] # # patch "sqlite/insert.c" # from [89d184422d85db0418e0f66032ccea3657078ecd] # to [ca135e919c2a9241e83e8dd74316677fdd54fb6f] # # patch "sqlite/keywordhash.h" # from [1224129789df7a9d09fbef62e56cb5254915b78f] # to [8933d5a7116aadf5d7ba3d0b65204ee7b7dc1153] # # patch "sqlite/main.c" # from [65fc7de0b3c2e5b637c000ecf419c35de2525ef9] # to [345ffcf44506bda3b53355c08cf22aecbded27e7] # # patch "sqlite/malloc.c" # from [fa9bbccc4e6d099cd04c2518d238a1669c9d1020] # to [3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7] # # patch "sqlite/os_common.h" # from [a38233cd3b1f260db6f01f1093295d5708130065] # to [a5c446d3b93f09f369d13bf217de4bed3437dd1c] # # patch "sqlite/os_unix.c" # from [4099d05dc4b01997e80a289f3c6a220688e5cff5] # to [9d2a421acc607262e63ccf31e3fe86e5f2520af6] # # patch "sqlite/pager.c" # from [79a4587cc5e84a7ca1e211fa273bb2071a78447b] # to [cdf561d3ae4009be902df714da4518dc3522e206] # # patch "sqlite/prepare.c" # from [609bb27860ce98ab39889fecc0998dfd8220891b] # to [3257b63db949aee338a16ad23e09df8d56c1c36f] # # patch "sqlite/sqlite3.h" # from [535f235f65b21ca83ff426b755a49e4ca3624dee] # to [27fa51628d94ae3662564e1a039705072694fe1c] # # patch "sqlite/sqliteInt.h" # from [81183ae71162818bf60478e738ff68604128bb06] # to [aaf44ba52e0afe1327baae8082e3662d7b36723b] # # patch "sqlite/sqliteLimit.h" # from [ee8903fcebd2a83f9c6192f1e869b6e09e927226] # to [f14609c27636ebc217c9603ade26dbdd7d0f6afa] # # patch "sqlite/tokenize.c" # from [0f0955ef7b8ab99ba2d3099faa89b80ccba3733a] # to [e959754c67bbd0cf0b03520f7344a536a7ac2915] # # patch "sqlite/trigger.c" # from [420192efe3e6f03addf7897c60c3c8bf913d3493] # to [355cdf7019dfa5468bf531347f7568283a288746] # # patch "sqlite/utf.c" # from [01b2aba02b10d12903e9e1ff897215c9faf6b662] # to [68873142d65d686e59af4886073c0a67a1230171] # # patch "sqlite/vdbe.c" # from [d2181793909247b264d089d8aa2a20ef1294a49e] # to [cf973bd1af5fbda845b0f759bb06eb19ff42e215] # # patch "sqlite/vdbeapi.c" # from [fe3b713d5d37f8dfff1aa7546dae213a0e492f10] # to [220b81132abaf0f620edb8da48799a77daef12a7] # # patch "sqlite/vdbeaux.c" # from [ca1d673fd5e45fe9ba994391b11568c48a7e1b59] # to [d626e0f8cd78b4280bcb7af25d5c5566348ba87a] # # patch "sqlite/where.c" # from [12387641659605318ae03d87f0687f223dfc9568] # to [c7e13b81ff8777e402d047a695fbf322e67c89e1] # ============================================================ --- sqlite/btree.c c1cc6660b01d9e9f4329a9ab559d6a991c2be638 +++ sqlite/btree.c be3f7d6d20f65c997f2f67d5b31d63aa74de6845 @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.392 2007/06/26 01:04:49 drh Exp $ +** $Id: btree.c,v 1.396 2007/08/13 14:56:44 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -421,11 +421,13 @@ static int ptrmapGet(BtShared *pBt, Pgno */ #define findCell(pPage, iCell) \ ((pPage)->aData + get2byte(&(pPage)->aData[(pPage)->cellOffset+2*(iCell)])) +#ifdef SQLITE_TEST u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){ assert( iCell>=0 ); assert( iCellaData[pPage->hdrOffset+3]) ); return findCell(pPage, iCell); } +#endif /* ** This a more complex version of sqlite3BtreeFindCell() that works for @@ -2009,7 +2011,7 @@ static int autoVacuumCommit(BtShared *pB assert(nFin==0 || pBt->nTrunc==0 || nFin<=pBt->nTrunc); rc = SQLITE_OK; if( pBt->nTrunc ){ - sqlite3PagerWrite(pBt->pPage1->pDbPage); + rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); put4byte(&pBt->pPage1->aData[32], 0); put4byte(&pBt->pPage1->aData[36], 0); pBt->nTrunc = nFin; @@ -2791,8 +2793,8 @@ static int accessPayload( if( offset>=ovflSize ){ /* The only reason to read this page is to obtain the page ** number for the next page in the overflow chain. The page - ** data is not required. So first try to lookup the overflow - ** page-list cache, if any, then fall back to the getOverflowPage() + ** data is not required. So first try to lookup the overflow + ** page-list cache, if any, then fall back to the getOverflowPage() ** function. */ #ifndef SQLITE_OMIT_INCRBLOB @@ -4771,7 +4773,7 @@ static int balance_nonroot(MemPage *pPag memcpy(&pNew->aData[8], pCell, 4); pTemp = 0; }else if( leafData ){ - /* If the tree is a leaf-data tree, and the siblings are leaves, + /* If the tree is a leaf-data tree, and the siblings are leaves, ** then there is no divider cell in apCell[]. Instead, the divider ** cell consists of the integer key for the right-most cell of ** the sibling-page assembled above only. @@ -4963,7 +4965,6 @@ static int balance_shallower(MemPage *pP } } #endif - if( rc!=SQLITE_OK ) goto end_shallow_balance; releasePage(pChild); } end_shallow_balance: ============================================================ --- sqlite/expr.c de9f55b1baed00199466028ad96967208d487798 +++ sqlite/expr.c 9bc05ed44feb04b585c72162fbb30d89b268feb6 @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.300 2007/06/25 16:29:34 danielk1977 Exp $ +** $Id: expr.c,v 1.303 2007/08/07 17:13:04 drh Exp $ */ #include "sqliteInt.h" #include @@ -177,7 +177,7 @@ static int binaryCompareP1(Expr *pExpr1, ** Argument pRight (but not pLeft) may be a null pointer. In this case, ** it is not considered. */ -CollSeq* sqlite3BinaryCompareCollSeq( +CollSeq *sqlite3BinaryCompareCollSeq( Parse *pParse, Expr *pLeft, Expr *pRight @@ -1140,11 +1140,17 @@ static int lookupName( for(j=0; jnExpr; j++){ char *zAs = pEList->a[j].zName; if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ - Expr *pDup; + Expr *pDup, *pOrig; assert( pExpr->pLeft==0 && pExpr->pRight==0 ); assert( pExpr->pList==0 ); assert( pExpr->pSelect==0 ); - pDup = sqlite3ExprDup(pEList->a[j].pExpr); + pOrig = pEList->a[j].pExpr; + if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){ + sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); + sqliteFree(zCol); + return 2; + } + pDup = sqlite3ExprDup(pOrig); if( pExpr->flags & EP_ExpCollate ){ pDup->pColl = pExpr->pColl; pDup->flags |= EP_ExpCollate; @@ -1572,7 +1578,7 @@ void sqlite3CodeSubselect(Parse *pParse, }else if( pExpr->pList ){ /* Case 2: expr IN (exprlist) ** - ** For each expression, build an index key from the evaluation and + ** For each expression, build an index key from the evaluation and ** store it in the temporary table. If is a column, then use ** that columns affinity when building index keys. If is not ** a column, use numeric affinity. @@ -2052,7 +2058,7 @@ void sqlite3ExprCode(Parse *pParse, Expr if( !pParse->trigStack ){ sqlite3ErrorMsg(pParse, "RAISE() may only be used within a trigger-program"); - return; + return; } if( pExpr->iColumn!=OE_Ignore ){ assert( pExpr->iColumn==OE_Rollback || ============================================================ --- sqlite/func.c 6b45261aa2c514f642201b90493af68469c04af6 +++ sqlite/func.c 28daebcddce30030f167afb3a7ed881a043b98b0 @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.161 2007/06/22 15:21:16 danielk1977 Exp $ +** $Id: func.c,v 1.163 2007/07/26 06:50:06 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -26,6 +26,7 @@ #include "vdbeInt.h" #include "os.h" + /* ** Return the collating function associated with a function. */ @@ -398,15 +399,6 @@ static const struct compareInfo likeInfo static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; /* -** Read a single UTF-8 character and return its value. -*/ -u32 sqlite3ReadUtf8(const unsigned char *z){ - u32 c; - SQLITE_READ_UTF8(z, c); - return c; -} - -/* ** Compare two UTF-8 strings for equality where the first string can ** potentially be a "glob" expression. Return true (1) if they ** are the same and false (0) if they are different. @@ -440,97 +432,102 @@ static int patternCompare( const struct compareInfo *pInfo, /* Information about how to do the compare */ const int esc /* The escape character */ ){ - register int c; + int c, c2; int invert; int seen; - int c2; u8 matchOne = pInfo->matchOne; u8 matchAll = pInfo->matchAll; u8 matchSet = pInfo->matchSet; u8 noCase = pInfo->noCase; int prevEscape = 0; /* True if the previous character was 'escape' */ - while( (c = *zPattern)!=0 ){ + while( (c = sqlite3Utf8Read(zPattern,0,&zPattern))!=0 ){ if( !prevEscape && c==matchAll ){ - while( (c=zPattern[1]) == matchAll || c == matchOne ){ - if( c==matchOne ){ - if( *zString==0 ) return 0; - SQLITE_SKIP_UTF8(zString); + while( (c=sqlite3Utf8Read(zPattern,0,&zPattern)) == matchAll + || c == matchOne ){ + if( c==matchOne && sqlite3Utf8Read(zString, 0, &zString)==0 ){ + return 0; } - zPattern++; } - if( c && esc && sqlite3ReadUtf8(&zPattern[1])==esc ){ - u8 const *zTemp = &zPattern[1]; - SQLITE_SKIP_UTF8(zTemp); - c = *zTemp; - } - if( c==0 ) return 1; - if( c==matchSet ){ - assert( esc==0 ); /* This is GLOB, not LIKE */ - while( *zString && patternCompare(&zPattern[1],zString,pInfo,esc)==0 ){ + if( c==0 ){ + return 1; + }else if( c==esc ){ + c = sqlite3Utf8Read(zPattern, 0, &zPattern); + if( c==0 ){ + return 0; + } + }else if( c==matchSet ){ + assert( esc==0 ); /* This is GLOB, not LIKE */ + assert( matchSet<0x80 ); /* '[' is a single-byte character */ + while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){ SQLITE_SKIP_UTF8(zString); } return *zString!=0; - }else{ - while( (c2 = *zString)!=0 ){ - if( noCase ){ - c2 = sqlite3UpperToLower[c2]; - c = sqlite3UpperToLower[c]; - while( c2 != 0 && c2 != c ){ c2 = sqlite3UpperToLower[*++zString]; } - }else{ - while( c2 != 0 && c2 != c ){ c2 = *++zString; } + } + while( (c2 = sqlite3Utf8Read(zString,0,&zString))!=0 ){ + if( noCase ){ + c2 = c2<0x80 ? sqlite3UpperToLower[c2] : c2; + c = c<0x80 ? sqlite3UpperToLower[c] : c; + while( c2 != 0 && c2 != c ){ + c2 = sqlite3Utf8Read(zString, 0, &zString); + if( c2<0x80 ) c2 = sqlite3UpperToLower[c2]; } - if( c2==0 ) return 0; - if( patternCompare(&zPattern[1],zString,pInfo,esc) ) return 1; - SQLITE_SKIP_UTF8(zString); + }else{ + while( c2 != 0 && c2 != c ){ + c2 = sqlite3Utf8Read(zString, 0, &zString); + } } - return 0; + if( c2==0 ) return 0; + if( patternCompare(zPattern,zString,pInfo,esc) ) return 1; } + return 0; }else if( !prevEscape && c==matchOne ){ - if( *zString==0 ) return 0; - SQLITE_SKIP_UTF8(zString); - zPattern++; + if( sqlite3Utf8Read(zString, 0, &zString)==0 ){ + return 0; + } }else if( c==matchSet ){ int prior_c = 0; assert( esc==0 ); /* This only occurs for GLOB, not LIKE */ seen = 0; invert = 0; - c = sqlite3ReadUtf8(zString); + c = sqlite3Utf8Read(zString, 0, &zString); if( c==0 ) return 0; - c2 = *++zPattern; - if( c2=='^' ){ invert = 1; c2 = *++zPattern; } + c2 = sqlite3Utf8Read(zPattern, 0, &zPattern); + if( c2=='^' ){ + invert = 1; + c2 = sqlite3Utf8Read(zPattern, 0, &zPattern); + } if( c2==']' ){ if( c==']' ) seen = 1; - c2 = *++zPattern; + c2 = sqlite3Utf8Read(zPattern, 0, &zPattern); } - while( (c2 = sqlite3ReadUtf8(zPattern))!=0 && c2!=']' ){ - if( c2=='-' && zPattern[1]!=']' && zPattern[1]!=0 && prior_c>0 ){ - zPattern++; - c2 = sqlite3ReadUtf8(zPattern); + while( c2 && c2!=']' ){ + if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){ + c2 = sqlite3Utf8Read(zPattern, 0, &zPattern); if( c>=prior_c && c<=c2 ) seen = 1; prior_c = 0; - }else if( c==c2 ){ - seen = 1; - prior_c = c2; }else{ + if( c==c2 ){ + seen = 1; + } prior_c = c2; } - SQLITE_SKIP_UTF8(zPattern); + c2 = sqlite3Utf8Read(zPattern, 0, &zPattern); } - if( c2==0 || (seen ^ invert)==0 ) return 0; - SQLITE_SKIP_UTF8(zString); - zPattern++; - }else if( esc && !prevEscape && sqlite3ReadUtf8(zPattern)==esc){ + if( c2==0 || (seen ^ invert)==0 ){ + return 0; + } + }else if( esc==c && !prevEscape ){ prevEscape = 1; - SQLITE_SKIP_UTF8(zPattern); }else{ + c2 = sqlite3Utf8Read(zString, 0, &zString); if( noCase ){ - if( sqlite3UpperToLower[c] != sqlite3UpperToLower[*zString] ) return 0; - }else{ - if( c != *zString ) return 0; + c = c<0x80 ? sqlite3UpperToLower[c] : c; + c2 = c2<0x80 ? sqlite3UpperToLower[c2] : c2; } - zPattern++; - zString++; + if( c!=c2 ){ + return 0; + } prevEscape = 0; } } @@ -590,7 +587,7 @@ static void likeFunc( "ESCAPE expression must be a single character", -1); return; } - escape = sqlite3ReadUtf8(zEsc); + escape = sqlite3Utf8Read(zEsc, 0, &zEsc); } if( zA && zB ){ struct compareInfo *pInfo = sqlite3_user_data(context); @@ -1121,6 +1118,7 @@ static void test_auxdata( if( zAux ){ zRet[i*2] = '1'; if( strcmp(zAux, z) ){ + free_test_auxdata((void *)zRet); sqlite3_result_error(pCtx, "Auxilary data corruption", -1); return; } ============================================================ --- sqlite/insert.c 89d184422d85db0418e0f66032ccea3657078ecd +++ sqlite/insert.c ca135e919c2a9241e83e8dd74316677fdd54fb6f @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.187 2007/06/26 10:38:55 danielk1977 Exp $ +** $Id: insert.c,v 1.188 2007/07/23 19:39:47 drh Exp $ */ #include "sqliteInt.h" @@ -1027,7 +1027,7 @@ void sqlite3GenerateConstraintChecks( assert( pParse->ckOffset==nCol ); pParse->ckOffset = 0; onError = overrideError!=OE_Default ? overrideError : OE_Abort; - if( onError==OE_Ignore || onError==OE_Replace ){ + if( onError==OE_Ignore ){ sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest); }else{ ============================================================ --- sqlite/keywordhash.h 1224129789df7a9d09fbef62e56cb5254915b78f +++ sqlite/keywordhash.h 8933d5a7116aadf5d7ba3d0b65204ee7b7dc1153 @@ -1,8 +1,8 @@ /***** This file contains automatically generated code ****** ** ** The code in this file has been automatically generated by ** -** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.30 2007/05/04 18:30:41 drh Exp $ +** $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.31 2007/07/30 18:26:20 rse Exp $ ** ** The code in this file implements a function that determines whether ** or not a given identifier is really an SQL keyword. The same thing ============================================================ --- sqlite/main.c 65fc7de0b3c2e5b637c000ecf419c35de2525ef9 +++ sqlite/main.c 345ffcf44506bda3b53355c08cf22aecbded27e7 @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.377 2007/06/22 15:21:16 danielk1977 Exp $ +** $Id: main.c,v 1.378 2007/08/13 15:28:34 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -240,6 +240,7 @@ void sqlite3RollbackAll(sqlite3 *db){ } sqlite3VtabRollback(db); if( db->flags&SQLITE_InternChanges ){ + sqlite3ExpirePreparedStatements(db); sqlite3ResetInternalSchema(db, 0); } ============================================================ --- sqlite/malloc.c fa9bbccc4e6d099cd04c2518d238a1669c9d1020 +++ sqlite/malloc.c 3850ab4a2edfb190ffee353c5674ebd8c6b4ccc7 @@ -12,7 +12,7 @@ ** Memory allocation functions used throughout sqlite. ** ** -** $Id: malloc.c,v 1.3 2007/06/15 20:29:20 drh Exp $ +** $Id: malloc.c,v 1.4 2007/08/08 01:04:52 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -792,10 +792,10 @@ void sqlite3SetString(char **pz, ...){ ** then the connection error-code (the value returned by sqlite3_errcode()) ** is set to SQLITE_NOMEM. */ -int sqlite3_mallocHasFailed = 0; +int sqlite3MallocHasFailed = 0; int sqlite3ApiExit(sqlite3* db, int rc){ if( sqlite3MallocFailed() ){ - sqlite3_mallocHasFailed = 0; + sqlite3MallocHasFailed = 0; sqlite3OsLeaveMutex(); sqlite3Error(db, SQLITE_NOMEM, 0); rc = SQLITE_NOMEM; @@ -809,8 +809,8 @@ void sqlite3FailedMalloc(){ void sqlite3FailedMalloc(){ if( !sqlite3MallocFailed() ){ sqlite3OsEnterMutex(); - assert( sqlite3_mallocHasFailed==0 ); - sqlite3_mallocHasFailed = 1; + assert( sqlite3MallocHasFailed==0 ); + sqlite3MallocHasFailed = 1; } } ============================================================ --- sqlite/os_common.h a38233cd3b1f260db6f01f1093295d5708130065 +++ sqlite/os_common.h a5c446d3b93f09f369d13bf217de4bed3437dd1c @@ -36,8 +36,8 @@ unsigned int sqlite3_pending_byte = 0x40 unsigned int sqlite3_pending_byte = 0x40000000; #endif +#ifdef SQLITE_DEBUG int sqlite3_os_trace = 0; -#ifdef SQLITE_DEBUG #define OSTRACE1(X) if( sqlite3_os_trace ) sqlite3DebugPrintf(X) #define OSTRACE2(X,Y) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y) #define OSTRACE3(X,Y,Z) if( sqlite3_os_trace ) sqlite3DebugPrintf(X,Y,Z) ============================================================ --- sqlite/os_unix.c 4099d05dc4b01997e80a289f3c6a220688e5cff5 +++ sqlite/os_unix.c 9d2a421acc607262e63ccf31e3fe86e5f2520af6 @@ -376,12 +376,12 @@ typedef enum { ** file systems that are known to be unsupported */ typedef enum { - posixLockingStyle = 0, /* standard posix-advisory locks */ - afpLockingStyle, /* use afp locks */ - flockLockingStyle, /* use flock() */ - dotlockLockingStyle, /* use .lock files */ - noLockingStyle, /* useful for read-only file system */ - unsupportedLockingStyle /* indicates unsupported file system */ + posixLockingStyle = 0, /* standard posix-advisory locks */ + afpLockingStyle, /* use afp locks */ + flockLockingStyle, /* use flock() */ + dotlockLockingStyle, /* use .lock files */ + noLockingStyle, /* useful for read-only file system */ + unsupportedLockingStyle /* indicates unsupported file system */ } sqlite3LockingStyle; #endif /* SQLITE_ENABLE_LOCKING_STYLE */ @@ -601,7 +601,7 @@ static sqlite3LockingStyle sqlite3Detect if( (!strcmp(fsInfo.f_fstypename, "hfs")) || (!strcmp(fsInfo.f_fstypename, "ufs")) ) - return posixLockingStyle; + return posixLockingStyle; if(!strcmp(fsInfo.f_fstypename, "afpfs")) return afpLockingStyle; @@ -1714,7 +1714,7 @@ struct ByteRangeLockPB2 int fd; /* file desc to assoc this lock with */ }; -#define afpfsByteRangeLock2FSCTL _IOWR('z', 23, struct ByteRangeLockPB2) +#define afpfsByteRangeLock2FSCTL _IOWR('z', 23, struct ByteRangeLockPB2) /* return 0 on success, 1 on failure. To match the behavior of the normal posix file locking (used in unixLock for example), we should @@ -1723,7 +1723,7 @@ static int _AFPFSSetLock(const char *pat static int _AFPFSSetLock(const char *path, int fd, unsigned long long offset, unsigned long long length, int setLockFlag) { - struct ByteRangeLockPB2 pb; + struct ByteRangeLockPB2 pb; int err; pb.unLockFlag = setLockFlag ? 0 : 1; ============================================================ --- sqlite/pager.c 79a4587cc5e84a7ca1e211fa273bb2071a78447b +++ sqlite/pager.c cdf561d3ae4009be902df714da4518dc3522e206 @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.351 2007/07/20 00:33:36 drh Exp $ +** @(#) $Id: pager.c,v 1.355 2007/08/11 00:26:21 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -562,7 +562,11 @@ static int pager_error(Pager *pPager, in */ static int pager_error(Pager *pPager, int rc){ int rc2 = rc & 0xff; - assert( pPager->errCode==SQLITE_FULL || pPager->errCode==SQLITE_OK ); + assert( + pPager->errCode==SQLITE_FULL || + pPager->errCode==SQLITE_OK || + (pPager->errCode & 0xff)==SQLITE_IOERR + ); if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR || @@ -1451,10 +1455,15 @@ static int pager_playback(Pager *pPager, } /* If nRec is 0 and this rollback is of a transaction created by this - ** process. In this case the rest of the journal file consists of - ** journalled copies of pages that need to be read back into the cache. + ** process and if this is the final header in the journal, then it means + ** that this part of the journal was being filled but has not yet been + ** synced to disk. Compute the number of pages based on the remaining + ** size of the file. + ** + ** The third term of the test was added to fix ticket #2565. */ - if( nRec==0 && !isHot ){ + if( nRec==0 && !isHot && + pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){ nRec = (szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager); } @@ -2755,7 +2764,7 @@ int sqlite3PagerReleaseMemory(int nReq){ pTmp->pNextAll = pPg->pNextAll; } nReleased += sqliteAllocSize(pPg); - IOTRACE(("PGFREE %p %d\n", pPager, pPg->pgno)); + IOTRACE(("PGFREE %p %d *\n", pPager, pPg->pgno)); PAGER_INCR(sqlite3_pager_pgfree_count); sqliteFree(pPg); } @@ -2767,7 +2776,11 @@ int sqlite3PagerReleaseMemory(int nReq){ ** The error will be returned to the user (or users, in the case ** of a shared pager cache) of the pager for which the error occured. */ - assert( (rc&0xff)==SQLITE_IOERR || rc==SQLITE_FULL ); + assert( + (rc&0xff)==SQLITE_IOERR || + rc==SQLITE_FULL || + rc==SQLITE_BUSY + ); assert( pPager->state>=PAGER_RESERVED ); pager_error(pPager, rc); } @@ -2856,8 +2869,8 @@ static int pagerSharedLock(Pager *pPager ** a write lock, so there is never any chance of two or more ** processes opening the journal at the same time. ** - ** Open the journal for read/write access. This is because in - ** exclusive-access mode the file descriptor will be kept open and + ** Open the journal for read/write access. This is because in + ** exclusive-access mode the file descriptor will be kept open and ** possibly used for a transaction later on. On some systems, the ** OsTruncate() call used in exclusive-access mode also requires ** a read/write file handle. @@ -3579,7 +3592,7 @@ static int pager_write(PgHdr *pPg){ PAGERID(pPager), pPg->pgno, pPg->needSync, pager_pagehash(pPg)); *(u32*)pEnd = saved; - /* An error has occured writing to the journal file. The + /* An error has occured writing to the journal file. The ** transaction will be rolled back by the layer above. */ if( rc!=SQLITE_OK ){ ============================================================ --- sqlite/prepare.c 609bb27860ce98ab39889fecc0998dfd8220891b +++ sqlite/prepare.c 3257b63db949aee338a16ad23e09df8d56c1c36f @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.51 2007/06/24 10:14:00 danielk1977 Exp $ +** $Id: prepare.c,v 1.52 2007/08/13 14:41:19 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -337,7 +337,7 @@ int sqlite3Init(sqlite3 *db, char **pzEr */ int sqlite3Init(sqlite3 *db, char **pzErrMsg){ int i, rc; - int called_initone = 0; + int commit_internal = !(db->flags&SQLITE_InternChanges); if( db->init.busy ) return SQLITE_OK; rc = SQLITE_OK; @@ -348,7 +348,6 @@ int sqlite3Init(sqlite3 *db, char **pzEr if( rc ){ sqlite3ResetInternalSchema(db, i); } - called_initone = 1; } /* Once all the other databases have been initialised, load the schema @@ -361,12 +360,11 @@ int sqlite3Init(sqlite3 *db, char **pzEr if( rc ){ sqlite3ResetInternalSchema(db, 1); } - called_initone = 1; } #endif db->init.busy = 0; - if( rc==SQLITE_OK && called_initone ){ + if( rc==SQLITE_OK && commit_internal ){ sqlite3CommitInternalChanges(db); } ============================================================ --- sqlite/sqlite3.h 535f235f65b21ca83ff426b755a49e4ca3624dee +++ sqlite/sqlite3.h 27fa51628d94ae3662564e1a039705072694fe1c @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.218 2007/07/19 12:41:40 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.219 2007/08/08 12:11:21 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -44,6 +44,13 @@ extern "C" { #endif /* +** Add the ability to override 'extern' +*/ +#ifndef SQLITE_EXTERN +# define SQLITE_EXTERN extern +#endif + +/* ** Make sure these symbols where not defined by some previous header ** file. */ @@ -81,8 +88,8 @@ extern "C" { ** ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()]. */ -#define SQLITE_VERSION "3.4.1" -#define SQLITE_VERSION_NUMBER 3004001 +#define SQLITE_VERSION "3.4.2" +#define SQLITE_VERSION_NUMBER 3004002 /* ** CAPI3REF: Run-Time Library Version Numbers @@ -100,7 +107,7 @@ extern "C" { ** is provided for DLL users who can only access functions and not ** constants within the DLL. */ -extern const char sqlite3_version[]; +SQLITE_EXTERN const char sqlite3_version[]; const char *sqlite3_libversion(void); int sqlite3_libversion_number(void); @@ -2020,7 +2027,7 @@ int sqlite3_sleep(int); ** it is not safe to invoke this routine after [sqlite3_open()] has ** been called. */ -extern char *sqlite3_temp_directory; +SQLITE_EXTERN char *sqlite3_temp_directory; /* ** CAPI3REF: Test To See If The Databse Is In Auto-Commit Mode ============================================================ --- sqlite/sqliteInt.h 81183ae71162818bf60478e738ff68604128bb06 +++ sqlite/sqliteInt.h aaf44ba52e0afe1327baae8082e3662d7b36723b @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.578 2007/06/26 10:38:55 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.585 2007/08/08 12:11:21 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -256,15 +256,15 @@ extern int sqlite3_iLine; /* #endif -/* Variable sqlite3_mallocHasFailed is set to true after a malloc() +/* Variable sqlite3MallocHasFailed is set to true after a malloc() ** failure occurs. ** ** The sqlite3MallocFailed() macro returns true if a malloc has failed ** in this thread since the last call to sqlite3ApiExit(), or false ** otherwise. */ -extern int sqlite3_mallocHasFailed; -#define sqlite3MallocFailed() (sqlite3_mallocHasFailed && sqlite3OsInMutex(1)) +extern int sqlite3MallocHasFailed; +#define sqlite3MallocFailed() (sqlite3MallocHasFailed && sqlite3OsInMutex(1)) #define sqliteFree(x) sqlite3FreeX(x) #define sqliteAllocSize(x) sqlite3AllocSize(x) @@ -1477,11 +1477,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 */ @@ -1549,69 +1549,15 @@ typedef struct { } 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; - -/* -** A lookup table used by the SQLITE_READ_UTF8 macro. The definition -** is in utf.c. +** 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. */ -extern const unsigned char sqlite3UtfTrans1[]; - -/* -** Macros for reading UTF8 characters. -** -** SQLITE_READ_UTF8(x,c) reads a single UTF8 value out of x and writes -** that value into c. The type of x must be unsigned char*. The type -** of c must be unsigned int. -** -** SQLITE_SKIP_UTF8(x) advances x forward by one character. The type of -** x must be unsigned char*. -** -** Notes On Invalid UTF-8: -** -** * These macros never allow a 7-bit character (0x00 through 0x7f) to -** be encoded as a multi-byte character. Any multi-byte character that -** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd. -** -** * These macros never allow a UTF16 surrogate value to be encoded. -** If a multi-byte character attempts to encode a value between -** 0xd800 and 0xe000 then it is rendered as 0xfffd. -** -** * Bytes in the range of 0x80 through 0xbf which occur as the first -** byte of a character are interpreted as single-byte characters -** and rendered as themselves even though they are technically -** invalid characters. -** -** * These routines accept an infinite number of different UTF8 encodings -** for unicode values 0x80 and greater. They do not change over-length -** encodings to 0xfffd as some systems recommend. -** -*/ -#define SQLITE_READ_UTF8(zIn, c) { \ - c = *(zIn++); \ - if( c>=0xc0 ){ \ - c = sqlite3UtfTrans1[c-0xc0]; \ - while( (*zIn & 0xc0)==0x80 ){ \ - c = (c<<6) + (0x3f & *(zIn++)); \ - } \ - if( c<0x80 \ - || (c&0xFFFFF800)==0xD800 \ - || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \ - } \ -} #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 ** builds) or a function call (for debugging). If it is a function call, @@ -1830,7 +1776,7 @@ int sqlite3Utf8CharLen(const char *pData int sqlite3FitsIn64Bits(const char *); int sqlite3Utf16ByteLen(const void *pData, int nChar); int sqlite3Utf8CharLen(const char *pData, int nByte); -u32 sqlite3ReadUtf8(const unsigned char *); +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 *); @@ -1853,7 +1799,6 @@ void sqlite3VdbeSetChanges(sqlite3 *, in int sqlite3CheckCollSeq(Parse *, CollSeq *); 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); @@ -1902,6 +1847,13 @@ int sqlite3OpenTempDatabase(Parse *); void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *); int sqlite3OpenTempDatabase(Parse *); +/* +** 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*); @@ -1963,7 +1915,7 @@ void sqlite3ExprListCheckLength(Parse*, void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**); int sqlite3Reprepare(Vdbe*); void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*); -CollSeq* sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); +CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); #if SQLITE_MAX_EXPR_DEPTH>0 void sqlite3ExprSetHeight(Expr *); @@ -1972,9 +1924,7 @@ CollSeq* sqlite3BinaryCompareCollSeq(Par #define sqlite3ExprSetHeight(x) #endif -u32 sqlite3Get2byte(const u8*); u32 sqlite3Get4byte(const u8*); -void sqlite3Put2byte(u8*, u32); void sqlite3Put4byte(u8*, u32); #ifdef SQLITE_SSE @@ -1997,6 +1947,6 @@ void sqlite3Put4byte(u8*, u32); # define IOTRACE(A) # define sqlite3VdbeIOTraceSql(X) #endif -extern void (*sqlite3_io_trace)(const char*,...); +SQLITE_EXTERN void (*sqlite3_io_trace)(const char*,...); #endif ============================================================ --- sqlite/sqliteLimit.h ee8903fcebd2a83f9c6192f1e869b6e09e927226 +++ sqlite/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa @@ -52,7 +52,7 @@ ** The hard limit here is the same as SQLITE_MAX_LENGTH. */ #ifndef SQLITE_MAX_SQL_LENGTH -# define SQLITE_MAX_SQL_LENGTH SQLITE_MAX_LENGTH +# define SQLITE_MAX_SQL_LENGTH 1000000 #endif /* ============================================================ --- sqlite/tokenize.c 0f0955ef7b8ab99ba2d3099faa89b80ccba3733a +++ sqlite/tokenize.c e959754c67bbd0cf0b03520f7344a536a7ac2915 @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.130 2007/07/13 10:26:08 drh Exp $ +** $Id: tokenize.c,v 1.131 2007/07/23 19:31:17 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -381,13 +381,6 @@ int sqlite3GetToken(const unsigned char } /* -** The interface to the LEMON-generated parser -*/ -void *sqlite3ParserAlloc(void*(*)(size_t)); -void sqlite3ParserFree(void*, void(*)(void*)); -void sqlite3Parser(void*, int, Token, Parse*); - -/* ** Run the parser on the given SQL string. The parser structure is ** passed in. An SQLITE_ status code is returned. If an error occurs ** and pzErrMsg!=NULL then an error message might be written into ============================================================ --- sqlite/trigger.c 420192efe3e6f03addf7897c60c3c8bf913d3493 +++ sqlite/trigger.c 355cdf7019dfa5468bf531347f7568283a288746 @@ -673,21 +673,21 @@ static int codeTriggerProgram( pParse->trigStack->orconf = orconf; switch( pTriggerStep->op ){ case TK_SELECT: { - Select *ss = sqlite3SelectDup(pTriggerStep->pSelect); + Select *ss = sqlite3SelectDup(pTriggerStep->pSelect); if( ss ){ sqlite3SelectResolve(pParse, ss, 0); sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0); sqlite3SelectDelete(ss); } - break; + break; } case TK_UPDATE: { SrcList *pSrc; pSrc = targetSrcList(pParse, pTriggerStep); sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0); sqlite3Update(pParse, pSrc, - sqlite3ExprListDup(pTriggerStep->pExprList), - sqlite3ExprDup(pTriggerStep->pWhere), orconf); + sqlite3ExprListDup(pTriggerStep->pExprList), + sqlite3ExprDup(pTriggerStep->pWhere), orconf); sqlite3VdbeAddOp(v, OP_ResetCount, 1, 0); break; } ============================================================ --- sqlite/utf.c 01b2aba02b10d12903e9e1ff897215c9faf6b662 +++ sqlite/utf.c 68873142d65d686e59af4886073c0a67a1230171 @@ -12,7 +12,7 @@ ** This file contains routines used to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** -** $Id: utf.c,v 1.51 2007/05/23 16:23:09 danielk1977 Exp $ +** $Id: utf.c,v 1.53 2007/08/07 17:04:59 drh Exp $ ** ** Notes on UTF-8: ** @@ -49,7 +49,7 @@ const int sqlite3one = 1; ** This lookup table is used to help decode the first byte of ** a multi-byte UTF8 character. */ -const unsigned char sqlite3UtfTrans1[] = { +static const unsigned char sqlite3UtfTrans1[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -60,6 +60,7 @@ const unsigned char sqlite3UtfTrans1[] = 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00, }; + #define WRITE_UTF8(zOut, c) { \ if( c<0x00080 ){ \ *zOut++ = (c&0xFF); \ @@ -127,6 +128,54 @@ const unsigned char sqlite3UtfTrans1[] = } /* +** Translate a single UTF-8 character. Return the unicode value. +** +** During translation, assume that the byte that zTerm points +** is a 0x00. +** +** Write a pointer to the next unread byte back into *pzNext. +** +** Notes On Invalid UTF-8: +** +** * This routine never allows a 7-bit character (0x00 through 0x7f) to +** be encoded as a multi-byte character. Any multi-byte character that +** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd. +** +** * This routine never allows a UTF16 surrogate value to be encoded. +** If a multi-byte character attempts to encode a value between +** 0xd800 and 0xe000 then it is rendered as 0xfffd. +** +** * Bytes in the range of 0x80 through 0xbf which occur as the first +** byte of a character are interpreted as single-byte characters +** and rendered as themselves even though they are technically +** invalid characters. +** +** * This routine accepts an infinite number of different UTF8 encodings +** for unicode values 0x80 and greater. It do not change over-length +** encodings to 0xfffd as some systems recommend. +*/ +int sqlite3Utf8Read( + const unsigned char *z, /* First byte of UTF-8 character */ + const unsigned char *zTerm, /* Pretend this byte is 0x00 */ + const unsigned char **pzNext /* Write first byte past UTF-8 char here */ +){ + int c = *(z++); + if( c>=0xc0 ){ + c = sqlite3UtfTrans1[c-0xc0]; + while( z!=zTerm && (*z & 0xc0)==0x80 ){ + c = (c<<6) + (0x3f & *(z++)); + } + if( c<0x80 + || (c&0xFFFFF800)==0xD800 + || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } + } + *pzNext = z; + return c; +} + + + +/* ** If the TRANSLATE_TRACE macro is defined, the value of each Mem is ** printed on stderr on the way into and out of sqlite3VdbeMemTranslate(). */ @@ -219,81 +268,19 @@ int sqlite3VdbeMemTranslate(Mem *pMem, u z = zOut; if( pMem->enc==SQLITE_UTF8 ){ - unsigned int iExtra = 0xD800; - - if( 0==(pMem->flags&MEM_Term) && zTerm>zIn && (zTerm[-1]&0x80) ){ - /* This UTF8 string is not nul-terminated, and the last byte is - ** not a character in the ascii range (codpoints 0..127). This - ** means the SQLITE_READ_UTF8() macro might read past the end - ** of the allocated buffer. - ** - ** There are four possibilities: - ** - ** 1. The last byte is the first byte of a non-ASCII character, - ** - ** 2. The final N bytes of the input string are continuation bytes - ** and immediately preceding them is the first byte of a - ** non-ASCII character. - ** - ** 3. The final N bytes of the input string are continuation bytes - ** and immediately preceding them is a byte that encodes a - ** character in the ASCII range. - ** - ** 4. The entire string consists of continuation characters. - ** - ** Cases (3) and (4) require no special handling. The SQLITE_READ_UTF8() - ** macro will not overread the buffer in these cases. - */ - unsigned char *zExtra = &zTerm[-1]; - while( zExtra>zIn && (zExtra[0]&0xC0)==0x80 ){ - zExtra--; - } - - if( (zExtra[0]&0xC0)==0xC0 ){ - /* Make a copy of the last character encoding in the input string. - ** Then make sure it is nul-terminated and use SQLITE_READ_UTF8() - ** to decode the codepoint. Store the codepoint in variable iExtra, - ** it will be appended to the output string later. - */ - unsigned char *zFree = 0; - unsigned char zBuf[16]; - int nExtra = (pMem->n+zIn-zExtra); - zTerm = zExtra; - if( nExtra>15 ){ - zExtra = sqliteMallocRaw(nExtra+1); - if( !zExtra ){ - return SQLITE_NOMEM; - } - zFree = zExtra; - }else{ - zExtra = zBuf; - } - memcpy(zExtra, zTerm, nExtra); - zExtra[nExtra] = '\0'; - SQLITE_READ_UTF8(zExtra, iExtra); - sqliteFree(zFree); - } - } - if( desiredEnc==SQLITE_UTF16LE ){ /* UTF-8 -> UTF-16 Little-endian */ while( zIn UTF-16 Big-endian */ while( zInn = z - zOut; *z++ = 0; @@ -477,11 +464,11 @@ int sqlite3Utf8To8(unsigned char *zIn){ int sqlite3Utf8To8(unsigned char *zIn){ unsigned char *zOut = zIn; unsigned char *zStart = zIn; - int c; + unsigned char *zTerm; + u32 c; - while(1){ - SQLITE_READ_UTF8(zIn, c); - if( c==0 ) break; + while( zIn[0] ){ + c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); if( c!=0xfffd ){ WRITE_UTF8(zOut, c); } @@ -501,6 +488,7 @@ void sqlite3UtfSelfTest(){ unsigned int i, t; unsigned char zBuf[20]; unsigned char *z; + unsigned char *zTerm; int n; unsigned int c; @@ -509,8 +497,9 @@ void sqlite3UtfSelfTest(){ WRITE_UTF8(z, i); n = z-zBuf; z[0] = 0; + zTerm = z; z = zBuf; - SQLITE_READ_UTF8(z, c); + c = sqlite3Utf8Read(z, zTerm, (const u8**)&z); t = i; if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD; if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD; ============================================================ --- sqlite/vdbe.c d2181793909247b264d089d8aa2a20ef1294a49e +++ sqlite/vdbe.c cf973bd1af5fbda845b0f759bb06eb19ff42e215 @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.636 2007/07/01 21:18:40 drh Exp $ +** $Id: vdbe.c,v 1.639 2007/07/26 06:50:06 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -1289,7 +1289,19 @@ case OP_Function: { if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; (*ctx.pFunc->xFunc)(&ctx, n, apVal); if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse; - if( sqlite3MallocFailed() ) goto no_mem; + if( sqlite3MallocFailed() ){ + /* Even though a malloc() has failed, the implementation of the + ** user function may have called an sqlite3_result_XXX() function + ** to return a value. The following call releases any resources + ** associated with such a value. + ** + ** Note: Maybe MemRelease() should be called if sqlite3SafetyOn() + ** fails also (the if(...) statement above). But if people are + ** misusing sqlite, they have bigger problems than a leaked value. + */ + sqlite3VdbeMemRelease(&ctx.s); + goto no_mem; + } popStack(&pTos, n); /* If any auxilary data functions have been called by this user function, @@ -4299,7 +4311,7 @@ case OP_IntegrityCk: { if( (pTos[-nRoot].flags & MEM_Int)==0 ) break; } assert( nRoot>0 ); - aRoot = sqliteMallocRaw( sizeof(int*)*(nRoot+1) ); + aRoot = sqliteMallocRaw( sizeof(int)*(nRoot+1) ); if( aRoot==0 ) goto no_mem; j = pOp->p1; assert( j>=0 && jnMem ); ============================================================ --- sqlite/vdbeapi.c fe3b713d5d37f8dfff1aa7546dae213a0e492f10 +++ sqlite/vdbeapi.c 220b81132abaf0f620edb8da48799a77daef12a7 @@ -390,13 +390,13 @@ void sqlite3_set_auxdata( ){ struct AuxData *pAuxData; VdbeFunc *pVdbeFunc; - if( iArg<0 ) return; + if( iArg<0 ) goto failed; pVdbeFunc = pCtx->pVdbeFunc; if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){ int nMalloc = sizeof(VdbeFunc) + sizeof(struct AuxData)*iArg; pVdbeFunc = sqliteRealloc(pVdbeFunc, nMalloc); - if( !pVdbeFunc ) return; + if( !pVdbeFunc ) goto failed; pCtx->pVdbeFunc = pVdbeFunc; memset(&pVdbeFunc->apAux[pVdbeFunc->nAux], 0, sizeof(struct AuxData)*(iArg+1-pVdbeFunc->nAux)); @@ -410,6 +410,12 @@ void sqlite3_set_auxdata( } pAuxData->pAux = pAux; pAuxData->xDelete = xDelete; + return; + +failed: + if( xDelete ){ + xDelete(pAux); + } } /* ============================================================ --- sqlite/vdbeaux.c ca1d673fd5e45fe9ba994391b11568c48a7e1b59 +++ sqlite/vdbeaux.c d626e0f8cd78b4280bcb7af25d5c5566348ba87a @@ -793,8 +793,9 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){ if( nOp<1 ) return; pOp = &p->aOp[nOp-1]; if( pOp->opcode==OP_Noop && pOp->p3!=0 ){ - char *z = sqlite3StrDup(pOp->p3); int i, j; + char z[1000]; + sqlite3_snprintf(sizeof(z), z, "%s", pOp->p3); for(i=0; isspace((unsigned char)z[i]); i++){} for(j=0; z[i]; i++){ if( isspace((unsigned char)z[i]) ){ @@ -807,7 +808,6 @@ void sqlite3VdbeIOTraceSql(Vdbe *p){ } z[j] = 0; sqlite3_io_trace("SQL %s\n", z); - sqliteFree(z); } } #endif /* !SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE */ @@ -1435,7 +1435,7 @@ int sqlite3VdbeHalt(Vdbe *p){ */ if( db->autoCommit && db->activeVdbeCnt==1 ){ if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ - /* The auto-commit flag is true, and the vdbe program was + /* The auto-commit flag is true, and the vdbe program was ** successful or hit an 'OR FAIL' constraint. This means a commit ** is required. */ @@ -1600,9 +1600,6 @@ int sqlite3VdbeReset(Vdbe *p){ #endif p->magic = VDBE_MAGIC_INIT; p->aborted = 0; - if( p->rc==SQLITE_SCHEMA ){ - sqlite3ResetInternalSchema(db, 0); - } return p->rc & db->errMask; } ============================================================ --- sqlite/where.c 12387641659605318ae03d87f0687f223dfc9568 +++ sqlite/where.c c7e13b81ff8777e402d047a695fbf322e67c89e1 @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.253 2007/06/11 12:56:15 drh Exp $ +** $Id: where.c,v 1.254 2007/07/30 14:40:48 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -383,10 +383,22 @@ static int allowedOp(int op){ /* ** Commute a comparision operator. Expressions of the form "X op Y" ** are converted into "Y op X". +** +** If a collation sequence is associated with either the left or right +** side of the comparison, it remains associated with the same side after +** the commutation. So "Y collate NOCASE op X" becomes +** "X collate NOCASE op Y". This is because any collation sequence on +** the left hand side of a comparison overrides any collation sequence +** attached to the right. For the same reason the EP_ExpCollate flag +** is not commuted. */ static void exprCommute(Expr *pExpr){ + u16 expRight = (pExpr->pRight->flags & EP_ExpCollate); + u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate); assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); + pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft; + pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight; SWAP(Expr*,pExpr->pRight,pExpr->pLeft); if( pExpr->op>=TK_GT ){ assert( TK_LT==TK_GT+2 );