您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ sqlite3ResetInternalSchema函数代码示例

51自学网 2021-06-03 08:14:24
  C++
这篇教程C++ sqlite3ResetInternalSchema函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中sqlite3ResetInternalSchema函数的典型用法代码示例。如果您正苦于以下问题:C++ sqlite3ResetInternalSchema函数的具体用法?C++ sqlite3ResetInternalSchema怎么用?C++ sqlite3ResetInternalSchema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了sqlite3ResetInternalSchema函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sqlite3RollbackAll

/*** Rollback all database files.*/void sqlite3RollbackAll(sqlite3 *db){  int i;  int inTrans = 0;  assert( sqlite3_mutex_held(db->mutex) );  sqlite3MallocEnterBenignBlock(1);                 /* Enter benign region */  for(i=0; i<db->nDb; i++){    if( db->aDb[i].pBt ){      if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){        inTrans = 1;      }      sqlite3BtreeRollback(db->aDb[i].pBt);      db->aDb[i].inTrans = 0;    }  }  sqlite3VtabRollback(db);  sqlite3MallocLeaveBenignBlock();                 /* Leave benign region */  if( db->flags&SQLITE_InternChanges ){    sqlite3ExpirePreparedStatements(db);    sqlite3ResetInternalSchema(db, 0);  }  /* If one has been configured, invoke the rollback-hook callback */  if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){    db->xRollbackCallback(db->pRollbackArg);  }}
开发者ID:guange2015,项目名称:sqlite-for-symbian,代码行数:30,


示例2: createModule

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, 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,


示例3: sqlite3RollbackAll

/*** Rollback all database files.*/void sqlite3RollbackAll(sqlite3 *db){  int i;  int inTrans = 0;  assert( sqlite3_mutex_held(db->mutex) );  sqlite3FaultBenign(SQLITE_FAULTINJECTOR_MALLOC, 1);  for(i=0; i<db->nDb; i++){    if( db->aDb[i].pBt ){      if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){        inTrans = 1;      }      sqlite3BtreeRollback(db->aDb[i].pBt);      db->aDb[i].inTrans = 0;    }  }  sqlite3VtabRollback(db);  sqlite3FaultBenign(SQLITE_FAULTINJECTOR_MALLOC, 0);  if( db->flags&SQLITE_InternChanges ){    sqlite3ExpirePreparedStatements(db);    sqlite3ResetInternalSchema(db, 0);  }  /* If one has been configured, invoke the rollback-hook callback */  if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){    db->xRollbackCallback(db->pRollbackArg);  }}
开发者ID:wolfspelz,项目名称:Apollo,代码行数:30,


示例4: sqlite3Init

/*** Initialize all database files - the main database file, the file** used to store temporary tables, and any additional database files** created using ATTACH statements.  Return a success code.  If an** error occurs, write an error message into *pzErrMsg.**** After the database is initialized, the SQLITE_Initialized** bit is set in the flags field of the sqlite structure. */int sqlite3Init(sqlite3 *db, char **pzErrMsg){  int i, rc;    if( db->init.busy ) return SQLITE_OK;  assert( (db->flags & SQLITE_Initialized)==0 );  rc = SQLITE_OK;  db->init.busy = 1;  for(i=0; rc==SQLITE_OK && i<db->nDb; i++){    if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;    rc = sqlite3InitOne(db, i, pzErrMsg);    if( rc ){      sqlite3ResetInternalSchema(db, i);    }  }  /* Once all the other databases have been initialised, load the schema  ** for the TEMP database. This is loaded last, as the TEMP database  ** schema may contain references to objects in other databases.  */#ifndef SQLITE_OMIT_TEMPDB  if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){    rc = sqlite3InitOne(db, 1, pzErrMsg);    if( rc ){      sqlite3ResetInternalSchema(db, 1);    }  }#endif  db->init.busy = 0;  if( rc==SQLITE_OK ){    db->flags |= SQLITE_Initialized;    sqlite3CommitInternalChanges(db);  }  if( rc!=SQLITE_OK ){    db->flags &= ~SQLITE_Initialized;  }  return rc;}
开发者ID:DSD-TELCEL-ESCOM,项目名称:INE-Votation-Distributed-System,代码行数:48,


示例5: invalidateTempStorage

/*** Invalidate temp storage, either when the temp storage is changed** from default, or when 'file' and the temp_store_directory has changed*/static int invalidateTempStorage(Parse *pParse){  sqlite3 *db = pParse->db;  if( db->aDb[1].pBt!=0 ){    if( db->flags & SQLITE_InTrans ){      sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "        "from within a transaction");      return SQLITE_ERROR;    }    sqlite3BtreeClose(db->aDb[1].pBt);    db->aDb[1].pBt = 0;    sqlite3ResetInternalSchema(db, 0);  }  return SQLITE_OK;}
开发者ID:tmarques,项目名称:waheela,代码行数:18,


示例6: sqlite3VdbeFinalize

/*** Clean up and delete a VDBE after execution.  Return an integer which is** the result code.  Write any error message text into *pzErrMsg.*/int sqlite3VdbeFinalize(Vdbe *p){  int rc = SQLITE_OK;  sqlite3 *db = p->db;  if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){    rc = sqlite3VdbeReset(p);  }else if( p->magic!=VDBE_MAGIC_INIT ){    /* sqlite3Error(p->db, SQLITE_MISUSE, 0); */    return SQLITE_MISUSE;  }  sqlite3VdbeDelete(p);  if( rc==SQLITE_SCHEMA ){    sqlite3ResetInternalSchema(db, 0);  }  return rc;}
开发者ID:Shad000w,项目名称:NWNX2-windows,代码行数:20,


示例7: detachFunc

/*** An SQL user-function registered to do the work of an DETACH statement. The** three arguments to the function come directly from a detach statement:****     DETACH DATABASE x****     SELECT sqlite_detach(x)*/static void detachFunc(  sqlite3_context *context,  int NotUsed,  sqlite3_value **argv){  const char *zName = (const char *)sqlite3_value_text(argv[0]);  sqlite3 *db = sqlite3_context_db_handle(context);  int i;  Db *pDb = 0;  char zErr[128];  UNUSED_PARAMETER(NotUsed);  if( zName==0 ) zName = "";  for(i=0; i<db->nDb; i++){    pDb = &db->aDb[i];    if( pDb->pBt==0 ) continue;    if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;  }  if( i>=db->nDb ){    sqlite3_snprintf(sizeof(zErr),zErr, "no such database: %s", zName);    goto detach_error;  }  if( i<2 ){    sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);    goto detach_error;  }  if( !db->autoCommit ){    sqlite3_snprintf(sizeof(zErr), zErr,                     "cannot DETACH database within transaction");    goto detach_error;  }  if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){    sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);    goto detach_error;  }  sqlite3BtreeClose(pDb->pBt);  pDb->pBt = 0;  pDb->pSchema = 0;  sqlite3ResetInternalSchema(db, 0);  return;detach_error:  sqlite3_result_error(context, zErr, -1);}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:55,


