Fossil SCM
Update the built-in SQLite to version 3.28.0.
Commit
14db745dfe74a7e812e45aec020dffff186ec58a2b7893f60196ced4563b60f9
Parent
3350be2c0744c89…
2 files changed
+193
-111
+1
-1
+193
-111
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1162,11 +1162,11 @@ | ||
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.28.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3028000 |
| 1167 | -#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f" | |
| 1167 | +#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" | |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| @@ -13416,11 +13416,11 @@ | ||
| 13416 | 13416 | struct Hash { |
| 13417 | 13417 | unsigned int htsize; /* Number of buckets in the hash table */ |
| 13418 | 13418 | unsigned int count; /* Number of entries in this table */ |
| 13419 | 13419 | HashElem *first; /* The first element of the array */ |
| 13420 | 13420 | struct _ht { /* the hash table */ |
| 13421 | - int count; /* Number of entries with this hash */ | |
| 13421 | + unsigned int count; /* Number of entries with this hash */ | |
| 13422 | 13422 | HashElem *chain; /* Pointer to first entry with this hash */ |
| 13423 | 13423 | } *ht; |
| 13424 | 13424 | }; |
| 13425 | 13425 | |
| 13426 | 13426 | /* Each element in the hash table is an instance of the following |
| @@ -29858,15 +29858,15 @@ | ||
| 29858 | 29858 | ** This routine transforms the internal text encoding used by pMem to |
| 29859 | 29859 | ** desiredEnc. It is an error if the string is already of the desired |
| 29860 | 29860 | ** encoding, or if *pMem does not contain a string value. |
| 29861 | 29861 | */ |
| 29862 | 29862 | SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ |
| 29863 | - int len; /* Maximum length of output string in bytes */ | |
| 29864 | - unsigned char *zOut; /* Output buffer */ | |
| 29865 | - unsigned char *zIn; /* Input iterator */ | |
| 29866 | - unsigned char *zTerm; /* End of input */ | |
| 29867 | - unsigned char *z; /* Output iterator */ | |
| 29863 | + sqlite3_int64 len; /* Maximum length of output string in bytes */ | |
| 29864 | + unsigned char *zOut; /* Output buffer */ | |
| 29865 | + unsigned char *zIn; /* Input iterator */ | |
| 29866 | + unsigned char *zTerm; /* End of input */ | |
| 29867 | + unsigned char *z; /* Output iterator */ | |
| 29868 | 29868 | unsigned int c; |
| 29869 | 29869 | |
| 29870 | 29870 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 29871 | 29871 | assert( pMem->flags&MEM_Str ); |
| 29872 | 29872 | assert( pMem->enc!=desiredEnc ); |
| @@ -29911,18 +29911,18 @@ | ||
| 29911 | 29911 | ** translating a 2-byte character to a 4-byte UTF-8 character. |
| 29912 | 29912 | ** A single byte is required for the output string |
| 29913 | 29913 | ** nul-terminator. |
| 29914 | 29914 | */ |
| 29915 | 29915 | pMem->n &= ~1; |
| 29916 | - len = pMem->n * 2 + 1; | |
| 29916 | + len = 2 * (sqlite3_int64)pMem->n + 1; | |
| 29917 | 29917 | }else{ |
| 29918 | 29918 | /* When converting from UTF-8 to UTF-16 the maximum growth is caused |
| 29919 | 29919 | ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16 |
| 29920 | 29920 | ** character. Two bytes are required in the output buffer for the |
| 29921 | 29921 | ** nul-terminator. |
| 29922 | 29922 | */ |
| 29923 | - len = pMem->n * 2 + 2; | |
| 29923 | + len = 2 * (sqlite3_int64)pMem->n + 2; | |
| 29924 | 29924 | } |
| 29925 | 29925 | |
| 29926 | 29926 | /* Set zIn to point at the start of the input buffer and zTerm to point 1 |
| 29927 | 29927 | ** byte past the end. |
| 29928 | 29928 | ** |
| @@ -31790,11 +31790,11 @@ | ||
| 31790 | 31790 | |
| 31791 | 31791 | nInt = nName/4 + 3; |
| 31792 | 31792 | assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ |
| 31793 | 31793 | if( pIn==0 || pIn[1]+nInt > pIn[0] ){ |
| 31794 | 31794 | /* Enlarge the allocation */ |
| 31795 | - int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt; | |
| 31795 | + sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt; | |
| 31796 | 31796 | VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int)); |
| 31797 | 31797 | if( pOut==0 ) return pIn; |
| 31798 | 31798 | if( pIn==0 ) pOut[1] = 2; |
| 31799 | 31799 | pIn = pOut; |
| 31800 | 31800 | pIn[0] = nAlloc; |
| @@ -31996,11 +31996,11 @@ | ||
| 31996 | 31996 | const Hash *pH, /* The pH to be searched */ |
| 31997 | 31997 | const char *pKey, /* The key we are searching for */ |
| 31998 | 31998 | unsigned int *pHash /* Write the hash value here */ |
| 31999 | 31999 | ){ |
| 32000 | 32000 | HashElem *elem; /* Used to loop thru the element list */ |
| 32001 | - int count; /* Number of elements left to test */ | |
| 32001 | + unsigned int count; /* Number of elements left to test */ | |
| 32002 | 32002 | unsigned int h; /* The computed hash */ |
| 32003 | 32003 | static HashElem nullElement = { 0, 0, 0, 0 }; |
| 32004 | 32004 | |
| 32005 | 32005 | if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 32006 | 32006 | struct _ht *pEntry; |
| @@ -32044,12 +32044,12 @@ | ||
| 32044 | 32044 | if( pH->ht ){ |
| 32045 | 32045 | pEntry = &pH->ht[h]; |
| 32046 | 32046 | if( pEntry->chain==elem ){ |
| 32047 | 32047 | pEntry->chain = elem->next; |
| 32048 | 32048 | } |
| 32049 | + assert( pEntry->count>0 ); | |
| 32049 | 32050 | pEntry->count--; |
| 32050 | - assert( pEntry->count>=0 ); | |
| 32051 | 32051 | } |
| 32052 | 32052 | sqlite3_free( elem ); |
| 32053 | 32053 | pH->count--; |
| 32054 | 32054 | if( pH->count==0 ){ |
| 32055 | 32055 | assert( pH->first==0 ); |
| @@ -49129,13 +49129,11 @@ | ||
| 49129 | 49129 | ** Malloc function used by SQLite to obtain space from the buffer configured |
| 49130 | 49130 | ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer |
| 49131 | 49131 | ** exists, this function falls back to sqlite3Malloc(). |
| 49132 | 49132 | */ |
| 49133 | 49133 | SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){ |
| 49134 | - /* During rebalance operations on a corrupt database file, it is sometimes | |
| 49135 | - ** (rarely) possible to overread the temporary page buffer by a few bytes. | |
| 49136 | - ** Enlarge the allocation slightly so that this does not cause problems. */ | |
| 49134 | + assert( sz<=65536+8 ); /* These allocations are never very large */ | |
| 49137 | 49135 | return pcache1Alloc(sz); |
| 49138 | 49136 | } |
| 49139 | 49137 | |
| 49140 | 49138 | /* |
| 49141 | 49139 | ** Free an allocated buffer obtained from sqlite3PageMalloc(). |
| @@ -58889,11 +58887,11 @@ | ||
| 58889 | 58887 | ){ |
| 58890 | 58888 | int rc = SQLITE_OK; |
| 58891 | 58889 | |
| 58892 | 58890 | /* Enlarge the pWal->apWiData[] array if required */ |
| 58893 | 58891 | if( pWal->nWiData<=iPage ){ |
| 58894 | - int nByte = sizeof(u32*)*(iPage+1); | |
| 58892 | + sqlite3_int64 nByte = sizeof(u32*)*(iPage+1); | |
| 58895 | 58893 | volatile u32 **apNew; |
| 58896 | 58894 | apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 58897 | 58895 | if( !apNew ){ |
| 58898 | 58896 | *ppPage = 0; |
| 58899 | 58897 | return SQLITE_NOMEM_BKPT; |
| @@ -58993,10 +58991,11 @@ | ||
| 58993 | 58991 | s1 = s2 = 0; |
| 58994 | 58992 | } |
| 58995 | 58993 | |
| 58996 | 58994 | assert( nByte>=8 ); |
| 58997 | 58995 | assert( (nByte&0x00000007)==0 ); |
| 58996 | + assert( nByte<=65536 ); | |
| 58998 | 58997 | |
| 58999 | 58998 | if( nativeCksum ){ |
| 59000 | 58999 | do { |
| 59001 | 59000 | s1 += *aData++ + s2; |
| 59002 | 59001 | s2 += *aData++ + s1; |
| @@ -59930,11 +59929,11 @@ | ||
| 59930 | 59929 | */ |
| 59931 | 59930 | static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ |
| 59932 | 59931 | WalIterator *p; /* Return value */ |
| 59933 | 59932 | int nSegment; /* Number of segments to merge */ |
| 59934 | 59933 | u32 iLast; /* Last frame in log */ |
| 59935 | - int nByte; /* Number of bytes to allocate */ | |
| 59934 | + sqlite3_int64 nByte; /* Number of bytes to allocate */ | |
| 59936 | 59935 | int i; /* Iterator variable */ |
| 59937 | 59936 | ht_slot *aTmp; /* Temp space used by merge-sort */ |
| 59938 | 59937 | int rc = SQLITE_OK; /* Return Code */ |
| 59939 | 59938 | |
| 59940 | 59939 | /* This routine only runs while holding the checkpoint lock. And |
| @@ -76469,13 +76468,15 @@ | ||
| 76469 | 76468 | ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array |
| 76470 | 76469 | ** by the minimum* amount required until the size reaches 512. Normal |
| 76471 | 76470 | ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current |
| 76472 | 76471 | ** size of the op array or add 1KB of space, whichever is smaller. */ |
| 76473 | 76472 | #ifdef SQLITE_TEST_REALLOC_STRESS |
| 76474 | - int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp); | |
| 76473 | + sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc | |
| 76474 | + : (sqlite3_int64)v->nOpAlloc+nOp); | |
| 76475 | 76475 | #else |
| 76476 | - int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op))); | |
| 76476 | + sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc | |
| 76477 | + : (sqlite3_int64)(1024/sizeof(Op))); | |
| 76477 | 76478 | UNUSED_PARAMETER(nOp); |
| 76478 | 76479 | #endif |
| 76479 | 76480 | |
| 76480 | 76481 | /* Ensure that the size of a VDBE does not grow too large */ |
| 76481 | 76482 | if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ |
| @@ -77259,11 +77260,11 @@ | ||
| 77259 | 77260 | int addrLoop, /* Address of loop counter */ |
| 77260 | 77261 | int addrVisit, /* Address of rows visited counter */ |
| 77261 | 77262 | LogEst nEst, /* Estimated number of output rows */ |
| 77262 | 77263 | const char *zName /* Name of table or index being scanned */ |
| 77263 | 77264 | ){ |
| 77264 | - int nByte = (p->nScan+1) * sizeof(ScanStatus); | |
| 77265 | + sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus); | |
| 77265 | 77266 | ScanStatus *aNew; |
| 77266 | 77267 | aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 77267 | 77268 | if( aNew ){ |
| 77268 | 77269 | ScanStatus *pNew = &aNew[p->nScan++]; |
| 77269 | 77270 | pNew->addrExplain = addrExplain; |
| @@ -78380,13 +78381,13 @@ | ||
| 78380 | 78381 | /* An instance of this object describes bulk memory available for use |
| 78381 | 78382 | ** by subcomponents of a prepared statement. Space is allocated out |
| 78382 | 78383 | ** of a ReusableSpace object by the allocSpace() routine below. |
| 78383 | 78384 | */ |
| 78384 | 78385 | struct ReusableSpace { |
| 78385 | - u8 *pSpace; /* Available memory */ | |
| 78386 | - int nFree; /* Bytes of available memory */ | |
| 78387 | - int nNeeded; /* Total bytes that could not be allocated */ | |
| 78386 | + u8 *pSpace; /* Available memory */ | |
| 78387 | + sqlite3_int64 nFree; /* Bytes of available memory */ | |
| 78388 | + sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */ | |
| 78388 | 78389 | }; |
| 78389 | 78390 | |
| 78390 | 78391 | /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf |
| 78391 | 78392 | ** from the ReusableSpace object. Return a pointer to the allocated |
| 78392 | 78393 | ** memory on success. If insufficient memory is available in the |
| @@ -78402,11 +78403,11 @@ | ||
| 78402 | 78403 | ** statement. |
| 78403 | 78404 | */ |
| 78404 | 78405 | static void *allocSpace( |
| 78405 | 78406 | struct ReusableSpace *p, /* Bulk memory available for allocation */ |
| 78406 | 78407 | void *pBuf, /* Pointer to a prior allocation */ |
| 78407 | - int nByte /* Bytes of memory needed */ | |
| 78408 | + sqlite3_int64 nByte /* Bytes of memory needed */ | |
| 78408 | 78409 | ){ |
| 78409 | 78410 | assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) ); |
| 78410 | 78411 | if( pBuf==0 ){ |
| 78411 | 78412 | nByte = ROUND8(nByte); |
| 78412 | 78413 | if( nByte <= p->nFree ){ |
| @@ -81359,11 +81360,11 @@ | ||
| 81359 | 81360 | assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 ); |
| 81360 | 81361 | assert( db->init.busy==0 ); |
| 81361 | 81362 | assert( p->zSql!=0 ); |
| 81362 | 81363 | sqlite3OsCurrentTimeInt64(db->pVfs, &iNow); |
| 81363 | 81364 | iElapse = (iNow - p->startTime)*1000000; |
| 81364 | -#ifndef SQLITE_OMIT_DEPRECATED | |
| 81365 | +#ifndef SQLITE_OMIT_DEPRECATED | |
| 81365 | 81366 | if( db->xProfile ){ |
| 81366 | 81367 | db->xProfile(db->pProfileArg, p->zSql, iElapse); |
| 81367 | 81368 | } |
| 81368 | 81369 | #endif |
| 81369 | 81370 | if( db->mTrace & SQLITE_TRACE_PROFILE ){ |
| @@ -92255,11 +92256,11 @@ | ||
| 92255 | 92256 | int nRem; /* Bytes remaining to copy */ |
| 92256 | 92257 | |
| 92257 | 92258 | /* Extend the p->aAlloc[] allocation if required. */ |
| 92258 | 92259 | if( p->nAlloc<nByte ){ |
| 92259 | 92260 | u8 *aNew; |
| 92260 | - int nNew = MAX(128, p->nAlloc*2); | |
| 92261 | + sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc); | |
| 92261 | 92262 | while( nByte>nNew ) nNew = nNew*2; |
| 92262 | 92263 | aNew = sqlite3Realloc(p->aAlloc, nNew); |
| 92263 | 92264 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 92264 | 92265 | p->nAlloc = nNew; |
| 92265 | 92266 | p->aAlloc = aNew; |
| @@ -93546,19 +93547,23 @@ | ||
| 93546 | 93547 | if( pSorter->list.aMemory ){ |
| 93547 | 93548 | int nMin = pSorter->iMemory + nReq; |
| 93548 | 93549 | |
| 93549 | 93550 | if( nMin>pSorter->nMemory ){ |
| 93550 | 93551 | u8 *aNew; |
| 93551 | - int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory; | |
| 93552 | - int nNew = pSorter->nMemory * 2; | |
| 93552 | + sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory; | |
| 93553 | + int iListOff = -1; | |
| 93554 | + if( pSorter->list.pList ){ | |
| 93555 | + iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory; | |
| 93556 | + } | |
| 93553 | 93557 | while( nNew < nMin ) nNew = nNew*2; |
| 93554 | 93558 | if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize; |
| 93555 | 93559 | if( nNew < nMin ) nNew = nMin; |
| 93556 | - | |
| 93557 | 93560 | aNew = sqlite3Realloc(pSorter->list.aMemory, nNew); |
| 93558 | 93561 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 93559 | - pSorter->list.pList = (SorterRecord*)&aNew[iListOff]; | |
| 93562 | + if( iListOff>=0 ){ | |
| 93563 | + pSorter->list.pList = (SorterRecord*)&aNew[iListOff]; | |
| 93564 | + } | |
| 93560 | 93565 | pSorter->list.aMemory = aNew; |
| 93561 | 93566 | pSorter->nMemory = nNew; |
| 93562 | 93567 | } |
| 93563 | 93568 | |
| 93564 | 93569 | pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory]; |
| @@ -98204,11 +98209,11 @@ | ||
| 98204 | 98209 | */ |
| 98205 | 98210 | #ifndef SQLITE_OMIT_CTE |
| 98206 | 98211 | static With *withDup(sqlite3 *db, With *p){ |
| 98207 | 98212 | With *pRet = 0; |
| 98208 | 98213 | if( p ){ |
| 98209 | - int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1); | |
| 98214 | + sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1); | |
| 98210 | 98215 | pRet = sqlite3DbMallocZero(db, nByte); |
| 98211 | 98216 | if( pRet ){ |
| 98212 | 98217 | int i; |
| 98213 | 98218 | pRet->nCte = p->nCte; |
| 98214 | 98219 | for(i=0; i<p->nCte; i++){ |
| @@ -98469,11 +98474,11 @@ | ||
| 98469 | 98474 | } |
| 98470 | 98475 | pList->nExpr = 0; |
| 98471 | 98476 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 98472 | 98477 | ExprList *pNew; |
| 98473 | 98478 | pNew = sqlite3DbRealloc(db, pList, |
| 98474 | - sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0])); | |
| 98479 | + sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0])); | |
| 98475 | 98480 | if( pNew==0 ){ |
| 98476 | 98481 | goto no_mem; |
| 98477 | 98482 | } |
| 98478 | 98483 | pList = pNew; |
| 98479 | 98484 | } |
| @@ -106165,11 +106170,11 @@ | ||
| 106165 | 106170 | } |
| 106166 | 106171 | sqlite3BtreeLeaveAll(db); |
| 106167 | 106172 | assert( zErrDyn==0 || rc!=SQLITE_OK ); |
| 106168 | 106173 | } |
| 106169 | 106174 | #ifdef SQLITE_USER_AUTHENTICATION |
| 106170 | - if( rc==SQLITE_OK ){ | |
| 106175 | + if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){ | |
| 106171 | 106176 | u8 newAuth = 0; |
| 106172 | 106177 | rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| 106173 | 106178 | if( newAuth<db->auth.authLevel ){ |
| 106174 | 106179 | rc = SQLITE_AUTH_USER; |
| 106175 | 106180 | } |
| @@ -110602,23 +110607,22 @@ | ||
| 110602 | 110607 | int szEntry, /* Size of each object in the array */ |
| 110603 | 110608 | int *pnEntry, /* Number of objects currently in use */ |
| 110604 | 110609 | int *pIdx /* Write the index of a new slot here */ |
| 110605 | 110610 | ){ |
| 110606 | 110611 | char *z; |
| 110607 | - int n = *pnEntry; | |
| 110612 | + sqlite3_int64 n = *pIdx = *pnEntry; | |
| 110608 | 110613 | if( (n & (n-1))==0 ){ |
| 110609 | - int sz = (n==0) ? 1 : 2*n; | |
| 110614 | + sqlite3_int64 sz = (n==0) ? 1 : 2*n; | |
| 110610 | 110615 | void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry); |
| 110611 | 110616 | if( pNew==0 ){ |
| 110612 | 110617 | *pIdx = -1; |
| 110613 | 110618 | return pArray; |
| 110614 | 110619 | } |
| 110615 | 110620 | pArray = pNew; |
| 110616 | 110621 | } |
| 110617 | 110622 | z = (char*)pArray; |
| 110618 | 110623 | memset(&z[n * szEntry], 0, szEntry); |
| 110619 | - *pIdx = n; | |
| 110620 | 110624 | ++*pnEntry; |
| 110621 | 110625 | return pArray; |
| 110622 | 110626 | } |
| 110623 | 110627 | |
| 110624 | 110628 | /* |
| @@ -110725,11 +110729,11 @@ | ||
| 110725 | 110729 | assert( iStart<=pSrc->nSrc ); |
| 110726 | 110730 | |
| 110727 | 110731 | /* Allocate additional space if needed */ |
| 110728 | 110732 | if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){ |
| 110729 | 110733 | SrcList *pNew; |
| 110730 | - int nAlloc = pSrc->nSrc*2+nExtra; | |
| 110734 | + sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra; | |
| 110731 | 110735 | sqlite3 *db = pParse->db; |
| 110732 | 110736 | |
| 110733 | 110737 | if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){ |
| 110734 | 110738 | sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d", |
| 110735 | 110739 | SQLITE_MAX_SRCLIST); |
| @@ -111482,11 +111486,11 @@ | ||
| 111482 | 111486 | } |
| 111483 | 111487 | } |
| 111484 | 111488 | } |
| 111485 | 111489 | |
| 111486 | 111490 | if( pWith ){ |
| 111487 | - int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte); | |
| 111491 | + sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte); | |
| 111488 | 111492 | pNew = sqlite3DbRealloc(db, pWith, nByte); |
| 111489 | 111493 | }else{ |
| 111490 | 111494 | pNew = sqlite3DbMallocZero(db, sizeof(*pWith)); |
| 111491 | 111495 | } |
| 111492 | 111496 | assert( (pNew!=0 && zName!=0) || db->mallocFailed ); |
| @@ -134593,13 +134597,17 @@ | ||
| 134593 | 134597 | ** Add a new module argument to pTable->azModuleArg[]. |
| 134594 | 134598 | ** The string is not copied - the pointer is stored. The |
| 134595 | 134599 | ** string will be freed automatically when the table is |
| 134596 | 134600 | ** deleted. |
| 134597 | 134601 | */ |
| 134598 | -static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){ | |
| 134599 | - int nBytes = sizeof(char *)*(2+pTable->nModuleArg); | |
| 134602 | +static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ | |
| 134603 | + sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg); | |
| 134600 | 134604 | char **azModuleArg; |
| 134605 | + sqlite3 *db = pParse->db; | |
| 134606 | + if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ | |
| 134607 | + sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); | |
| 134608 | + } | |
| 134601 | 134609 | azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); |
| 134602 | 134610 | if( azModuleArg==0 ){ |
| 134603 | 134611 | sqlite3DbFree(db, zArg); |
| 134604 | 134612 | }else{ |
| 134605 | 134613 | int i = pTable->nModuleArg++; |
| @@ -134630,13 +134638,13 @@ | ||
| 134630 | 134638 | assert( 0==pTable->pIndex ); |
| 134631 | 134639 | |
| 134632 | 134640 | db = pParse->db; |
| 134633 | 134641 | |
| 134634 | 134642 | assert( pTable->nModuleArg==0 ); |
| 134635 | - addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); | |
| 134636 | - addModuleArgument(db, pTable, 0); | |
| 134637 | - addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); | |
| 134643 | + addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName)); | |
| 134644 | + addModuleArgument(pParse, pTable, 0); | |
| 134645 | + addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName)); | |
| 134638 | 134646 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 134639 | 134647 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| 134640 | 134648 | ); |
| 134641 | 134649 | pParse->sNameToken.n = (int)( |
| 134642 | 134650 | &pModuleName->z[pModuleName->n] - pParse->sNameToken.z |
| @@ -134665,11 +134673,11 @@ | ||
| 134665 | 134673 | static void addArgumentToVtab(Parse *pParse){ |
| 134666 | 134674 | if( pParse->sArg.z && pParse->pNewTable ){ |
| 134667 | 134675 | const char *z = (const char*)pParse->sArg.z; |
| 134668 | 134676 | int n = pParse->sArg.n; |
| 134669 | 134677 | sqlite3 *db = pParse->db; |
| 134670 | - addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n)); | |
| 134678 | + addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n)); | |
| 134671 | 134679 | } |
| 134672 | 134680 | } |
| 134673 | 134681 | |
| 134674 | 134682 | /* |
| 134675 | 134683 | ** The parser calls this routine after the CREATE VIRTUAL TABLE statement |
| @@ -134954,11 +134962,12 @@ | ||
| 134954 | 134962 | const int ARRAY_INCR = 5; |
| 134955 | 134963 | |
| 134956 | 134964 | /* Grow the sqlite3.aVTrans array if required */ |
| 134957 | 134965 | if( (db->nVTrans%ARRAY_INCR)==0 ){ |
| 134958 | 134966 | VTable **aVTrans; |
| 134959 | - int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR); | |
| 134967 | + sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)* | |
| 134968 | + ((sqlite3_int64)db->nVTrans + ARRAY_INCR); | |
| 134960 | 134969 | aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes); |
| 134961 | 134970 | if( !aVTrans ){ |
| 134962 | 134971 | return SQLITE_NOMEM_BKPT; |
| 134963 | 134972 | } |
| 134964 | 134973 | memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR); |
| @@ -135450,13 +135459,13 @@ | ||
| 135450 | 135459 | pMod->pEpoTab = pTab; |
| 135451 | 135460 | pTab->nTabRef = 1; |
| 135452 | 135461 | pTab->pSchema = db->aDb[0].pSchema; |
| 135453 | 135462 | assert( pTab->nModuleArg==0 ); |
| 135454 | 135463 | pTab->iPKey = -1; |
| 135455 | - addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); | |
| 135456 | - addModuleArgument(db, pTab, 0); | |
| 135457 | - addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); | |
| 135464 | + addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); | |
| 135465 | + addModuleArgument(pParse, pTab, 0); | |
| 135466 | + addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); | |
| 135458 | 135467 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| 135459 | 135468 | if( rc ){ |
| 135460 | 135469 | sqlite3ErrorMsg(pParse, "%s", zErr); |
| 135461 | 135470 | sqlite3DbFree(db, zErr); |
| 135462 | 135471 | sqlite3VtabEponymousTableClear(db, pMod); |
| @@ -155309,11 +155318,11 @@ | ||
| 155309 | 155318 | if( sz==0 || cnt==0 ){ |
| 155310 | 155319 | sz = 0; |
| 155311 | 155320 | pStart = 0; |
| 155312 | 155321 | }else if( pBuf==0 ){ |
| 155313 | 155322 | sqlite3BeginBenignMalloc(); |
| 155314 | - pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */ | |
| 155323 | + pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */ | |
| 155315 | 155324 | sqlite3EndBenignMalloc(); |
| 155316 | 155325 | if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; |
| 155317 | 155326 | }else{ |
| 155318 | 155327 | pStart = pBuf; |
| 155319 | 155328 | } |
| @@ -169347,12 +169356,12 @@ | ||
| 169347 | 169356 | }else{ |
| 169348 | 169357 | char const **aArg = 0; |
| 169349 | 169358 | int iArg = 0; |
| 169350 | 169359 | z = &z[n+1]; |
| 169351 | 169360 | while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){ |
| 169352 | - int nNew = sizeof(char *)*(iArg+1); | |
| 169353 | - char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew); | |
| 169361 | + sqlite3_int64 nNew = sizeof(char *)*(iArg+1); | |
| 169362 | + char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew); | |
| 169354 | 169363 | if( !aNew ){ |
| 169355 | 169364 | sqlite3_free(zCopy); |
| 169356 | 169365 | sqlite3_free((void *)aArg); |
| 169357 | 169366 | return SQLITE_NOMEM; |
| 169358 | 169367 | } |
| @@ -170255,11 +170264,11 @@ | ||
| 170255 | 170264 | |
| 170256 | 170265 | fts3tokResetCursor(pCsr); |
| 170257 | 170266 | if( idxNum==1 ){ |
| 170258 | 170267 | const char *zByte = (const char *)sqlite3_value_text(apVal[0]); |
| 170259 | 170268 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 170260 | - pCsr->zInput = sqlite3_malloc(nByte+1); | |
| 170269 | + pCsr->zInput = sqlite3_malloc64(nByte+1); | |
| 170261 | 170270 | if( pCsr->zInput==0 ){ |
| 170262 | 170271 | rc = SQLITE_NOMEM; |
| 170263 | 170272 | }else{ |
| 170264 | 170273 | memcpy(pCsr->zInput, zByte, nByte); |
| 170265 | 170274 | pCsr->zInput[nByte] = 0; |
| @@ -172119,12 +172128,13 @@ | ||
| 172119 | 172128 | nElem = 1; |
| 172120 | 172129 | } |
| 172121 | 172130 | } |
| 172122 | 172131 | |
| 172123 | 172132 | if( nElem>0 ){ |
| 172124 | - int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *); | |
| 172125 | - pReader = (Fts3SegReader *)sqlite3_malloc(nByte); | |
| 172133 | + sqlite3_int64 nByte; | |
| 172134 | + nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *); | |
| 172135 | + pReader = (Fts3SegReader *)sqlite3_malloc64(nByte); | |
| 172126 | 172136 | if( !pReader ){ |
| 172127 | 172137 | rc = SQLITE_NOMEM; |
| 172128 | 172138 | }else{ |
| 172129 | 172139 | memset(pReader, 0, nByte); |
| 172130 | 172140 | pReader->iIdx = 0x7FFFFFFF; |
| @@ -173734,11 +173744,11 @@ | ||
| 173734 | 173744 | int nBlob; /* Number of bytes in the BLOB */ |
| 173735 | 173745 | sqlite3_stmt *pStmt; /* Statement used to insert the encoding */ |
| 173736 | 173746 | int rc; /* Result code from subfunctions */ |
| 173737 | 173747 | |
| 173738 | 173748 | if( *pRC ) return; |
| 173739 | - pBlob = sqlite3_malloc( 10*p->nColumn ); | |
| 173749 | + pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn ); | |
| 173740 | 173750 | if( pBlob==0 ){ |
| 173741 | 173751 | *pRC = SQLITE_NOMEM; |
| 173742 | 173752 | return; |
| 173743 | 173753 | } |
| 173744 | 173754 | fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob); |
| @@ -173784,11 +173794,11 @@ | ||
| 173784 | 173794 | int rc; /* Result code from subfunctions */ |
| 173785 | 173795 | |
| 173786 | 173796 | const int nStat = p->nColumn+2; |
| 173787 | 173797 | |
| 173788 | 173798 | if( *pRC ) return; |
| 173789 | - a = sqlite3_malloc( (sizeof(u32)+10)*nStat ); | |
| 173799 | + a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat ); | |
| 173790 | 173800 | if( a==0 ){ |
| 173791 | 173801 | *pRC = SQLITE_NOMEM; |
| 173792 | 173802 | return; |
| 173793 | 173803 | } |
| 173794 | 173804 | pBlob = (char*)&a[nStat]; |
| @@ -173905,12 +173915,12 @@ | ||
| 173905 | 173915 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 173906 | 173916 | sqlite3_free(zSql); |
| 173907 | 173917 | } |
| 173908 | 173918 | |
| 173909 | 173919 | if( rc==SQLITE_OK ){ |
| 173910 | - int nByte = sizeof(u32) * (p->nColumn+1)*3; | |
| 173911 | - aSz = (u32 *)sqlite3_malloc(nByte); | |
| 173920 | + sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3; | |
| 173921 | + aSz = (u32 *)sqlite3_malloc64(nByte); | |
| 173912 | 173922 | if( aSz==0 ){ |
| 173913 | 173923 | rc = SQLITE_NOMEM; |
| 173914 | 173924 | }else{ |
| 173915 | 173925 | memset(aSz, 0, nByte); |
| 173916 | 173926 | aSzIns = &aSz[p->nColumn+1]; |
| @@ -173972,16 +173982,16 @@ | ||
| 173972 | 173982 | int nSeg, /* Number of segments to merge */ |
| 173973 | 173983 | Fts3MultiSegReader *pCsr /* Cursor object to populate */ |
| 173974 | 173984 | ){ |
| 173975 | 173985 | int rc; /* Return Code */ |
| 173976 | 173986 | sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */ |
| 173977 | - int nByte; /* Bytes allocated at pCsr->apSegment[] */ | |
| 173987 | + sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */ | |
| 173978 | 173988 | |
| 173979 | 173989 | /* Allocate space for the Fts3MultiSegReader.aCsr[] array */ |
| 173980 | 173990 | memset(pCsr, 0, sizeof(*pCsr)); |
| 173981 | 173991 | nByte = sizeof(Fts3SegReader *) * nSeg; |
| 173982 | - pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte); | |
| 173992 | + pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte); | |
| 173983 | 173993 | |
| 173984 | 173994 | if( pCsr->apSegment==0 ){ |
| 173985 | 173995 | rc = SQLITE_NOMEM; |
| 173986 | 173996 | }else{ |
| 173987 | 173997 | memset(pCsr->apSegment, 0, nByte); |
| @@ -175957,11 +175967,11 @@ | ||
| 175957 | 175967 | rc = SQLITE_CONSTRAINT; |
| 175958 | 175968 | goto update_out; |
| 175959 | 175969 | } |
| 175960 | 175970 | |
| 175961 | 175971 | /* Allocate space to hold the change in document sizes */ |
| 175962 | - aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 ); | |
| 175972 | + aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2); | |
| 175963 | 175973 | if( aSzDel==0 ){ |
| 175964 | 175974 | rc = SQLITE_NOMEM; |
| 175965 | 175975 | goto update_out; |
| 175966 | 175976 | } |
| 175967 | 175977 | aSzIns = &aSzDel[p->nColumn+1]; |
| @@ -176211,21 +176221,23 @@ | ||
| 176211 | 176221 | */ |
| 176212 | 176222 | |
| 176213 | 176223 | /* |
| 176214 | 176224 | ** Allocate a two-slot MatchinfoBuffer object. |
| 176215 | 176225 | */ |
| 176216 | -static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){ | |
| 176226 | +static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){ | |
| 176217 | 176227 | MatchinfoBuffer *pRet; |
| 176218 | - int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer); | |
| 176219 | - int nStr = (int)strlen(zMatchinfo); | |
| 176228 | + sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) | |
| 176229 | + + sizeof(MatchinfoBuffer); | |
| 176230 | + sqlite3_int64 nStr = strlen(zMatchinfo); | |
| 176220 | 176231 | |
| 176221 | - pRet = sqlite3_malloc(nByte + nStr+1); | |
| 176232 | + pRet = sqlite3_malloc64(nByte + nStr+1); | |
| 176222 | 176233 | if( pRet ){ |
| 176223 | 176234 | memset(pRet, 0, nByte); |
| 176224 | 176235 | pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; |
| 176225 | - pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1); | |
| 176226 | - pRet->nElem = nElem; | |
| 176236 | + pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] | |
| 176237 | + + sizeof(u32)*((int)nElem+1); | |
| 176238 | + pRet->nElem = (int)nElem; | |
| 176227 | 176239 | pRet->zMatchinfo = ((char*)pRet) + nByte; |
| 176228 | 176240 | memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1); |
| 176229 | 176241 | pRet->aRef[0] = 1; |
| 176230 | 176242 | } |
| 176231 | 176243 | |
| @@ -177082,12 +177094,12 @@ | ||
| 177082 | 177094 | } |
| 177083 | 177095 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 177084 | 177096 | return SQLITE_ERROR; |
| 177085 | 177097 | } |
| 177086 | 177098 | |
| 177087 | -static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ | |
| 177088 | - int nVal; /* Number of integers output by cArg */ | |
| 177099 | +static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ | |
| 177100 | + size_t nVal; /* Number of integers output by cArg */ | |
| 177089 | 177101 | |
| 177090 | 177102 | switch( cArg ){ |
| 177091 | 177103 | case FTS3_MATCHINFO_NDOC: |
| 177092 | 177104 | case FTS3_MATCHINFO_NPHRASE: |
| 177093 | 177105 | case FTS3_MATCHINFO_NCOL: |
| @@ -177367,11 +177379,11 @@ | ||
| 177367 | 177379 | } |
| 177368 | 177380 | break; |
| 177369 | 177381 | |
| 177370 | 177382 | case FTS3_MATCHINFO_LHITS_BM: |
| 177371 | 177383 | case FTS3_MATCHINFO_LHITS: { |
| 177372 | - int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); | |
| 177384 | + size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); | |
| 177373 | 177385 | memset(pInfo->aMatchinfo, 0, nZero); |
| 177374 | 177386 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 177375 | 177387 | break; |
| 177376 | 177388 | } |
| 177377 | 177389 | |
| @@ -177436,11 +177448,11 @@ | ||
| 177436 | 177448 | ** matchinfo function has been called for this query. In this case |
| 177437 | 177449 | ** allocate the array used to accumulate the matchinfo data and |
| 177438 | 177450 | ** initialize those elements that are constant for every row. |
| 177439 | 177451 | */ |
| 177440 | 177452 | if( pCsr->pMIBuffer==0 ){ |
| 177441 | - int nMatchinfo = 0; /* Number of u32 elements in match-info */ | |
| 177453 | + size_t nMatchinfo = 0; /* Number of u32 elements in match-info */ | |
| 177442 | 177454 | int i; /* Used to iterate through zArg */ |
| 177443 | 177455 | |
| 177444 | 177456 | /* Determine the number of phrases in the query */ |
| 177445 | 177457 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 177446 | 177458 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -185697,11 +185709,11 @@ | ||
| 185697 | 185709 | && (s.z++, geopolySkipSpace(&s)==0) |
| 185698 | 185710 | ){ |
| 185699 | 185711 | GeoPoly *pOut; |
| 185700 | 185712 | int x = 1; |
| 185701 | 185713 | s.nVertex--; /* Remove the redundant vertex at the end */ |
| 185702 | - pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) ); | |
| 185714 | + pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) ); | |
| 185703 | 185715 | x = 1; |
| 185704 | 185716 | if( pOut==0 ) goto parse_json_err; |
| 185705 | 185717 | pOut->nVertex = s.nVertex; |
| 185706 | 185718 | memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord)); |
| 185707 | 185719 | pOut->hdr[0] = *(unsigned char*)&x; |
| @@ -186083,11 +186095,11 @@ | ||
| 186083 | 186095 | else if( r>mxY ) mxY = (float)r; |
| 186084 | 186096 | } |
| 186085 | 186097 | if( pRc ) *pRc = SQLITE_OK; |
| 186086 | 186098 | if( aCoord==0 ){ |
| 186087 | 186099 | geopolyBboxFill: |
| 186088 | - pOut = sqlite3_realloc(p, GEOPOLY_SZ(4)); | |
| 186100 | + pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4)); | |
| 186089 | 186101 | if( pOut==0 ){ |
| 186090 | 186102 | sqlite3_free(p); |
| 186091 | 186103 | if( context ) sqlite3_result_error_nomem(context); |
| 186092 | 186104 | if( pRc ) *pRc = SQLITE_NOMEM; |
| 186093 | 186105 | return 0; |
| @@ -186479,13 +186491,13 @@ | ||
| 186479 | 186491 | |
| 186480 | 186492 | /* |
| 186481 | 186493 | ** Determine the overlap between two polygons |
| 186482 | 186494 | */ |
| 186483 | 186495 | static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){ |
| 186484 | - int nVertex = p1->nVertex + p2->nVertex + 2; | |
| 186496 | + sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2; | |
| 186485 | 186497 | GeoOverlap *p; |
| 186486 | - int nByte; | |
| 186498 | + sqlite3_int64 nByte; | |
| 186487 | 186499 | GeoEvent *pThisEvent; |
| 186488 | 186500 | double rX; |
| 186489 | 186501 | int rc = 0; |
| 186490 | 186502 | int needSort = 0; |
| 186491 | 186503 | GeoSegment *pActive = 0; |
| @@ -186493,11 +186505,11 @@ | ||
| 186493 | 186505 | unsigned char aOverlap[4]; |
| 186494 | 186506 | |
| 186495 | 186507 | nByte = sizeof(GeoEvent)*nVertex*2 |
| 186496 | 186508 | + sizeof(GeoSegment)*nVertex |
| 186497 | 186509 | + sizeof(GeoOverlap); |
| 186498 | - p = sqlite3_malloc( nByte ); | |
| 186510 | + p = sqlite3_malloc64( nByte ); | |
| 186499 | 186511 | if( p==0 ) return -1; |
| 186500 | 186512 | p->aEvent = (GeoEvent*)&p[1]; |
| 186501 | 186513 | p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2]; |
| 186502 | 186514 | p->nEvent = p->nSegment = 0; |
| 186503 | 186515 | geopolyAddSegments(p, p1, 1); |
| @@ -186652,22 +186664,22 @@ | ||
| 186652 | 186664 | char **pzErr, /* OUT: Error message, if any */ |
| 186653 | 186665 | int isCreate /* True for xCreate, false for xConnect */ |
| 186654 | 186666 | ){ |
| 186655 | 186667 | int rc = SQLITE_OK; |
| 186656 | 186668 | Rtree *pRtree; |
| 186657 | - int nDb; /* Length of string argv[1] */ | |
| 186658 | - int nName; /* Length of string argv[2] */ | |
| 186669 | + sqlite3_int64 nDb; /* Length of string argv[1] */ | |
| 186670 | + sqlite3_int64 nName; /* Length of string argv[2] */ | |
| 186659 | 186671 | sqlite3_str *pSql; |
| 186660 | 186672 | char *zSql; |
| 186661 | 186673 | int ii; |
| 186662 | 186674 | |
| 186663 | 186675 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 186664 | 186676 | |
| 186665 | 186677 | /* Allocate the sqlite3_vtab structure */ |
| 186666 | - nDb = (int)strlen(argv[1]); | |
| 186667 | - nName = (int)strlen(argv[2]); | |
| 186668 | - pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); | |
| 186678 | + nDb = strlen(argv[1]); | |
| 186679 | + nName = strlen(argv[2]); | |
| 186680 | + pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2); | |
| 186669 | 186681 | if( !pRtree ){ |
| 186670 | 186682 | return SQLITE_NOMEM; |
| 186671 | 186683 | } |
| 186672 | 186684 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 186673 | 186685 | pRtree->nBusy = 1; |
| @@ -189088,10 +189100,15 @@ | ||
| 189088 | 189100 | ** abIndexed: |
| 189089 | 189101 | ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise, |
| 189090 | 189102 | ** it points to an array of flags nTblCol elements in size. The flag is |
| 189091 | 189103 | ** set for each column that is either a part of the PK or a part of an |
| 189092 | 189104 | ** index. Or clear otherwise. |
| 189105 | +** | |
| 189106 | +** If there are one or more partial indexes on the table, all fields of | |
| 189107 | +** this array set set to 1. This is because in that case, the module has | |
| 189108 | +** no way to tell which fields will be required to add and remove entries | |
| 189109 | +** from the partial indexes. | |
| 189093 | 189110 | ** |
| 189094 | 189111 | */ |
| 189095 | 189112 | struct RbuObjIter { |
| 189096 | 189113 | sqlite3_stmt *pTblIter; /* Iterate through tables */ |
| 189097 | 189114 | sqlite3_stmt *pIdxIter; /* Index iterator */ |
| @@ -189883,11 +189900,11 @@ | ||
| 189883 | 189900 | ** error code in the rbu handle passed as the first argument. Or, if an |
| 189884 | 189901 | ** error has already occurred when this function is called, return NULL |
| 189885 | 189902 | ** immediately without attempting the allocation or modifying the stored |
| 189886 | 189903 | ** error code. |
| 189887 | 189904 | */ |
| 189888 | -static void *rbuMalloc(sqlite3rbu *p, int nByte){ | |
| 189905 | +static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){ | |
| 189889 | 189906 | void *pRet = 0; |
| 189890 | 189907 | if( p->rc==SQLITE_OK ){ |
| 189891 | 189908 | assert( nByte>0 ); |
| 189892 | 189909 | pRet = sqlite3_malloc64(nByte); |
| 189893 | 189910 | if( pRet==0 ){ |
| @@ -189904,11 +189921,11 @@ | ||
| 189904 | 189921 | ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that |
| 189905 | 189922 | ** there is room for at least nCol elements. If an OOM occurs, store an |
| 189906 | 189923 | ** error code in the RBU handle passed as the first argument. |
| 189907 | 189924 | */ |
| 189908 | 189925 | static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){ |
| 189909 | - int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; | |
| 189926 | + sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; | |
| 189910 | 189927 | char **azNew; |
| 189911 | 189928 | |
| 189912 | 189929 | azNew = (char**)rbuMalloc(p, nByte); |
| 189913 | 189930 | if( azNew ){ |
| 189914 | 189931 | pIter->azTblCol = azNew; |
| @@ -190098,12 +190115,16 @@ | ||
| 190098 | 190115 | } |
| 190099 | 190116 | |
| 190100 | 190117 | pIter->nIndex = 0; |
| 190101 | 190118 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){ |
| 190102 | 190119 | const char *zIdx = (const char*)sqlite3_column_text(pList, 1); |
| 190120 | + int bPartial = sqlite3_column_int(pList, 4); | |
| 190103 | 190121 | sqlite3_stmt *pXInfo = 0; |
| 190104 | 190122 | if( zIdx==0 ) break; |
| 190123 | + if( bPartial ){ | |
| 190124 | + memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol); | |
| 190125 | + } | |
| 190105 | 190126 | p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg, |
| 190106 | 190127 | sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx) |
| 190107 | 190128 | ); |
| 190108 | 190129 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 190109 | 190130 | int iCid = sqlite3_column_int(pXInfo, 1); |
| @@ -190544,11 +190565,11 @@ | ||
| 190544 | 190565 | ** when this function is called, NULL is returned immediately, without |
| 190545 | 190566 | ** attempting the allocation or modifying the stored error code. |
| 190546 | 190567 | */ |
| 190547 | 190568 | static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){ |
| 190548 | 190569 | char *zRet = 0; |
| 190549 | - int nByte = nBind*2 + 1; | |
| 190570 | + sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1; | |
| 190550 | 190571 | |
| 190551 | 190572 | zRet = (char*)rbuMalloc(p, nByte); |
| 190552 | 190573 | if( zRet ){ |
| 190553 | 190574 | int i; |
| 190554 | 190575 | for(i=0; i<nBind; i++){ |
| @@ -190805,10 +190826,66 @@ | ||
| 190805 | 190826 | |
| 190806 | 190827 | if( rc!=SQLITE_OK ){ |
| 190807 | 190828 | sqlite3_result_error_code(pCtx, rc); |
| 190808 | 190829 | } |
| 190809 | 190830 | } |
| 190831 | + | |
| 190832 | +static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){ | |
| 190833 | + sqlite3_stmt *pStmt = 0; | |
| 190834 | + int rc = p->rc; | |
| 190835 | + char *zRet = 0; | |
| 190836 | + | |
| 190837 | + if( rc==SQLITE_OK ){ | |
| 190838 | + rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, | |
| 190839 | + "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?" | |
| 190840 | + ); | |
| 190841 | + } | |
| 190842 | + if( rc==SQLITE_OK ){ | |
| 190843 | + int rc2; | |
| 190844 | + rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC); | |
| 190845 | + if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ | |
| 190846 | + const char *zSql = (const char*)sqlite3_column_text(pStmt, 0); | |
| 190847 | + if( zSql ){ | |
| 190848 | + int nParen = 0; /* Number of open parenthesis */ | |
| 190849 | + int i; | |
| 190850 | + for(i=0; zSql[i]; i++){ | |
| 190851 | + char c = zSql[i]; | |
| 190852 | + if( c=='(' ){ | |
| 190853 | + nParen++; | |
| 190854 | + } | |
| 190855 | + else if( c==')' ){ | |
| 190856 | + nParen--; | |
| 190857 | + if( nParen==0 ){ | |
| 190858 | + i++; | |
| 190859 | + break; | |
| 190860 | + } | |
| 190861 | + }else if( c=='"' || c=='\'' || c=='`' ){ | |
| 190862 | + for(i++; 1; i++){ | |
| 190863 | + if( zSql[i]==c ){ | |
| 190864 | + if( zSql[i+1]!=c ) break; | |
| 190865 | + i++; | |
| 190866 | + } | |
| 190867 | + } | |
| 190868 | + }else if( c=='[' ){ | |
| 190869 | + for(i++; 1; i++){ | |
| 190870 | + if( zSql[i]==']' ) break; | |
| 190871 | + } | |
| 190872 | + } | |
| 190873 | + } | |
| 190874 | + if( zSql[i] ){ | |
| 190875 | + zRet = rbuStrndup(&zSql[i], &rc); | |
| 190876 | + } | |
| 190877 | + } | |
| 190878 | + } | |
| 190879 | + | |
| 190880 | + rc2 = sqlite3_finalize(pStmt); | |
| 190881 | + if( rc==SQLITE_OK ) rc = rc2; | |
| 190882 | + } | |
| 190883 | + | |
| 190884 | + p->rc = rc; | |
| 190885 | + return zRet; | |
| 190886 | +} | |
| 190810 | 190887 | |
| 190811 | 190888 | /* |
| 190812 | 190889 | ** Ensure that the SQLite statement handles required to update the |
| 190813 | 190890 | ** target database object currently indicated by the iterator passed |
| 190814 | 190891 | ** as the second argument are available. |
| @@ -190835,17 +190912,19 @@ | ||
| 190835 | 190912 | const char *zTbl = pIter->zTbl; |
| 190836 | 190913 | char *zImposterCols = 0; /* Columns for imposter table */ |
| 190837 | 190914 | char *zImposterPK = 0; /* Primary key declaration for imposter */ |
| 190838 | 190915 | char *zWhere = 0; /* WHERE clause on PK columns */ |
| 190839 | 190916 | char *zBind = 0; |
| 190917 | + char *zPart = 0; | |
| 190840 | 190918 | int nBind = 0; |
| 190841 | 190919 | |
| 190842 | 190920 | assert( pIter->eType!=RBU_PK_VTAB ); |
| 190843 | 190921 | zCollist = rbuObjIterGetIndexCols( |
| 190844 | 190922 | p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind |
| 190845 | 190923 | ); |
| 190846 | 190924 | zBind = rbuObjIterGetBindlist(p, nBind); |
| 190925 | + zPart = rbuObjIterGetIndexWhere(p, pIter); | |
| 190847 | 190926 | |
| 190848 | 190927 | /* Create the imposter table used to write to this index. */ |
| 190849 | 190928 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); |
| 190850 | 190929 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum); |
| 190851 | 190930 | rbuMPrintfExec(p, p->dbMain, |
| @@ -190874,32 +190953,34 @@ | ||
| 190874 | 190953 | /* Create the SELECT statement to read keys in sorted order */ |
| 190875 | 190954 | if( p->rc==SQLITE_OK ){ |
| 190876 | 190955 | char *zSql; |
| 190877 | 190956 | if( rbuIsVacuum(p) ){ |
| 190878 | 190957 | zSql = sqlite3_mprintf( |
| 190879 | - "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s", | |
| 190958 | + "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s", | |
| 190880 | 190959 | zCollist, |
| 190881 | 190960 | pIter->zDataTbl, |
| 190882 | - zCollist, zLimit | |
| 190961 | + zPart, zCollist, zLimit | |
| 190883 | 190962 | ); |
| 190884 | 190963 | }else |
| 190885 | 190964 | |
| 190886 | 190965 | if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 190887 | 190966 | zSql = sqlite3_mprintf( |
| 190888 | - "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s", | |
| 190967 | + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s", | |
| 190889 | 190968 | zCollist, p->zStateDb, pIter->zDataTbl, |
| 190890 | - zCollist, zLimit | |
| 190969 | + zPart, zCollist, zLimit | |
| 190891 | 190970 | ); |
| 190892 | 190971 | }else{ |
| 190893 | 190972 | zSql = sqlite3_mprintf( |
| 190894 | - "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " | |
| 190973 | + "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s " | |
| 190895 | 190974 | "UNION ALL " |
| 190896 | 190975 | "SELECT %s, rbu_control FROM '%q' " |
| 190897 | - "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 " | |
| 190976 | + "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 " | |
| 190898 | 190977 | "ORDER BY %s%s", |
| 190899 | - zCollist, p->zStateDb, pIter->zDataTbl, | |
| 190978 | + zCollist, p->zStateDb, pIter->zDataTbl, zPart, | |
| 190900 | 190979 | zCollist, pIter->zDataTbl, |
| 190980 | + zPart, | |
| 190981 | + (zPart ? "AND" : "WHERE"), | |
| 190901 | 190982 | zCollist, zLimit |
| 190902 | 190983 | ); |
| 190903 | 190984 | } |
| 190904 | 190985 | p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql); |
| 190905 | 190986 | } |
| @@ -190906,10 +190987,11 @@ | ||
| 190906 | 190987 | |
| 190907 | 190988 | sqlite3_free(zImposterCols); |
| 190908 | 190989 | sqlite3_free(zImposterPK); |
| 190909 | 190990 | sqlite3_free(zWhere); |
| 190910 | 190991 | sqlite3_free(zBind); |
| 190992 | + sqlite3_free(zPart); | |
| 190911 | 190993 | }else{ |
| 190912 | 190994 | int bRbuRowid = (pIter->eType==RBU_PK_VTAB) |
| 190913 | 190995 | ||(pIter->eType==RBU_PK_NONE) |
| 190914 | 190996 | ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p)); |
| 190915 | 190997 | const char *zTbl = pIter->zTbl; /* Table this step applies to */ |
| @@ -193339,11 +193421,11 @@ | ||
| 193339 | 193421 | ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space |
| 193340 | 193422 | ** instead of a file on disk. */ |
| 193341 | 193423 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 193342 | 193424 | if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ |
| 193343 | 193425 | if( iRegion<=p->nShm ){ |
| 193344 | - int nByte = (iRegion+1) * sizeof(char*); | |
| 193426 | + sqlite3_int64 nByte = (iRegion+1) * sizeof(char*); | |
| 193345 | 193427 | char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte); |
| 193346 | 193428 | if( apNew==0 ){ |
| 193347 | 193429 | rc = SQLITE_NOMEM; |
| 193348 | 193430 | }else{ |
| 193349 | 193431 | memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm)); |
| @@ -195850,11 +195932,11 @@ | ||
| 195850 | 195932 | */ |
| 195851 | 195933 | static int sessionGrowHash(int bPatchset, SessionTable *pTab){ |
| 195852 | 195934 | if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){ |
| 195853 | 195935 | int i; |
| 195854 | 195936 | SessionChange **apNew; |
| 195855 | - int nNew = (pTab->nChange ? pTab->nChange : 128) * 2; | |
| 195937 | + sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128); | |
| 195856 | 195938 | |
| 195857 | 195939 | apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew); |
| 195858 | 195940 | if( apNew==0 ){ |
| 195859 | 195941 | if( pTab->nChange==0 ){ |
| 195860 | 195942 | return SQLITE_ERROR; |
| @@ -196777,11 +196859,11 @@ | ||
| 196777 | 196859 | ** If not, use sqlite3_realloc() to grow the buffer so that there is. |
| 196778 | 196860 | ** |
| 196779 | 196861 | ** If successful, return zero. Otherwise, if an OOM condition is encountered, |
| 196780 | 196862 | ** set *pRc to SQLITE_NOMEM and return non-zero. |
| 196781 | 196863 | */ |
| 196782 | -static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){ | |
| 196864 | +static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){ | |
| 196783 | 196865 | if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){ |
| 196784 | 196866 | u8 *aNew; |
| 196785 | 196867 | i64 nNew = p->nAlloc ? p->nAlloc : 128; |
| 196786 | 196868 | do { |
| 196787 | 196869 | nNew = nNew*2; |
| @@ -197895,11 +197977,11 @@ | ||
| 197895 | 197977 | rc = SQLITE_CORRUPT_BKPT; |
| 197896 | 197978 | } |
| 197897 | 197979 | } |
| 197898 | 197980 | |
| 197899 | 197981 | if( rc==SQLITE_OK ){ |
| 197900 | - int iPK = sizeof(sqlite3_value*)*p->nCol*2; | |
| 197982 | + size_t iPK = sizeof(sqlite3_value*)*p->nCol*2; | |
| 197901 | 197983 | memset(p->tblhdr.aBuf, 0, iPK); |
| 197902 | 197984 | memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy); |
| 197903 | 197985 | p->in.iNext += nCopy; |
| 197904 | 197986 | } |
| 197905 | 197987 | |
| @@ -199199,11 +199281,11 @@ | ||
| 199199 | 199281 | SessionBuffer cons = pApply->constraints; |
| 199200 | 199282 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 199201 | 199283 | |
| 199202 | 199284 | rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0); |
| 199203 | 199285 | if( rc==SQLITE_OK ){ |
| 199204 | - int nByte = 2*pApply->nCol*sizeof(sqlite3_value*); | |
| 199286 | + size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); | |
| 199205 | 199287 | int rc2; |
| 199206 | 199288 | pIter2->bPatchset = bPatchset; |
| 199207 | 199289 | pIter2->zTab = (char*)zTab; |
| 199208 | 199290 | pIter2->nCol = pApply->nCol; |
| 199209 | 199291 | pIter2->abPK = pApply->abPK; |
| @@ -212488,11 +212570,11 @@ | ||
| 212488 | 212570 | pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl |
| 212489 | 212571 | ); |
| 212490 | 212572 | if( aDlidx==0 ){ |
| 212491 | 212573 | p->rc = SQLITE_NOMEM; |
| 212492 | 212574 | }else{ |
| 212493 | - int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx); | |
| 212575 | + size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx); | |
| 212494 | 212576 | memset(&aDlidx[pWriter->nDlidx], 0, nByte); |
| 212495 | 212577 | pWriter->aDlidx = aDlidx; |
| 212496 | 212578 | pWriter->nDlidx = nLvl; |
| 212497 | 212579 | } |
| 212498 | 212580 | } |
| @@ -217839,18 +217921,18 @@ | ||
| 217839 | 217921 | ){ |
| 217840 | 217922 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217841 | 217923 | int rc = sqlite3_overload_function(pGlobal->db, zName, -1); |
| 217842 | 217924 | if( rc==SQLITE_OK ){ |
| 217843 | 217925 | Fts5Auxiliary *pAux; |
| 217844 | - int nName; /* Size of zName in bytes, including \0 */ | |
| 217845 | - int nByte; /* Bytes of space to allocate */ | |
| 217926 | + sqlite3_int64 nName; /* Size of zName in bytes, including \0 */ | |
| 217927 | + sqlite3_int64 nByte; /* Bytes of space to allocate */ | |
| 217846 | 217928 | |
| 217847 | - nName = (int)strlen(zName) + 1; | |
| 217929 | + nName = strlen(zName) + 1; | |
| 217848 | 217930 | nByte = sizeof(Fts5Auxiliary) + nName; |
| 217849 | - pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte); | |
| 217931 | + pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte); | |
| 217850 | 217932 | if( pAux ){ |
| 217851 | - memset(pAux, 0, nByte); | |
| 217933 | + memset(pAux, 0, (size_t)nByte); | |
| 217852 | 217934 | pAux->zFunc = (char*)&pAux[1]; |
| 217853 | 217935 | memcpy(pAux->zFunc, zName, nName); |
| 217854 | 217936 | pAux->pGlobal = pGlobal; |
| 217855 | 217937 | pAux->pUserData = pUserData; |
| 217856 | 217938 | pAux->xFunc = xFunc; |
| @@ -217876,19 +217958,19 @@ | ||
| 217876 | 217958 | fts5_tokenizer *pTokenizer, /* Tokenizer implementation */ |
| 217877 | 217959 | void(*xDestroy)(void*) /* Destructor for pUserData */ |
| 217878 | 217960 | ){ |
| 217879 | 217961 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217880 | 217962 | Fts5TokenizerModule *pNew; |
| 217881 | - int nName; /* Size of zName and its \0 terminator */ | |
| 217882 | - int nByte; /* Bytes of space to allocate */ | |
| 217963 | + sqlite3_int64 nName; /* Size of zName and its \0 terminator */ | |
| 217964 | + sqlite3_int64 nByte; /* Bytes of space to allocate */ | |
| 217883 | 217965 | int rc = SQLITE_OK; |
| 217884 | 217966 | |
| 217885 | - nName = (int)strlen(zName) + 1; | |
| 217967 | + nName = strlen(zName) + 1; | |
| 217886 | 217968 | nByte = sizeof(Fts5TokenizerModule) + nName; |
| 217887 | - pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte); | |
| 217969 | + pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte); | |
| 217888 | 217970 | if( pNew ){ |
| 217889 | - memset(pNew, 0, nByte); | |
| 217971 | + memset(pNew, 0, (size_t)nByte); | |
| 217890 | 217972 | pNew->zName = (char*)&pNew[1]; |
| 217891 | 217973 | memcpy(pNew->zName, zName, nName); |
| 217892 | 217974 | pNew->pUserData = pUserData; |
| 217893 | 217975 | pNew->x = *pTokenizer; |
| 217894 | 217976 | pNew->xDestroy = xDestroy; |
| @@ -218019,11 +218101,11 @@ | ||
| 218019 | 218101 | int nArg, /* Number of args */ |
| 218020 | 218102 | sqlite3_value **apUnused /* Function arguments */ |
| 218021 | 218103 | ){ |
| 218022 | 218104 | assert( nArg==0 ); |
| 218023 | 218105 | UNUSED_PARAM2(nArg, apUnused); |
| 218024 | - sqlite3_result_text(pCtx, "fts5: 2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f", -1, SQLITE_TRANSIENT); | |
| 218106 | + sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT); | |
| 218025 | 218107 | } |
| 218026 | 218108 | |
| 218027 | 218109 | /* |
| 218028 | 218110 | ** Return true if zName is the extension on one of the shadow tables used |
| 218029 | 218111 | ** by this module. |
| @@ -219664,11 +219746,11 @@ | ||
| 219664 | 219746 | int i; |
| 219665 | 219747 | memset(p, 0, sizeof(Unicode61Tokenizer)); |
| 219666 | 219748 | |
| 219667 | 219749 | p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE; |
| 219668 | 219750 | p->nFold = 64; |
| 219669 | - p->aFold = sqlite3_malloc(p->nFold * sizeof(char)); | |
| 219751 | + p->aFold = sqlite3_malloc64(p->nFold * sizeof(char)); | |
| 219670 | 219752 | if( p->aFold==0 ){ |
| 219671 | 219753 | rc = SQLITE_NOMEM; |
| 219672 | 219754 | } |
| 219673 | 219755 | |
| 219674 | 219756 | /* Search for a "categories" argument */ |
| @@ -222783,12 +222865,12 @@ | ||
| 222783 | 222865 | } |
| 222784 | 222866 | #endif /* SQLITE_CORE */ |
| 222785 | 222867 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 222786 | 222868 | |
| 222787 | 222869 | /************** End of stmt.c ************************************************/ |
| 222788 | -#if __LINE__!=222788 | |
| 222870 | +#if __LINE__!=222870 | |
| 222789 | 222871 | #undef SQLITE_SOURCE_ID |
| 222790 | -#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35alt2" | |
| 222872 | +#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2" | |
| 222791 | 222873 | #endif |
| 222792 | 222874 | /* Return the source-id for this library */ |
| 222793 | 222875 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 222794 | 222876 | /************************** End of sqlite3.c ******************************/ |
| 222795 | 222877 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.28.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3028000 |
| 1167 | #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -13416,11 +13416,11 @@ | |
| 13416 | struct Hash { |
| 13417 | unsigned int htsize; /* Number of buckets in the hash table */ |
| 13418 | unsigned int count; /* Number of entries in this table */ |
| 13419 | HashElem *first; /* The first element of the array */ |
| 13420 | struct _ht { /* the hash table */ |
| 13421 | int count; /* Number of entries with this hash */ |
| 13422 | HashElem *chain; /* Pointer to first entry with this hash */ |
| 13423 | } *ht; |
| 13424 | }; |
| 13425 | |
| 13426 | /* Each element in the hash table is an instance of the following |
| @@ -29858,15 +29858,15 @@ | |
| 29858 | ** This routine transforms the internal text encoding used by pMem to |
| 29859 | ** desiredEnc. It is an error if the string is already of the desired |
| 29860 | ** encoding, or if *pMem does not contain a string value. |
| 29861 | */ |
| 29862 | SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ |
| 29863 | int len; /* Maximum length of output string in bytes */ |
| 29864 | unsigned char *zOut; /* Output buffer */ |
| 29865 | unsigned char *zIn; /* Input iterator */ |
| 29866 | unsigned char *zTerm; /* End of input */ |
| 29867 | unsigned char *z; /* Output iterator */ |
| 29868 | unsigned int c; |
| 29869 | |
| 29870 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 29871 | assert( pMem->flags&MEM_Str ); |
| 29872 | assert( pMem->enc!=desiredEnc ); |
| @@ -29911,18 +29911,18 @@ | |
| 29911 | ** translating a 2-byte character to a 4-byte UTF-8 character. |
| 29912 | ** A single byte is required for the output string |
| 29913 | ** nul-terminator. |
| 29914 | */ |
| 29915 | pMem->n &= ~1; |
| 29916 | len = pMem->n * 2 + 1; |
| 29917 | }else{ |
| 29918 | /* When converting from UTF-8 to UTF-16 the maximum growth is caused |
| 29919 | ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16 |
| 29920 | ** character. Two bytes are required in the output buffer for the |
| 29921 | ** nul-terminator. |
| 29922 | */ |
| 29923 | len = pMem->n * 2 + 2; |
| 29924 | } |
| 29925 | |
| 29926 | /* Set zIn to point at the start of the input buffer and zTerm to point 1 |
| 29927 | ** byte past the end. |
| 29928 | ** |
| @@ -31790,11 +31790,11 @@ | |
| 31790 | |
| 31791 | nInt = nName/4 + 3; |
| 31792 | assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ |
| 31793 | if( pIn==0 || pIn[1]+nInt > pIn[0] ){ |
| 31794 | /* Enlarge the allocation */ |
| 31795 | int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt; |
| 31796 | VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int)); |
| 31797 | if( pOut==0 ) return pIn; |
| 31798 | if( pIn==0 ) pOut[1] = 2; |
| 31799 | pIn = pOut; |
| 31800 | pIn[0] = nAlloc; |
| @@ -31996,11 +31996,11 @@ | |
| 31996 | const Hash *pH, /* The pH to be searched */ |
| 31997 | const char *pKey, /* The key we are searching for */ |
| 31998 | unsigned int *pHash /* Write the hash value here */ |
| 31999 | ){ |
| 32000 | HashElem *elem; /* Used to loop thru the element list */ |
| 32001 | int count; /* Number of elements left to test */ |
| 32002 | unsigned int h; /* The computed hash */ |
| 32003 | static HashElem nullElement = { 0, 0, 0, 0 }; |
| 32004 | |
| 32005 | if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 32006 | struct _ht *pEntry; |
| @@ -32044,12 +32044,12 @@ | |
| 32044 | if( pH->ht ){ |
| 32045 | pEntry = &pH->ht[h]; |
| 32046 | if( pEntry->chain==elem ){ |
| 32047 | pEntry->chain = elem->next; |
| 32048 | } |
| 32049 | pEntry->count--; |
| 32050 | assert( pEntry->count>=0 ); |
| 32051 | } |
| 32052 | sqlite3_free( elem ); |
| 32053 | pH->count--; |
| 32054 | if( pH->count==0 ){ |
| 32055 | assert( pH->first==0 ); |
| @@ -49129,13 +49129,11 @@ | |
| 49129 | ** Malloc function used by SQLite to obtain space from the buffer configured |
| 49130 | ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer |
| 49131 | ** exists, this function falls back to sqlite3Malloc(). |
| 49132 | */ |
| 49133 | SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){ |
| 49134 | /* During rebalance operations on a corrupt database file, it is sometimes |
| 49135 | ** (rarely) possible to overread the temporary page buffer by a few bytes. |
| 49136 | ** Enlarge the allocation slightly so that this does not cause problems. */ |
| 49137 | return pcache1Alloc(sz); |
| 49138 | } |
| 49139 | |
| 49140 | /* |
| 49141 | ** Free an allocated buffer obtained from sqlite3PageMalloc(). |
| @@ -58889,11 +58887,11 @@ | |
| 58889 | ){ |
| 58890 | int rc = SQLITE_OK; |
| 58891 | |
| 58892 | /* Enlarge the pWal->apWiData[] array if required */ |
| 58893 | if( pWal->nWiData<=iPage ){ |
| 58894 | int nByte = sizeof(u32*)*(iPage+1); |
| 58895 | volatile u32 **apNew; |
| 58896 | apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 58897 | if( !apNew ){ |
| 58898 | *ppPage = 0; |
| 58899 | return SQLITE_NOMEM_BKPT; |
| @@ -58993,10 +58991,11 @@ | |
| 58993 | s1 = s2 = 0; |
| 58994 | } |
| 58995 | |
| 58996 | assert( nByte>=8 ); |
| 58997 | assert( (nByte&0x00000007)==0 ); |
| 58998 | |
| 58999 | if( nativeCksum ){ |
| 59000 | do { |
| 59001 | s1 += *aData++ + s2; |
| 59002 | s2 += *aData++ + s1; |
| @@ -59930,11 +59929,11 @@ | |
| 59930 | */ |
| 59931 | static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ |
| 59932 | WalIterator *p; /* Return value */ |
| 59933 | int nSegment; /* Number of segments to merge */ |
| 59934 | u32 iLast; /* Last frame in log */ |
| 59935 | int nByte; /* Number of bytes to allocate */ |
| 59936 | int i; /* Iterator variable */ |
| 59937 | ht_slot *aTmp; /* Temp space used by merge-sort */ |
| 59938 | int rc = SQLITE_OK; /* Return Code */ |
| 59939 | |
| 59940 | /* This routine only runs while holding the checkpoint lock. And |
| @@ -76469,13 +76468,15 @@ | |
| 76469 | ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array |
| 76470 | ** by the minimum* amount required until the size reaches 512. Normal |
| 76471 | ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current |
| 76472 | ** size of the op array or add 1KB of space, whichever is smaller. */ |
| 76473 | #ifdef SQLITE_TEST_REALLOC_STRESS |
| 76474 | int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp); |
| 76475 | #else |
| 76476 | int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 76477 | UNUSED_PARAMETER(nOp); |
| 76478 | #endif |
| 76479 | |
| 76480 | /* Ensure that the size of a VDBE does not grow too large */ |
| 76481 | if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ |
| @@ -77259,11 +77260,11 @@ | |
| 77259 | int addrLoop, /* Address of loop counter */ |
| 77260 | int addrVisit, /* Address of rows visited counter */ |
| 77261 | LogEst nEst, /* Estimated number of output rows */ |
| 77262 | const char *zName /* Name of table or index being scanned */ |
| 77263 | ){ |
| 77264 | int nByte = (p->nScan+1) * sizeof(ScanStatus); |
| 77265 | ScanStatus *aNew; |
| 77266 | aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 77267 | if( aNew ){ |
| 77268 | ScanStatus *pNew = &aNew[p->nScan++]; |
| 77269 | pNew->addrExplain = addrExplain; |
| @@ -78380,13 +78381,13 @@ | |
| 78380 | /* An instance of this object describes bulk memory available for use |
| 78381 | ** by subcomponents of a prepared statement. Space is allocated out |
| 78382 | ** of a ReusableSpace object by the allocSpace() routine below. |
| 78383 | */ |
| 78384 | struct ReusableSpace { |
| 78385 | u8 *pSpace; /* Available memory */ |
| 78386 | int nFree; /* Bytes of available memory */ |
| 78387 | int nNeeded; /* Total bytes that could not be allocated */ |
| 78388 | }; |
| 78389 | |
| 78390 | /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf |
| 78391 | ** from the ReusableSpace object. Return a pointer to the allocated |
| 78392 | ** memory on success. If insufficient memory is available in the |
| @@ -78402,11 +78403,11 @@ | |
| 78402 | ** statement. |
| 78403 | */ |
| 78404 | static void *allocSpace( |
| 78405 | struct ReusableSpace *p, /* Bulk memory available for allocation */ |
| 78406 | void *pBuf, /* Pointer to a prior allocation */ |
| 78407 | int nByte /* Bytes of memory needed */ |
| 78408 | ){ |
| 78409 | assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) ); |
| 78410 | if( pBuf==0 ){ |
| 78411 | nByte = ROUND8(nByte); |
| 78412 | if( nByte <= p->nFree ){ |
| @@ -81359,11 +81360,11 @@ | |
| 81359 | assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 ); |
| 81360 | assert( db->init.busy==0 ); |
| 81361 | assert( p->zSql!=0 ); |
| 81362 | sqlite3OsCurrentTimeInt64(db->pVfs, &iNow); |
| 81363 | iElapse = (iNow - p->startTime)*1000000; |
| 81364 | #ifndef SQLITE_OMIT_DEPRECATED |
| 81365 | if( db->xProfile ){ |
| 81366 | db->xProfile(db->pProfileArg, p->zSql, iElapse); |
| 81367 | } |
| 81368 | #endif |
| 81369 | if( db->mTrace & SQLITE_TRACE_PROFILE ){ |
| @@ -92255,11 +92256,11 @@ | |
| 92255 | int nRem; /* Bytes remaining to copy */ |
| 92256 | |
| 92257 | /* Extend the p->aAlloc[] allocation if required. */ |
| 92258 | if( p->nAlloc<nByte ){ |
| 92259 | u8 *aNew; |
| 92260 | int nNew = MAX(128, p->nAlloc*2); |
| 92261 | while( nByte>nNew ) nNew = nNew*2; |
| 92262 | aNew = sqlite3Realloc(p->aAlloc, nNew); |
| 92263 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 92264 | p->nAlloc = nNew; |
| 92265 | p->aAlloc = aNew; |
| @@ -93546,19 +93547,23 @@ | |
| 93546 | if( pSorter->list.aMemory ){ |
| 93547 | int nMin = pSorter->iMemory + nReq; |
| 93548 | |
| 93549 | if( nMin>pSorter->nMemory ){ |
| 93550 | u8 *aNew; |
| 93551 | int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory; |
| 93552 | int nNew = pSorter->nMemory * 2; |
| 93553 | while( nNew < nMin ) nNew = nNew*2; |
| 93554 | if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize; |
| 93555 | if( nNew < nMin ) nNew = nMin; |
| 93556 | |
| 93557 | aNew = sqlite3Realloc(pSorter->list.aMemory, nNew); |
| 93558 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 93559 | pSorter->list.pList = (SorterRecord*)&aNew[iListOff]; |
| 93560 | pSorter->list.aMemory = aNew; |
| 93561 | pSorter->nMemory = nNew; |
| 93562 | } |
| 93563 | |
| 93564 | pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory]; |
| @@ -98204,11 +98209,11 @@ | |
| 98204 | */ |
| 98205 | #ifndef SQLITE_OMIT_CTE |
| 98206 | static With *withDup(sqlite3 *db, With *p){ |
| 98207 | With *pRet = 0; |
| 98208 | if( p ){ |
| 98209 | int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1); |
| 98210 | pRet = sqlite3DbMallocZero(db, nByte); |
| 98211 | if( pRet ){ |
| 98212 | int i; |
| 98213 | pRet->nCte = p->nCte; |
| 98214 | for(i=0; i<p->nCte; i++){ |
| @@ -98469,11 +98474,11 @@ | |
| 98469 | } |
| 98470 | pList->nExpr = 0; |
| 98471 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 98472 | ExprList *pNew; |
| 98473 | pNew = sqlite3DbRealloc(db, pList, |
| 98474 | sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0])); |
| 98475 | if( pNew==0 ){ |
| 98476 | goto no_mem; |
| 98477 | } |
| 98478 | pList = pNew; |
| 98479 | } |
| @@ -106165,11 +106170,11 @@ | |
| 106165 | } |
| 106166 | sqlite3BtreeLeaveAll(db); |
| 106167 | assert( zErrDyn==0 || rc!=SQLITE_OK ); |
| 106168 | } |
| 106169 | #ifdef SQLITE_USER_AUTHENTICATION |
| 106170 | if( rc==SQLITE_OK ){ |
| 106171 | u8 newAuth = 0; |
| 106172 | rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| 106173 | if( newAuth<db->auth.authLevel ){ |
| 106174 | rc = SQLITE_AUTH_USER; |
| 106175 | } |
| @@ -110602,23 +110607,22 @@ | |
| 110602 | int szEntry, /* Size of each object in the array */ |
| 110603 | int *pnEntry, /* Number of objects currently in use */ |
| 110604 | int *pIdx /* Write the index of a new slot here */ |
| 110605 | ){ |
| 110606 | char *z; |
| 110607 | int n = *pnEntry; |
| 110608 | if( (n & (n-1))==0 ){ |
| 110609 | int sz = (n==0) ? 1 : 2*n; |
| 110610 | void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry); |
| 110611 | if( pNew==0 ){ |
| 110612 | *pIdx = -1; |
| 110613 | return pArray; |
| 110614 | } |
| 110615 | pArray = pNew; |
| 110616 | } |
| 110617 | z = (char*)pArray; |
| 110618 | memset(&z[n * szEntry], 0, szEntry); |
| 110619 | *pIdx = n; |
| 110620 | ++*pnEntry; |
| 110621 | return pArray; |
| 110622 | } |
| 110623 | |
| 110624 | /* |
| @@ -110725,11 +110729,11 @@ | |
| 110725 | assert( iStart<=pSrc->nSrc ); |
| 110726 | |
| 110727 | /* Allocate additional space if needed */ |
| 110728 | if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){ |
| 110729 | SrcList *pNew; |
| 110730 | int nAlloc = pSrc->nSrc*2+nExtra; |
| 110731 | sqlite3 *db = pParse->db; |
| 110732 | |
| 110733 | if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){ |
| 110734 | sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d", |
| 110735 | SQLITE_MAX_SRCLIST); |
| @@ -111482,11 +111486,11 @@ | |
| 111482 | } |
| 111483 | } |
| 111484 | } |
| 111485 | |
| 111486 | if( pWith ){ |
| 111487 | int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte); |
| 111488 | pNew = sqlite3DbRealloc(db, pWith, nByte); |
| 111489 | }else{ |
| 111490 | pNew = sqlite3DbMallocZero(db, sizeof(*pWith)); |
| 111491 | } |
| 111492 | assert( (pNew!=0 && zName!=0) || db->mallocFailed ); |
| @@ -134593,13 +134597,17 @@ | |
| 134593 | ** Add a new module argument to pTable->azModuleArg[]. |
| 134594 | ** The string is not copied - the pointer is stored. The |
| 134595 | ** string will be freed automatically when the table is |
| 134596 | ** deleted. |
| 134597 | */ |
| 134598 | static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){ |
| 134599 | int nBytes = sizeof(char *)*(2+pTable->nModuleArg); |
| 134600 | char **azModuleArg; |
| 134601 | azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); |
| 134602 | if( azModuleArg==0 ){ |
| 134603 | sqlite3DbFree(db, zArg); |
| 134604 | }else{ |
| 134605 | int i = pTable->nModuleArg++; |
| @@ -134630,13 +134638,13 @@ | |
| 134630 | assert( 0==pTable->pIndex ); |
| 134631 | |
| 134632 | db = pParse->db; |
| 134633 | |
| 134634 | assert( pTable->nModuleArg==0 ); |
| 134635 | addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 134636 | addModuleArgument(db, pTable, 0); |
| 134637 | addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| 134638 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 134639 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| 134640 | ); |
| 134641 | pParse->sNameToken.n = (int)( |
| 134642 | &pModuleName->z[pModuleName->n] - pParse->sNameToken.z |
| @@ -134665,11 +134673,11 @@ | |
| 134665 | static void addArgumentToVtab(Parse *pParse){ |
| 134666 | if( pParse->sArg.z && pParse->pNewTable ){ |
| 134667 | const char *z = (const char*)pParse->sArg.z; |
| 134668 | int n = pParse->sArg.n; |
| 134669 | sqlite3 *db = pParse->db; |
| 134670 | addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n)); |
| 134671 | } |
| 134672 | } |
| 134673 | |
| 134674 | /* |
| 134675 | ** The parser calls this routine after the CREATE VIRTUAL TABLE statement |
| @@ -134954,11 +134962,12 @@ | |
| 134954 | const int ARRAY_INCR = 5; |
| 134955 | |
| 134956 | /* Grow the sqlite3.aVTrans array if required */ |
| 134957 | if( (db->nVTrans%ARRAY_INCR)==0 ){ |
| 134958 | VTable **aVTrans; |
| 134959 | int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR); |
| 134960 | aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes); |
| 134961 | if( !aVTrans ){ |
| 134962 | return SQLITE_NOMEM_BKPT; |
| 134963 | } |
| 134964 | memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR); |
| @@ -135450,13 +135459,13 @@ | |
| 135450 | pMod->pEpoTab = pTab; |
| 135451 | pTab->nTabRef = 1; |
| 135452 | pTab->pSchema = db->aDb[0].pSchema; |
| 135453 | assert( pTab->nModuleArg==0 ); |
| 135454 | pTab->iPKey = -1; |
| 135455 | addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 135456 | addModuleArgument(db, pTab, 0); |
| 135457 | addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 135458 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| 135459 | if( rc ){ |
| 135460 | sqlite3ErrorMsg(pParse, "%s", zErr); |
| 135461 | sqlite3DbFree(db, zErr); |
| 135462 | sqlite3VtabEponymousTableClear(db, pMod); |
| @@ -155309,11 +155318,11 @@ | |
| 155309 | if( sz==0 || cnt==0 ){ |
| 155310 | sz = 0; |
| 155311 | pStart = 0; |
| 155312 | }else if( pBuf==0 ){ |
| 155313 | sqlite3BeginBenignMalloc(); |
| 155314 | pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */ |
| 155315 | sqlite3EndBenignMalloc(); |
| 155316 | if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; |
| 155317 | }else{ |
| 155318 | pStart = pBuf; |
| 155319 | } |
| @@ -169347,12 +169356,12 @@ | |
| 169347 | }else{ |
| 169348 | char const **aArg = 0; |
| 169349 | int iArg = 0; |
| 169350 | z = &z[n+1]; |
| 169351 | while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){ |
| 169352 | int nNew = sizeof(char *)*(iArg+1); |
| 169353 | char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew); |
| 169354 | if( !aNew ){ |
| 169355 | sqlite3_free(zCopy); |
| 169356 | sqlite3_free((void *)aArg); |
| 169357 | return SQLITE_NOMEM; |
| 169358 | } |
| @@ -170255,11 +170264,11 @@ | |
| 170255 | |
| 170256 | fts3tokResetCursor(pCsr); |
| 170257 | if( idxNum==1 ){ |
| 170258 | const char *zByte = (const char *)sqlite3_value_text(apVal[0]); |
| 170259 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 170260 | pCsr->zInput = sqlite3_malloc(nByte+1); |
| 170261 | if( pCsr->zInput==0 ){ |
| 170262 | rc = SQLITE_NOMEM; |
| 170263 | }else{ |
| 170264 | memcpy(pCsr->zInput, zByte, nByte); |
| 170265 | pCsr->zInput[nByte] = 0; |
| @@ -172119,12 +172128,13 @@ | |
| 172119 | nElem = 1; |
| 172120 | } |
| 172121 | } |
| 172122 | |
| 172123 | if( nElem>0 ){ |
| 172124 | int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *); |
| 172125 | pReader = (Fts3SegReader *)sqlite3_malloc(nByte); |
| 172126 | if( !pReader ){ |
| 172127 | rc = SQLITE_NOMEM; |
| 172128 | }else{ |
| 172129 | memset(pReader, 0, nByte); |
| 172130 | pReader->iIdx = 0x7FFFFFFF; |
| @@ -173734,11 +173744,11 @@ | |
| 173734 | int nBlob; /* Number of bytes in the BLOB */ |
| 173735 | sqlite3_stmt *pStmt; /* Statement used to insert the encoding */ |
| 173736 | int rc; /* Result code from subfunctions */ |
| 173737 | |
| 173738 | if( *pRC ) return; |
| 173739 | pBlob = sqlite3_malloc( 10*p->nColumn ); |
| 173740 | if( pBlob==0 ){ |
| 173741 | *pRC = SQLITE_NOMEM; |
| 173742 | return; |
| 173743 | } |
| 173744 | fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob); |
| @@ -173784,11 +173794,11 @@ | |
| 173784 | int rc; /* Result code from subfunctions */ |
| 173785 | |
| 173786 | const int nStat = p->nColumn+2; |
| 173787 | |
| 173788 | if( *pRC ) return; |
| 173789 | a = sqlite3_malloc( (sizeof(u32)+10)*nStat ); |
| 173790 | if( a==0 ){ |
| 173791 | *pRC = SQLITE_NOMEM; |
| 173792 | return; |
| 173793 | } |
| 173794 | pBlob = (char*)&a[nStat]; |
| @@ -173905,12 +173915,12 @@ | |
| 173905 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 173906 | sqlite3_free(zSql); |
| 173907 | } |
| 173908 | |
| 173909 | if( rc==SQLITE_OK ){ |
| 173910 | int nByte = sizeof(u32) * (p->nColumn+1)*3; |
| 173911 | aSz = (u32 *)sqlite3_malloc(nByte); |
| 173912 | if( aSz==0 ){ |
| 173913 | rc = SQLITE_NOMEM; |
| 173914 | }else{ |
| 173915 | memset(aSz, 0, nByte); |
| 173916 | aSzIns = &aSz[p->nColumn+1]; |
| @@ -173972,16 +173982,16 @@ | |
| 173972 | int nSeg, /* Number of segments to merge */ |
| 173973 | Fts3MultiSegReader *pCsr /* Cursor object to populate */ |
| 173974 | ){ |
| 173975 | int rc; /* Return Code */ |
| 173976 | sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */ |
| 173977 | int nByte; /* Bytes allocated at pCsr->apSegment[] */ |
| 173978 | |
| 173979 | /* Allocate space for the Fts3MultiSegReader.aCsr[] array */ |
| 173980 | memset(pCsr, 0, sizeof(*pCsr)); |
| 173981 | nByte = sizeof(Fts3SegReader *) * nSeg; |
| 173982 | pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte); |
| 173983 | |
| 173984 | if( pCsr->apSegment==0 ){ |
| 173985 | rc = SQLITE_NOMEM; |
| 173986 | }else{ |
| 173987 | memset(pCsr->apSegment, 0, nByte); |
| @@ -175957,11 +175967,11 @@ | |
| 175957 | rc = SQLITE_CONSTRAINT; |
| 175958 | goto update_out; |
| 175959 | } |
| 175960 | |
| 175961 | /* Allocate space to hold the change in document sizes */ |
| 175962 | aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 ); |
| 175963 | if( aSzDel==0 ){ |
| 175964 | rc = SQLITE_NOMEM; |
| 175965 | goto update_out; |
| 175966 | } |
| 175967 | aSzIns = &aSzDel[p->nColumn+1]; |
| @@ -176211,21 +176221,23 @@ | |
| 176211 | */ |
| 176212 | |
| 176213 | /* |
| 176214 | ** Allocate a two-slot MatchinfoBuffer object. |
| 176215 | */ |
| 176216 | static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){ |
| 176217 | MatchinfoBuffer *pRet; |
| 176218 | int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer); |
| 176219 | int nStr = (int)strlen(zMatchinfo); |
| 176220 | |
| 176221 | pRet = sqlite3_malloc(nByte + nStr+1); |
| 176222 | if( pRet ){ |
| 176223 | memset(pRet, 0, nByte); |
| 176224 | pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; |
| 176225 | pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1); |
| 176226 | pRet->nElem = nElem; |
| 176227 | pRet->zMatchinfo = ((char*)pRet) + nByte; |
| 176228 | memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1); |
| 176229 | pRet->aRef[0] = 1; |
| 176230 | } |
| 176231 | |
| @@ -177082,12 +177094,12 @@ | |
| 177082 | } |
| 177083 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 177084 | return SQLITE_ERROR; |
| 177085 | } |
| 177086 | |
| 177087 | static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 177088 | int nVal; /* Number of integers output by cArg */ |
| 177089 | |
| 177090 | switch( cArg ){ |
| 177091 | case FTS3_MATCHINFO_NDOC: |
| 177092 | case FTS3_MATCHINFO_NPHRASE: |
| 177093 | case FTS3_MATCHINFO_NCOL: |
| @@ -177367,11 +177379,11 @@ | |
| 177367 | } |
| 177368 | break; |
| 177369 | |
| 177370 | case FTS3_MATCHINFO_LHITS_BM: |
| 177371 | case FTS3_MATCHINFO_LHITS: { |
| 177372 | int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); |
| 177373 | memset(pInfo->aMatchinfo, 0, nZero); |
| 177374 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 177375 | break; |
| 177376 | } |
| 177377 | |
| @@ -177436,11 +177448,11 @@ | |
| 177436 | ** matchinfo function has been called for this query. In this case |
| 177437 | ** allocate the array used to accumulate the matchinfo data and |
| 177438 | ** initialize those elements that are constant for every row. |
| 177439 | */ |
| 177440 | if( pCsr->pMIBuffer==0 ){ |
| 177441 | int nMatchinfo = 0; /* Number of u32 elements in match-info */ |
| 177442 | int i; /* Used to iterate through zArg */ |
| 177443 | |
| 177444 | /* Determine the number of phrases in the query */ |
| 177445 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 177446 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -185697,11 +185709,11 @@ | |
| 185697 | && (s.z++, geopolySkipSpace(&s)==0) |
| 185698 | ){ |
| 185699 | GeoPoly *pOut; |
| 185700 | int x = 1; |
| 185701 | s.nVertex--; /* Remove the redundant vertex at the end */ |
| 185702 | pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) ); |
| 185703 | x = 1; |
| 185704 | if( pOut==0 ) goto parse_json_err; |
| 185705 | pOut->nVertex = s.nVertex; |
| 185706 | memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord)); |
| 185707 | pOut->hdr[0] = *(unsigned char*)&x; |
| @@ -186083,11 +186095,11 @@ | |
| 186083 | else if( r>mxY ) mxY = (float)r; |
| 186084 | } |
| 186085 | if( pRc ) *pRc = SQLITE_OK; |
| 186086 | if( aCoord==0 ){ |
| 186087 | geopolyBboxFill: |
| 186088 | pOut = sqlite3_realloc(p, GEOPOLY_SZ(4)); |
| 186089 | if( pOut==0 ){ |
| 186090 | sqlite3_free(p); |
| 186091 | if( context ) sqlite3_result_error_nomem(context); |
| 186092 | if( pRc ) *pRc = SQLITE_NOMEM; |
| 186093 | return 0; |
| @@ -186479,13 +186491,13 @@ | |
| 186479 | |
| 186480 | /* |
| 186481 | ** Determine the overlap between two polygons |
| 186482 | */ |
| 186483 | static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){ |
| 186484 | int nVertex = p1->nVertex + p2->nVertex + 2; |
| 186485 | GeoOverlap *p; |
| 186486 | int nByte; |
| 186487 | GeoEvent *pThisEvent; |
| 186488 | double rX; |
| 186489 | int rc = 0; |
| 186490 | int needSort = 0; |
| 186491 | GeoSegment *pActive = 0; |
| @@ -186493,11 +186505,11 @@ | |
| 186493 | unsigned char aOverlap[4]; |
| 186494 | |
| 186495 | nByte = sizeof(GeoEvent)*nVertex*2 |
| 186496 | + sizeof(GeoSegment)*nVertex |
| 186497 | + sizeof(GeoOverlap); |
| 186498 | p = sqlite3_malloc( nByte ); |
| 186499 | if( p==0 ) return -1; |
| 186500 | p->aEvent = (GeoEvent*)&p[1]; |
| 186501 | p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2]; |
| 186502 | p->nEvent = p->nSegment = 0; |
| 186503 | geopolyAddSegments(p, p1, 1); |
| @@ -186652,22 +186664,22 @@ | |
| 186652 | char **pzErr, /* OUT: Error message, if any */ |
| 186653 | int isCreate /* True for xCreate, false for xConnect */ |
| 186654 | ){ |
| 186655 | int rc = SQLITE_OK; |
| 186656 | Rtree *pRtree; |
| 186657 | int nDb; /* Length of string argv[1] */ |
| 186658 | int nName; /* Length of string argv[2] */ |
| 186659 | sqlite3_str *pSql; |
| 186660 | char *zSql; |
| 186661 | int ii; |
| 186662 | |
| 186663 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 186664 | |
| 186665 | /* Allocate the sqlite3_vtab structure */ |
| 186666 | nDb = (int)strlen(argv[1]); |
| 186667 | nName = (int)strlen(argv[2]); |
| 186668 | pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2); |
| 186669 | if( !pRtree ){ |
| 186670 | return SQLITE_NOMEM; |
| 186671 | } |
| 186672 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 186673 | pRtree->nBusy = 1; |
| @@ -189088,10 +189100,15 @@ | |
| 189088 | ** abIndexed: |
| 189089 | ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise, |
| 189090 | ** it points to an array of flags nTblCol elements in size. The flag is |
| 189091 | ** set for each column that is either a part of the PK or a part of an |
| 189092 | ** index. Or clear otherwise. |
| 189093 | ** |
| 189094 | */ |
| 189095 | struct RbuObjIter { |
| 189096 | sqlite3_stmt *pTblIter; /* Iterate through tables */ |
| 189097 | sqlite3_stmt *pIdxIter; /* Index iterator */ |
| @@ -189883,11 +189900,11 @@ | |
| 189883 | ** error code in the rbu handle passed as the first argument. Or, if an |
| 189884 | ** error has already occurred when this function is called, return NULL |
| 189885 | ** immediately without attempting the allocation or modifying the stored |
| 189886 | ** error code. |
| 189887 | */ |
| 189888 | static void *rbuMalloc(sqlite3rbu *p, int nByte){ |
| 189889 | void *pRet = 0; |
| 189890 | if( p->rc==SQLITE_OK ){ |
| 189891 | assert( nByte>0 ); |
| 189892 | pRet = sqlite3_malloc64(nByte); |
| 189893 | if( pRet==0 ){ |
| @@ -189904,11 +189921,11 @@ | |
| 189904 | ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that |
| 189905 | ** there is room for at least nCol elements. If an OOM occurs, store an |
| 189906 | ** error code in the RBU handle passed as the first argument. |
| 189907 | */ |
| 189908 | static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){ |
| 189909 | int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; |
| 189910 | char **azNew; |
| 189911 | |
| 189912 | azNew = (char**)rbuMalloc(p, nByte); |
| 189913 | if( azNew ){ |
| 189914 | pIter->azTblCol = azNew; |
| @@ -190098,12 +190115,16 @@ | |
| 190098 | } |
| 190099 | |
| 190100 | pIter->nIndex = 0; |
| 190101 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){ |
| 190102 | const char *zIdx = (const char*)sqlite3_column_text(pList, 1); |
| 190103 | sqlite3_stmt *pXInfo = 0; |
| 190104 | if( zIdx==0 ) break; |
| 190105 | p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg, |
| 190106 | sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx) |
| 190107 | ); |
| 190108 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 190109 | int iCid = sqlite3_column_int(pXInfo, 1); |
| @@ -190544,11 +190565,11 @@ | |
| 190544 | ** when this function is called, NULL is returned immediately, without |
| 190545 | ** attempting the allocation or modifying the stored error code. |
| 190546 | */ |
| 190547 | static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){ |
| 190548 | char *zRet = 0; |
| 190549 | int nByte = nBind*2 + 1; |
| 190550 | |
| 190551 | zRet = (char*)rbuMalloc(p, nByte); |
| 190552 | if( zRet ){ |
| 190553 | int i; |
| 190554 | for(i=0; i<nBind; i++){ |
| @@ -190805,10 +190826,66 @@ | |
| 190805 | |
| 190806 | if( rc!=SQLITE_OK ){ |
| 190807 | sqlite3_result_error_code(pCtx, rc); |
| 190808 | } |
| 190809 | } |
| 190810 | |
| 190811 | /* |
| 190812 | ** Ensure that the SQLite statement handles required to update the |
| 190813 | ** target database object currently indicated by the iterator passed |
| 190814 | ** as the second argument are available. |
| @@ -190835,17 +190912,19 @@ | |
| 190835 | const char *zTbl = pIter->zTbl; |
| 190836 | char *zImposterCols = 0; /* Columns for imposter table */ |
| 190837 | char *zImposterPK = 0; /* Primary key declaration for imposter */ |
| 190838 | char *zWhere = 0; /* WHERE clause on PK columns */ |
| 190839 | char *zBind = 0; |
| 190840 | int nBind = 0; |
| 190841 | |
| 190842 | assert( pIter->eType!=RBU_PK_VTAB ); |
| 190843 | zCollist = rbuObjIterGetIndexCols( |
| 190844 | p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind |
| 190845 | ); |
| 190846 | zBind = rbuObjIterGetBindlist(p, nBind); |
| 190847 | |
| 190848 | /* Create the imposter table used to write to this index. */ |
| 190849 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); |
| 190850 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum); |
| 190851 | rbuMPrintfExec(p, p->dbMain, |
| @@ -190874,32 +190953,34 @@ | |
| 190874 | /* Create the SELECT statement to read keys in sorted order */ |
| 190875 | if( p->rc==SQLITE_OK ){ |
| 190876 | char *zSql; |
| 190877 | if( rbuIsVacuum(p) ){ |
| 190878 | zSql = sqlite3_mprintf( |
| 190879 | "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s", |
| 190880 | zCollist, |
| 190881 | pIter->zDataTbl, |
| 190882 | zCollist, zLimit |
| 190883 | ); |
| 190884 | }else |
| 190885 | |
| 190886 | if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 190887 | zSql = sqlite3_mprintf( |
| 190888 | "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s", |
| 190889 | zCollist, p->zStateDb, pIter->zDataTbl, |
| 190890 | zCollist, zLimit |
| 190891 | ); |
| 190892 | }else{ |
| 190893 | zSql = sqlite3_mprintf( |
| 190894 | "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' " |
| 190895 | "UNION ALL " |
| 190896 | "SELECT %s, rbu_control FROM '%q' " |
| 190897 | "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 " |
| 190898 | "ORDER BY %s%s", |
| 190899 | zCollist, p->zStateDb, pIter->zDataTbl, |
| 190900 | zCollist, pIter->zDataTbl, |
| 190901 | zCollist, zLimit |
| 190902 | ); |
| 190903 | } |
| 190904 | p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql); |
| 190905 | } |
| @@ -190906,10 +190987,11 @@ | |
| 190906 | |
| 190907 | sqlite3_free(zImposterCols); |
| 190908 | sqlite3_free(zImposterPK); |
| 190909 | sqlite3_free(zWhere); |
| 190910 | sqlite3_free(zBind); |
| 190911 | }else{ |
| 190912 | int bRbuRowid = (pIter->eType==RBU_PK_VTAB) |
| 190913 | ||(pIter->eType==RBU_PK_NONE) |
| 190914 | ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p)); |
| 190915 | const char *zTbl = pIter->zTbl; /* Table this step applies to */ |
| @@ -193339,11 +193421,11 @@ | |
| 193339 | ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space |
| 193340 | ** instead of a file on disk. */ |
| 193341 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 193342 | if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ |
| 193343 | if( iRegion<=p->nShm ){ |
| 193344 | int nByte = (iRegion+1) * sizeof(char*); |
| 193345 | char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte); |
| 193346 | if( apNew==0 ){ |
| 193347 | rc = SQLITE_NOMEM; |
| 193348 | }else{ |
| 193349 | memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm)); |
| @@ -195850,11 +195932,11 @@ | |
| 195850 | */ |
| 195851 | static int sessionGrowHash(int bPatchset, SessionTable *pTab){ |
| 195852 | if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){ |
| 195853 | int i; |
| 195854 | SessionChange **apNew; |
| 195855 | int nNew = (pTab->nChange ? pTab->nChange : 128) * 2; |
| 195856 | |
| 195857 | apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew); |
| 195858 | if( apNew==0 ){ |
| 195859 | if( pTab->nChange==0 ){ |
| 195860 | return SQLITE_ERROR; |
| @@ -196777,11 +196859,11 @@ | |
| 196777 | ** If not, use sqlite3_realloc() to grow the buffer so that there is. |
| 196778 | ** |
| 196779 | ** If successful, return zero. Otherwise, if an OOM condition is encountered, |
| 196780 | ** set *pRc to SQLITE_NOMEM and return non-zero. |
| 196781 | */ |
| 196782 | static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){ |
| 196783 | if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){ |
| 196784 | u8 *aNew; |
| 196785 | i64 nNew = p->nAlloc ? p->nAlloc : 128; |
| 196786 | do { |
| 196787 | nNew = nNew*2; |
| @@ -197895,11 +197977,11 @@ | |
| 197895 | rc = SQLITE_CORRUPT_BKPT; |
| 197896 | } |
| 197897 | } |
| 197898 | |
| 197899 | if( rc==SQLITE_OK ){ |
| 197900 | int iPK = sizeof(sqlite3_value*)*p->nCol*2; |
| 197901 | memset(p->tblhdr.aBuf, 0, iPK); |
| 197902 | memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy); |
| 197903 | p->in.iNext += nCopy; |
| 197904 | } |
| 197905 | |
| @@ -199199,11 +199281,11 @@ | |
| 199199 | SessionBuffer cons = pApply->constraints; |
| 199200 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 199201 | |
| 199202 | rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0); |
| 199203 | if( rc==SQLITE_OK ){ |
| 199204 | int nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 199205 | int rc2; |
| 199206 | pIter2->bPatchset = bPatchset; |
| 199207 | pIter2->zTab = (char*)zTab; |
| 199208 | pIter2->nCol = pApply->nCol; |
| 199209 | pIter2->abPK = pApply->abPK; |
| @@ -212488,11 +212570,11 @@ | |
| 212488 | pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl |
| 212489 | ); |
| 212490 | if( aDlidx==0 ){ |
| 212491 | p->rc = SQLITE_NOMEM; |
| 212492 | }else{ |
| 212493 | int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx); |
| 212494 | memset(&aDlidx[pWriter->nDlidx], 0, nByte); |
| 212495 | pWriter->aDlidx = aDlidx; |
| 212496 | pWriter->nDlidx = nLvl; |
| 212497 | } |
| 212498 | } |
| @@ -217839,18 +217921,18 @@ | |
| 217839 | ){ |
| 217840 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217841 | int rc = sqlite3_overload_function(pGlobal->db, zName, -1); |
| 217842 | if( rc==SQLITE_OK ){ |
| 217843 | Fts5Auxiliary *pAux; |
| 217844 | int nName; /* Size of zName in bytes, including \0 */ |
| 217845 | int nByte; /* Bytes of space to allocate */ |
| 217846 | |
| 217847 | nName = (int)strlen(zName) + 1; |
| 217848 | nByte = sizeof(Fts5Auxiliary) + nName; |
| 217849 | pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte); |
| 217850 | if( pAux ){ |
| 217851 | memset(pAux, 0, nByte); |
| 217852 | pAux->zFunc = (char*)&pAux[1]; |
| 217853 | memcpy(pAux->zFunc, zName, nName); |
| 217854 | pAux->pGlobal = pGlobal; |
| 217855 | pAux->pUserData = pUserData; |
| 217856 | pAux->xFunc = xFunc; |
| @@ -217876,19 +217958,19 @@ | |
| 217876 | fts5_tokenizer *pTokenizer, /* Tokenizer implementation */ |
| 217877 | void(*xDestroy)(void*) /* Destructor for pUserData */ |
| 217878 | ){ |
| 217879 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217880 | Fts5TokenizerModule *pNew; |
| 217881 | int nName; /* Size of zName and its \0 terminator */ |
| 217882 | int nByte; /* Bytes of space to allocate */ |
| 217883 | int rc = SQLITE_OK; |
| 217884 | |
| 217885 | nName = (int)strlen(zName) + 1; |
| 217886 | nByte = sizeof(Fts5TokenizerModule) + nName; |
| 217887 | pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte); |
| 217888 | if( pNew ){ |
| 217889 | memset(pNew, 0, nByte); |
| 217890 | pNew->zName = (char*)&pNew[1]; |
| 217891 | memcpy(pNew->zName, zName, nName); |
| 217892 | pNew->pUserData = pUserData; |
| 217893 | pNew->x = *pTokenizer; |
| 217894 | pNew->xDestroy = xDestroy; |
| @@ -218019,11 +218101,11 @@ | |
| 218019 | int nArg, /* Number of args */ |
| 218020 | sqlite3_value **apUnused /* Function arguments */ |
| 218021 | ){ |
| 218022 | assert( nArg==0 ); |
| 218023 | UNUSED_PARAM2(nArg, apUnused); |
| 218024 | sqlite3_result_text(pCtx, "fts5: 2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f", -1, SQLITE_TRANSIENT); |
| 218025 | } |
| 218026 | |
| 218027 | /* |
| 218028 | ** Return true if zName is the extension on one of the shadow tables used |
| 218029 | ** by this module. |
| @@ -219664,11 +219746,11 @@ | |
| 219664 | int i; |
| 219665 | memset(p, 0, sizeof(Unicode61Tokenizer)); |
| 219666 | |
| 219667 | p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE; |
| 219668 | p->nFold = 64; |
| 219669 | p->aFold = sqlite3_malloc(p->nFold * sizeof(char)); |
| 219670 | if( p->aFold==0 ){ |
| 219671 | rc = SQLITE_NOMEM; |
| 219672 | } |
| 219673 | |
| 219674 | /* Search for a "categories" argument */ |
| @@ -222783,12 +222865,12 @@ | |
| 222783 | } |
| 222784 | #endif /* SQLITE_CORE */ |
| 222785 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 222786 | |
| 222787 | /************** End of stmt.c ************************************************/ |
| 222788 | #if __LINE__!=222788 |
| 222789 | #undef SQLITE_SOURCE_ID |
| 222790 | #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35alt2" |
| 222791 | #endif |
| 222792 | /* Return the source-id for this library */ |
| 222793 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 222794 | /************************** End of sqlite3.c ******************************/ |
| 222795 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.28.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3028000 |
| 1167 | #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -13416,11 +13416,11 @@ | |
| 13416 | struct Hash { |
| 13417 | unsigned int htsize; /* Number of buckets in the hash table */ |
| 13418 | unsigned int count; /* Number of entries in this table */ |
| 13419 | HashElem *first; /* The first element of the array */ |
| 13420 | struct _ht { /* the hash table */ |
| 13421 | unsigned int count; /* Number of entries with this hash */ |
| 13422 | HashElem *chain; /* Pointer to first entry with this hash */ |
| 13423 | } *ht; |
| 13424 | }; |
| 13425 | |
| 13426 | /* Each element in the hash table is an instance of the following |
| @@ -29858,15 +29858,15 @@ | |
| 29858 | ** This routine transforms the internal text encoding used by pMem to |
| 29859 | ** desiredEnc. It is an error if the string is already of the desired |
| 29860 | ** encoding, or if *pMem does not contain a string value. |
| 29861 | */ |
| 29862 | SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ |
| 29863 | sqlite3_int64 len; /* Maximum length of output string in bytes */ |
| 29864 | unsigned char *zOut; /* Output buffer */ |
| 29865 | unsigned char *zIn; /* Input iterator */ |
| 29866 | unsigned char *zTerm; /* End of input */ |
| 29867 | unsigned char *z; /* Output iterator */ |
| 29868 | unsigned int c; |
| 29869 | |
| 29870 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 29871 | assert( pMem->flags&MEM_Str ); |
| 29872 | assert( pMem->enc!=desiredEnc ); |
| @@ -29911,18 +29911,18 @@ | |
| 29911 | ** translating a 2-byte character to a 4-byte UTF-8 character. |
| 29912 | ** A single byte is required for the output string |
| 29913 | ** nul-terminator. |
| 29914 | */ |
| 29915 | pMem->n &= ~1; |
| 29916 | len = 2 * (sqlite3_int64)pMem->n + 1; |
| 29917 | }else{ |
| 29918 | /* When converting from UTF-8 to UTF-16 the maximum growth is caused |
| 29919 | ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16 |
| 29920 | ** character. Two bytes are required in the output buffer for the |
| 29921 | ** nul-terminator. |
| 29922 | */ |
| 29923 | len = 2 * (sqlite3_int64)pMem->n + 2; |
| 29924 | } |
| 29925 | |
| 29926 | /* Set zIn to point at the start of the input buffer and zTerm to point 1 |
| 29927 | ** byte past the end. |
| 29928 | ** |
| @@ -31790,11 +31790,11 @@ | |
| 31790 | |
| 31791 | nInt = nName/4 + 3; |
| 31792 | assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */ |
| 31793 | if( pIn==0 || pIn[1]+nInt > pIn[0] ){ |
| 31794 | /* Enlarge the allocation */ |
| 31795 | sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt; |
| 31796 | VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int)); |
| 31797 | if( pOut==0 ) return pIn; |
| 31798 | if( pIn==0 ) pOut[1] = 2; |
| 31799 | pIn = pOut; |
| 31800 | pIn[0] = nAlloc; |
| @@ -31996,11 +31996,11 @@ | |
| 31996 | const Hash *pH, /* The pH to be searched */ |
| 31997 | const char *pKey, /* The key we are searching for */ |
| 31998 | unsigned int *pHash /* Write the hash value here */ |
| 31999 | ){ |
| 32000 | HashElem *elem; /* Used to loop thru the element list */ |
| 32001 | unsigned int count; /* Number of elements left to test */ |
| 32002 | unsigned int h; /* The computed hash */ |
| 32003 | static HashElem nullElement = { 0, 0, 0, 0 }; |
| 32004 | |
| 32005 | if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 32006 | struct _ht *pEntry; |
| @@ -32044,12 +32044,12 @@ | |
| 32044 | if( pH->ht ){ |
| 32045 | pEntry = &pH->ht[h]; |
| 32046 | if( pEntry->chain==elem ){ |
| 32047 | pEntry->chain = elem->next; |
| 32048 | } |
| 32049 | assert( pEntry->count>0 ); |
| 32050 | pEntry->count--; |
| 32051 | } |
| 32052 | sqlite3_free( elem ); |
| 32053 | pH->count--; |
| 32054 | if( pH->count==0 ){ |
| 32055 | assert( pH->first==0 ); |
| @@ -49129,13 +49129,11 @@ | |
| 49129 | ** Malloc function used by SQLite to obtain space from the buffer configured |
| 49130 | ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer |
| 49131 | ** exists, this function falls back to sqlite3Malloc(). |
| 49132 | */ |
| 49133 | SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){ |
| 49134 | assert( sz<=65536+8 ); /* These allocations are never very large */ |
| 49135 | return pcache1Alloc(sz); |
| 49136 | } |
| 49137 | |
| 49138 | /* |
| 49139 | ** Free an allocated buffer obtained from sqlite3PageMalloc(). |
| @@ -58889,11 +58887,11 @@ | |
| 58887 | ){ |
| 58888 | int rc = SQLITE_OK; |
| 58889 | |
| 58890 | /* Enlarge the pWal->apWiData[] array if required */ |
| 58891 | if( pWal->nWiData<=iPage ){ |
| 58892 | sqlite3_int64 nByte = sizeof(u32*)*(iPage+1); |
| 58893 | volatile u32 **apNew; |
| 58894 | apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte); |
| 58895 | if( !apNew ){ |
| 58896 | *ppPage = 0; |
| 58897 | return SQLITE_NOMEM_BKPT; |
| @@ -58993,10 +58991,11 @@ | |
| 58991 | s1 = s2 = 0; |
| 58992 | } |
| 58993 | |
| 58994 | assert( nByte>=8 ); |
| 58995 | assert( (nByte&0x00000007)==0 ); |
| 58996 | assert( nByte<=65536 ); |
| 58997 | |
| 58998 | if( nativeCksum ){ |
| 58999 | do { |
| 59000 | s1 += *aData++ + s2; |
| 59001 | s2 += *aData++ + s1; |
| @@ -59930,11 +59929,11 @@ | |
| 59929 | */ |
| 59930 | static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){ |
| 59931 | WalIterator *p; /* Return value */ |
| 59932 | int nSegment; /* Number of segments to merge */ |
| 59933 | u32 iLast; /* Last frame in log */ |
| 59934 | sqlite3_int64 nByte; /* Number of bytes to allocate */ |
| 59935 | int i; /* Iterator variable */ |
| 59936 | ht_slot *aTmp; /* Temp space used by merge-sort */ |
| 59937 | int rc = SQLITE_OK; /* Return Code */ |
| 59938 | |
| 59939 | /* This routine only runs while holding the checkpoint lock. And |
| @@ -76469,13 +76468,15 @@ | |
| 76468 | ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array |
| 76469 | ** by the minimum* amount required until the size reaches 512. Normal |
| 76470 | ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current |
| 76471 | ** size of the op array or add 1KB of space, whichever is smaller. */ |
| 76472 | #ifdef SQLITE_TEST_REALLOC_STRESS |
| 76473 | sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc |
| 76474 | : (sqlite3_int64)v->nOpAlloc+nOp); |
| 76475 | #else |
| 76476 | sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc |
| 76477 | : (sqlite3_int64)(1024/sizeof(Op))); |
| 76478 | UNUSED_PARAMETER(nOp); |
| 76479 | #endif |
| 76480 | |
| 76481 | /* Ensure that the size of a VDBE does not grow too large */ |
| 76482 | if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ |
| @@ -77259,11 +77260,11 @@ | |
| 77260 | int addrLoop, /* Address of loop counter */ |
| 77261 | int addrVisit, /* Address of rows visited counter */ |
| 77262 | LogEst nEst, /* Estimated number of output rows */ |
| 77263 | const char *zName /* Name of table or index being scanned */ |
| 77264 | ){ |
| 77265 | sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus); |
| 77266 | ScanStatus *aNew; |
| 77267 | aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 77268 | if( aNew ){ |
| 77269 | ScanStatus *pNew = &aNew[p->nScan++]; |
| 77270 | pNew->addrExplain = addrExplain; |
| @@ -78380,13 +78381,13 @@ | |
| 78381 | /* An instance of this object describes bulk memory available for use |
| 78382 | ** by subcomponents of a prepared statement. Space is allocated out |
| 78383 | ** of a ReusableSpace object by the allocSpace() routine below. |
| 78384 | */ |
| 78385 | struct ReusableSpace { |
| 78386 | u8 *pSpace; /* Available memory */ |
| 78387 | sqlite3_int64 nFree; /* Bytes of available memory */ |
| 78388 | sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */ |
| 78389 | }; |
| 78390 | |
| 78391 | /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf |
| 78392 | ** from the ReusableSpace object. Return a pointer to the allocated |
| 78393 | ** memory on success. If insufficient memory is available in the |
| @@ -78402,11 +78403,11 @@ | |
| 78403 | ** statement. |
| 78404 | */ |
| 78405 | static void *allocSpace( |
| 78406 | struct ReusableSpace *p, /* Bulk memory available for allocation */ |
| 78407 | void *pBuf, /* Pointer to a prior allocation */ |
| 78408 | sqlite3_int64 nByte /* Bytes of memory needed */ |
| 78409 | ){ |
| 78410 | assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) ); |
| 78411 | if( pBuf==0 ){ |
| 78412 | nByte = ROUND8(nByte); |
| 78413 | if( nByte <= p->nFree ){ |
| @@ -81359,11 +81360,11 @@ | |
| 81360 | assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 ); |
| 81361 | assert( db->init.busy==0 ); |
| 81362 | assert( p->zSql!=0 ); |
| 81363 | sqlite3OsCurrentTimeInt64(db->pVfs, &iNow); |
| 81364 | iElapse = (iNow - p->startTime)*1000000; |
| 81365 | #ifndef SQLITE_OMIT_DEPRECATED |
| 81366 | if( db->xProfile ){ |
| 81367 | db->xProfile(db->pProfileArg, p->zSql, iElapse); |
| 81368 | } |
| 81369 | #endif |
| 81370 | if( db->mTrace & SQLITE_TRACE_PROFILE ){ |
| @@ -92255,11 +92256,11 @@ | |
| 92256 | int nRem; /* Bytes remaining to copy */ |
| 92257 | |
| 92258 | /* Extend the p->aAlloc[] allocation if required. */ |
| 92259 | if( p->nAlloc<nByte ){ |
| 92260 | u8 *aNew; |
| 92261 | sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc); |
| 92262 | while( nByte>nNew ) nNew = nNew*2; |
| 92263 | aNew = sqlite3Realloc(p->aAlloc, nNew); |
| 92264 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 92265 | p->nAlloc = nNew; |
| 92266 | p->aAlloc = aNew; |
| @@ -93546,19 +93547,23 @@ | |
| 93547 | if( pSorter->list.aMemory ){ |
| 93548 | int nMin = pSorter->iMemory + nReq; |
| 93549 | |
| 93550 | if( nMin>pSorter->nMemory ){ |
| 93551 | u8 *aNew; |
| 93552 | sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory; |
| 93553 | int iListOff = -1; |
| 93554 | if( pSorter->list.pList ){ |
| 93555 | iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory; |
| 93556 | } |
| 93557 | while( nNew < nMin ) nNew = nNew*2; |
| 93558 | if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize; |
| 93559 | if( nNew < nMin ) nNew = nMin; |
| 93560 | aNew = sqlite3Realloc(pSorter->list.aMemory, nNew); |
| 93561 | if( !aNew ) return SQLITE_NOMEM_BKPT; |
| 93562 | if( iListOff>=0 ){ |
| 93563 | pSorter->list.pList = (SorterRecord*)&aNew[iListOff]; |
| 93564 | } |
| 93565 | pSorter->list.aMemory = aNew; |
| 93566 | pSorter->nMemory = nNew; |
| 93567 | } |
| 93568 | |
| 93569 | pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory]; |
| @@ -98204,11 +98209,11 @@ | |
| 98209 | */ |
| 98210 | #ifndef SQLITE_OMIT_CTE |
| 98211 | static With *withDup(sqlite3 *db, With *p){ |
| 98212 | With *pRet = 0; |
| 98213 | if( p ){ |
| 98214 | sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1); |
| 98215 | pRet = sqlite3DbMallocZero(db, nByte); |
| 98216 | if( pRet ){ |
| 98217 | int i; |
| 98218 | pRet->nCte = p->nCte; |
| 98219 | for(i=0; i<p->nCte; i++){ |
| @@ -98469,11 +98474,11 @@ | |
| 98474 | } |
| 98475 | pList->nExpr = 0; |
| 98476 | }else if( (pList->nExpr & (pList->nExpr-1))==0 ){ |
| 98477 | ExprList *pNew; |
| 98478 | pNew = sqlite3DbRealloc(db, pList, |
| 98479 | sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0])); |
| 98480 | if( pNew==0 ){ |
| 98481 | goto no_mem; |
| 98482 | } |
| 98483 | pList = pNew; |
| 98484 | } |
| @@ -106165,11 +106170,11 @@ | |
| 106170 | } |
| 106171 | sqlite3BtreeLeaveAll(db); |
| 106172 | assert( zErrDyn==0 || rc!=SQLITE_OK ); |
| 106173 | } |
| 106174 | #ifdef SQLITE_USER_AUTHENTICATION |
| 106175 | if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){ |
| 106176 | u8 newAuth = 0; |
| 106177 | rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| 106178 | if( newAuth<db->auth.authLevel ){ |
| 106179 | rc = SQLITE_AUTH_USER; |
| 106180 | } |
| @@ -110602,23 +110607,22 @@ | |
| 110607 | int szEntry, /* Size of each object in the array */ |
| 110608 | int *pnEntry, /* Number of objects currently in use */ |
| 110609 | int *pIdx /* Write the index of a new slot here */ |
| 110610 | ){ |
| 110611 | char *z; |
| 110612 | sqlite3_int64 n = *pIdx = *pnEntry; |
| 110613 | if( (n & (n-1))==0 ){ |
| 110614 | sqlite3_int64 sz = (n==0) ? 1 : 2*n; |
| 110615 | void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry); |
| 110616 | if( pNew==0 ){ |
| 110617 | *pIdx = -1; |
| 110618 | return pArray; |
| 110619 | } |
| 110620 | pArray = pNew; |
| 110621 | } |
| 110622 | z = (char*)pArray; |
| 110623 | memset(&z[n * szEntry], 0, szEntry); |
| 110624 | ++*pnEntry; |
| 110625 | return pArray; |
| 110626 | } |
| 110627 | |
| 110628 | /* |
| @@ -110725,11 +110729,11 @@ | |
| 110729 | assert( iStart<=pSrc->nSrc ); |
| 110730 | |
| 110731 | /* Allocate additional space if needed */ |
| 110732 | if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){ |
| 110733 | SrcList *pNew; |
| 110734 | sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra; |
| 110735 | sqlite3 *db = pParse->db; |
| 110736 | |
| 110737 | if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){ |
| 110738 | sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d", |
| 110739 | SQLITE_MAX_SRCLIST); |
| @@ -111482,11 +111486,11 @@ | |
| 111486 | } |
| 111487 | } |
| 111488 | } |
| 111489 | |
| 111490 | if( pWith ){ |
| 111491 | sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte); |
| 111492 | pNew = sqlite3DbRealloc(db, pWith, nByte); |
| 111493 | }else{ |
| 111494 | pNew = sqlite3DbMallocZero(db, sizeof(*pWith)); |
| 111495 | } |
| 111496 | assert( (pNew!=0 && zName!=0) || db->mallocFailed ); |
| @@ -134593,13 +134597,17 @@ | |
| 134597 | ** Add a new module argument to pTable->azModuleArg[]. |
| 134598 | ** The string is not copied - the pointer is stored. The |
| 134599 | ** string will be freed automatically when the table is |
| 134600 | ** deleted. |
| 134601 | */ |
| 134602 | static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ |
| 134603 | sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg); |
| 134604 | char **azModuleArg; |
| 134605 | sqlite3 *db = pParse->db; |
| 134606 | if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 134607 | sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); |
| 134608 | } |
| 134609 | azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes); |
| 134610 | if( azModuleArg==0 ){ |
| 134611 | sqlite3DbFree(db, zArg); |
| 134612 | }else{ |
| 134613 | int i = pTable->nModuleArg++; |
| @@ -134630,13 +134638,13 @@ | |
| 134638 | assert( 0==pTable->pIndex ); |
| 134639 | |
| 134640 | db = pParse->db; |
| 134641 | |
| 134642 | assert( pTable->nModuleArg==0 ); |
| 134643 | addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 134644 | addModuleArgument(pParse, pTable, 0); |
| 134645 | addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| 134646 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 134647 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| 134648 | ); |
| 134649 | pParse->sNameToken.n = (int)( |
| 134650 | &pModuleName->z[pModuleName->n] - pParse->sNameToken.z |
| @@ -134665,11 +134673,11 @@ | |
| 134673 | static void addArgumentToVtab(Parse *pParse){ |
| 134674 | if( pParse->sArg.z && pParse->pNewTable ){ |
| 134675 | const char *z = (const char*)pParse->sArg.z; |
| 134676 | int n = pParse->sArg.n; |
| 134677 | sqlite3 *db = pParse->db; |
| 134678 | addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n)); |
| 134679 | } |
| 134680 | } |
| 134681 | |
| 134682 | /* |
| 134683 | ** The parser calls this routine after the CREATE VIRTUAL TABLE statement |
| @@ -134954,11 +134962,12 @@ | |
| 134962 | const int ARRAY_INCR = 5; |
| 134963 | |
| 134964 | /* Grow the sqlite3.aVTrans array if required */ |
| 134965 | if( (db->nVTrans%ARRAY_INCR)==0 ){ |
| 134966 | VTable **aVTrans; |
| 134967 | sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)* |
| 134968 | ((sqlite3_int64)db->nVTrans + ARRAY_INCR); |
| 134969 | aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes); |
| 134970 | if( !aVTrans ){ |
| 134971 | return SQLITE_NOMEM_BKPT; |
| 134972 | } |
| 134973 | memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR); |
| @@ -135450,13 +135459,13 @@ | |
| 135459 | pMod->pEpoTab = pTab; |
| 135460 | pTab->nTabRef = 1; |
| 135461 | pTab->pSchema = db->aDb[0].pSchema; |
| 135462 | assert( pTab->nModuleArg==0 ); |
| 135463 | pTab->iPKey = -1; |
| 135464 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 135465 | addModuleArgument(pParse, pTab, 0); |
| 135466 | addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 135467 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| 135468 | if( rc ){ |
| 135469 | sqlite3ErrorMsg(pParse, "%s", zErr); |
| 135470 | sqlite3DbFree(db, zErr); |
| 135471 | sqlite3VtabEponymousTableClear(db, pMod); |
| @@ -155309,11 +155318,11 @@ | |
| 155318 | if( sz==0 || cnt==0 ){ |
| 155319 | sz = 0; |
| 155320 | pStart = 0; |
| 155321 | }else if( pBuf==0 ){ |
| 155322 | sqlite3BeginBenignMalloc(); |
| 155323 | pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */ |
| 155324 | sqlite3EndBenignMalloc(); |
| 155325 | if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; |
| 155326 | }else{ |
| 155327 | pStart = pBuf; |
| 155328 | } |
| @@ -169347,12 +169356,12 @@ | |
| 169356 | }else{ |
| 169357 | char const **aArg = 0; |
| 169358 | int iArg = 0; |
| 169359 | z = &z[n+1]; |
| 169360 | while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){ |
| 169361 | sqlite3_int64 nNew = sizeof(char *)*(iArg+1); |
| 169362 | char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew); |
| 169363 | if( !aNew ){ |
| 169364 | sqlite3_free(zCopy); |
| 169365 | sqlite3_free((void *)aArg); |
| 169366 | return SQLITE_NOMEM; |
| 169367 | } |
| @@ -170255,11 +170264,11 @@ | |
| 170264 | |
| 170265 | fts3tokResetCursor(pCsr); |
| 170266 | if( idxNum==1 ){ |
| 170267 | const char *zByte = (const char *)sqlite3_value_text(apVal[0]); |
| 170268 | int nByte = sqlite3_value_bytes(apVal[0]); |
| 170269 | pCsr->zInput = sqlite3_malloc64(nByte+1); |
| 170270 | if( pCsr->zInput==0 ){ |
| 170271 | rc = SQLITE_NOMEM; |
| 170272 | }else{ |
| 170273 | memcpy(pCsr->zInput, zByte, nByte); |
| 170274 | pCsr->zInput[nByte] = 0; |
| @@ -172119,12 +172128,13 @@ | |
| 172128 | nElem = 1; |
| 172129 | } |
| 172130 | } |
| 172131 | |
| 172132 | if( nElem>0 ){ |
| 172133 | sqlite3_int64 nByte; |
| 172134 | nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *); |
| 172135 | pReader = (Fts3SegReader *)sqlite3_malloc64(nByte); |
| 172136 | if( !pReader ){ |
| 172137 | rc = SQLITE_NOMEM; |
| 172138 | }else{ |
| 172139 | memset(pReader, 0, nByte); |
| 172140 | pReader->iIdx = 0x7FFFFFFF; |
| @@ -173734,11 +173744,11 @@ | |
| 173744 | int nBlob; /* Number of bytes in the BLOB */ |
| 173745 | sqlite3_stmt *pStmt; /* Statement used to insert the encoding */ |
| 173746 | int rc; /* Result code from subfunctions */ |
| 173747 | |
| 173748 | if( *pRC ) return; |
| 173749 | pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn ); |
| 173750 | if( pBlob==0 ){ |
| 173751 | *pRC = SQLITE_NOMEM; |
| 173752 | return; |
| 173753 | } |
| 173754 | fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob); |
| @@ -173784,11 +173794,11 @@ | |
| 173794 | int rc; /* Result code from subfunctions */ |
| 173795 | |
| 173796 | const int nStat = p->nColumn+2; |
| 173797 | |
| 173798 | if( *pRC ) return; |
| 173799 | a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat ); |
| 173800 | if( a==0 ){ |
| 173801 | *pRC = SQLITE_NOMEM; |
| 173802 | return; |
| 173803 | } |
| 173804 | pBlob = (char*)&a[nStat]; |
| @@ -173905,12 +173915,12 @@ | |
| 173915 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 173916 | sqlite3_free(zSql); |
| 173917 | } |
| 173918 | |
| 173919 | if( rc==SQLITE_OK ){ |
| 173920 | sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3; |
| 173921 | aSz = (u32 *)sqlite3_malloc64(nByte); |
| 173922 | if( aSz==0 ){ |
| 173923 | rc = SQLITE_NOMEM; |
| 173924 | }else{ |
| 173925 | memset(aSz, 0, nByte); |
| 173926 | aSzIns = &aSz[p->nColumn+1]; |
| @@ -173972,16 +173982,16 @@ | |
| 173982 | int nSeg, /* Number of segments to merge */ |
| 173983 | Fts3MultiSegReader *pCsr /* Cursor object to populate */ |
| 173984 | ){ |
| 173985 | int rc; /* Return Code */ |
| 173986 | sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */ |
| 173987 | sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */ |
| 173988 | |
| 173989 | /* Allocate space for the Fts3MultiSegReader.aCsr[] array */ |
| 173990 | memset(pCsr, 0, sizeof(*pCsr)); |
| 173991 | nByte = sizeof(Fts3SegReader *) * nSeg; |
| 173992 | pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte); |
| 173993 | |
| 173994 | if( pCsr->apSegment==0 ){ |
| 173995 | rc = SQLITE_NOMEM; |
| 173996 | }else{ |
| 173997 | memset(pCsr->apSegment, 0, nByte); |
| @@ -175957,11 +175967,11 @@ | |
| 175967 | rc = SQLITE_CONSTRAINT; |
| 175968 | goto update_out; |
| 175969 | } |
| 175970 | |
| 175971 | /* Allocate space to hold the change in document sizes */ |
| 175972 | aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2); |
| 175973 | if( aSzDel==0 ){ |
| 175974 | rc = SQLITE_NOMEM; |
| 175975 | goto update_out; |
| 175976 | } |
| 175977 | aSzIns = &aSzDel[p->nColumn+1]; |
| @@ -176211,21 +176221,23 @@ | |
| 176221 | */ |
| 176222 | |
| 176223 | /* |
| 176224 | ** Allocate a two-slot MatchinfoBuffer object. |
| 176225 | */ |
| 176226 | static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){ |
| 176227 | MatchinfoBuffer *pRet; |
| 176228 | sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) |
| 176229 | + sizeof(MatchinfoBuffer); |
| 176230 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 176231 | |
| 176232 | pRet = sqlite3_malloc64(nByte + nStr+1); |
| 176233 | if( pRet ){ |
| 176234 | memset(pRet, 0, nByte); |
| 176235 | pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; |
| 176236 | pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] |
| 176237 | + sizeof(u32)*((int)nElem+1); |
| 176238 | pRet->nElem = (int)nElem; |
| 176239 | pRet->zMatchinfo = ((char*)pRet) + nByte; |
| 176240 | memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1); |
| 176241 | pRet->aRef[0] = 1; |
| 176242 | } |
| 176243 | |
| @@ -177082,12 +177094,12 @@ | |
| 177094 | } |
| 177095 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 177096 | return SQLITE_ERROR; |
| 177097 | } |
| 177098 | |
| 177099 | static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 177100 | size_t nVal; /* Number of integers output by cArg */ |
| 177101 | |
| 177102 | switch( cArg ){ |
| 177103 | case FTS3_MATCHINFO_NDOC: |
| 177104 | case FTS3_MATCHINFO_NPHRASE: |
| 177105 | case FTS3_MATCHINFO_NCOL: |
| @@ -177367,11 +177379,11 @@ | |
| 177379 | } |
| 177380 | break; |
| 177381 | |
| 177382 | case FTS3_MATCHINFO_LHITS_BM: |
| 177383 | case FTS3_MATCHINFO_LHITS: { |
| 177384 | size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); |
| 177385 | memset(pInfo->aMatchinfo, 0, nZero); |
| 177386 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 177387 | break; |
| 177388 | } |
| 177389 | |
| @@ -177436,11 +177448,11 @@ | |
| 177448 | ** matchinfo function has been called for this query. In this case |
| 177449 | ** allocate the array used to accumulate the matchinfo data and |
| 177450 | ** initialize those elements that are constant for every row. |
| 177451 | */ |
| 177452 | if( pCsr->pMIBuffer==0 ){ |
| 177453 | size_t nMatchinfo = 0; /* Number of u32 elements in match-info */ |
| 177454 | int i; /* Used to iterate through zArg */ |
| 177455 | |
| 177456 | /* Determine the number of phrases in the query */ |
| 177457 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 177458 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -185697,11 +185709,11 @@ | |
| 185709 | && (s.z++, geopolySkipSpace(&s)==0) |
| 185710 | ){ |
| 185711 | GeoPoly *pOut; |
| 185712 | int x = 1; |
| 185713 | s.nVertex--; /* Remove the redundant vertex at the end */ |
| 185714 | pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) ); |
| 185715 | x = 1; |
| 185716 | if( pOut==0 ) goto parse_json_err; |
| 185717 | pOut->nVertex = s.nVertex; |
| 185718 | memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord)); |
| 185719 | pOut->hdr[0] = *(unsigned char*)&x; |
| @@ -186083,11 +186095,11 @@ | |
| 186095 | else if( r>mxY ) mxY = (float)r; |
| 186096 | } |
| 186097 | if( pRc ) *pRc = SQLITE_OK; |
| 186098 | if( aCoord==0 ){ |
| 186099 | geopolyBboxFill: |
| 186100 | pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4)); |
| 186101 | if( pOut==0 ){ |
| 186102 | sqlite3_free(p); |
| 186103 | if( context ) sqlite3_result_error_nomem(context); |
| 186104 | if( pRc ) *pRc = SQLITE_NOMEM; |
| 186105 | return 0; |
| @@ -186479,13 +186491,13 @@ | |
| 186491 | |
| 186492 | /* |
| 186493 | ** Determine the overlap between two polygons |
| 186494 | */ |
| 186495 | static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){ |
| 186496 | sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2; |
| 186497 | GeoOverlap *p; |
| 186498 | sqlite3_int64 nByte; |
| 186499 | GeoEvent *pThisEvent; |
| 186500 | double rX; |
| 186501 | int rc = 0; |
| 186502 | int needSort = 0; |
| 186503 | GeoSegment *pActive = 0; |
| @@ -186493,11 +186505,11 @@ | |
| 186505 | unsigned char aOverlap[4]; |
| 186506 | |
| 186507 | nByte = sizeof(GeoEvent)*nVertex*2 |
| 186508 | + sizeof(GeoSegment)*nVertex |
| 186509 | + sizeof(GeoOverlap); |
| 186510 | p = sqlite3_malloc64( nByte ); |
| 186511 | if( p==0 ) return -1; |
| 186512 | p->aEvent = (GeoEvent*)&p[1]; |
| 186513 | p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2]; |
| 186514 | p->nEvent = p->nSegment = 0; |
| 186515 | geopolyAddSegments(p, p1, 1); |
| @@ -186652,22 +186664,22 @@ | |
| 186664 | char **pzErr, /* OUT: Error message, if any */ |
| 186665 | int isCreate /* True for xCreate, false for xConnect */ |
| 186666 | ){ |
| 186667 | int rc = SQLITE_OK; |
| 186668 | Rtree *pRtree; |
| 186669 | sqlite3_int64 nDb; /* Length of string argv[1] */ |
| 186670 | sqlite3_int64 nName; /* Length of string argv[2] */ |
| 186671 | sqlite3_str *pSql; |
| 186672 | char *zSql; |
| 186673 | int ii; |
| 186674 | |
| 186675 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 186676 | |
| 186677 | /* Allocate the sqlite3_vtab structure */ |
| 186678 | nDb = strlen(argv[1]); |
| 186679 | nName = strlen(argv[2]); |
| 186680 | pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2); |
| 186681 | if( !pRtree ){ |
| 186682 | return SQLITE_NOMEM; |
| 186683 | } |
| 186684 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 186685 | pRtree->nBusy = 1; |
| @@ -189088,10 +189100,15 @@ | |
| 189100 | ** abIndexed: |
| 189101 | ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise, |
| 189102 | ** it points to an array of flags nTblCol elements in size. The flag is |
| 189103 | ** set for each column that is either a part of the PK or a part of an |
| 189104 | ** index. Or clear otherwise. |
| 189105 | ** |
| 189106 | ** If there are one or more partial indexes on the table, all fields of |
| 189107 | ** this array set set to 1. This is because in that case, the module has |
| 189108 | ** no way to tell which fields will be required to add and remove entries |
| 189109 | ** from the partial indexes. |
| 189110 | ** |
| 189111 | */ |
| 189112 | struct RbuObjIter { |
| 189113 | sqlite3_stmt *pTblIter; /* Iterate through tables */ |
| 189114 | sqlite3_stmt *pIdxIter; /* Index iterator */ |
| @@ -189883,11 +189900,11 @@ | |
| 189900 | ** error code in the rbu handle passed as the first argument. Or, if an |
| 189901 | ** error has already occurred when this function is called, return NULL |
| 189902 | ** immediately without attempting the allocation or modifying the stored |
| 189903 | ** error code. |
| 189904 | */ |
| 189905 | static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){ |
| 189906 | void *pRet = 0; |
| 189907 | if( p->rc==SQLITE_OK ){ |
| 189908 | assert( nByte>0 ); |
| 189909 | pRet = sqlite3_malloc64(nByte); |
| 189910 | if( pRet==0 ){ |
| @@ -189904,11 +189921,11 @@ | |
| 189921 | ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that |
| 189922 | ** there is room for at least nCol elements. If an OOM occurs, store an |
| 189923 | ** error code in the RBU handle passed as the first argument. |
| 189924 | */ |
| 189925 | static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){ |
| 189926 | sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol; |
| 189927 | char **azNew; |
| 189928 | |
| 189929 | azNew = (char**)rbuMalloc(p, nByte); |
| 189930 | if( azNew ){ |
| 189931 | pIter->azTblCol = azNew; |
| @@ -190098,12 +190115,16 @@ | |
| 190115 | } |
| 190116 | |
| 190117 | pIter->nIndex = 0; |
| 190118 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){ |
| 190119 | const char *zIdx = (const char*)sqlite3_column_text(pList, 1); |
| 190120 | int bPartial = sqlite3_column_int(pList, 4); |
| 190121 | sqlite3_stmt *pXInfo = 0; |
| 190122 | if( zIdx==0 ) break; |
| 190123 | if( bPartial ){ |
| 190124 | memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol); |
| 190125 | } |
| 190126 | p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg, |
| 190127 | sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx) |
| 190128 | ); |
| 190129 | while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){ |
| 190130 | int iCid = sqlite3_column_int(pXInfo, 1); |
| @@ -190544,11 +190565,11 @@ | |
| 190565 | ** when this function is called, NULL is returned immediately, without |
| 190566 | ** attempting the allocation or modifying the stored error code. |
| 190567 | */ |
| 190568 | static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){ |
| 190569 | char *zRet = 0; |
| 190570 | sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1; |
| 190571 | |
| 190572 | zRet = (char*)rbuMalloc(p, nByte); |
| 190573 | if( zRet ){ |
| 190574 | int i; |
| 190575 | for(i=0; i<nBind; i++){ |
| @@ -190805,10 +190826,66 @@ | |
| 190826 | |
| 190827 | if( rc!=SQLITE_OK ){ |
| 190828 | sqlite3_result_error_code(pCtx, rc); |
| 190829 | } |
| 190830 | } |
| 190831 | |
| 190832 | static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){ |
| 190833 | sqlite3_stmt *pStmt = 0; |
| 190834 | int rc = p->rc; |
| 190835 | char *zRet = 0; |
| 190836 | |
| 190837 | if( rc==SQLITE_OK ){ |
| 190838 | rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, |
| 190839 | "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?" |
| 190840 | ); |
| 190841 | } |
| 190842 | if( rc==SQLITE_OK ){ |
| 190843 | int rc2; |
| 190844 | rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC); |
| 190845 | if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 190846 | const char *zSql = (const char*)sqlite3_column_text(pStmt, 0); |
| 190847 | if( zSql ){ |
| 190848 | int nParen = 0; /* Number of open parenthesis */ |
| 190849 | int i; |
| 190850 | for(i=0; zSql[i]; i++){ |
| 190851 | char c = zSql[i]; |
| 190852 | if( c=='(' ){ |
| 190853 | nParen++; |
| 190854 | } |
| 190855 | else if( c==')' ){ |
| 190856 | nParen--; |
| 190857 | if( nParen==0 ){ |
| 190858 | i++; |
| 190859 | break; |
| 190860 | } |
| 190861 | }else if( c=='"' || c=='\'' || c=='`' ){ |
| 190862 | for(i++; 1; i++){ |
| 190863 | if( zSql[i]==c ){ |
| 190864 | if( zSql[i+1]!=c ) break; |
| 190865 | i++; |
| 190866 | } |
| 190867 | } |
| 190868 | }else if( c=='[' ){ |
| 190869 | for(i++; 1; i++){ |
| 190870 | if( zSql[i]==']' ) break; |
| 190871 | } |
| 190872 | } |
| 190873 | } |
| 190874 | if( zSql[i] ){ |
| 190875 | zRet = rbuStrndup(&zSql[i], &rc); |
| 190876 | } |
| 190877 | } |
| 190878 | } |
| 190879 | |
| 190880 | rc2 = sqlite3_finalize(pStmt); |
| 190881 | if( rc==SQLITE_OK ) rc = rc2; |
| 190882 | } |
| 190883 | |
| 190884 | p->rc = rc; |
| 190885 | return zRet; |
| 190886 | } |
| 190887 | |
| 190888 | /* |
| 190889 | ** Ensure that the SQLite statement handles required to update the |
| 190890 | ** target database object currently indicated by the iterator passed |
| 190891 | ** as the second argument are available. |
| @@ -190835,17 +190912,19 @@ | |
| 190912 | const char *zTbl = pIter->zTbl; |
| 190913 | char *zImposterCols = 0; /* Columns for imposter table */ |
| 190914 | char *zImposterPK = 0; /* Primary key declaration for imposter */ |
| 190915 | char *zWhere = 0; /* WHERE clause on PK columns */ |
| 190916 | char *zBind = 0; |
| 190917 | char *zPart = 0; |
| 190918 | int nBind = 0; |
| 190919 | |
| 190920 | assert( pIter->eType!=RBU_PK_VTAB ); |
| 190921 | zCollist = rbuObjIterGetIndexCols( |
| 190922 | p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind |
| 190923 | ); |
| 190924 | zBind = rbuObjIterGetBindlist(p, nBind); |
| 190925 | zPart = rbuObjIterGetIndexWhere(p, pIter); |
| 190926 | |
| 190927 | /* Create the imposter table used to write to this index. */ |
| 190928 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1); |
| 190929 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum); |
| 190930 | rbuMPrintfExec(p, p->dbMain, |
| @@ -190874,32 +190953,34 @@ | |
| 190953 | /* Create the SELECT statement to read keys in sorted order */ |
| 190954 | if( p->rc==SQLITE_OK ){ |
| 190955 | char *zSql; |
| 190956 | if( rbuIsVacuum(p) ){ |
| 190957 | zSql = sqlite3_mprintf( |
| 190958 | "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s", |
| 190959 | zCollist, |
| 190960 | pIter->zDataTbl, |
| 190961 | zPart, zCollist, zLimit |
| 190962 | ); |
| 190963 | }else |
| 190964 | |
| 190965 | if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 190966 | zSql = sqlite3_mprintf( |
| 190967 | "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s", |
| 190968 | zCollist, p->zStateDb, pIter->zDataTbl, |
| 190969 | zPart, zCollist, zLimit |
| 190970 | ); |
| 190971 | }else{ |
| 190972 | zSql = sqlite3_mprintf( |
| 190973 | "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s " |
| 190974 | "UNION ALL " |
| 190975 | "SELECT %s, rbu_control FROM '%q' " |
| 190976 | "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 " |
| 190977 | "ORDER BY %s%s", |
| 190978 | zCollist, p->zStateDb, pIter->zDataTbl, zPart, |
| 190979 | zCollist, pIter->zDataTbl, |
| 190980 | zPart, |
| 190981 | (zPart ? "AND" : "WHERE"), |
| 190982 | zCollist, zLimit |
| 190983 | ); |
| 190984 | } |
| 190985 | p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql); |
| 190986 | } |
| @@ -190906,10 +190987,11 @@ | |
| 190987 | |
| 190988 | sqlite3_free(zImposterCols); |
| 190989 | sqlite3_free(zImposterPK); |
| 190990 | sqlite3_free(zWhere); |
| 190991 | sqlite3_free(zBind); |
| 190992 | sqlite3_free(zPart); |
| 190993 | }else{ |
| 190994 | int bRbuRowid = (pIter->eType==RBU_PK_VTAB) |
| 190995 | ||(pIter->eType==RBU_PK_NONE) |
| 190996 | ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p)); |
| 190997 | const char *zTbl = pIter->zTbl; /* Table this step applies to */ |
| @@ -193339,11 +193421,11 @@ | |
| 193421 | ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space |
| 193422 | ** instead of a file on disk. */ |
| 193423 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 193424 | if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){ |
| 193425 | if( iRegion<=p->nShm ){ |
| 193426 | sqlite3_int64 nByte = (iRegion+1) * sizeof(char*); |
| 193427 | char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte); |
| 193428 | if( apNew==0 ){ |
| 193429 | rc = SQLITE_NOMEM; |
| 193430 | }else{ |
| 193431 | memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm)); |
| @@ -195850,11 +195932,11 @@ | |
| 195932 | */ |
| 195933 | static int sessionGrowHash(int bPatchset, SessionTable *pTab){ |
| 195934 | if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){ |
| 195935 | int i; |
| 195936 | SessionChange **apNew; |
| 195937 | sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128); |
| 195938 | |
| 195939 | apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew); |
| 195940 | if( apNew==0 ){ |
| 195941 | if( pTab->nChange==0 ){ |
| 195942 | return SQLITE_ERROR; |
| @@ -196777,11 +196859,11 @@ | |
| 196859 | ** If not, use sqlite3_realloc() to grow the buffer so that there is. |
| 196860 | ** |
| 196861 | ** If successful, return zero. Otherwise, if an OOM condition is encountered, |
| 196862 | ** set *pRc to SQLITE_NOMEM and return non-zero. |
| 196863 | */ |
| 196864 | static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){ |
| 196865 | if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){ |
| 196866 | u8 *aNew; |
| 196867 | i64 nNew = p->nAlloc ? p->nAlloc : 128; |
| 196868 | do { |
| 196869 | nNew = nNew*2; |
| @@ -197895,11 +197977,11 @@ | |
| 197977 | rc = SQLITE_CORRUPT_BKPT; |
| 197978 | } |
| 197979 | } |
| 197980 | |
| 197981 | if( rc==SQLITE_OK ){ |
| 197982 | size_t iPK = sizeof(sqlite3_value*)*p->nCol*2; |
| 197983 | memset(p->tblhdr.aBuf, 0, iPK); |
| 197984 | memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy); |
| 197985 | p->in.iNext += nCopy; |
| 197986 | } |
| 197987 | |
| @@ -199199,11 +199281,11 @@ | |
| 199281 | SessionBuffer cons = pApply->constraints; |
| 199282 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 199283 | |
| 199284 | rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0); |
| 199285 | if( rc==SQLITE_OK ){ |
| 199286 | size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 199287 | int rc2; |
| 199288 | pIter2->bPatchset = bPatchset; |
| 199289 | pIter2->zTab = (char*)zTab; |
| 199290 | pIter2->nCol = pApply->nCol; |
| 199291 | pIter2->abPK = pApply->abPK; |
| @@ -212488,11 +212570,11 @@ | |
| 212570 | pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl |
| 212571 | ); |
| 212572 | if( aDlidx==0 ){ |
| 212573 | p->rc = SQLITE_NOMEM; |
| 212574 | }else{ |
| 212575 | size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx); |
| 212576 | memset(&aDlidx[pWriter->nDlidx], 0, nByte); |
| 212577 | pWriter->aDlidx = aDlidx; |
| 212578 | pWriter->nDlidx = nLvl; |
| 212579 | } |
| 212580 | } |
| @@ -217839,18 +217921,18 @@ | |
| 217921 | ){ |
| 217922 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217923 | int rc = sqlite3_overload_function(pGlobal->db, zName, -1); |
| 217924 | if( rc==SQLITE_OK ){ |
| 217925 | Fts5Auxiliary *pAux; |
| 217926 | sqlite3_int64 nName; /* Size of zName in bytes, including \0 */ |
| 217927 | sqlite3_int64 nByte; /* Bytes of space to allocate */ |
| 217928 | |
| 217929 | nName = strlen(zName) + 1; |
| 217930 | nByte = sizeof(Fts5Auxiliary) + nName; |
| 217931 | pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte); |
| 217932 | if( pAux ){ |
| 217933 | memset(pAux, 0, (size_t)nByte); |
| 217934 | pAux->zFunc = (char*)&pAux[1]; |
| 217935 | memcpy(pAux->zFunc, zName, nName); |
| 217936 | pAux->pGlobal = pGlobal; |
| 217937 | pAux->pUserData = pUserData; |
| 217938 | pAux->xFunc = xFunc; |
| @@ -217876,19 +217958,19 @@ | |
| 217958 | fts5_tokenizer *pTokenizer, /* Tokenizer implementation */ |
| 217959 | void(*xDestroy)(void*) /* Destructor for pUserData */ |
| 217960 | ){ |
| 217961 | Fts5Global *pGlobal = (Fts5Global*)pApi; |
| 217962 | Fts5TokenizerModule *pNew; |
| 217963 | sqlite3_int64 nName; /* Size of zName and its \0 terminator */ |
| 217964 | sqlite3_int64 nByte; /* Bytes of space to allocate */ |
| 217965 | int rc = SQLITE_OK; |
| 217966 | |
| 217967 | nName = strlen(zName) + 1; |
| 217968 | nByte = sizeof(Fts5TokenizerModule) + nName; |
| 217969 | pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte); |
| 217970 | if( pNew ){ |
| 217971 | memset(pNew, 0, (size_t)nByte); |
| 217972 | pNew->zName = (char*)&pNew[1]; |
| 217973 | memcpy(pNew->zName, zName, nName); |
| 217974 | pNew->pUserData = pUserData; |
| 217975 | pNew->x = *pTokenizer; |
| 217976 | pNew->xDestroy = xDestroy; |
| @@ -218019,11 +218101,11 @@ | |
| 218101 | int nArg, /* Number of args */ |
| 218102 | sqlite3_value **apUnused /* Function arguments */ |
| 218103 | ){ |
| 218104 | assert( nArg==0 ); |
| 218105 | UNUSED_PARAM2(nArg, apUnused); |
| 218106 | sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT); |
| 218107 | } |
| 218108 | |
| 218109 | /* |
| 218110 | ** Return true if zName is the extension on one of the shadow tables used |
| 218111 | ** by this module. |
| @@ -219664,11 +219746,11 @@ | |
| 219746 | int i; |
| 219747 | memset(p, 0, sizeof(Unicode61Tokenizer)); |
| 219748 | |
| 219749 | p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE; |
| 219750 | p->nFold = 64; |
| 219751 | p->aFold = sqlite3_malloc64(p->nFold * sizeof(char)); |
| 219752 | if( p->aFold==0 ){ |
| 219753 | rc = SQLITE_NOMEM; |
| 219754 | } |
| 219755 | |
| 219756 | /* Search for a "categories" argument */ |
| @@ -222783,12 +222865,12 @@ | |
| 222865 | } |
| 222866 | #endif /* SQLITE_CORE */ |
| 222867 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 222868 | |
| 222869 | /************** End of stmt.c ************************************************/ |
| 222870 | #if __LINE__!=222870 |
| 222871 | #undef SQLITE_SOURCE_ID |
| 222872 | #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2" |
| 222873 | #endif |
| 222874 | /* Return the source-id for this library */ |
| 222875 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 222876 | /************************** End of sqlite3.c ******************************/ |
| 222877 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -123,11 +123,11 @@ | ||
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | 126 | #define SQLITE_VERSION "3.28.0" |
| 127 | 127 | #define SQLITE_VERSION_NUMBER 3028000 |
| 128 | -#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f" | |
| 128 | +#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| 134 | 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.28.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3028000 |
| 128 | #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.28.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3028000 |
| 128 | #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| 134 |