这篇教程C++ sqlite3BtreePager函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中sqlite3BtreePager函数的典型用法代码示例。如果您正苦于以下问题:C++ sqlite3BtreePager函数的具体用法?C++ sqlite3BtreePager怎么用?C++ sqlite3BtreePager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了sqlite3BtreePager函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3 *db, int nDb, const void *zKey, int nKey){ BOTANSQLITE_TRACE("sqlite3CodecAttach"); void *pCodec = NULL; if (!zKey || nKey <= 0) { Pager *pager = sqlite3BtreePager(db->aDb[nDb].pBt); // No key specified, could mean either use the main db's encryption or no encryption if (nDb != 0 && nKey < 0) { // Is an attached database, therefore use the key of main database, if main database is encrypted void *pMainCodec = sqlite3PagerGetCodec(sqlite3BtreePager(db->aDb[0].pBt)); if (pMainCodec) { pCodec = InitializeFromOtherCodec(pMainCodec, db); sqlite3PagerSetCodec( pager, Codec, CodecSizeChange, PagerFreeCodec, pCodec); } } else { // No encryption requested sqlite3PagerSetCodec(pager, NULL, NULL, NULL, NULL); } } else { // Key specified, setup encryption key for database pCodec = InitializeNewCodec(db); assert(nKey >= 0); SetWriteKey(pCodec, (const char*) zKey, (size_t) nKey); if (HandleError(pCodec)) { DeleteCodec(pCodec); return SQLITE_ERROR; } SetReadIsWrite(pCodec); sqlite3PagerSetCodec( sqlite3BtreePager(db->aDb[nDb].pBt), Codec, CodecSizeChange, PagerFreeCodec, pCodec); } if (HandleError(pCodec)) return SQLITE_ERROR; return SQLITE_OK;}
开发者ID:kullo,项目名称:smartsqlite,代码行数:57,
示例2: backupOnePage/*** Parameter zSrcData points to a buffer containing the data for ** page iSrcPg from the source database. Copy this data into the ** destination database.*/static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData){ Pager * const pDestPager = sqlite3BtreePager(p->pDest); const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); const int nCopy = MIN(nSrcPgsz, nDestPgsz); const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; int rc = SQLITE_OK; i64 iOff; assert( p->bDestLocked ); assert( !isFatalError(p->rc) ); assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ); assert( zSrcData ); /* Catch the case where the destination is an in-memory database and the ** page sizes of the source and destination differ. */ if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(sqlite3BtreePager(p->pDest)) ){ rc = SQLITE_READONLY; } /* This loop runs once for each destination page spanned by the source ** page. For each iteration, variable iOff is set to the byte offset ** of the destination page. */ for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){ DbPage *pDestPg = 0; Pgno iDest = (Pgno)(iOff/nDestPgsz)+1; if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue; if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg)) && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg)) ){ const u8 *zIn = &zSrcData[iOff%nSrcPgsz]; u8 *zDestData = sqlite3PagerGetData(pDestPg); u8 *zOut = &zDestData[iOff%nDestPgsz]; /* Copy the data from the source page into the destination page. ** Then clear the Btree layer MemPage.isInit flag. Both this module ** and the pager code use this trick (clearing the first byte ** of the page 'extra' space to invalidate the Btree layers ** cached parse of the page). MemPage.isInit is marked ** "MUST BE FIRST" for this purpose. */ memcpy(zOut, zIn, nCopy); ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0; } sqlite3PagerUnref(pDestPg); } return rc;}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:57,
示例3: sqlite3CodecAttach// Called by sqlite and sqlite3_key_interop to attach a key to a database.int sqlite3CodecAttach(sqlite3 *db, int nDb, const void *pKey, int nKeyLen){ int rc = SQLITE_ERROR; HCRYPTKEY hKey = 0; // No key specified, could mean either use the main db's encryption or no encryption if (!pKey || !nKeyLen) { if (!nDb) { return SQLITE_OK; // Main database, no key specified so not encrypted } else // Attached database, use the main database's key { // Get the encryption block for the main database and attempt to duplicate the key // for use by the attached database Pager *p = sqlite3BtreePager(db->aDb[0].pBt); LPCRYPTBLOCK pBlock = (LPCRYPTBLOCK)sqlite3pager_get_codecarg(p); if (!pBlock) return SQLITE_OK; // Main database is not encrypted so neither will be any attached database if (!pBlock->hReadKey) return SQLITE_OK; // Not encrypted if (!CryptDuplicateKey(pBlock->hReadKey, NULL, 0, &hKey)) return rc; // Unable to duplicate the key } } else // User-supplied passphrase, so create a cryptographic key out of it { hKey = DeriveKey(pKey, nKeyLen); if (hKey == MAXDWORD) { sqlite3Error(db, rc, SQLITECRYPTERROR_PROVIDER); return rc; } } // Create a new encryption block and assign the codec to the new attached database if (hKey) { Pager *p = sqlite3BtreePager(db->aDb[nDb].pBt); LPCRYPTBLOCK pBlock = CreateCryptBlock(hKey, p, -1, NULL); if (!pBlock) return SQLITE_NOMEM; sqlite3PagerSetCodec(p, sqlite3Codec, sqlite3CodecSizeChange, sqlite3CodecFree, pBlock); //db->aDb[nDb].pAux = pBlock; //db->aDb[nDb].xFreeAux = DestroyCryptBlock; rc = SQLITE_OK; } return rc;}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:52,
示例4: btree_ismemdb/*** Usage: btree_ismemdb ID**** Return true if the B-Tree is currently stored entirely in memory.*/static int btree_ismemdb( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; int res; sqlite3_file *pFile; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be /"", argv[0], " ID/"", 0); return TCL_ERROR; } pBt = sqlite3TestTextToPtr(argv[1]); sqlite3_mutex_enter(pBt->db->mutex); sqlite3BtreeEnter(pBt); pFile = sqlite3PagerFile(sqlite3BtreePager(pBt)); res = (pFile->pMethods==0); sqlite3BtreeLeave(pBt); sqlite3_mutex_leave(pBt->db->mutex); Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res)); return SQLITE_OK;}
开发者ID:AlvarHHM,项目名称:sqlite,代码行数:30,
示例5: sqlite3_file_control/*** Invoke the xFileControl method on a particular database.*/EXPORT_C int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){ int rc = SQLITE_ERROR; int iDb; sqlite3_mutex_enter(db->mutex); if( zDbName==0 ){ iDb = 0; }else{ for(iDb=0; iDb<db->nDb; iDb++){ if( strcmp(db->aDb[iDb].zName, zDbName)==0 ) break; } } if( iDb<db->nDb ){ Btree *pBtree = db->aDb[iDb].pBt; if( pBtree ){ Pager *pPager; sqlite3BtreeEnter(pBtree); pPager = sqlite3BtreePager(pBtree); if( pPager ){ sqlite3_file *fd = sqlite3PagerFile(pPager); if( fd ){ rc = sqlite3OsFileControl(fd, op, pArg); } } sqlite3BtreeLeave(pBtree); } } sqlite3_mutex_leave(db->mutex); return rc; }
开发者ID:guange2015,项目名称:sqlite-for-symbian,代码行数:32,
示例6: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) { struct Db *pDb = &db->aDb[nDb]; CODEC_TRACE(("sqlite3CodecAttach: entered nDb=%d zKey=%s, nKey=%d/n", nDb, zKey, nKey)); sqlcipher_activate(); if(nKey && zKey && pDb->pBt) { int rc; Pager *pPager = pDb->pBt->pBt->pPager; sqlite3_file *fd = sqlite3Pager_get_fd(pPager); codec_ctx *ctx; /* point the internal codec argument against the contet to be prepared */ rc = sqlcipher_codec_ctx_init(&ctx, pDb, pDb->pBt->pBt->pPager, fd, zKey, nKey); sqlite3pager_sqlite3PagerSetCodec(sqlite3BtreePager(pDb->pBt), sqlite3Codec, NULL, sqlite3FreeCodecArg, (void *) ctx); codec_set_btree_to_codec_pagesize(db, pDb, ctx); /* if fd is null, then this is an in-memory database and we dont' want to overwrite the AutoVacuum settings if not null, then set to the default */ sqlite3_mutex_enter(db->mutex); if(fd != NULL) { sqlite3BtreeSetAutoVacuum(pDb->pBt, SQLITE_DEFAULT_AUTOVACUUM); } sqlite3_mutex_leave(db->mutex); } return SQLITE_OK;}
开发者ID:git109,项目名称:sqlcipher,代码行数:31,
示例7: attachBackupObject/*** Register this backup object with the associated source pager for** callbacks when pages are changed or the cache invalidated.*/static void attachBackupObject(sqlite3_backup *p){ sqlite3_backup **pp; assert( sqlite3BtreeHoldsMutex(p->pSrc) ); pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc)); p->pNext = *pp; *pp = p; p->isAttached = 1;}
开发者ID:SCALE-GmbH,项目名称:sqlcipher,代码行数:12,
示例8: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3* db, int nDb, const void* zKey, int nKey){ /* Attach a key to a database. */ Codec* codec = (Codec*) sqlite3_malloc(sizeof(Codec)); CodecInit(codec); /* No key specified, could mean either use the main db's encryption or no encryption */ if (zKey == NULL || nKey <= 0) { /* No key specified */ if (nDb != 0 && nKey > 0) { Codec* mainCodec = (Codec*) mySqlite3PagerGetCodec(sqlite3BtreePager(db->aDb[0].pBt)); /* Attached database, therefore use the key of main database, if main database is encrypted */ if (mainCodec != NULL && CodecIsEncrypted(mainCodec)) { CodecCopy(codec, mainCodec); CodecSetBtree(codec, db->aDb[nDb].pBt);#if (SQLITE_VERSION_NUMBER >= 3006016) mySqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, sqlite3CodecSizeChange, sqlite3CodecFree, codec);#else#if (SQLITE_VERSION_NUMBER >= 3003014) sqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, codec);#else sqlite3pager_set_codec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, codec);#endif db->aDb[nDb].pAux = codec; db->aDb[nDb].xFreeAux = sqlite3CodecFree;#endif } else { CodecSetIsEncrypted(codec, 0); sqlite3_free(codec); } } } else { /* Key specified, setup encryption key for database */ CodecSetIsEncrypted(codec, 1); CodecSetHasReadKey(codec, 1); CodecSetHasWriteKey(codec, 1); CodecGenerateReadKey(codec, (char*) zKey, nKey); CodecCopyKey(codec, 1); CodecSetBtree(codec, db->aDb[nDb].pBt);#if (SQLITE_VERSION_NUMBER >= 3006016) mySqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, sqlite3CodecSizeChange, sqlite3CodecFree, codec);#else#if (SQLITE_VERSION_NUMBER >= 3003014) sqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, codec);#else sqlite3pager_set_codec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, codec);#endif db->aDb[nDb].pAux = codec; db->aDb[nDb].xFreeAux = sqlite3CodecFree;#endif } return SQLITE_OK;}
开发者ID:PanYuntao,项目名称:FreeSQLiteEncryption,代码行数:60,
示例9: sqlite3CodecGetKey// Once a password has been supplied and a key created, we don't keep the // original password for security purposes. Therefore return NULL.void sqlite3CodecGetKey(sqlite3 *db, int nDb, void **ppKey, int *pnKeyLen){ Btree *pbt = db->aDb[0].pBt; Pager *p = sqlite3BtreePager(pbt); LPCRYPTBLOCK pBlock = (LPCRYPTBLOCK)sqlite3pager_get_codecarg(p); if (ppKey) *ppKey = 0; if (pnKeyLen && pBlock) *pnKeyLen = 1;}
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:11,
示例10: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) { struct Db *pDb = &db->aDb[nDb]; if(nKey && zKey && pDb->pBt) { codec_ctx *ctx; Pager *pPager = pDb->pBt->pBt->pPager; int prepared_key_sz; ctx = sqlite3Malloc(sizeof(codec_ctx)); if(ctx == NULL) return SQLITE_NOMEM; memset(ctx, 0, sizeof(codec_ctx)); /* initialize all pointers and values to 0 */ ctx->pBt = pDb->pBt; /* assign pointer to database btree structure */ /* pre-allocate a page buffer of PageSize bytes. This will be used as a persistent buffer for encryption and decryption operations to avoid overhead of multiple memory allocations*/ ctx->buffer = sqlite3Malloc(sqlite3BtreeGetPageSize(ctx->pBt)); if(ctx->buffer == NULL) return SQLITE_NOMEM; ctx->key_sz = EVP_CIPHER_key_length(CIPHER); ctx->iv_sz = EVP_CIPHER_iv_length(CIPHER); /* allocate space for salt data */ ctx->salt = sqlite3Malloc(FILE_HEADER_SZ); if(ctx->salt == NULL) return SQLITE_NOMEM; /* allocate space for salt data */ ctx->key = sqlite3Malloc(ctx->key_sz); if(ctx->key == NULL) return SQLITE_NOMEM; /* allocate space for raw key data */ ctx->pass = sqlite3Malloc(nKey); if(ctx->pass == NULL) return SQLITE_NOMEM; memcpy(ctx->pass, zKey, nKey); ctx->pass_sz = nKey; /* read the first 16 bytes directly off the database file. This is the salt. */ sqlite3_file *fd = sqlite3Pager_get_fd(pPager); if(fd == NULL || sqlite3OsRead(fd, ctx->salt, 16, 0) != SQLITE_OK) { /* if unable to read the bytes, generate random salt */ RAND_pseudo_bytes(ctx->salt, FILE_HEADER_SZ); } codec_prepare_key(db, zKey, nKey, ctx->salt, FILE_HEADER_SZ, ctx->key, &prepared_key_sz); assert(prepared_key_sz == ctx->key_sz); sqlite3BtreeSetPageSize(ctx->pBt, sqlite3BtreeGetPageSize(ctx->pBt), ctx->iv_sz, 0); sqlite3PagerSetCodec(sqlite3BtreePager(pDb->pBt), sqlite3Codec, (void *) ctx); return SQLITE_OK; } return SQLITE_ERROR;}
开发者ID:qianwang,项目名称:sqlcipher,代码行数:53,
示例11: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3 *db, int nDb, const void *zKey, int nKey){ void *pCodec; if (zKey == NULL || nKey <= 0) { // No key specified, could mean either use the main db's encryption or no encryption if (nDb != 0 && nKey < 0) { //Is an attached database, therefore use the key of main database, if main database is encrypted void *pMainCodec = sqlite3PagerGetCodec(sqlite3BtreePager(db->aDb[0].pBt)); if (pMainCodec != NULL) { pCodec = InitializeFromOtherCodec(pMainCodec, db); sqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, sqlite3CodecSizeChange, sqlite3PagerFreeCodec, pCodec); } } } else { // Key specified, setup encryption key for database pCodec = InitializeNewCodec(db); GenerateWriteKey(pCodec, (const char*) zKey, nKey); SetReadIsWrite(pCodec); sqlite3PagerSetCodec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, sqlite3CodecSizeChange, sqlite3PagerFreeCodec, pCodec); } if (HandleError(pCodec)) return SQLITE_ERROR; return SQLITE_OK;}
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:38,
示例12: sqlite3CodecGetKeyvoid sqlite3CodecGetKey(sqlite3* db, int nDb, void** zKey, int* nKey){ /* // The unencrypted password is not stored for security reasons // therefore always return NULL // If the main database is encrypted a key length of 1 is returned. // In that case an attached database will get the same encryption key // as the main database if no key was explicitly given for the attached database. */ Codec* mainCodec = (Codec*) mySqlite3PagerGetCodec(sqlite3BtreePager(db->aDb[0].pBt)); int keylen = (mainCodec != NULL && CodecIsEncrypted(mainCodec)) ? 1 : 0; *zKey = NULL; *nKey = keylen;}
开发者ID:Konanan,项目名称:quicktest,代码行数:14,
示例13: doWalCallbacks/*** This function is called after a transaction has been committed. It ** invokes callbacks registered with sqlite3_wal_hook() as required.*/static int doWalCallbacks(sqlite3 *db){ int rc = SQLITE_OK;#ifndef SQLITE_OMIT_WAL int i; for(i=0; i<db->nDb; i++){ Btree *pBt = db->aDb[i].pBt; if( pBt ){ int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt)); if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){ rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry); } } }#endif return rc;}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:20,
示例14: GetPagerstatic int GetPager(sqlite3 *db, const char *zName, Pager **pPager, unsigned *pnPageSize){ Btree *pBt = NULL; int i; for( i=0; i<db->nDb; ++i ){ if( ascii_strcasecmp(db->aDb[i].zName, zName)==0 ){ pBt = db->aDb[i].pBt; break; } } if( !pBt ){ return SQLITE_ERROR; } *pPager = sqlite3BtreePager(pBt); *pnPageSize = sqlite3BtreeGetPageSize(pBt) - sqlite3BtreeGetReserve(pBt); return SQLITE_OK;}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:18,
示例15: btree_pager_stats/*** Usage: btree_pager_stats ID**** Returns pager statistics*/static int btree_pager_stats( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; int i; int *a; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be /"", argv[0], " ID/"", 0); return TCL_ERROR; } pBt = sqlite3TestTextToPtr(argv[1]); /* Normally in this file, with a b-tree handle opened using the ** [btree_open] command it is safe to call sqlite3BtreeEnter() directly. ** But this function is sometimes called with a btree handle obtained ** from an open SQLite connection (using [btree_from_db]). In this case ** we need to obtain the mutex for the controlling SQLite handle before ** it is safe to call sqlite3BtreeEnter(). */ sqlite3_mutex_enter(pBt->db->mutex); sqlite3BtreeEnter(pBt); a = sqlite3PagerStats(sqlite3BtreePager(pBt)); for(i=0; i<11; i++){ static char *zName[] = { "ref", "page", "max", "size", "state", "err", "hit", "miss", "ovfl", "read", "write" }; char zBuf[100]; Tcl_AppendElement(interp, zName[i]); sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",a[i]); Tcl_AppendElement(interp, zBuf); } sqlite3BtreeLeave(pBt); /* Release the mutex on the SQLite handle that controls this b-tree */ sqlite3_mutex_leave(pBt->db->mutex); return TCL_OK;}
开发者ID:AlexL871,项目名称:rt-thread-stm32f4discovery,代码行数:49,
示例16: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey) { struct Db *pDb = &db->aDb[nDb]; //RAWLOG_INFO("sqlite3CodecAttach"); if ( nKey && pKey && pDb->pBt ) { Pager *pPager = sqlite3BtreePager(pDb->pBt); sqlite3_file *fd; CRhoSqliteCodecCtx* pRhoCtx = sqlite3Malloc(sizeof(CRhoSqliteCodecCtx)); memset(pRhoCtx, 0, sizeof(CRhoSqliteCodecCtx)); pRhoCtx->m_szPartition = sqlite3Malloc(nKey); memcpy(pRhoCtx->m_szPartition, pKey, nKey); pRhoCtx->m_nPartLen = nKey; pRhoCtx->m_pPageBuffer = sqlite3Malloc(SQLITE_DEFAULT_PAGE_SIZE); sqlite3PagerSetCodec( pPager, sqlite3Codec, NULL, sqlite3FreeCodecArg, (void *)pRhoCtx ); fd = (isOpen(pPager->fd)) ? pPager->fd : NULL; sqlite3_mutex_enter(db->mutex); /* Always overwrite page size and set to the default because the first page of the database in encrypted and thus sqlite can't effectively determine the pagesize. this causes an issue in cases where bytes 16 & 17 of the page header are a power of 2 as reported by John Lehman Note: before forcing the page size we need to force pageSizeFixed to 0, else sqliteBtreeSetPageSize will block the change */ pDb->pBt->pBt->pageSizeFixed = 0; sqlite3BtreeSetPageSize( pDb->pBt, SQLITE_DEFAULT_PAGE_SIZE, EVP_MAX_IV_LENGTH, 0 ); /* if fd is null, then this is an in-memory database and we dont' want to overwrite the AutoVacuum settings if not null, then set to the default */ if ( fd != NULL ) sqlite3BtreeSetAutoVacuum(pDb->pBt, SQLITE_DEFAULT_AUTOVACUUM); sqlite3_mutex_leave(db->mutex); } return SQLITE_OK;}
开发者ID:4nkh,项目名称:rhodes,代码行数:44,
示例17: dbpageConnect/*** Connect to or create a dbpagevfs virtual table.*/static int dbpageConnect( sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVtab, char **pzErr){ DbpageTable *pTab = 0; int rc = SQLITE_OK; int iDb; if( argc>=4 ){ Token nm; sqlite3TokenInit(&nm, (char*)argv[3]); iDb = sqlite3FindDb(db, &nm); if( iDb<0 ){ *pzErr = sqlite3_mprintf("no such schema: %s", argv[3]); return SQLITE_ERROR; } }else{ iDb = 0; } rc = sqlite3_declare_vtab(db, "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)"); if( rc==SQLITE_OK ){ pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable)); if( pTab==0 ) rc = SQLITE_NOMEM_BKPT; } assert( rc==SQLITE_OK || pTab==0 ); if( rc==SQLITE_OK ){ Btree *pBt = db->aDb[iDb].pBt; memset(pTab, 0, sizeof(DbpageTable)); pTab->db = db; pTab->iDb = iDb; pTab->pPager = pBt ? sqlite3BtreePager(pBt) : 0; } *ppVtab = (sqlite3_vtab*)pTab; return rc;}
开发者ID:cznic,项目名称:cc,代码行数:44,
示例18: btree_pager_ref_dump/*** Usage: btree_pager_ref_dump ID**** Print out all outstanding pages.*/static int btree_pager_ref_dump( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */){ Btree *pBt; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be /"", argv[0], " ID/"", 0); return TCL_ERROR; } pBt = sqlite3TextToPtr(argv[1]);#ifdef SQLITE_TEST sqlite3BtreeEnter(pBt); sqlite3PagerRefdump(sqlite3BtreePager(pBt)); sqlite3BtreeLeave(pBt);#endif return TCL_OK;}
开发者ID:Jacob-jiangbo,项目名称:my-test,代码行数:26,
示例19: statSizeAndOffset/*** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on** the current value of pCsr->iPageno.*/static void statSizeAndOffset(StatCursor *pCsr){ StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab; Btree *pBt = pTab->db->aDb[pTab->iDb].pBt; Pager *pPager = sqlite3BtreePager(pBt); sqlite3_file *fd; sqlite3_int64 x[2]; /* The default page size and offset */ pCsr->szPage = sqlite3BtreeGetPageSize(pBt); pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); /* If connected to a ZIPVFS backend, override the page size and ** offset with actual values obtained from ZIPVFS. */ fd = sqlite3PagerFile(pPager); x[0] = pCsr->iPageno; if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){ pCsr->iOffset = x[0]; pCsr->szPage = (int)x[1]; }}
开发者ID:1018824313,项目名称:sqlite,代码行数:25,
示例20: sqlite3CodecGetKeyvoid sqlite3CodecGetKey(sqlite3* db, int nDb, void **zKey, int *nKey){ BOTANSQLITE_TRACE("sqlite3CodecGetKey"); Btree *pbt = db->aDb[nDb].pBt; Pager *pPager = sqlite3BtreePager(pbt); assert(pPager); void *pCodec = sqlite3PagerGetCodec(pPager); if (pCodec) { size_t nKeySize; GetWriteKey(pCodec, (char**)zKey, &nKeySize); *nKey = (int)nKeySize; } else { *zKey = NULL; *nKey = 0; }}
开发者ID:kullo,项目名称:smartsqlite,代码行数:21,
示例21: sqlite3CodecGetKeyvoid sqlite3CodecGetKey(sqlite3* db, int nDb, void **zKey, int *nKey) { struct Db *pDb = &db->aDb[nDb]; //RAWLOG_INFO("sqlite3CodecGetKey"); if( pDb->pBt ) { Pager *pPager = sqlite3BtreePager(pDb->pBt); CRhoSqliteCodecCtx *pRhoCtx = (CRhoSqliteCodecCtx *) sqlite3PagerGetCodec(pPager); if ( pRhoCtx ) { /* if the codec has an attached codec_context user the raw key data */ *zKey = pRhoCtx->m_szPartition; *nKey = pRhoCtx->m_nPartLen; } else { *zKey = NULL; *nKey = 0; } }}
开发者ID:4nkh,项目名称:rhodes,代码行数:21,
示例22: sqlite3CodecAttachint sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) { struct Db *pDb = &db->aDb[nDb]; CODEC_TRACE(("sqlite3CodecAttach: entered nDb=%d zKey=%s, nKey=%d/n", nDb, (char *)zKey, nKey)); if(nKey && zKey && pDb->pBt) { int rc; Pager *pPager = pDb->pBt->pBt->pPager; sqlite3_file *fd = sqlite3Pager_get_fd(pPager); codec_ctx *ctx; sqlcipher_activate(); /* perform internal initialization for sqlcipher */ sqlite3_mutex_enter(db->mutex); /* point the internal codec argument against the contet to be prepared */ rc = sqlcipher_codec_ctx_init(&ctx, pDb, pDb->pBt->pBt->pPager, fd, zKey, nKey); if(rc != SQLITE_OK) return rc; /* initialization failed, do not attach potentially corrupted context */ sqlite3pager_sqlite3PagerSetCodec(sqlite3BtreePager(pDb->pBt), sqlite3Codec, NULL, sqlite3FreeCodecArg, (void *) ctx); codec_set_btree_to_codec_pagesize(db, pDb, ctx); /* force secure delete. This has the benefit of wiping internal data when deleted and also ensures that all pages are written to disk (i.e. not skipped by sqlite3PagerDontWrite optimizations) */ sqlite3BtreeSecureDelete(pDb->pBt, 1); /* if fd is null, then this is an in-memory database and we dont' want to overwrite the AutoVacuum settings if not null, then set to the default */ if(fd != NULL) { sqlite3BtreeSetAutoVacuum(pDb->pBt, SQLITE_DEFAULT_AUTOVACUUM); } sqlite3_mutex_leave(db->mutex); } return SQLITE_OK;}
开发者ID:CoderXL,项目名称:sqlcipher,代码行数:40,
示例23: dbpageFilter/*** idxNum:**** 0 schema=main, full table scan** 1 schema=main, pgno=?1** 2 schema=?1, full table scan** 3 schema=?1, pgno=?2**** idxStr is not used*/static int dbpageFilter( sqlite3_vtab_cursor *pCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv){ DbpageCursor *pCsr = (DbpageCursor *)pCursor; DbpageTable *pTab = (DbpageTable *)pCursor->pVtab; int rc; sqlite3 *db = pTab->db; Btree *pBt; /* Default setting is no rows of result */ pCsr->pgno = 1; pCsr->mxPgno = 0; if( idxNum & 2 ){ const char *zSchema; assert( argc>=1 ); zSchema = (const char*)sqlite3_value_text(argv[0]); pCsr->iDb = sqlite3FindDbName(db, zSchema); if( pCsr->iDb<0 ) return SQLITE_OK; }else{ pCsr->iDb = 0; } pBt = db->aDb[pCsr->iDb].pBt; if( pBt==0 ) return SQLITE_OK; pCsr->pPager = sqlite3BtreePager(pBt); pCsr->szPage = sqlite3BtreeGetPageSize(pBt); pCsr->mxPgno = sqlite3BtreeLastPage(pBt); if( idxNum & 1 ){ assert( argc>(idxNum>>1) ); pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]); if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){ pCsr->pgno = 1; pCsr->mxPgno = 0; }else{ pCsr->mxPgno = pCsr->pgno; } }else{
开发者ID:HongliYu,项目名称:firefox-ios,代码行数:49,
示例24: sqlite3_rekey_v2int sqlite3_rekey_v2(sqlite3 *db, const char *zDbName, const void *zKey, int nKey){ /* Changes the encryption key for an existing database. */ int dbIndex = dbFindIndex(db, zDbName); int rc = SQLITE_ERROR; Btree* pbt = db->aDb[dbIndex].pBt; Pager* pPager = sqlite3BtreePager(pbt); Codec* codec = (Codec*) mySqlite3PagerGetCodec(pPager); if ((zKey == NULL || nKey == 0) && (codec == NULL || !CodecIsEncrypted(codec))) { /* // Database not encrypted and key not specified // therefore do nothing */ return SQLITE_OK; } if (codec == NULL || !CodecIsEncrypted(codec)) { /* // Database not encrypted, but key specified // therefore encrypt database */ if (codec == NULL) { codec = (Codec*) sqlite3_malloc(sizeof(Codec)); CodecInit(codec); } CodecSetIsEncrypted(codec, 1); CodecSetHasReadKey(codec, 0); /* Original database is not encrypted */ CodecSetHasWriteKey(codec, 1); CodecGenerateWriteKey(codec, (char*) zKey, nKey); CodecSetBtree(codec, pbt);#if (SQLITE_VERSION_NUMBER >= 3006016) mySqlite3PagerSetCodec(pPager, sqlite3Codec, sqlite3CodecSizeChange, sqlite3CodecFree, codec);#else#if (SQLITE_VERSION_NUMBER >= 3003014) sqlite3PagerSetCodec(pPager, sqlite3Codec, codec);#else sqlite3pager_set_codec(pPager, sqlite3Codec, codec);#endif db->aDb[dbIndex].pAux = codec; db->aDb[dbIndex].xFreeAux = sqlite3CodecFree;#endif } else if (zKey == NULL || nKey == 0) { /* // Database encrypted, but key not specified // therefore decrypt database // Keep read key, drop write key */ CodecSetHasWriteKey(codec, 0); } else { /* // Database encrypted and key specified // therefore re-encrypt database with new key // Keep read key, change write key to new key */ CodecGenerateWriteKey(codec, (char*) zKey, nKey); CodecSetHasWriteKey(codec, 1); } sqlite3_mutex_enter(db->mutex); /* Start transaction */ rc = sqlite3BtreeBeginTrans(pbt, 1); if (!rc) { int pageSize = sqlite3BtreeGetPageSize(pbt); Pgno nSkip = WX_PAGER_MJ_PGNO(pageSize);#if (SQLITE_VERSION_NUMBER >= 3003014) DbPage *pPage;#else void *pPage;#endif Pgno n; /* Rewrite all pages using the new encryption key (if specified) */#if (SQLITE_VERSION_NUMBER >= 3007001) Pgno nPage; int nPageCount = -1; sqlite3PagerPagecount(pPager, &nPageCount); nPage = nPageCount;#elif (SQLITE_VERSION_NUMBER >= 3006000) int nPageCount = -1; int rc = sqlite3PagerPagecount(pPager, &nPageCount); Pgno nPage = (Pgno) nPageCount;#elif (SQLITE_VERSION_NUMBER >= 3003014) Pgno nPage = sqlite3PagerPagecount(pPager);#else Pgno nPage = sqlite3pager_pagecount(pPager);#endif for (n = 1; rc == SQLITE_OK && n <= nPage; n++) { if (n == nSkip) continue;//.........这里部分代码省略.........
开发者ID:Konanan,项目名称:quicktest,代码行数:101,
示例25: statNext/*** Move a statvfs cursor to the next entry in the file.*/static int statNext(sqlite3_vtab_cursor *pCursor){ int rc; int nPayload; char *z; StatCursor *pCsr = (StatCursor *)pCursor; StatTable *pTab = (StatTable *)pCursor->pVtab; Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt; Pager *pPager = sqlite3BtreePager(pBt); sqlite3_free(pCsr->zPath); pCsr->zPath = 0;statNextRestart: if( pCsr->aPage[0].pPg==0 ){ rc = sqlite3_step(pCsr->pStmt); if( rc==SQLITE_ROW ){ int nPage; u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1); sqlite3PagerPagecount(pPager, &nPage); if( nPage==0 ){ pCsr->isEof = 1; return sqlite3_reset(pCsr->pStmt); } rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0); pCsr->aPage[0].iPgno = iRoot; pCsr->aPage[0].iCell = 0; pCsr->aPage[0].zPath = z = sqlite3_mprintf("/"); pCsr->iPage = 0; if( z==0 ) rc = SQLITE_NOMEM_BKPT; }else{ pCsr->isEof = 1; return sqlite3_reset(pCsr->pStmt); } }else{ /* Page p itself has already been visited. */ StatPage *p = &pCsr->aPage[pCsr->iPage]; while( p->iCell<p->nCell ){ StatCell *pCell = &p->aCell[p->iCell]; if( pCell->iOvfl<pCell->nOvfl ){ int nUsable; sqlite3BtreeEnter(pBt); nUsable = sqlite3BtreeGetPageSize(pBt) - sqlite3BtreeGetReserveNoMutex(pBt); sqlite3BtreeLeave(pBt); pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; pCsr->zPagetype = "overflow"; pCsr->nCell = 0; pCsr->nMxPayload = 0; pCsr->zPath = z = sqlite3_mprintf( "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl ); if( pCell->iOvfl<pCell->nOvfl-1 ){ pCsr->nUnused = 0; pCsr->nPayload = nUsable - 4; }else{ pCsr->nPayload = pCell->nLastOvfl; pCsr->nUnused = nUsable - 4 - pCsr->nPayload; } pCell->iOvfl++; statSizeAndOffset(pCsr); return z==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK; } if( p->iRightChildPg ) break; p->iCell++; } if( !p->iRightChildPg || p->iCell>p->nCell ){ statClearPage(p); if( pCsr->iPage==0 ) return statNext(pCursor); pCsr->iPage--; goto statNextRestart; /* Tail recursion */ } pCsr->iPage++; assert( p==&pCsr->aPage[pCsr->iPage-1] ); if( p->iCell==p->nCell ){ p[1].iPgno = p->iRightChildPg; }else{ p[1].iPgno = p->aCell[p->iCell].iChildPg; } rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0); p[1].iCell = 0; p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); p->iCell++; if( z==0 ) rc = SQLITE_NOMEM_BKPT; } /* Populate the StatCursor fields with the values to be returned ** by the xColumn() and xRowid() methods. */ if( rc==SQLITE_OK ){ int i; StatPage *p = &pCsr->aPage[pCsr->iPage];//.........这里部分代码省略.........
开发者ID:1018824313,项目名称:sqlite,代码行数:101,
示例26: sqlite3Pragma//.........这里部分代码省略......... }else{ iCookie = 5; } if( zRight ){ /* Write the specified cookie value */ static const VdbeOpList setCookie[] = { { OP_Transaction, 0, 1, 0}, /* 0 */ { OP_Integer, 0, 0, 0}, /* 1 */ { OP_SetCookie, 0, 0, 0}, /* 2 */ }; int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie); sqlite3VdbeChangeP1(v, addr, iDb); sqlite3VdbeChangeP1(v, addr+1, atoi(zRight)); sqlite3VdbeChangeP1(v, addr+2, iDb); sqlite3VdbeChangeP2(v, addr+2, iCookie); }else{ /* Read the specified cookie value */ static const VdbeOpList readCookie[] = { { OP_ReadCookie, 0, 0, 0}, /* 0 */ { OP_Callback, 1, 0, 0} }; int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie); sqlite3VdbeChangeP1(v, addr, iDb); sqlite3VdbeChangeP2(v, addr, iCookie); sqlite3VdbeSetNumCols(v, 1); } }#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) /* ** Report the current state of file logs for all databases */ if( sqlite3StrICmp(zLeft, "lock_status")==0 ){ static const char *const azLockName[] = { "unlocked", "shared", "reserved", "pending", "exclusive" }; int i; Vdbe *v = sqlite3GetVdbe(pParse); sqlite3VdbeSetNumCols(v, 2); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC); sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC); for(i=0; i<db->nDb; i++){ Btree *pBt; Pager *pPager; if( db->aDb[i].zName==0 ) continue; sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC); pBt = db->aDb[i].pBt; if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC); }else{ int j = sqlite3pager_lockstate(pPager); sqlite3VdbeOp3(v, OP_String8, 0, 0, (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC); } sqlite3VdbeAddOp(v, OP_Callback, 2, 0); } }else#endif#ifdef SQLITE_SSE /* ** Check to see if the sqlite_statements table exists. Create it ** if it does not. */ if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){ extern int sqlite3CreateStatementsTable(Parse*); sqlite3CreateStatementsTable(pParse); }else#endif#if SQLITE_HAS_CODEC if( sqlite3StrICmp(zLeft, "key")==0 ){ sqlite3_key(db, zRight, strlen(zRight)); }else#endif {} if( v ){ /* Code an OP_Expire at the end of each PRAGMA program to cause ** the VDBE implementing the pragma to expire. Most (all?) pragmas ** are only valid for a single execution. */ sqlite3VdbeAddOp(v, OP_Expire, 1, 0); /* ** Reset the safety level, in case the fullfsync flag or synchronous ** setting changed. */ if( db->autoCommit ){ sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, (db->flags&SQLITE_FullFSync)!=0); } }pragma_out: sqliteFree(zLeft); sqliteFree(zRight);}
开发者ID:tmarques,项目名称:waheela,代码行数:101,
示例27: sqlite3_rekeyint sqlite3_rekey(sqlite3 *db, const void *zKey, int nKey){ BOTANSQLITE_TRACE("sqlite3_rekey"); // Changes the encryption key for an existing database. int rc = SQLITE_ERROR; Btree *pbt = db->aDb[0].pBt; Pager *pPager = sqlite3BtreePager(pbt); void *pCodec = sqlite3PagerGetCodec(pPager); if ((!zKey || nKey <= 0) && !pCodec) { // Database not encrypted and key not specified. Do nothing return SQLITE_OK; } if (!pCodec) { // Database not encrypted, but key specified. Encrypt database pCodec = InitializeNewCodec(db); assert(nKey >= 0); SetWriteKey(pCodec, (const char*) zKey, (size_t) nKey); if (HandleError(pCodec)) { DeleteCodec(pCodec); return SQLITE_ERROR; } sqlite3PagerSetCodec(pPager, Codec, CodecSizeChange, PagerFreeCodec, pCodec); } else if (!zKey || nKey <= 0) { // Database encrypted, but key not specified. Decrypt database // Keep read key, drop write key DropWriteKey(pCodec); } else { // Database encrypted and key specified. Re-encrypt database with new key // Keep read key, change write key to new key assert(nKey >= 0); SetWriteKey(pCodec, (const char*) zKey, (size_t) nKey); if (HandleError(pCodec)) return SQLITE_ERROR; } // Start transaction rc = sqlite3BtreeBeginTrans(pbt, 1); if (rc == SQLITE_OK) { // Rewrite all pages using the new encryption key (if specified) int nPageCount = -1; sqlite3PagerPagecount(pPager, &nPageCount); Pgno nPage = (Pgno) nPageCount; Pgno nSkip = PAGER_MJ_PGNO(pPager); DbPage *pPage; Pgno n; for (n = 1; rc == SQLITE_OK && n <= nPage; n++) { if (n == nSkip) continue; rc = sqlite3PagerGet(pPager, n, &pPage, 0); if (rc == SQLITE_OK) { rc = sqlite3PagerWrite(pPage); sqlite3PagerUnref(pPage); } else { sqlite3ErrorWithMsg(db, SQLITE_ERROR, "%s", "Error while rekeying database page. Transaction Canceled."); } } } else { sqlite3ErrorWithMsg(db, SQLITE_ERROR, "%s", "Error beginning rekey transaction. Make sure that the current encryption key is correct."); } if (rc == SQLITE_OK) { // All good, commit rc = sqlite3BtreeCommit(pbt); if (rc == SQLITE_OK) { //Database rekeyed and committed successfully, update read key if (HasWriteKey(pCodec)) { SetReadIsWrite(pCodec); } else //No write key == no longer encrypted { sqlite3PagerSetCodec(pPager, NULL, NULL, NULL, NULL); } } else { //FIXME: can't trigger this, not sure if rollback is needed, reference implementation didn't rollback//.........这里部分代码省略.........
开发者ID:kullo,项目名称:smartsqlite,代码行数:101,
示例28: 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,
示例29: sqlite3_db_status/* ** Query status information for a single database connection */SQLITE_API int sqlite3_db_status( sqlite3 *db, /* The database connection whose status is desired */ int op, /* Status verb */ int *pCurrent, /* Write current value here */ int *pHighwater, /* Write high-water mark here */ int resetFlag /* Reset high-water mark if true */){ int rc = SQLITE_OK; /* Return code */ sqlite3_mutex_enter(db->mutex); switch( op ){ case SQLITE_DBSTATUS_LOOKASIDE_USED: { *pCurrent = db->lookaside.nOut; *pHighwater = db->lookaside.mxOut; if( resetFlag ){ db->lookaside.mxOut = db->lookaside.nOut; } break; } case SQLITE_DBSTATUS_LOOKASIDE_HIT: case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: { testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT ); testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE ); testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL ); assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 ); *pCurrent = 0; *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT]; if( resetFlag ){ db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; } break; } /* ** Return an approximation for the amount of memory currently used ** by all pagers associated with the given database connection. The ** highwater mark is meaningless and is returned as zero. */ case SQLITE_DBSTATUS_CACHE_USED: { int totalUsed = 0; int i; sqlite3BtreeEnterAll(db); for(i=0; i<db->nDb; i++){ Btree *pBt = db->aDb[i].pBt; if( pBt ){ Pager *pPager = sqlite3BtreePager(pBt); totalUsed += sqlite3PagerMemUsed(pPager); } } sqlite3BtreeLeaveAll(db); *pCurrent = totalUsed; *pHighwater = 0; break; } /* ** *pCurrent gets an accurate estimate of the amount of memory used ** to store the schema for all databases (main, temp, and any ATTACHed ** databases. *pHighwater is set to zero. */ case SQLITE_DBSTATUS_SCHEMA_USED: { int i; /* Used to iterate through schemas */ int nByte = 0; /* Used to accumulate return value */ sqlite3BtreeEnterAll(db); db->pnBytesFreed = &nByte; for(i=0; i<db->nDb; i++){ Schema *pSchema = db->aDb[i].pSchema; if( ALWAYS(pSchema!=0) ){ HashElem *p; nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * ( pSchema->tblHash.count + pSchema->trigHash.count + pSchema->idxHash.count + pSchema->fkeyHash.count ); nByte += sqlite3MallocSize(pSchema->tblHash.ht); nByte += sqlite3MallocSize(pSchema->trigHash.ht); nByte += sqlite3MallocSize(pSchema->idxHash.ht); nByte += sqlite3MallocSize(pSchema->fkeyHash.ht); for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){ sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p)); } for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){ sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); } } } db->pnBytesFreed = 0; sqlite3BtreeLeaveAll(db); *pHighwater = 0; *pCurrent = nByte;//.........这里部分代码省略.........
开发者ID:pchernev,项目名称:Objective-C-iOS-Categories,代码行数:101,
示例30: sqlite3RunVacuum/*** This routine implements the OP_Vacuum opcode of the VDBE.*/int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ int rc = SQLITE_OK; /* Return code from service routines */ Btree *pMain; /* The database being vacuumed */ Pager *pMainPager; /* Pager for database being vacuumed */ Btree *pTemp; /* The temporary database we vacuum into */ char *zSql = 0; /* SQL statements */ int saved_flags; /* Saved value of the db->flags */ int saved_nChange; /* Saved value of db->nChange */ int saved_nTotalChange; /* Saved value of db->nTotalChange */ Db *pDb = 0; /* Database to detach at end of vacuum */ int isMemDb; /* True is vacuuming a :memory: database */ int nRes; /* Save the current value of the write-schema flag before setting it. */ saved_flags = db->flags; saved_nChange = db->nChange; saved_nTotalChange = db->nTotalChange; db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; if( !db->autoCommit ){ sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); rc = SQLITE_ERROR; goto end_of_vacuum; } pMain = db->aDb[0].pBt; pMainPager = sqlite3BtreePager(pMain); isMemDb = sqlite3PagerFile(pMainPager)->pMethods==0; /* Attach the temporary database as 'vacuum_db'. The synchronous pragma ** can be set to 'off' for this file, as it is not recovered if a crash ** occurs anyway. The integrity of the database is maintained by a ** (possibly synchronous) transaction opened on the main database before ** sqlite3BtreeCopyFile() is called. ** ** An optimisation would be to use a non-journaled pager. ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but ** that actually made the VACUUM run slower. Very little journalling ** actually occurs when doing a vacuum since the vacuum_db is initially ** empty. Only the journal header is written. Apparently it takes more ** time to parse and run the PRAGMA to turn journalling off than it does ** to write the journal header file. */ zSql = "ATTACH '' AS vacuum_db;"; rc = execSql(db, zSql); if( rc!=SQLITE_OK ) goto end_of_vacuum; pDb = &db->aDb[db->nDb-1]; assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 ); pTemp = db->aDb[db->nDb-1].pBt; nRes = sqlite3BtreeGetReserve(pMain); /* A VACUUM cannot change the pagesize of an encrypted database. */#ifdef SQLITE_HAS_CODEC if( db->nextPagesize ){ extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); int nKey; char *zKey; sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); if( nKey ) db->nextPagesize = 0; }#endif if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes) || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes)) || db->mallocFailed ){ rc = SQLITE_NOMEM; goto end_of_vacuum; } rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF"); if( rc!=SQLITE_OK ){ goto end_of_vacuum; }#ifndef SQLITE_OMIT_AUTOVACUUM sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac : sqlite3BtreeGetAutoVacuum(pMain));#endif /* Begin a transaction */ rc = execSql(db, "BEGIN EXCLUSIVE;"); if( rc!=SQLITE_OK ) goto end_of_vacuum; /* Query the schema of the main database. Create a mirror schema ** in the temporary database. */ rc = execExecSql(db, "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) " " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'" " AND rootpage>0" ); if( rc!=SQLITE_OK ) goto end_of_vacuum; rc = execExecSql(db, "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)" " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' "); if( rc!=SQLITE_OK ) goto end_of_vacuum; rc = execExecSql(db, //.........这里部分代码省略.........
开发者ID:kfengbest,项目名称:GenericDB,代码行数:101,
注:本文中的sqlite3BtreePager函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ sqlite3DbFree函数代码示例 C++ sqlite3BtreeLeave函数代码示例 |