示例8: sqlite3Detach

/*** This routine is called by the parser to process a DETACH statement:****    DETACH DATABASE dbname**** The pDbname argument is the name of the database in the DETACH statement.*/void sqlite3Detach(Parse *pParse, Token *pDbname){  int i;  sqlite3 *db;  Vdbe *v;  Db *pDb = 0;  char *zName;  v = sqlite3GetVdbe(pParse);  if( !v ) return;  sqlite3VdbeAddOp(v, OP_Expire, 0, 0);  sqlite3VdbeAddOp(v, OP_Halt, 0, 0);  if( pParse->explain ) return;  db = pParse->db;  zName = sqlite3NameFromToken(pDbname);  if( zName==0 ) return;  for(i=0; i<db->nDb; i++){    pDb = &db->aDb[i];    if( pDb->pBt==0 ) continue;    if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;  }  if( i>=db->nDb ){    sqlite3ErrorMsg(pParse, "no such database: %z", zName);    return;  }  if( i<2 ){    sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);    return;  }  sqliteFree(zName);  if( !db->autoCommit ){    sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");    pParse->rc = SQLITE_ERROR;    return;  }#ifndef SQLITE_OMIT_AUTHORIZATION  if( sqlite3AuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){    return;  }#endif /* SQLITE_OMIT_AUTHORIZATION */  sqlite3BtreeClose(pDb->pBt);  pDb->pBt = 0;  sqlite3ResetInternalSchema(db, 0);}
开发者ID:stephen-hill,项目名称:musicCube,代码行数:50,


示例9: sqlite3_create_module

/*** External API function used to create a new virtual-table module.*/int sqlite3_create_module(  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 */){  int nName = strlen(zName);  Module *pMod = (Module *)sqliteMallocRaw(sizeof(Module) + nName + 1);  if( pMod ){    char *zCopy = (char *)(&pMod[1]);    strcpy(zCopy, zName);    pMod->zName = zCopy;    pMod->pModule = pModule;    pMod->pAux = pAux;    pMod = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);    sqliteFree(pMod);    sqlite3ResetInternalSchema(db, 0);  }  return sqlite3ApiExit(db, SQLITE_OK);}
开发者ID:Bracket-,项目名称:psp-ports,代码行数:23,


示例10: sqlite3RollbackAll

/*** Rollback all database files.*/void sqlite3RollbackAll(sqlite3 *db){  int i;  int inTrans = 0;  for(i=0; i<db->nDb; i++){    if( db->aDb[i].pBt ){      if( sqlite3BtreeIsInTrans(db->aDb[i].pBt) ){        inTrans = 1;      }      sqlite3BtreeRollback(db->aDb[i].pBt);      db->aDb[i].inTrans = 0;    }  }  if( db->flags&SQLITE_InternChanges ){    sqlite3ResetInternalSchema(db, 0);  }  /* If one has been configured, invoke the rollback-hook callback */  if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){    db->xRollbackCallback(db->pRollbackArg);  }}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:24,


示例11: detachFunc

/*** An SQL user-function registered to do the work of an DETACH statement. The** three arguments to the function come directly from a detach statement:****     DETACH DATABASE x****     SELECT sqlite_detach(x)*/static void detachFunc(  sqlite3_context *context,  int argc,  sqlite3_value **argv){  const char *zName = (const char *)sqlite3_value_text(argv[0]);  sqlite3 *db = sqlite3_user_data(context);  int i;  Db *pDb = 0;  char zErr[128];  assert(zName);  for(i=0; i<db->nDb; i++){    pDb = &db->aDb[i];    if( pDb->pBt==0 ) continue;    if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;  }  if( i>=db->nDb ){    sqlite3_snprintf(sizeof(zErr), zErr, "no such database: %s", zName);    goto detach_error;  }  if( i<2 ){    sqlite3_snprintf(sizeof(zErr), zErr, "cannot detach database %s", zName);    goto detach_error;  }  if( !db->autoCommit ){    strcpy(zErr, "cannot DETACH database within transaction");    goto detach_error;  }  sqlite3BtreeClose(pDb->pBt);  pDb->pBt = 0;  pDb->pSchema = 0;  sqlite3ResetInternalSchema(db, 0);  return;detach_error:  sqlite3_result_error(context, zErr, -1);}
开发者ID:MagicalTux,项目名称:nezumi,代码行数:48,


示例12: sqlite3Prepare

