这篇教程C++ sqlite3DbMallocRaw函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中sqlite3DbMallocRaw函数的典型用法代码示例。如果您正苦于以下问题:C++ sqlite3DbMallocRaw函数的具体用法?C++ sqlite3DbMallocRaw怎么用?C++ sqlite3DbMallocRaw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了sqlite3DbMallocRaw函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: assert/*** Resize the block of memory pointed to by p to n bytes. If the** resize fails, set the mallocFailed flag in the connection object.*/void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){ void *pNew = 0; assert( db!=0 ); assert( sqlite3_mutex_held(db->mutex) ); if( db->mallocFailed==0 ){ if( p==0 ){ return sqlite3DbMallocRaw(db, n); } if( isLookaside(db, p) ){ if( n<=db->lookaside.sz ){ return p; } pNew = sqlite3DbMallocRaw(db, n); if( pNew ){ memcpy(pNew, p, db->lookaside.sz); sqlite3DbFree(db, p); } }else{ pNew = sqlite3_realloc(p, n); if( !pNew ){ db->mallocFailed = 1; } } } return pNew;}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:30,
示例2: assert/*** Resize the block of memory pointed to by p to n bytes. If the** resize fails, set the mallocFailed flag in the connection object.*/void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ void *pNew = 0; assert( db!=0 ); assert( sqlite3_mutex_held(db->mutex) ); if( db->mallocFailed==0 ){ if( p==0 ){ return sqlite3DbMallocRaw(db, n); } if( isLookaside(db, p) ){ if( n<=db->lookaside.sz ){ return p; } pNew = sqlite3DbMallocRaw(db, n); if( pNew ){ memcpy(pNew, p, db->lookaside.sz); sqlite3DbFree(db, p); } }else{ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); sqlite3MemdebugSetType(p, MEMTYPE_HEAP); pNew = sqlite3_realloc64(p, n); if( !pNew ){ db->mallocFailed = 1; } sqlite3MemdebugSetType(pNew, (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); } } return pNew;}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:35,
示例3: vdbeSorterIterInit/*** Initialize iterator pIter to scan through the PMA stored in file pFile** starting at offset iStart and ending at offset iEof-1. This function ** leaves the iterator pointing to the first key in the PMA (or EOF if the ** PMA is empty).*/static int vdbeSorterIterInit( sqlite3 *db, /* Database handle */ const VdbeSorter *pSorter, /* Sorter object */ i64 iStart, /* Start offset in pFile */ VdbeSorterIter *pIter, /* Iterator to populate */ i64 *pnByte /* IN/OUT: Increment this value by PMA size */){ int rc = SQLITE_OK; int nBuf; nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt); assert( pSorter->iWriteOff>iStart ); assert( pIter->aAlloc==0 ); assert( pIter->aBuffer==0 ); pIter->pFile = pSorter->pTemp1; pIter->iReadOff = iStart; pIter->nAlloc = 128; pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc); pIter->nBuffer = nBuf; pIter->aBuffer = (u8 *)sqlite3DbMallocRaw(db, nBuf); if( !pIter->aBuffer ){ rc = SQLITE_NOMEM; }else{ int iBuf; iBuf = iStart % nBuf; if( iBuf ){ int nRead = nBuf - iBuf; if( (iStart + nRead) > pSorter->iWriteOff ){ nRead = (int)(pSorter->iWriteOff - iStart); } rc = sqlite3OsRead( pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart ); assert( rc!=SQLITE_IOERR_SHORT_READ ); } if( rc==SQLITE_OK ){ u64 nByte; /* Size of PMA in bytes */ pIter->iEof = pSorter->iWriteOff; rc = vdbeSorterIterVarint(db, pIter, &nByte); pIter->iEof = pIter->iReadOff + nByte; *pnByte += nByte; } } if( rc==SQLITE_OK ){ rc = vdbeSorterIterNext(db, pIter); } return rc;}
开发者ID:jiankangshiye,项目名称:mysqlite,代码行数:59,
示例4: sqlite3VdbeMemNulTerminate/*** Make sure the given Mem is /u0000 terminated.*/int sqlite3VdbeMemNulTerminate(Mem *pMem){ assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & MEM_Str)==0 ){ return SQLITE_OK; /* Nothing to do */ } if( pMem->flags & (MEM_Static|MEM_Ephem) ){ return sqlite3VdbeMemMakeWriteable(pMem); }else{ char *z; sqlite3VdbeMemExpandBlob(pMem); z = sqlite3DbMallocRaw(pMem->db, pMem->n+2); if( !z ){ return SQLITE_NOMEM; } memcpy(z, pMem->z, pMem->n); z[pMem->n] = 0; z[pMem->n+1] = 0; if( pMem->xDel ){ pMem->xDel(pMem->z); }else{ sqlite3_free(pMem->z); } pMem->xDel = 0; pMem->z = z; pMem->flags |= MEM_Term; } return SQLITE_OK;}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:31,
示例5: sqlite3VdbeMemMakeWriteable/*** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes** of the Mem.z[] array can be modified.**** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.*/int sqlite3VdbeMemMakeWriteable(Mem *pMem){ int n; u8 *z; assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); expandBlob(pMem); if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){ return SQLITE_OK; } assert( (pMem->flags & MEM_Dyn)==0 ); assert( pMem->flags & (MEM_Str|MEM_Blob) ); if( (n = pMem->n)+2<sizeof(pMem->zShort) ){ z = (u8*)pMem->zShort; pMem->flags |= MEM_Short|MEM_Term; }else{ z = sqlite3DbMallocRaw(pMem->db, n+2 ); if( z==0 ){ return SQLITE_NOMEM; } pMem->flags |= MEM_Dyn|MEM_Term; pMem->xDel = 0; } memcpy(z, pMem->z, n ); z[n] = 0; z[n+1] = 0; pMem->z = (char*)z; pMem->flags &= ~(MEM_Ephem|MEM_Static); assert(0==(1&(int)pMem->z)); return SQLITE_OK;}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:35,
示例6: recordFunc/* ** The implementation of the sqlite_record() function. This function accepts ** a single argument of any type. The return value is a formatted database ** record (a blob) containing the argument value. ** ** This is used to convert the value stored in the 'sample' column of the ** sqlite_stat3 table to the record format SQLite uses internally. */static void recordFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ const int file_format = 1; int iSerial; /* Serial type */ int nSerial; /* Bytes of space for iSerial as varint */ int nVal; /* Bytes of space required for argv[0] */ int nRet; sqlite3 *db; u8 *aRet; UNUSED_PARAMETER( argc ); iSerial = sqlite3VdbeSerialType(argv[0], file_format); nSerial = sqlite3VarintLen(iSerial); nVal = sqlite3VdbeSerialTypeLen(iSerial); db = sqlite3_context_db_handle(context); nRet = 1 + nSerial + nVal; aRet = sqlite3DbMallocRaw(db, nRet); if( aRet==0 ){ sqlite3_result_error_nomem(context); }else{ aRet[0] = nSerial+1; sqlite3PutVarint(&aRet[1], iSerial); sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format); sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); sqlite3DbFree(db, aRet); }}
开发者ID:pchernev,项目名称:Objective-C-iOS-Categories,代码行数:39,
示例7: whereClauseInsert/*** Add a single new WhereTerm entry to the WhereClause object pWC.** The new WhereTerm object is constructed from Expr p and with wtFlags.** The index in pWC->a[] of the new WhereTerm is returned on success.** 0 is returned if the new WhereTerm could not be added due to a memory** allocation error. The memory allocation failure will be recorded in** the db->mallocFailed flag so that higher-level functions can detect it.**** This routine will increase the size of the pWC->a[] array as necessary.**** If the wtFlags argument includes TERM_DYNAMIC, then responsibility** for freeing the expression p is assumed by the WhereClause object pWC.** This is true even if this routine fails to allocate a new WhereTerm.**** WARNING: This routine might reallocate the space used to store** WhereTerms. All pointers to WhereTerms should be invalidated after** calling this routine. Such pointers may be reinitialized by referencing** the pWC->a[] array.*/static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){ WhereTerm *pTerm; int idx; testcase( wtFlags & TERM_VIRTUAL ); if( pWC->nTerm>=pWC->nSlot ){ WhereTerm *pOld = pWC->a; sqlite3 *db = pWC->pWInfo->pParse->db; pWC->a = sqlite3DbMallocRaw(db, sizeof(pWC->a[0])*pWC->nSlot*2 ); if( pWC->a==0 ){ if( wtFlags & TERM_DYNAMIC ){ sqlite3ExprDelete(db, p); } pWC->a = pOld; return 0; } memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); if( pOld!=pWC->aStatic ){ sqlite3DbFree(db, pOld); } pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm)); } pTerm = &pWC->a[idx = pWC->nTerm++]; if( p && ExprHasProperty(p, EP_Unlikely) ){ pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; }else{ pTerm->truthProb = 1; } pTerm->pExpr = sqlite3ExprSkipCollate(p); pTerm->wtFlags = wtFlags; pTerm->pWC = pWC; pTerm->iParent = -1; return idx;}
开发者ID:yaoweidong,项目名称:sqlite,代码行数:53,
示例8: createModulestatic int createModule( sqlite3 *db, /* Database in which module is registered */ const char *zName, /* Name assigned to this module */ const sqlite3_module *pModule, /* The definition of the module */ void *pAux, /* Context pointer for xCreate/xConnect */ void (*xDestroy)(void *) /* Module destructor function */) { int rc, nName; Module *pMod; sqlite3_mutex_enter(db->mutex); nName = strlen(zName); pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); if( pMod ){ char *zCopy = (char *)(&pMod[1]); memcpy(zCopy, zName, nName+1); pMod->zName = zCopy; pMod->pModule = pModule; pMod->pAux = pAux; pMod->xDestroy = xDestroy; pMod = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); if( pMod && pMod->xDestroy ){ pMod->xDestroy(pMod->pAux); } sqlite3_free(pMod); sqlite3ResetInternalSchema(db, 0); } rc = sqlite3ApiExit(db, SQLITE_OK); sqlite3_mutex_leave(db->mutex); return rc;}
开发者ID:berte,项目名称:mediaplayer,代码行数:31,
示例9: sqlite3VdbeMemGrow/*** Make sure pMem->z points to a writable allocation of at least ** n bytes.**** If the memory cell currently contains string or blob data** and the third argument passed to this function is true, the ** current content of the cell is preserved. Otherwise, it may** be discarded. **** This function sets the MEM_Dyn flag and clears any xDel callback.** It also clears MEM_Ephem and MEM_Static. If the preserve flag is ** not set, Mem.n is zeroed.*/int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ assert( 1 >= ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + ((pMem->flags&MEM_Ephem) ? 1 : 0) + ((pMem->flags&MEM_Static) ? 1 : 0) ); if( n<32 ) n = 32; if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ if( preserve && pMem->z==pMem->zMalloc ){ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); preserve = 0; }else{ sqlite3DbFree(pMem->db, pMem->zMalloc); pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); } } if( preserve && pMem->z && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ memcpy(pMem->zMalloc, pMem->z, pMem->n); } if( pMem->flags&MEM_Dyn && pMem->xDel ){ pMem->xDel((void *)(pMem->z)); } pMem->z = pMem->zMalloc; if( pMem->z==0 ){ pMem->flags = MEM_Null; }else{ pMem->flags &= ~(MEM_Ephem|MEM_Static); } pMem->xDel = 0; return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:48,
示例10: sqlite3RowSetInsert/*** Insert a new value into a RowSet.**** The mallocFailed flag of the database connection is set if a** memory allocation fails.*/void sqlite3RowSetInsert(RowSet *p, i64 rowid){ struct RowSetEntry *pEntry; struct RowSetEntry *pLast; if( p==0 ) return; /* Must have been a malloc failure */ if( p->nFresh==0 ){ struct RowSetChunk *pNew; pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew)); if( pNew==0 ){ return; } pNew->pNext = p->pChunk; p->pChunk = pNew; p->pFresh = pNew->aEntry; p->nFresh = ROWSET_ENTRY_PER_CHUNK; } pEntry = p->pFresh++; p->nFresh--; pEntry->v = rowid; pEntry->pNext = 0; pLast = p->pLast; if( pLast ){ if( p->isSorted && rowid<=pLast->v ){ p->isSorted = 0; } pLast->pNext = pEntry; }else{ assert( p->pEntry==0 ); p->pEntry = pEntry; } p->pLast = pEntry;}
开发者ID:erik-knudsen,项目名称:eCos-enhancements,代码行数:37,
示例11: vdbeSorterIterInit/*** Initialize iterator pIter to scan through the PMA stored in file pFile** starting at offset iStart and ending at offset iEof-1. This function ** leaves the iterator pointing to the first key in the PMA (or EOF if the ** PMA is empty).*/static int vdbeSorterIterInit( sqlite3 *db, /* Database handle */ VdbeSorter *pSorter, /* Sorter object */ i64 iStart, /* Start offset in pFile */ VdbeSorterIter *pIter, /* Iterator to populate */ i64 *pnByte /* IN/OUT: Increment this value by PMA size */){ int rc; assert( pSorter->iWriteOff>iStart ); assert( pIter->aAlloc==0 ); pIter->pFile = pSorter->pTemp1; pIter->iReadOff = iStart; pIter->nAlloc = 128; pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc); if( !pIter->aAlloc ){ rc = SQLITE_NOMEM; }else{ i64 nByte; /* Total size of PMA in bytes */ rc = vdbeSorterReadVarint(pSorter->pTemp1, &pIter->iReadOff, &nByte); *pnByte += nByte; pIter->iEof = pIter->iReadOff + nByte; } if( rc==SQLITE_OK ){ rc = vdbeSorterIterNext(db, pIter); } return rc;}
开发者ID:77songsong,项目名称:sqlite3,代码行数:34,
示例12: testcase/*** Allocate and zero memory. If the allocation fails, make** the mallocFailed flag in the connection pointer.*/void *sqlite3DbMallocZero(sqlite3 *db, u64 n){ void *p; testcase( db==0 ); p = sqlite3DbMallocRaw(db, n); if( p ) memset(p, 0, (size_t)n); return p;}
开发者ID:ftes,项目名称:sqlite-simple-enclave,代码行数:11,
示例13: sqlite3DbMallocRaw/*** Allocate and zero memory. If the allocation fails, make** the mallocFailed flag in the connection pointer.*/void *sqlite3DbMallocZero(sqlite3 *db, int n){ void *p = sqlite3DbMallocRaw(db, n); if( p ){ memset(p, 0, n); } return p;}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:11,
示例14: sqlite3RowSetInsert/*** Insert a new value into a RowSet.**** The mallocFailed flag of the database connection is set if a** memory allocation fails.*/void sqlite3RowSetInsert(RowSet *p, i64 rowid){ struct RowSetEntry *pEntry; /* The new entry */ struct RowSetEntry *pLast; /* The last prior entry */ assert( p!=0 ); if( p->nFresh==0 ){ struct RowSetChunk *pNew; pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew)); if( pNew==0 ){ return; } pNew->pNextChunk = p->pChunk; p->pChunk = pNew; p->pFresh = pNew->aEntry; p->nFresh = ROWSET_ENTRY_PER_CHUNK; } pEntry = p->pFresh++; p->nFresh--; pEntry->v = rowid; pEntry->pRight = 0; pLast = p->pLast; if( pLast ){ if( p->isSorted && rowid<=pLast->v ){ p->isSorted = 0; } pLast->pRight = pEntry; }else{ assert( p->pEntry==0 ); /* Fires if INSERT after SMALLEST */ p->pEntry = pEntry; } p->pLast = pEntry;}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:37,
示例15: sqlite3DbMallocRaw/*** Allocate and zero memory. If the allocation fails, make** the mallocFailed flag in the connection pointer.*/void *sqlite3DbMallocZero(sqlite3 *db, u64 n){ void *p = sqlite3DbMallocRaw(db, n); if( p ){ memset(p, 0, (size_t)n); } return p;}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:11,
示例16: strlen/*** Make a copy of a string in memory obtained from sqliteMalloc(). These ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This** is because when memory debugging is turned on, these two functions are ** called via macros that record the current file and line number in the** ThreadData structure.*/char *sqlite3DbStrDup(sqlite3 *db, const char *z){ char *zNew; size_t n; if( z==0 ){ return 0; } n = strlen(z) + 1; zNew = sqlite3DbMallocRaw(db, n); if( zNew ){ memcpy(zNew, z, n); } return zNew;}
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:20,
示例17: sqlite3Strlen30/*** Make a copy of a string in memory obtained from sqliteMalloc(). These ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This** is because when memory debugging is turned on, these two functions are ** called via macros that record the current file and line number in the** ThreadData structure.*/char *sqlite3DbStrDup(sqlite3 *db, const char *z){ char *zNew; size_t n; if( z==0 ){ return 0; } n = sqlite3Strlen30(z) + 1; assert( (n&0x7fffffff)==n ); zNew = sqlite3DbMallocRaw(db, (int)n); if( zNew ){ memcpy(zNew, z, n); } return zNew;}
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:21,
示例18: sqlite3VdbeSorterWrite/*** Add a record to the sorter.*/SQLITE_PRIVATE int sqlite3VdbeSorterWrite( sqlite3 *db, /* Database handle */ const VdbeCursor *pCsr, /* Sorter cursor */ Mem *pVal /* Memory cell containing record */){ VdbeSorter *pSorter = pCsr->pSorter; int rc = SQLITE_OK; /* Return Code */ SorterRecord *pNew; /* New list element */ assert( pSorter ); pSorter->nInMemory += sqlite3VarintLen(pVal->n) + pVal->n; pNew = (SorterRecord *)sqlite3DbMallocRaw(db, pVal->n + sizeof(SorterRecord)); if( pNew==0 ){ rc = SQLITE_NOMEM; }else{ pNew->pVal = (void *)&pNew[1]; memcpy(pNew->pVal, pVal->z, pVal->n); pNew->nVal = pVal->n; pNew->pNext = pSorter->pRecord; pSorter->pRecord = pNew; } /* See if the contents of the sorter should now be written out. They ** are written out when either of the following are true: ** ** * The total memory allocated for the in-memory list is greater ** than (page-size * cache-size), or ** ** * The total memory allocated for the in-memory list is greater ** than (page-size * 10) and sqlite3HeapNearlyFull() returns true. */ if( rc==SQLITE_OK && pSorter->mxPmaSize>0 && ( (pSorter->nInMemory>pSorter->mxPmaSize) || (pSorter->nInMemory>pSorter->mnPmaSize && sqlite3HeapNearlyFull()) )){#ifdef SQLITE_DEBUG i64 nExpect = pSorter->iWriteOff + sqlite3VarintLen(pSorter->nInMemory) + pSorter->nInMemory;#endif rc = vdbeSorterListToPMA(db, pCsr); pSorter->nInMemory = 0; assert( rc!=SQLITE_OK || (nExpect==pSorter->iWriteOff) ); } return rc;}
开发者ID:jiankangshiye,项目名称:mysqlite,代码行数:51,
示例19: sqlite3VdbeMemSetRowSet/*** Delete any previous value and set the value of pMem to be an** empty boolean index.*/void sqlite3VdbeMemSetRowSet(Mem *pMem){ sqlite3 *db = pMem->db; assert( db!=0 ); assert( (pMem->flags & MEM_RowSet)==0 ); sqlite3VdbeMemRelease(pMem); pMem->zMalloc = sqlite3DbMallocRaw(db, 64); if( db->mallocFailed ){ pMem->flags = MEM_Null; }else{ assert( pMem->zMalloc ); pMem->u.pRowSet = sqlite3RowSetInit(db, pMem->zMalloc, sqlite3DbMallocSize(db, pMem->zMalloc)); assert( pMem->u.pRowSet!=0 ); pMem->flags = MEM_RowSet; }}
开发者ID:HappyDanger,项目名称:sqlcipher,代码行数:20,
示例20: assert/*** Allocate a new RowSetEntry object that is associated with the** given RowSet. Return a pointer to the new and completely uninitialized** objected.**** In an OOM situation, the RowSet.db->mallocFailed flag is set and this** routine returns NULL.*/static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){ assert( p!=0 ); if( p->nFresh==0 ){ struct RowSetChunk *pNew; pNew = sqlite3DbMallocRaw(p->db, sizeof(*pNew)); if( pNew==0 ){ return 0; } pNew->pNextChunk = p->pChunk; p->pChunk = pNew; p->pFresh = pNew->aEntry; p->nFresh = ROWSET_ENTRY_PER_CHUNK; } p->nFresh--; return p->pFresh++;}
开发者ID:520060628,项目名称:Sqlite3.07.14,代码行数:24,
示例21: fileWriterInit/*** Initialize a file-writer object.*/static void fileWriterInit( sqlite3 *db, /* Database (for malloc) */ sqlite3_file *pFile, /* File to write to */ FileWriter *p, /* Object to populate */ i64 iStart /* Offset of pFile to begin writing at */){ int nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt); memset(p, 0, sizeof(FileWriter)); p->aBuffer = (u8 *)sqlite3DbMallocRaw(db, nBuf); if( !p->aBuffer ){ p->eFWErr = SQLITE_NOMEM; }else{ p->iBufEnd = p->iBufStart = (iStart % nBuf); p->iWriteOff = iStart - p->iBufStart; p->nBuffer = nBuf; p->pFile = pFile; }}
开发者ID:jiankangshiye,项目名称:mysqlite,代码行数:22,
示例22: sqlite3VdbeMemGrow/*** Make sure pMem->z points to a writable allocation of at least ** n bytes.**** If the third argument passed to this function is true, then memory** cell pMem must contain a string or blob. In this case the content is** preserved. Otherwise, if the third parameter to this function is false,** any current string or blob value may be discarded.**** This function sets the MEM_Dyn flag and clears any xDel callback.** It also clears MEM_Ephem and MEM_Static. If the preserve flag is ** not set, Mem.n is zeroed.*/int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ assert( 1 >= ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + ((pMem->flags&MEM_Ephem) ? 1 : 0) + ((pMem->flags&MEM_Static) ? 1 : 0) ); assert( (pMem->flags&MEM_RowSet)==0 ); /* If the preserve flag is set to true, then the memory cell must already ** contain a valid string or blob value. */ assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); if( n<32 ) n = 32; if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ if( preserve && pMem->z==pMem->zMalloc ){ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); preserve = 0; }else{ sqlite3DbFree(pMem->db, pMem->zMalloc); pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); } } if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ memcpy(pMem->zMalloc, pMem->z, pMem->n); } if( pMem->flags&MEM_Dyn && pMem->xDel ){ assert( pMem->xDel!=SQLITE_DYNAMIC ); pMem->xDel((void *)(pMem->z)); } pMem->z = pMem->zMalloc; if( pMem->z==0 ){ pMem->flags = MEM_Null; }else{ pMem->flags &= ~(MEM_Ephem|MEM_Static); } pMem->xDel = 0; return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);}
开发者ID:HappyDanger,项目名称:sqlcipher,代码行数:54,
示例23: createModule/*** The actual function that does the work of creating a new module.** This function implements the sqlite3_create_module() and** sqlite3_create_module_v2() interfaces.*/static int createModule( sqlite3 *db, /* Database in which module is registered */ const char *zName, /* Name assigned to this module */ const sqlite3_module *pModule, /* The definition of the module */ void *pAux, /* Context pointer for xCreate/xConnect */ void (*xDestroy)(void *) /* Module destructor function */){ int rc = SQLITE_OK; int nName; sqlite3_mutex_enter(db->mutex); nName = sqlite3Strlen30(zName); if( sqlite3HashFind(&db->aModule, zName) ){ rc = SQLITE_MISUSE_BKPT; }else{ Module *pMod; pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); if( pMod ){ Module *pDel; char *zCopy = (char *)(&pMod[1]); memcpy(zCopy, zName, nName+1); pMod->zName = zCopy; pMod->pModule = pModule; pMod->pAux = pAux; pMod->xDestroy = xDestroy; pMod->pEpoTab = 0; pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod); assert( pDel==0 || pDel==pMod ); if( pDel ){ db->mallocFailed = 1; sqlite3DbFree(db, pDel); } } } rc = sqlite3ApiExit(db, rc); if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux); sqlite3_mutex_leave(db->mutex); return rc;}
开发者ID:ngdmcc,项目名称:sqlite,代码行数:45,
示例24: sqlite3VdbeMemExpandBlobint sqlite3VdbeMemExpandBlob(Mem *pMem){ if( pMem->flags & MEM_Zero ){ char *pNew; int nByte; assert( (pMem->flags & MEM_Blob)!=0 ); nByte = pMem->n + pMem->u.i; if( nByte<=0 ) nByte = 1; assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); pNew = sqlite3DbMallocRaw(pMem->db, nByte); if( pNew==0 ){ return SQLITE_NOMEM; } memcpy(pNew, pMem->z, pMem->n); memset(&pNew[pMem->n], 0, pMem->u.i); sqlite3VdbeMemRelease(pMem); pMem->z = pNew; pMem->n += pMem->u.i; pMem->u.i = 0; pMem->flags &= ~(MEM_Zero|MEM_Static|MEM_Ephem|MEM_Short|MEM_Term); pMem->flags |= MEM_Dyn; } return SQLITE_OK;}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:23,
示例25: sqlite3VdbeMemDynamicify/*** Make the given Mem object MEM_Dyn.**** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.*/int sqlite3VdbeMemDynamicify(Mem *pMem){ int n; u8 *z; assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); expandBlob(pMem); if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){ return SQLITE_OK; } assert( (pMem->flags & MEM_Dyn)==0 ); n = pMem->n; assert( pMem->flags & (MEM_Str|MEM_Blob) ); z = sqlite3DbMallocRaw(pMem->db, n+2 ); if( z==0 ){ return SQLITE_NOMEM; } pMem->flags |= MEM_Dyn|MEM_Term; pMem->xDel = 0; memcpy(z, pMem->z, n ); z[n] = 0; z[n+1] = 0; pMem->z = (char*)z; pMem->flags &= ~(MEM_Ephem|MEM_Static|MEM_Short); return SQLITE_OK;}
开发者ID:ChunHungLiu,项目名称:Reclass-2015,代码行数:29,
示例26: sqlite3DbMallocRaw/*** Create a new Upsert object.*/Upsert *sqlite3UpsertNew( sqlite3 *db, /* Determines which memory allocator to use */ ExprList *pTarget, /* Target argument to ON CONFLICT, or NULL */ Expr *pTargetWhere, /* Optional WHERE clause on the target */ ExprList *pSet, /* UPDATE columns, or NULL for a DO NOTHING */ Expr *pWhere /* WHERE clause for the ON CONFLICT UPDATE */){ Upsert *pNew; pNew = sqlite3DbMallocRaw(db, sizeof(Upsert)); if( pNew==0 ){ sqlite3ExprListDelete(db, pTarget); sqlite3ExprDelete(db, pTargetWhere); sqlite3ExprListDelete(db, pSet); sqlite3ExprDelete(db, pWhere); return 0; }else{ pNew->pUpsertTarget = pTarget; pNew->pUpsertTargetWhere = pTargetWhere; pNew->pUpsertSet = pSet; pNew->pUpsertWhere = pWhere; pNew->pUpsertIdx = 0; } return pNew;}
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:27,
示例27: sqlite3Update//.........这里部分代码省略.........# define tmask 0#endif#ifdef SQLITE_OMIT_VIEW# undef isView# define isView 0#endif if( sqlite3ViewGetColumnNames(pParse, pTab) ){ goto update_cleanup; } if( sqlite3IsReadOnly(pParse, pTab, tmask) ){ goto update_cleanup; } /* Allocate a cursors for the main database table and for all indices. ** The index cursors might not be used, but if they are used they ** need to occur right after the database cursor. So go ahead and ** allocate enough space, just in case. */ pTabList->a[0].iCursor = iBaseCur = iDataCur = pParse->nTab++; iIdxCur = iDataCur+1; pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ if( IsPrimaryKeyIndex(pIdx) && pPk!=0 ){ iDataCur = pParse->nTab; pTabList->a[0].iCursor = iDataCur; } pParse->nTab++; } /* Allocate space for aXRef[], aRegIdx[], and aToOpen[]. ** Initialize aXRef[] and aToOpen[] to their default values. */ aXRef = sqlite3DbMallocRaw(db, sizeof(int) * (pTab->nCol+nIdx) + nIdx+2 ); if( aXRef==0 ) goto update_cleanup; aRegIdx = aXRef+pTab->nCol; aToOpen = (u8*)(aRegIdx+nIdx); memset(aToOpen, 1, nIdx+1); aToOpen[nIdx+1] = 0; for(i=0; i<pTab->nCol; i++) aXRef[i] = -1; /* Initialize the name-context */ memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; sNC.pSrcList = pTabList; /* Resolve the column names in all the expressions of the ** of the UPDATE statement. Also find the column index ** for each column to be updated in the pChanges array. For each ** column to be updated, make sure we have authorization to change ** that column. */ chngRowid = chngPk = 0; for(i=0; i<pChanges->nExpr; i++){ if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ goto update_cleanup; } for(j=0; j<pTab->nCol; j++){ if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){ if( j==pTab->iPKey ){ chngRowid = 1; pRowidExpr = pChanges->a[i].pExpr; }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){ chngPk = 1; } aXRef[j] = i;
开发者ID:hoangdoanh,项目名称:sqlite,代码行数:67,
示例28: sqlite3VdbeMemTranslate/*** This routine transforms the internal text encoding used by pMem to** desiredEnc. It is an error if the string is already of the desired** encoding, or if *pMem does not contain a string value.*/int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ int len; /* Maximum length of output string in bytes */ unsigned char *zOut; /* Output buffer */ unsigned char *zIn; /* Input iterator */ unsigned char *zTerm; /* End of input */ unsigned char *z; /* Output iterator */ unsigned int c; assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( pMem->flags&MEM_Str ); assert( pMem->enc!=desiredEnc ); assert( pMem->enc!=0 ); assert( pMem->n>=0 );#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG) { char zBuf[100]; sqlite3VdbeMemPrettyPrint(pMem, zBuf); fprintf(stderr, "INPUT: %s/n", zBuf); }#endif /* If the translation is between UTF-16 little and big endian, then ** all that is required is to swap the byte order. This case is handled ** differently from the others. */ if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){ u8 temp; int rc; rc = sqlite3VdbeMemMakeWriteable(pMem); if( rc!=SQLITE_OK ){ assert( rc==SQLITE_NOMEM ); return SQLITE_NOMEM; } zIn = (u8*)pMem->z; zTerm = &zIn[pMem->n]; while( zIn<zTerm ){ temp = *zIn; *zIn = *(zIn+1); zIn++; *zIn++ = temp; } pMem->enc = desiredEnc; goto translate_out; } /* Set len to the maximum number of bytes required in the output buffer. */ if( desiredEnc==SQLITE_UTF8 ){ /* When converting from UTF-16, the maximum growth results from ** translating a 2-byte character to a 4-byte UTF-8 character. ** A single byte is required for the output string ** nul-terminator. */ len = pMem->n * 2 + 1; }else{ /* When converting from UTF-8 to UTF-16 the maximum growth is caused ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16 ** character. Two bytes are required in the output buffer for the ** nul-terminator. */ len = pMem->n * 2 + 2; } /* Set zIn to point at the start of the input buffer and zTerm to point 1 ** byte past the end. ** ** Variable zOut is set to point at the output buffer, space obtained ** from sqlite3_malloc(). */ zIn = (u8*)pMem->z; zTerm = &zIn[pMem->n]; zOut = sqlite3DbMallocRaw(pMem->db, len); if( !zOut ){ return SQLITE_NOMEM; } z = zOut; if( pMem->enc==SQLITE_UTF8 ){ if( desiredEnc==SQLITE_UTF16LE ){ /* UTF-8 -> UTF-16 Little-endian */ while( zIn<zTerm ){ /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */ READ_UTF8(zIn, zTerm, c); WRITE_UTF16LE(z, c); } }else{ assert( desiredEnc==SQLITE_UTF16BE ); /* UTF-8 -> UTF-16 Big-endian */ while( zIn<zTerm ){ /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */ READ_UTF8(zIn, zTerm, c); WRITE_UTF16BE(z, c); } } pMem->n = z - zOut;//.........这里部分代码省略.........
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:101,
示例29: attachFunc/*** An SQL user-function registered to do the work of an ATTACH statement. The** three arguments to the function come directly from an attach statement:**** ATTACH DATABASE x AS y KEY z**** SELECT sqlite_attach(x, y, z)**** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the** third argument.*/static void attachFunc( sqlite3_context *context, int NotUsed, sqlite3_value **argv){ int i; int rc = 0; sqlite3 *db = sqlite3_context_db_handle(context); const char *zName; const char *zFile; Db *aNew; char *zErrDyn = 0; UNUSED_PARAMETER(NotUsed); zFile = (const char *)sqlite3_value_text(argv[0]); zName = (const char *)sqlite3_value_text(argv[1]); if( zFile==0 ) zFile = ""; if( zName==0 ) zName = ""; /* Check for the following errors: ** ** * Too many attached databases, ** * Transaction currently open ** * Specified database name already being used. */ if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){ zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d", db->aLimit[SQLITE_LIMIT_ATTACHED] ); goto attach_error; } if( !db->autoCommit ){ zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction"); goto attach_error; } for(i=0; i<db->nDb; i++){ char *z = db->aDb[i].zName; assert( z && zName ); if( sqlite3StrICmp(z, zName)==0 ){ zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); goto attach_error; } } /* Allocate the new entry in the db->aDb[] array and initialise the schema ** hash tables. */ if( db->aDb==db->aDbStatic ){ aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 ); if( aNew==0 ) return; memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); }else{ aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); if( aNew==0 ) return; } db->aDb = aNew; aNew = &db->aDb[db->nDb]; memset(aNew, 0, sizeof(*aNew)); /* Open the database file. If the btree is successfully opened, use ** it to obtain the database schema. At this point the schema may ** or may not be initialised. */ rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE, db->openFlags | SQLITE_OPEN_MAIN_DB, &aNew->pBt); db->nDb++; if( rc==SQLITE_CONSTRAINT ){ rc = SQLITE_ERROR; zErrDyn = sqlite3MPrintf(db, "database is already attached"); }else if( rc==SQLITE_OK ){ Pager *pPager; aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt); if( !aNew->pSchema ){ rc = SQLITE_NOMEM; }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ zErrDyn = sqlite3MPrintf(db, "attached databases must use the same text encoding as main database"); rc = SQLITE_ERROR; } pPager = sqlite3BtreePager(aNew->pBt); sqlite3PagerLockingMode(pPager, db->dfltLockMode); sqlite3PagerJournalMode(pPager, db->dfltJournalMode); } aNew->zName = sqlite3DbStrDup(db, zName); aNew->safety_level = 3;#if SQLITE_HAS_CODEC//.........这里部分代码省略.........
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:101,
注:本文中的sqlite3DbMallocRaw函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ sqlite3DbMallocZero函数代码示例 C++ sqlite3DbFree函数代码示例 |