/*** Compile the UTF-8 encoded SQL statement zSql into a statement handle.*/int sqlite3Prepare(  sqlite3 *db,              /* Database handle. */  const char *zSql,         /* UTF-8 encoded SQL statement. */  int nBytes,               /* Length of zSql in bytes. */  int saveSqlFlag,          /* True to copy SQL text into the sqlite3_stmt */  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */  const char **pzTail       /* OUT: End of parsed string */){  Parse sParse;  char *zErrMsg = 0;  int rc = SQLITE_OK;  int i;  /* Assert that malloc() has not failed */  assert( !sqlite3MallocFailed() );  assert( ppStmt );  *ppStmt = 0;  if( sqlite3SafetyOn(db) ){    return SQLITE_MISUSE;  }  /* If any attached database schemas are locked, do not proceed with  ** compilation. Instead return SQLITE_LOCKED immediately.  */  for(i=0; i<db->nDb; i++) {    Btree *pBt = db->aDb[i].pBt;    if( pBt && sqlite3BtreeSchemaLocked(pBt) ){      const char *zDb = db->aDb[i].zName;      sqlite3Error(db, SQLITE_LOCKED, "database schema is locked: %s", zDb);      sqlite3SafetyOff(db);      return SQLITE_LOCKED;    }  }    memset(&sParse, 0, sizeof(sParse));  sParse.db = db;  if( nBytes>=0 && zSql[nBytes]!=0 ){    char *zSqlCopy = sqlite3StrNDup(zSql, nBytes);    sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);    sParse.zTail += zSql - zSqlCopy;    sqliteFree(zSqlCopy);  }else{    sqlite3RunParser(&sParse, zSql, &zErrMsg);  }  if( sqlite3MallocFailed() ){    sParse.rc = SQLITE_NOMEM;  }  if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;  if( sParse.checkSchema && !schemaIsValid(db) ){    sParse.rc = SQLITE_SCHEMA;  }  if( sParse.rc==SQLITE_SCHEMA ){    sqlite3ResetInternalSchema(db, 0);  }  if( sqlite3MallocFailed() ){    sParse.rc = SQLITE_NOMEM;  }  if( pzTail ){    *pzTail = sParse.zTail;  }  rc = sParse.rc;#ifndef SQLITE_OMIT_EXPLAIN  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){    if( sParse.explain==2 ){      sqlite3VdbeSetNumCols(sParse.pVdbe, 3);      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "order", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P3_STATIC);    }else{      sqlite3VdbeSetNumCols(sParse.pVdbe, 5);      sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P3_STATIC);      sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P3_STATIC);    }  }#endif  if( sqlite3SafetyOff(db) ){    rc = SQLITE_MISUSE;  }  if( rc==SQLITE_OK ){    if( saveSqlFlag ){      sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql);    }    *ppStmt = (sqlite3_stmt*)sParse.pVdbe;  }else if( sParse.pVdbe ){    sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);  }  if( zErrMsg ){    sqlite3Error(db, rc, "%s", zErrMsg);    sqliteFree(zErrMsg);//.........这里部分代码省略.........
开发者ID:9iky6,项目名称:amxmodx,代码行数:101,


示例13: sqlite3InitOne

//.........这里部分代码省略.........  **  ** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to  ** the possible values of meta[4].  */  if( rc==SQLITE_OK ){    int i;    for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){      rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);    }    if( rc ){      sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);      sqlite3BtreeCloseCursor(curMain);      return rc;    }  }else{    memset(meta, 0, sizeof(meta));  }  pDb->pSchema->schema_cookie = meta[0];  /* If opening a non-empty database, check the text encoding. For the  ** main database, set sqlite3.enc to the encoding of the main database.  ** For an attached db, it is an error if the encoding is not the same  ** as sqlite3.enc.  */  if( meta[4] ){  /* text encoding */    if( iDb==0 ){      /* If opening the main database, set ENC(db). */      ENC(db) = (u8)meta[4];      db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0);    }else{      /* If opening an attached database, the encoding much match ENC(db) */      if( meta[4]!=ENC(db) ){        sqlite3BtreeCloseCursor(curMain);        sqlite3SetString(pzErrMsg, "attached databases must use the same"            " text encoding as main database", (char*)0);        return SQLITE_ERROR;      }    }  }else{    DbSetProperty(db, iDb, DB_Empty);  }  pDb->pSchema->enc = ENC(db);  size = meta[2];  if( size==0 ){ size = MAX_PAGES; }  pDb->pSchema->cache_size = size;  sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);  /*  ** file_format==1    Version 3.0.0.  ** file_format==2    Version 3.1.3.  // ALTER TABLE ADD COLUMN  ** file_format==3    Version 3.1.4.  // ditto but with non-NULL defaults  ** file_format==4    Version 3.3.0.  // DESC indices.  Boolean constants  */  pDb->pSchema->file_format = meta[1];  if( pDb->pSchema->file_format==0 ){    pDb->pSchema->file_format = 1;  }  if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){    sqlite3BtreeCloseCursor(curMain);    sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);    return SQLITE_ERROR;  }  /* Read the schema information out of the schema tables  */  assert( db->init.busy );  if( rc==SQLITE_EMPTY ){    /* For an empty database, there is nothing to read */    rc = SQLITE_OK;  }else{    char *zSql;    zSql = sqlite3MPrintf(        "SELECT name, rootpage, sql FROM '%q'.%s",        db->aDb[iDb].zName, zMasterName);    sqlite3SafetyOff(db);    rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);    if( rc==SQLITE_ABORT ) rc = initData.rc;    sqlite3SafetyOn(db);    sqliteFree(zSql);#ifndef SQLITE_OMIT_ANALYZE    if( rc==SQLITE_OK ){      sqlite3AnalysisLoad(db, iDb);    }#endif    sqlite3BtreeCloseCursor(curMain);  }  if( sqlite3MallocFailed() ){    /* sqlite3SetString(pzErrMsg, "out of memory", (char*)0); */    rc = SQLITE_NOMEM;    sqlite3ResetInternalSchema(db, 0);  }  if( rc==SQLITE_OK ){    DbSetProperty(db, iDb, DB_SchemaLoaded);  }else{    sqlite3ResetInternalSchema(db, iDb);  }  return rc;}
开发者ID:9iky6,项目名称:amxmodx,代码行数:101,


示例14: sqlite3_close

/*** Close an existing SQLite database*/EXPORT_C int sqlite3_close(sqlite3 *db){  HashElem *i;  int j;  if( !db ){    return SQLITE_OK;  }  if( sqlite3SafetyCheck(db) ){    return SQLITE_MISUSE;  }  sqlite3_mutex_enter(db->mutex);#ifdef SQLITE_SSE  {    extern void sqlite3SseCleanup(sqlite3*);    sqlite3SseCleanup(db);  }#endif   sqlite3ResetInternalSchema(db, 0);  /* If a transaction is open, the ResetInternalSchema() call above  ** will not have called the xDisconnect() method on any virtual  ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()  ** call will do so. We need to do this before the check for active  ** SQL statements below, as the v-table implementation may be storing  ** some prepared statements internally.  */  sqlite3VtabRollback(db);  /* If there are any outstanding VMs, return SQLITE_BUSY. */  if( db->pVdbe ){    sqlite3Error(db, SQLITE_BUSY,         "Unable to close due to unfinalised statements");    sqlite3_mutex_leave(db->mutex);    return SQLITE_BUSY;  }  assert( !sqlite3SafetyCheck(db) );  /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database  ** cannot be opened for some reason. So this routine needs to run in  ** that case. But maybe there should be an extra magic value for the  ** "failed to open" state.  **  ** TODO: Coverage tests do not test the case where this condition is  ** true. It's hard to see how to cause it without messing with threads.  */  if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){    /* printf("DID NOT CLOSE/n"); fflush(stdout); */    sqlite3_mutex_leave(db->mutex);    return SQLITE_ERROR;  }  for(j=0; j<db->nDb; j++){    struct Db *pDb = &db->aDb[j];    if( pDb->pBt ){      sqlite3BtreeClose(pDb->pBt);      pDb->pBt = 0;      if( j!=1 ){        pDb->pSchema = 0;      }    }  }  sqlite3ResetInternalSchema(db, 0);  assert( db->nDb<=2 );  assert( db->aDb==db->aDbStatic );  for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){    FuncDef *pFunc, *pNext;    for(pFunc = (FuncDef*)sqliteHashData(i); pFunc; pFunc=pNext){      pNext = pFunc->pNext;      sqlite3_free(pFunc);    }  }  for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){    CollSeq *pColl = (CollSeq *)sqliteHashData(i);    /* Invoke any destructors registered for collation sequence user data. */    for(j=0; j<3; j++){      if( pColl[j].xDel ){        pColl[j].xDel(pColl[j].pUser);      }    }    sqlite3_free(pColl);  }  sqlite3HashClear(&db->aCollSeq);#ifndef SQLITE_OMIT_VIRTUALTABLE  for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){    Module *pMod = (Module *)sqliteHashData(i);    if( pMod->xDestroy ){      pMod->xDestroy(pMod->pAux);    }    sqlite3_free(pMod);  }  sqlite3HashClear(&db->aModule);#endif  sqlite3HashClear(&db->aFunc);//.........这里部分代码省略.........
开发者ID:guange2015,项目名称:sqlite-for-symbian,代码行数:101,


示例15: sqlite3RunVacuum

//.........这里部分代码省略.........      "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "  );  if( rc!=SQLITE_OK ) goto end_of_vacuum;  rc = execExecSql(db,       "SELECT 'INSERT INTO vacuum_db.' || quote(name) "      "|| ' SELECT * FROM ' || quote(name) || ';' "      "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"  );  if( rc!=SQLITE_OK ) goto end_of_vacuum;  /* Copy the triggers, views, and virtual tables from the main database  ** over to the temporary database.  None of these objects has any  ** associated storage, so all we have to do is copy their entries  ** from the SQLITE_MASTER table.  */  rc = execSql(db,      "INSERT INTO vacuum_db.sqlite_master "      "  SELECT type, name, tbl_name, rootpage, sql"      "    FROM sqlite_master"      "   WHERE type='view' OR type='trigger'"      "      OR (type='table' AND rootpage=0)"  );  if( rc ) goto end_of_vacuum;  /* At this point, unless the main db was completely empty, there is now a  ** transaction open on the vacuum database, but not on the main database.  ** Open a btree level transaction on the main database. This allows a  ** call to sqlite3BtreeCopyFile(). The main database btree level  ** transaction is then committed, so the SQL level never knows it was  ** opened for writing. This way, the SQL transaction used to create the  ** temporary database never needs to be committed.  */  if( rc==SQLITE_OK ){    u32 meta;    int i;    /* This array determines which meta meta values are preserved in the    ** vacuum.  Even entries are the meta value number and odd entries    ** are an increment to apply to the meta value after the vacuum.    ** The increment is used to increase the schema cookie so that other    ** connections to the same database will know to reread the schema.    */    static const unsigned char aCopy[] = {       1, 1,    /* Add one to the old schema cookie */       3, 0,    /* Preserve the default page cache size */       5, 0,    /* Preserve the default text encoding */       6, 0,    /* Preserve the user version */    };    assert( 1==sqlite3BtreeIsInTrans(pTemp) );    assert( 1==sqlite3BtreeIsInTrans(pMain) );    /* Copy Btree meta values */    for(i=0; i<ArraySize(aCopy); i+=2){      rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);      if( rc!=SQLITE_OK ) goto end_of_vacuum;      rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);      if( rc!=SQLITE_OK ) goto end_of_vacuum;    }    rc = sqlite3BtreeCopyFile(pMain, pTemp);    if( rc!=SQLITE_OK ) goto end_of_vacuum;    rc = sqlite3BtreeCommit(pTemp);    if( rc!=SQLITE_OK ) goto end_of_vacuum;#ifndef SQLITE_OMIT_AUTOVACUUM    sqlite3BtreeSetAutoVacuum(pMain, sqlite3BtreeGetAutoVacuum(pTemp));#endif    rc = sqlite3BtreeCommit(pMain);  }  if( rc==SQLITE_OK ){    rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes);  }end_of_vacuum:  /* Restore the original value of db->flags */  db->flags = saved_flags;  db->nChange = saved_nChange;  db->nTotalChange = saved_nTotalChange;  /* Currently there is an SQL level transaction open on the vacuum  ** database. No locks are held on any other files (since the main file  ** was committed at the btree level). So it safe to end the transaction  ** by manually setting the autoCommit flag to true and detaching the  ** vacuum database. The vacuum_db journal file is deleted when the pager  ** is closed by the DETACH.  */  db->autoCommit = 1;  if( pDb ){    sqlite3BtreeClose(pDb->pBt);    pDb->pBt = 0;    pDb->pSchema = 0;  }  sqlite3ResetInternalSchema(db, 0);  return rc;}
开发者ID:kfengbest,项目名称:GenericDB,代码行数:101,


示例16: attachFunc

//.........这里部分代码省略.........  }  db->aDb = aNew;  aNew = &db->aDb[db->nDb];  memset(aNew, 0, sizeof(*aNew));  rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,                        db->openFlags | SQLITE_OPEN_MAIN_DB);  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);    sqlite3BtreeSecureDelete(aNew->pBt,                             sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );  }  aNew->safety_level = 3;  aNew->zName = sqlite3DbStrDup(db, zName);  if( rc==SQLITE_OK && aNew->zName==0 ){    rc = SQLITE_NOMEM;  }#ifdef SQLITE_HAS_CODEC  if( rc==SQLITE_OK ){    extern int sqlite3CodecAttach(sqlite3*, int, const void*, int);    extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);    int nKey;    char *zKey;    int t = sqlite3_value_type(argv[2]);    switch( t ){      case SQLITE_INTEGER:      case SQLITE_FLOAT:        zErrDyn = sqlite3DbStrDup(db, "Invalid key value");        rc = SQLITE_ERROR;        break;              case SQLITE_TEXT:      case SQLITE_BLOB:        nKey = sqlite3_value_bytes(argv[2]);        zKey = (char *)sqlite3_value_blob(argv[2]);        rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        break;      case SQLITE_NULL:                sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);        if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){          rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        }        break;    }  }#endif  if( rc==SQLITE_OK ){    sqlite3BtreeEnterAll(db);    rc = sqlite3Init(db, &zErrDyn);    sqlite3BtreeLeaveAll(db);  }  if( rc ){    int iDb = db->nDb - 1;    assert( iDb>=2 );    if( db->aDb[iDb].pBt ){      sqlite3BtreeClose(db->aDb[iDb].pBt);      db->aDb[iDb].pBt = 0;      db->aDb[iDb].pSchema = 0;    }    sqlite3ResetInternalSchema(db, -1);    db->nDb = iDb;    if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){      db->mallocFailed = 1;      sqlite3DbFree(db, zErrDyn);      zErrDyn = sqlite3MPrintf(db, "out of memory");    }else if( zErrDyn==0 ){      zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);    }    goto attach_error;  }    return;attach_error:    if( zErrDyn ){    sqlite3_result_error(context, zErrDyn, -1);    sqlite3DbFree(db, zErrDyn);  }  if( rc ) sqlite3_result_error_code(context, rc);}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:101,


示例17: sqlite3_close

/*** Close an existing SQLite database*/int sqlite3_close(sqlite3 *db){  HashElem *i;  int j;  if( !db ){    return SQLITE_OK;  }  if( sqlite3SafetyCheck(db) ){    return SQLITE_MISUSE;  }#ifdef SQLITE_SSE  sqlite3_finalize(db->pFetch);#endif   /* If there are any outstanding VMs, return SQLITE_BUSY. */  if( db->pVdbe ){    sqlite3Error(db, SQLITE_BUSY,         "Unable to close due to unfinalised statements");    return SQLITE_BUSY;  }  assert( !sqlite3SafetyCheck(db) );  /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database  ** cannot be opened for some reason. So this routine needs to run in  ** that case. But maybe there should be an extra magic value for the  ** "failed to open" state.  */  if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){    /* printf("DID NOT CLOSE/n"); fflush(stdout); */    return SQLITE_ERROR;  }  for(j=0; j<db->nDb; j++){    struct Db *pDb = &db->aDb[j];    if( pDb->pBt ){      sqlite3BtreeClose(pDb->pBt);      pDb->pBt = 0;      if( j!=1 ){        pDb->pSchema = 0;      }    }  }  sqlite3ResetInternalSchema(db, 0);  assert( db->nDb<=2 );  assert( db->aDb==db->aDbStatic );  for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){    FuncDef *pFunc, *pNext;    for(pFunc = (FuncDef*)sqliteHashData(i); pFunc; pFunc=pNext){      pNext = pFunc->pNext;      sqliteFree(pFunc);    }  }  for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){    CollSeq *pColl = (CollSeq *)sqliteHashData(i);    sqliteFree(pColl);  }  sqlite3HashClear(&db->aCollSeq);  sqlite3HashClear(&db->aFunc);  sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */  if( db->pErr ){    sqlite3ValueFree(db->pErr);  }  db->magic = SQLITE_MAGIC_ERROR;  /* The temp-database schema is allocated differently from the other schema  ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).  ** So it needs to be freed here. Todo: Why not roll the temp schema into  ** the same sqliteMalloc() as the one that allocates the database   ** structure?  */  sqliteFree(db->aDb[1].pSchema);  sqliteFree(db);  sqlite3ReleaseThreadData();  return SQLITE_OK;}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:82,


示例18: sqlite3InitOne

//.........这里部分代码省略.........    int i;    for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){      rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);    }    if( rc ){      sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);      sqlite3BtreeCloseCursor(curMain);      return rc;    }  }else{    memset(meta, 0, sizeof(meta));  }  db->aDb[iDb].schema_cookie = meta[0];  /* If opening a non-empty database, check the text encoding. For the  ** main database, set sqlite3.enc to the encoding of the main database.  ** For an attached db, it is an error if the encoding is not the same  ** as sqlite3.enc.  */  if( meta[4] ){  /* text encoding */    if( iDb==0 ){      /* If opening the main database, set db->enc. */      db->enc = (u8)meta[4];      db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);    }else{      /* If opening an attached database, the encoding much match db->enc */      if( meta[4]!=db->enc ){        sqlite3BtreeCloseCursor(curMain);        sqlite3SetString(pzErrMsg, "attached databases must use the same"            " text encoding as main database", (char*)0);        return SQLITE_ERROR;      }    }  }  size = meta[2];  if( size==0 ){ size = MAX_PAGES; }  db->aDb[iDb].cache_size = size;  if( iDb==0 ){    db->file_format = meta[1];    if( db->file_format==0 ){      /* This happens if the database was initially empty */      db->file_format = 1;    }    if( db->file_format==2 || db->file_format==3 ){      /* File format 2 is treated exactly as file format 1. New       ** databases are created with file format 1.      */       db->file_format = 1;    }  }  /*  ** file_format==1    Version 3.0.0.  ** file_format==2    Version 3.1.3.  ** file_format==3    Version 3.1.4.  **  ** Version 3.0 can only use files with file_format==1. Version 3.1.3  ** can read and write files with file_format==1 or file_format==2.  ** Version 3.1.4 can read and write file formats 1, 2 and 3.  */  if( meta[1]>3 ){    sqlite3BtreeCloseCursor(curMain);    sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);    return SQLITE_ERROR;  }  sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);  /* Read the schema information out of the schema tables  */  assert( db->init.busy );  if( rc==SQLITE_EMPTY ){    /* For an empty database, there is nothing to read */    rc = SQLITE_OK;  }else{    char *zSql;    zSql = sqlite3MPrintf(        "SELECT name, rootpage, sql, '%s' FROM '%q'.%s",        zDbNum, db->aDb[iDb].zName, zMasterName);    sqlite3SafetyOff(db);    rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);    sqlite3SafetyOn(db);    sqliteFree(zSql);    sqlite3BtreeCloseCursor(curMain);  }  if( sqlite3_malloc_failed ){    sqlite3SetString(pzErrMsg, "out of memory", (char*)0);    rc = SQLITE_NOMEM;    sqlite3ResetInternalSchema(db, 0);  }  if( rc==SQLITE_OK ){    DbSetProperty(db, iDb, DB_SchemaLoaded);  }else{    sqlite3ResetInternalSchema(db, iDb);  }  return rc;}
开发者ID:DSD-TELCEL-ESCOM,项目名称:INE-Votation-Distributed-System,代码行数:101,


示例19: sqlite3_backup_step

//.........这里部分代码省略.........	 */	if (!sqlite3BtreeIsInTrans(p->pDest)) {		if (!p->pDest->connected) {			p->rc = btreeOpenEnvironment(p->pDest, 1);			if (p->rc != SQLITE_OK)				goto err;		}		if ((p->rc = sqlite3BtreeBeginTrans(p->pDest, 2))			!= SQLITE_OK)			goto err;	}	/* Only this process should be accessing the backup environment. */	if (p->pDest->pBt->nRef > 1) {		p->rc = SQLITE_BUSY;		goto err;	}	/*	 * Begin a transaction, a lock error or update could have caused	 * it to be released in a previous call to step.	 */	if (!p->srcTxn) {		dbenv = p->pSrc->pBt->dbenv;		if ((p->rc = dberr2sqlite(dbenv->txn_begin(dbenv,		    p->pSrc->family_txn, &p->srcTxn, 0))) != SQLITE_OK)			goto err;	}	/*	 * An update could have dropped or created a table, so recalculate	 * the list of tables.	 */	if (!p->tables) {		if ((p->rc = btreeGetPageCount(p->pSrc,		    &p->tables, &p->nPagecount, p->srcTxn)) != SQLITE_OK) {				sqlite3Error(p->pSrcDb, p->rc, 0);				goto err;		}		p->nRemaining = p->nPagecount;	}	/* Copy the pages. */	p->rc = btreeCopyPages(p, &pages);	if (p->rc == SQLITE_DONE) {		p->nRemaining = 0;		sqlite3ResetInternalSchema(p->pDestDb, p->iDb);		memset(&parse, 0, sizeof(parse));		parse.db = p->pDestDb;		p->rc = sqlite3ReadSchema(&parse);		if (p->rc == SQLITE_OK)			p->rc = SQLITE_DONE;	} else if (p->rc != SQLITE_OK)		goto err;	/*	 * The number of pages left to copy is an estimate, so	 * do not let the number go to zero unless we are really	 * done.	 */	if (p->rc != SQLITE_DONE) {		if ((u32)pages >= p->nRemaining)			p->nRemaining = 1;		else			p->nRemaining -= pages;	}err:	/*	 * This process updated the source database, so	 * the backup process has to restart.	 */	if (p->pSrc->updateDuringBackup > p->lastUpdate &&	    (p->rc == SQLITE_OK || p->rc == SQLITE_DONE)) {		int cleanCode;		returnCode = p->rc;		p->rc = SQLITE_LOCKED;		if ((cleanCode = backupCleanup(p)) != SQLITE_OK)			returnCode = p->rc = cleanCode;		else			backupReset(p);	} else {		returnCode = backupCleanup(p);		if (returnCode == SQLITE_OK ||		    (p->rc != SQLITE_OK && p->rc != SQLITE_DONE))			returnCode = p->rc;		else			p->rc = returnCode;	}	/*	 * On a locked or busy error the backup process is rolled back,	 * but can be restarted by the user.	 */	if ( returnCode == SQLITE_LOCKED || returnCode == SQLITE_BUSY )		backupReset(p);	else if ( returnCode != SQLITE_OK && returnCode != SQLITE_DONE ) {		sqlite3Error(p->pDestDb, p->rc, 0);	}	sqlite3_mutex_leave(p->pDestDb->mutex);	sqlite3_mutex_leave(p->pSrcDb->mutex);	return (returnCode);}
开发者ID:galaxyeye,项目名称:bdb,代码行数:101,


示例20: sqlite3Prepare

//.........这里部分代码省略.........  pParse->db = db;  if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){    char *zSqlCopy;    int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];    testcase( nBytes==mxLen );    testcase( nBytes==mxLen+1 );    if( nBytes>mxLen ){      sqlite3Error(db, SQLITE_TOOBIG, "statement too long");      (void)sqlite3SafetyOff(db);      rc = sqlite3ApiExit(db, SQLITE_TOOBIG);      goto end_prepare;    }    zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);    if( zSqlCopy ){      sqlite3RunParser(pParse, zSqlCopy, &zErrMsg);      sqlite3DbFree(db, zSqlCopy);      pParse->zTail = &zSql[pParse->zTail-zSqlCopy];    }else{      pParse->zTail = &zSql[nBytes];    }  }else{    sqlite3RunParser(pParse, zSql, &zErrMsg);  }  if( db->mallocFailed ){    pParse->rc = SQLITE_NOMEM;  }  if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;  if( pParse->checkSchema ){    schemaIsValid(pParse);  }  if( pParse->rc==SQLITE_SCHEMA ){    sqlite3ResetInternalSchema(db, 0);  }  if( db->mallocFailed ){    pParse->rc = SQLITE_NOMEM;  }  if( pzTail ){    *pzTail = pParse->zTail;  }  rc = pParse->rc;#ifndef SQLITE_OMIT_EXPLAIN  if( rc==SQLITE_OK && pParse->pVdbe && pParse->explain ){    static const char * const azColName[] = {       "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment",       "order", "from", "detail"    };    int iFirst, mx;    if( pParse->explain==2 ){      sqlite3VdbeSetNumCols(pParse->pVdbe, 3);      iFirst = 8;      mx = 11;    }else{      sqlite3VdbeSetNumCols(pParse->pVdbe, 8);      iFirst = 0;      mx = 8;    }    for(i=iFirst; i<mx; i++){      sqlite3VdbeSetColName(pParse->pVdbe, i-iFirst, COLNAME_NAME,                            azColName[i], SQLITE_STATIC);    }  }#endif
开发者ID:biddyweb,项目名称:mediastream-plus,代码行数:66,


示例21: attachFunc

//.........这里部分代码省略.........  if( db->aDb==db->aDbStatic ){    aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );    if( aNew==0 ){      return;    }    memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);  }else{    aNew = sqliteRealloc(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, MAX_PAGES, &aNew->pBt);  if( rc==SQLITE_OK ){    aNew->pSchema = sqlite3SchemaGet(aNew->pBt);    if( !aNew->pSchema ){      rc = SQLITE_NOMEM;    }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){      strcpy(zErr,         "attached databases must use the same text encoding as main database");      goto attach_error;    }  }  aNew->zName = sqliteStrDup(zName);  aNew->safety_level = 3;#if SQLITE_HAS_CODEC  {    extern int sqlite3CodecAttach(sqlite3*, int, void*, int);    extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);    int nKey;    char *zKey;    int t = sqlite3_value_type(argv[2]);    switch( t ){      case SQLITE_INTEGER:      case SQLITE_FLOAT:        zErrDyn = sqliteStrDup("Invalid key value");        rc = SQLITE_ERROR;        break;              case SQLITE_TEXT:      case SQLITE_BLOB:        nKey = sqlite3_value_bytes(argv[2]);        zKey = (char *)sqlite3_value_blob(argv[2]);        sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        break;      case SQLITE_NULL:        /* No key specified.  Use the key from the main database */        sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);        sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        break;    }  }#endif  /* If the file was opened successfully, read the schema for the new database.  ** If this fails, or if opening the file failed, then close the file and   ** remove the entry from the db->aDb[] array. i.e. put everything back the way  ** we found it.  */  if( rc==SQLITE_OK ){    sqlite3SafetyOn(db);    rc = sqlite3Init(db, &zErrDyn);    sqlite3SafetyOff(db);  }  if( rc ){    int i = db->nDb - 1;    assert( i>=2 );    if( db->aDb[i].pBt ){      sqlite3BtreeClose(db->aDb[i].pBt);      db->aDb[i].pBt = 0;      db->aDb[i].pSchema = 0;    }    sqlite3ResetInternalSchema(db, 0);    db->nDb = i;    sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);    goto attach_error;  }    return;attach_error:  /* Return an error if we get here */  if( zErrDyn ){    sqlite3_result_error(context, zErrDyn, -1);    sqliteFree(zErrDyn);  }else{    zErr[sizeof(zErr)-1] = 0;    sqlite3_result_error(context, zErr, -1);  }}
开发者ID:MagicalTux,项目名称:nezumi,代码行数:101,


示例22: attachFunc

//.........这里部分代码省略.........  /* 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  {    extern int sqlite3CodecAttach(sqlite3*, int, const void*, int);    extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);    int nKey;    char *zKey;    int t = sqlite3_value_type(argv[2]);    switch( t ){      case SQLITE_INTEGER:      case SQLITE_FLOAT:        zErrDyn = sqlite3DbStrDup(db, "Invalid key value");        rc = SQLITE_ERROR;        break;              case SQLITE_TEXT:      case SQLITE_BLOB:        nKey = sqlite3_value_bytes(argv[2]);        zKey = (char *)sqlite3_value_blob(argv[2]);        sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        break;      case SQLITE_NULL:        /* No key specified.  Use the key from the main database */        sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);        sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);        break;    }  }#endif  /* If the file was opened successfully, read the schema for the new database.  ** If this fails, or if opening the file failed, then close the file and   ** remove the entry from the db->aDb[] array. i.e. put everything back the way  ** we found it.  */  if( rc==SQLITE_OK ){    (void)sqlite3SafetyOn(db);    sqlite3BtreeEnterAll(db);    rc = sqlite3Init(db, &zErrDyn);    sqlite3BtreeLeaveAll(db);    (void)sqlite3SafetyOff(db);  }  if( rc ){    int iDb = db->nDb - 1;    assert( iDb>=2 );    if( db->aDb[iDb].pBt ){      sqlite3BtreeClose(db->aDb[iDb].pBt);      db->aDb[iDb].pBt = 0;      db->aDb[iDb].pSchema = 0;    }    sqlite3ResetInternalSchema(db, 0);    db->nDb = iDb;    if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){      db->mallocFailed = 1;      sqlite3DbFree(db, zErrDyn);      zErrDyn = sqlite3MPrintf(db, "out of memory");    }else if( zErrDyn==0 ){      zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile);    }    goto attach_error;  }    return;attach_error:  /* Return an error if we get here */  if( zErrDyn ){    sqlite3_result_error(context, zErrDyn, -1);    sqlite3DbFree(db, zErrDyn);  }  if( rc ) sqlite3_result_error_code(context, rc);}
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:101,


示例23: sqlite3Attach

//.........这里部分代码省略.........    pParse->rc = SQLITE_ERROR;    return;  }  if( !db->autoCommit ){    sqlite3ErrorMsg(pParse, "cannot ATTACH database within transaction");    pParse->rc = SQLITE_ERROR;    return;  }  zFile = sqlite3NameFromToken(pFilename);;  if( zFile==0 ) return;#ifndef SQLITE_OMIT_AUTHORIZATION  if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){    sqliteFree(zFile);    return;  }#endif /* SQLITE_OMIT_AUTHORIZATION */  zName = sqlite3NameFromToken(pDbname);  if( zName==0 ) return;  for(i=0; i<db->nDb; i++){    char *z = db->aDb[i].zName;    if( z && sqlite3StrICmp(z, zName)==0 ){      sqlite3ErrorMsg(pParse, "database %z is already in use", zName);      pParse->rc = SQLITE_ERROR;      sqliteFree(zFile);      return;    }  }  if( db->aDb==db->aDbStatic ){    aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );    if( aNew==0 ) return;    memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);  }else{    aNew = sqliteRealloc(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));  sqlite3HashInit(&aNew->tblHash, SQLITE_HASH_STRING, 0);  sqlite3HashInit(&aNew->idxHash, SQLITE_HASH_STRING, 0);  sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);  sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);  aNew->zName = zName;  aNew->safety_level = 3;  rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);  if( rc ){    sqlite3ErrorMsg(pParse, "unable to open database: %s", zFile);  }#if SQLITE_HAS_CODEC  {    extern int sqlite3CodecAttach(sqlite3*, int, void*, int);    char *zKey;    int nKey;    if( keyType==0 ){      /* No key specified.  Use the key from the main database */      extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*);      sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);    }else if( keyType==1 ){      /* Key specified as text */      zKey = sqlite3NameFromToken(pKey);      nKey = strlen(zKey);    }else{      /* Key specified as a BLOB */      char *zTemp;      assert( keyType==2 );      pKey->z++;      pKey->n--;      zTemp = sqlite3NameFromToken(pKey);      zKey = sqlite3HexToBlob(zTemp);      sqliteFree(zTemp);    }    sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);    if( keyType ){      sqliteFree(zKey);    }  }#endif  sqliteFree(zFile);  db->flags &= ~SQLITE_Initialized;  if( pParse->nErr==0 && rc==SQLITE_OK ){    rc = sqlite3ReadSchema(pParse);  }  if( rc ){    int i = db->nDb - 1;    assert( i>=2 );    if( db->aDb[i].pBt ){      sqlite3BtreeClose(db->aDb[i].pBt);      db->aDb[i].pBt = 0;    }    sqlite3ResetInternalSchema(db, 0);    if( 0==pParse->nErr ){      pParse->nErr++;      pParse->rc = SQLITE_ERROR;    }  }}
开发者ID:kanbang,项目名称:Colt,代码行数:101,


示例24: sqlite3RunVacuum

//.........这里部分代码省略.........  rc = execExecSql(db,       "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' "      "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' "  );  if( rc!=SQLITE_OK ) goto end_of_vacuum;  rc = execExecSql(db,       "SELECT 'INSERT INTO vacuum_db.' || quote(name) "      "|| ' SELECT * FROM ' || quote(name) || ';' "      "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"  );  if( rc!=SQLITE_OK ) goto end_of_vacuum;  /* Copy the triggers, views, and virtual tables from the main database  ** over to the temporary database.  None of these objects has any  ** associated storage, so all we have to do is copy their entries  ** from the SQLITE_MASTER table.  */  rc = execSql(db,      "INSERT INTO vacuum_db.sqlite_master "      "  SELECT type, name, tbl_name, rootpage, sql"      "    FROM sqlite_master"      "   WHERE type='view' OR type='trigger'"      "      OR (type='table' AND rootpage=0)"  );  if( rc ) goto end_of_vacuum;  /* At this point, unless the main db was completely empty, there is now a  ** transaction open on the vacuum database, but not on the main database.  ** Open a btree level transaction on the main database. This allows a  ** call to sqlite3BtreeCopyFile(). The main database btree level  ** transaction is then committed, so the SQL level never knows it was  ** opened for writing. This way, the SQL transaction used to create the  ** temporary database never needs to be committed.  */  if( rc==SQLITE_OK ){    u32 meta;    int i;    /* This array determines which meta meta values are preserved in the    ** vacuum.  Even entries are the meta value number and odd entries    ** are an increment to apply to the meta value after the vacuum.    ** The increment is used to increase the schema cookie so that other    ** connections to the same database will know to reread the schema.    */    static const unsigned char aCopy[] = {       1, 1,    /* Add one to the old schema cookie */       3, 0,    /* Preserve the default page cache size */       5, 0,    /* Preserve the default text encoding */       6, 0,    /* Preserve the user version */    };    assert( 1==sqlite3BtreeIsInTrans(pTemp) );    assert( 1==sqlite3BtreeIsInTrans(pMain) );    /* Copy Btree meta values */    for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){      rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);      if( rc!=SQLITE_OK ) goto end_of_vacuum;      rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);      if( rc!=SQLITE_OK ) goto end_of_vacuum;    }    rc = sqlite3BtreeCopyFile(pMain, pTemp);    if( rc!=SQLITE_OK ) goto end_of_vacuum;    rc = sqlite3BtreeCommit(pTemp);    if( rc!=SQLITE_OK ) goto end_of_vacuum;    rc = sqlite3BtreeCommit(pMain);  }end_of_vacuum:  /* Restore the original value of db->flags */  db->flags = saved_flags;  /* Currently there is an SQL level transaction open on the vacuum  ** database. No locks are held on any other files (since the main file  ** was committed at the btree level). So it safe to end the transaction  ** by manually setting the autoCommit flag to true and detaching the  ** vacuum database. The vacuum_db journal file is deleted when the pager  ** is closed by the DETACH.  */  db->autoCommit = 1;  if( pDb ){    sqlite3MallocDisallow();    sqlite3BtreeClose(pDb->pBt);    sqlite3MallocAllow();    pDb->pBt = 0;    pDb->pSchema = 0;  }  if( zTemp ){    sqlite3OsDelete(zTemp);    sqliteFree(zTemp);  }  sqliteFree( zSql );  sqlite3ResetInternalSchema(db, 0);  return rc;}
开发者ID:WeyrSDev,项目名称:gamecode3,代码行数:101,


示例25: sqlite3_prepare

/*** Compile the UTF-8 encoded SQL statement zSql into a statement handle.*/int sqlite3_prepare(  sqlite3 *db,              /* Database handle. */  const char *zSql,         /* UTF-8 encoded SQL statement. */  int nBytes,               /* Length of zSql in bytes. */  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */  const char** pzTail       /* OUT: End of parsed string */){  Parse sParse;  char *zErrMsg = 0;  int rc = SQLITE_OK;  if( sqlite3_malloc_failed ){    return SQLITE_NOMEM;  }  assert( ppStmt );  *ppStmt = 0;  if( sqlite3SafetyOn(db) ){    return SQLITE_MISUSE;  }  memset(&sParse, 0, sizeof(sParse));  sParse.db = db;  sqlite3RunParser(&sParse, zSql, &zErrMsg);  if( sqlite3_malloc_failed ){    rc = SQLITE_NOMEM;    sqlite3RollbackAll(db);    sqlite3ResetInternalSchema(db, 0);    db->flags &= ~SQLITE_InTrans;    goto prepare_out;  }  if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;  if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){    sParse.rc = SQLITE_SCHEMA;  }  if( sParse.rc==SQLITE_SCHEMA ){    sqlite3ResetInternalSchema(db, 0);  }  if( pzTail ) *pzTail = sParse.zTail;  rc = sParse.rc;#ifndef SQLITE_OMIT_EXPLAIN  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){    sqlite3VdbeSetNumCols(sParse.pVdbe, 5);    sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);    sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);    sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);    sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);    sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);  } #endifprepare_out:  if( sqlite3SafetyOff(db) ){    rc = SQLITE_MISUSE;  }  if( rc==SQLITE_OK ){    *ppStmt = (sqlite3_stmt*)sParse.pVdbe;  }else if( sParse.pVdbe ){    sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);  }  if( zErrMsg ){    sqlite3Error(db, rc, "%s", zErrMsg);    sqliteFree(zErrMsg);  }else{    sqlite3Error(db, rc, 0);  }  return rc;}
开发者ID:DSD-TELCEL-ESCOM,项目名称:INE-Votation-Distributed-System,代码行数:74,



注:本文中的sqlite3ResetInternalSchema函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ sqlite3SafetyCheck函数代码示例
C++ sqlite3NameFromToken函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。