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

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

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

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

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

示例1: memset

/*** Convert a UTF-16 string in the native encoding into a UTF-8 string.** Memory to hold the UTF-8 string is obtained from malloc and must be** freed by the calling function.**** NULL is returned if there is an allocation error.*/char *sqlite3utf16to8(const void *z, int nByte){  Mem m;  memset(&m, 0, sizeof(m));  sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);  sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);  assert( (m.flags & MEM_Term)!=0 || sqlite3MallocFailed() );  assert( (m.flags & MEM_Str)!=0 || sqlite3MallocFailed() );  return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z);}
开发者ID:moodboom,项目名称:Reusable,代码行数:16,


示例2: assert

/* This function is only available internally, it is not part of the** external API. It works in a similar way to sqlite3_value_text(),** except the data returned is in the encoding specified by the second** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or** SQLITE_UTF8.**** (2006-02-16:)  The enc value can be or-ed with SQLITE_UTF16_ALIGNED.** If that is the case, then the result must be aligned on an even byte** boundary.*/const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){  if( !pVal ) return 0;  assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );  if( pVal->flags&MEM_Null ){    return 0;  }  assert( (MEM_Blob>>3) == MEM_Str );  pVal->flags |= (pVal->flags & MEM_Blob)>>3;  if( pVal->flags&MEM_Str ){    sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED);    if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&(int)pVal->z) ){      assert( (pVal->flags & (MEM_Ephem|MEM_Static))!=0 );      if( sqlite3VdbeMemMakeWriteable(pVal)!=SQLITE_OK ){        return 0;      }    }    sqlite3VdbeMemNulTerminate(pVal);  }else{    assert( (pVal->flags&MEM_Blob)==0 );    sqlite3VdbeMemStringify(pVal, enc);    assert( 0==(1&(int)pVal->z) );  }  assert(pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) || sqlite3MallocFailed() );  if( pVal->enc==(enc & ~SQLITE_UTF16_ALIGNED) ){    return pVal->z;  }else{    return 0;  }}
开发者ID:9iky6,项目名称:amxmodx,代码行数:40,


示例3: sqlite3DropTrigger

/*** This function is called to drop a trigger from the database schema. **** This may be called directly from the parser and therefore identifies** the trigger by name.  The sqlite3DropTriggerPtr() routine does the** same job as this routine except it takes a pointer to the trigger** instead of the trigger name.**/void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){  Trigger *pTrigger = 0;  int i;  const char *zDb;  const char *zName;  int nName;  sqlite3 *db = pParse->db;  if( sqlite3MallocFailed() ) goto drop_trigger_cleanup;  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){    goto drop_trigger_cleanup;  }  assert( pName->nSrc==1 );  zDb = pName->a[0].zDatabase;  zName = pName->a[0].zName;  nName = strlen(zName);  for(i=OMIT_TEMPDB; i<db->nDb; i++){    int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */    if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;    pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);    if( pTrigger ) break;  }  if( !pTrigger ){    if( !noErr ){      sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);    }    goto drop_trigger_cleanup;  }  sqlite3DropTriggerPtr(pParse, pTrigger);drop_trigger_cleanup:  sqlite3SrcListDelete(pName);}
开发者ID:9iky6,项目名称:amxmodx,代码行数:42,


示例4: corruptSchema

/*** Fill the InitData structure with an error message that indicates** that the database is corrupt.*/static void corruptSchema(InitData *pData, const char *zExtra){  if( !sqlite3MallocFailed() ){    sqlite3SetString(pData->pzErrMsg, "malformed database schema",       zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);  }  pData->rc = SQLITE_CORRUPT;}
开发者ID:9iky6,项目名称:amxmodx,代码行数:11,


示例5: sqlite3_errcode

/*** Return the most recent error code generated by an SQLite routine. If NULL is** passed to this function, we assume a malloc() failed during sqlite3_open().*/int sqlite3_errcode(sqlite3 *db){  if( !db || sqlite3MallocFailed() ){    return SQLITE_NOMEM;  }  if( sqlite3SafetyCheck(db) ){    return SQLITE_MISUSE;  }  return db->errCode;}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:13,


示例6: parse

// Lua 调用入口函数// 参数:1个,sql string // 返回:2个,table_result, errMsgstatic int parse(lua_State * L) {    const char *sql = luaL_checkstring(L, 1);    if (sql == NULL || strlen(sql)==0){        return _parse_error(L, "args 1:sql can not be empty string.");    }    Parse *p = sqlite3ParseNew();    resetParseObject(p);    char *errMsg = 0;    sqlite3RunParser(p, sql, &errMsg);    if( sqlite3MallocFailed() ){        sqlite3ParseDelete(p);        return _parse_error(L, "malloc memory failed.");    }    if ( errMsg != NULL ){        _parse_error(L, errMsg);        free(errMsg);        sqlite3ParseDelete(p);        return 2;    }    if( p->rc == SQLITE_DONE ){        p->rc = SQLITE_OK;    }    if (p->rc != SQLITE_OK){        sqlite3ParseDelete(p);        static const int len =1024;        char buff[len];        memset(buff, 0, len);        snprintf(buff, len, "unknown parse result. rc=[%d].", p->rc);        printf(buff);        return _parse_error(L, buff);    }    lua_newtable(L); // push return 1: result-table    set_table_field_n(L, "rc", p->rc);    set_table_field_n(L, "explain", p->explain);    set_table_field_n(L, "flags", p->flags);    set_table_field_n(L, "nErr", p->nErr);    set_table_field_n(L, "nTab", p->nTab);    set_table_field_s(L, "sql", p->zSql, strlen(p->zSql));    set_table_field_s(L, "tail", p->zTail, strlen(p->zTail));    _to_lua_parse_result_array(L, &(p->parsed));    printf("[lua c-model]return success./n");    ///// end set result-table field ////////////////    lua_pushnil(L); // push return 2: err = nil    sqlite3ParseDelete(p);    return 2;}
开发者ID:toontong,项目名称:lua-sql-parse,代码行数:59,


示例7: sqlite3_create_collation

/*** Register a new collation sequence with the database handle db.*/int sqlite3_create_collation(  sqlite3* db,   const char *zName,   int enc,   void* pCtx,  int(*xCompare)(void*,int,const void*,int,const void*)){  int rc;  assert( !sqlite3MallocFailed() );  rc = createCollation(db, zName, enc, pCtx, xCompare);  return sqlite3ApiExit(db, rc);}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:15,


示例8: while

/*** Allocate and return N bytes of uninitialised memory by calling** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory ** by calling sqlite3_release_memory().*/void *sqlite3MallocRaw(int n, int doMemManage){  void *p = 0;  if( n>0 && !sqlite3MallocFailed() && (!doMemManage || enforceSoftLimit(n)) ){    while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) ){}    if( !p ){      sqlite3FailedMalloc();      OSMALLOC_FAILED();    }else if( doMemManage ){      updateMemoryUsedCount(OSSIZEOF(p));    }  }  return p;}
开发者ID:bazhenovc,项目名称:nebula3,代码行数:18,


示例9:

/*** Return UTF-8 encoded English language explanation of the most recent** error.*/const char *sqlite3_errmsg(sqlite3 *db){  const char *z;  if( !db || sqlite3MallocFailed() ){    return sqlite3ErrStr(SQLITE_NOMEM);  }  if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){    return sqlite3ErrStr(SQLITE_MISUSE);  }  z = (char*)sqlite3_value_text(db->pErr);  if( z==0 ){    z = sqlite3ErrStr(db->errCode);  }  return z;}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:18,


示例10: sqlite3_create_function

/*** Create new user functions.*/int sqlite3_create_function(  sqlite3 *db,  const char *zFunctionName,  int nArg,  int enc,  void *p,  void (*xFunc)(sqlite3_context*,int,sqlite3_value **),  void (*xStep)(sqlite3_context*,int,sqlite3_value **),  void (*xFinal)(sqlite3_context*)){  int rc;  assert( !sqlite3MallocFailed() );  rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);  return sqlite3ApiExit(db, rc);}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:19,


示例11: sqlite3_create_collation16

/*** Register a new collation sequence with the database handle db.*/int sqlite3_create_collation16(  sqlite3* db,   const char *zName,   int enc,   void* pCtx,  int(*xCompare)(void*,int,const void*,int,const void*)){  int rc = SQLITE_OK;  char *zName8;   assert( !sqlite3MallocFailed() );  zName8 = sqlite3utf16to8(zName, -1);  if( zName8 ){    rc = createCollation(db, zName8, enc, pCtx, xCompare);    sqliteFree(zName8);  }  return sqlite3ApiExit(db, rc);}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:20,


示例12: sqlite3_create_function16

int sqlite3_create_function16(  sqlite3 *db,  const void *zFunctionName,  int nArg,  int eTextRep,  void *p,  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),  void (*xStep)(sqlite3_context*,int,sqlite3_value**),  void (*xFinal)(sqlite3_context*)){  int rc;  char *zFunc8;  assert( !sqlite3MallocFailed() );  zFunc8 = sqlite3utf16to8(zFunctionName, -1);  rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);  sqliteFree(zFunc8);  return sqlite3ApiExit(db, rc);}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:20,


示例13: sqlite3HashFind

/*** Locate and return an entry from the db.aCollSeq hash table. If the entry** specified by zName and nName is not found and parameter 'create' is** true, then create a new entry. Otherwise return NULL.**** Each pointer stored in the sqlite3.aCollSeq hash table contains an** array of three CollSeq structures. The first is the collation sequence** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.**** Stored immediately after the three collation sequences is a copy of** the collation sequence name. A pointer to this string is stored in** each collation sequence structure.*/static CollSeq *findCollSeqEntry(  sqlite3 *db,  const char *zName,  int nName,  int create){  CollSeq *pColl;  if( nName<0 ) nName = strlen(zName);  pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);  if( 0==pColl && create ){    pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );    if( pColl ){      CollSeq *pDel = 0;      pColl[0].zName = (char*)&pColl[3];      pColl[0].enc = SQLITE_UTF8;      pColl[1].zName = (char*)&pColl[3];      pColl[1].enc = SQLITE_UTF16LE;      pColl[2].zName = (char*)&pColl[3];      pColl[2].enc = SQLITE_UTF16BE;      memcpy(pColl[0].zName, zName, nName);      pColl[0].zName[nName] = 0;      pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);      /* If a malloc() failure occured in sqlite3HashInsert(), it will       ** return the pColl pointer to be deleted (because it wasn't added      ** to the hash table).      */      assert( !pDel || (sqlite3MallocFailed() && pDel==pColl) );      if( pDel ){        sqliteFree(pDel);        pColl = 0;      }    }  }  return pColl;}
开发者ID:DrEastex,项目名称:Platinum,代码行数:50,


示例14: assert

/*** Return UTF-16 encoded English language explanation of the most recent** error.*/const void *sqlite3_errmsg16(sqlite3 *db){  /* Because all the characters in the string are in the unicode  ** range 0x00-0xFF, if we pad the big-endian string with a   ** zero byte, we can obtain the little-endian string with  ** &big_endian[1].  */  static const char outOfMemBe[] = {    0, 'o', 0, 'u', 0, 't', 0, ' ',     0, 'o', 0, 'f', 0, ' ',     0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0  };  static const char misuseBe [] = {    0, 'l', 0, 'i', 0, 'b', 0, 'r', 0, 'a', 0, 'r', 0, 'y', 0, ' ',     0, 'r', 0, 'o', 0, 'u', 0, 't', 0, 'i', 0, 'n', 0, 'e', 0, ' ',     0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, 'e', 0, 'd', 0, ' ',     0, 'o', 0, 'u', 0, 't', 0, ' ',     0, 'o', 0, 'f', 0, ' ',     0, 's', 0, 'e', 0, 'q', 0, 'u', 0, 'e', 0, 'n', 0, 'c', 0, 'e', 0, 0, 0  };  const void *z;  assert( !sqlite3MallocFailed() );  if( !db ){    return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);  }  if( sqlite3SafetyCheck(db) || db->errCode==SQLITE_MISUSE ){    return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);  }  z = sqlite3_value_text16(db->pErr);  if( z==0 ){    sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),         SQLITE_UTF8, SQLITE_STATIC);    z = sqlite3_value_text16(db->pErr);  }  sqlite3ApiExit(0, 0);  return z;}
开发者ID:3rdexp,项目名称:jezzitest,代码行数:41,


示例15: OSSIZEOF

/*** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The** pointer to the new allocation is returned.  If the Realloc() call fails,** attempt to free memory by calling sqlite3_release_memory().*/void *sqlite3Realloc(void *p, int n){  if( sqlite3MallocFailed() ){    return 0;  }  if( !p ){    return sqlite3Malloc(n, 1);  }else{    void *np = 0;#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT    int origSize = OSSIZEOF(p);#endif    if( enforceSoftLimit(n - origSize) ){      while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) ){}      if( !np ){        sqlite3FailedMalloc();        OSMALLOC_FAILED();      }else{        updateMemoryUsedCount(OSSIZEOF(np) - origSize);      }    }    return np;  }}
开发者ID:bazhenovc,项目名称:nebula3,代码行数:29,


示例16: sqlite3AlterRenameTable

/*** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" ** command. */void sqlite3AlterRenameTable(  Parse *pParse,            /* Parser context. */  SrcList *pSrc,            /* The table to rename. */  Token *pName              /* The new table name. */){  int iDb;                  /* Database that contains the table */  char *zDb;                /* Name of database iDb */  Table *pTab;              /* Table being renamed */  char *zName = 0;          /* NULL-terminated version of pName */   sqlite3 *db = pParse->db; /* Database connection */  int nTabName;             /* Number of UTF-8 characters in zTabName */  const char *zTabName;     /* Original name of the table */  Vdbe *v;#ifndef SQLITE_OMIT_TRIGGER  char *zWhere = 0;         /* Where clause to locate temp triggers */#endif  int isVirtualRename = 0;  /* True if this is a v-table with an xRename() */    if( sqlite3MallocFailed() ) goto exit_rename_table;  assert( pSrc->nSrc==1 );  pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);  if( !pTab ) goto exit_rename_table;  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  zDb = db->aDb[iDb].zName;  /* Get a NULL terminated version of the new table name. */  zName = sqlite3NameFromToken(pName);  if( !zName ) goto exit_rename_table;  /* Check that a table or index named 'zName' does not already exist  ** in database iDb. If so, this is an error.  */  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){    sqlite3ErrorMsg(pParse,         "there is already another table or index with this name: %s", zName);    goto exit_rename_table;  }  /* Make sure it is not a system table being altered, or a reserved name  ** that the table is being renamed to.  */  if( strlen(pTab->zName)>6 && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) ){    sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);    goto exit_rename_table;  }  if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){    goto exit_rename_table;  }#ifndef SQLITE_OMIT_AUTHORIZATION  /* Invoke the authorization callback. */  if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){    goto exit_rename_table;  }#endif#ifndef SQLITE_OMIT_VIRTUALTABLE  if( sqlite3ViewGetColumnNames(pParse, pTab) ){    goto exit_rename_table;  }  if( IsVirtual(pTab) && pTab->pMod->pModule->xRename ){    isVirtualRename = 1;  }#endif  /* Begin a transaction and code the VerifyCookie for database iDb.   ** Then modify the schema cookie (since the ALTER TABLE modifies the  ** schema). Open a statement transaction if the table is a virtual  ** table.  */  v = sqlite3GetVdbe(pParse);  if( v==0 ){    goto exit_rename_table;  }  sqlite3BeginWriteOperation(pParse, isVirtualRename, iDb);  sqlite3ChangeCookie(db, v, iDb);  /* If this is a virtual table, invoke the xRename() function if  ** one is defined. The xRename() callback will modify the names  ** of any resources used by the v-table implementation (including other  ** SQLite tables) that are identified by the name of the virtual table.  */#ifndef SQLITE_OMIT_VIRTUALTABLE  if( isVirtualRename ){    sqlite3VdbeOp3(v, OP_String8, 0, 0, zName, 0);    sqlite3VdbeOp3(v, OP_VRename, 0, 0, (const char*)pTab->pVtab, P3_VTAB);  }#endif  /* figure out how many UTF-8 characters are in zName */  zTabName = pTab->zName;  nTabName = sqlite3Utf8CharLen(zTabName, -1);  /* Modify the sqlite_master table to use the new table name. */  sqlite3NestedParse(pParse,//.........这里部分代码省略.........
开发者ID:3rdexp,项目名称:jezzitest,代码行数:101,


示例17: sqlite3InitCallback

/*** This is the callback routine for the code that initializes the** database.  See sqlite3Init() below for additional information.** This routine is also called from the OP_ParseSchema opcode of the VDBE.**** Each callback contains the following information:****     argv[0] = name of thing being created**     argv[1] = root page number for table or index. 0 for trigger or view.**     argv[2] = SQL text for the CREATE statement.***/int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){  InitData *pData = (InitData*)pInit;  sqlite3 *db = pData->db;  int iDb = pData->iDb;  pData->rc = SQLITE_OK;  DbClearProperty(db, iDb, DB_Empty);  if( sqlite3MallocFailed() ){    corruptSchema(pData, 0);    return SQLITE_NOMEM;  }  assert( argc==3 );  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */  if( argv[1]==0 ){    corruptSchema(pData, 0);    return 1;  }  assert( iDb>=0 && iDb<db->nDb );  if( argv[2] && argv[2][0] ){    /* Call the parser to process a CREATE TABLE, INDEX or VIEW.    ** But because db->init.busy is set to 1, no VDBE code is generated    ** or executed.  All the parser does is build the internal data    ** structures that describe the table, index, or view.    */    char *zErr;    int rc;    assert( db->init.busy );    db->init.iDb = iDb;    db->init.newTnum = atoi(argv[1]);    rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);    db->init.iDb = 0;    assert( rc!=SQLITE_OK || zErr==0 );    if( SQLITE_OK!=rc ){      pData->rc = rc;      if( rc==SQLITE_NOMEM ){        sqlite3FailedMalloc();      }else if( rc!=SQLITE_INTERRUPT ){        corruptSchema(pData, zErr);      }      sqlite3_free(zErr);      return 1;    }  }else{    /* If the SQL column is blank it means this is an index that    ** was created to be the PRIMARY KEY or to fulfill a UNIQUE    ** constraint for a CREATE TABLE.  The index should have already    ** been created when we processed the CREATE TABLE.  All we have    ** to do here is record the root page number for that index.    */    Index *pIndex;    pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);    if( pIndex==0 || pIndex->tnum!=0 ){      /* This can occur if there exists an index on a TEMP table which      ** has the same name as another index on a permanent index.  Since      ** the permanent table is hidden by the TEMP table, we can also      ** safely ignore the index on the permanent table.      */      /* Do Nothing */;    }else{      pIndex->tnum = atoi(argv[1]);    }  }  return 0;}
开发者ID:9iky6,项目名称:amxmodx,代码行数:77,


示例18: 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,


示例19: sqlite3BeginTrigger

/*** This is called by the parser when it sees a CREATE TRIGGER statement** up to the point of the BEGIN before the trigger actions.  A Trigger** structure is generated based on the information available and stored** in pParse->pNewTrigger.  After the trigger actions have been parsed, the** sqlite3FinishTrigger() function is called to complete the trigger** construction process.*/void sqlite3BeginTrigger(  Parse *pParse,      /* The parse context of the CREATE TRIGGER statement */  Token *pName1,      /* The name of the trigger */  Token *pName2,      /* The name of the trigger */  int tr_tm,          /* One of TK_BEFORE, TK_AFTER, TK_INSTEAD */  int op,             /* One of TK_INSERT, TK_UPDATE, TK_DELETE */  IdList *pColumns,   /* column list if this is an UPDATE OF trigger */  SrcList *pTableName,/* The name of the table/view the trigger applies to */  int foreach,        /* One of TK_ROW or TK_STATEMENT */  Expr *pWhen,        /* WHEN clause */  int isTemp,         /* True if the TEMPORARY keyword is present */  int noErr           /* Suppress errors if the trigger already exists */){  Trigger *pTrigger = 0;  Table *pTab;  char *zName = 0;        /* Name of the trigger */  sqlite3 *db = pParse->db;  int iDb;                /* The database to store the trigger in */  Token *pName;           /* The unqualified db name */  DbFixer sFix;  int iTabDb;  assert( pName1!=0 );   /* pName1->z might be NULL, but not pName1 itself */  assert( pName2!=0 );  if( isTemp ){    /* If TEMP was specified, then the trigger name may not be qualified. */    if( pName2->n>0 ){      sqlite3ErrorMsg(pParse, "temporary trigger may not have qualified name");      goto trigger_cleanup;    }    iDb = 1;    pName = pName1;  }else{    /* Figure out the db that the the trigger will be created in */    iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);    if( iDb<0 ){      goto trigger_cleanup;    }  }  /* If the trigger name was unqualified, and the table is a temp table,  ** then set iDb to 1 to create the trigger in the temporary database.  ** If sqlite3SrcListLookup() returns 0, indicating the table does not  ** exist, the error is caught by the block below.  */  if( !pTableName || sqlite3MallocFailed() ){    goto trigger_cleanup;  }  pTab = sqlite3SrcListLookup(pParse, pTableName);  if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){    iDb = 1;  }  /* Ensure the table name matches database name and that the table exists */  if( sqlite3MallocFailed() ) goto trigger_cleanup;  assert( pTableName->nSrc==1 );  if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&       sqlite3FixSrcList(&sFix, pTableName) ){    goto trigger_cleanup;  }  pTab = sqlite3SrcListLookup(pParse, pTableName);  if( !pTab ){    /* The table does not exist. */    goto trigger_cleanup;  }  if( IsVirtual(pTab) ){    sqlite3ErrorMsg(pParse, "cannot create triggers on virtual tables");    goto trigger_cleanup;  }  /* Check that the trigger name is not reserved and that no trigger of the  ** specified name exists */  zName = sqlite3NameFromToken(pName);  if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){    goto trigger_cleanup;  }  if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), zName,strlen(zName)) ){    if( !noErr ){      sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);    }    goto trigger_cleanup;  }  /* Do not create a trigger on a system table */  if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){    sqlite3ErrorMsg(pParse, "cannot create trigger on system table");    pParse->nErr++;    goto trigger_cleanup;  }  /* INSTEAD of triggers are only for views and views only support INSTEAD  ** of triggers.//.........这里部分代码省略.........
开发者ID:9iky6,项目名称:amxmodx,代码行数:101,


示例20: 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,


示例21: sqlite3RunParser

/*** Run the parser on the given SQL string.  The parser structure is** passed in.  An SQLITE_ status code is returned.  If an error occurs** and pzErrMsg!=NULL then an error message might be written into ** memory obtained from malloc() and *pzErrMsg made to point to that** error message.  Or maybe not.*/int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){  int nErr = 0;  int i;  void *pEngine;  int tokenType;  int lastTokenParsed = -1;  sqlite3 *db = pParse->db;  extern void *sqlite3ParserAlloc(void*(*)(int));  extern void sqlite3ParserFree(void*, void(*)(void*));  extern int sqlite3Parser(void*, int, Token, Parse*);  if( db->activeVdbeCnt==0 ){    db->u1.isInterrupted = 0;  }  pParse->rc = SQLITE_OK;  i = 0;  pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);  if( pEngine==0 ){    return SQLITE_NOMEM;  }  assert( pParse->sLastToken.dyn==0 );  assert( pParse->pNewTable==0 );  assert( pParse->pNewTrigger==0 );  assert( pParse->nVar==0 );  assert( pParse->nVarExpr==0 );  assert( pParse->nVarExprAlloc==0 );  assert( pParse->apVarExpr==0 );  pParse->zTail = pParse->zSql = zSql;  while( !sqlite3MallocFailed() && zSql[i]!=0 ){    assert( i>=0 );    pParse->sLastToken.z = (u8*)&zSql[i];    assert( pParse->sLastToken.dyn==0 );    pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);    i += pParse->sLastToken.n;    switch( tokenType ){      case TK_SPACE:      case TK_COMMENT: {        if( db->u1.isInterrupted ){          pParse->rc = SQLITE_INTERRUPT;          sqlite3SetString(pzErrMsg, "interrupt", (char*)0);          goto abort_parse;        }        break;      }      case TK_ILLEGAL: {        if( pzErrMsg ){          sqliteFree(*pzErrMsg);          *pzErrMsg = sqlite3MPrintf("unrecognized token: /"%T/"",                          &pParse->sLastToken);        }        nErr++;        goto abort_parse;      }      case TK_SEMI: {        pParse->zTail = &zSql[i];        /* Fall thru into the default case */      }      default: {        sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);        lastTokenParsed = tokenType;        if( pParse->rc!=SQLITE_OK ){          goto abort_parse;        }        break;      }    }  }abort_parse:  if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){    if( lastTokenParsed!=TK_SEMI ){      sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);      pParse->zTail = &zSql[i];    }    sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);  }  sqlite3ParserFree(pEngine, sqlite3FreeX);  if( sqlite3MallocFailed() ){    pParse->rc = SQLITE_NOMEM;  }  if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){    sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0);  }  if( pParse->zErrMsg ){    if( pzErrMsg && *pzErrMsg==0 ){      *pzErrMsg = pParse->zErrMsg;    }else{      sqliteFree(pParse->zErrMsg);    }    pParse->zErrMsg = 0;    if( !nErr ) nErr++;  }  if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){    sqlite3VdbeDelete(pParse->pVdbe);//.........这里部分代码省略.........
开发者ID:JJHOCK,项目名称:l2adenalib,代码行数:101,


示例22: sqlite3CreateFunc

/*** This function is exactly the same as sqlite3_create_function(), except** that it is designed to be called by internal code. The difference is** that if a malloc() fails in sqlite3_create_function(), an error code** is returned and the mallocFailed flag cleared. */int sqlite3CreateFunc(  sqlite3 *db,  const char *zFunctionName,  int nArg,  int enc,  void *pUserData,  void (*xFunc)(sqlite3_context*,int,sqlite3_value **),  void (*xStep)(sqlite3_context*,int,sqlite3_value **),  void (*xFinal)(sqlite3_context*)){  FuncDef *p;  int nName;  if( sqlite3SafetyCheck(db) ){    return SQLITE_MISUSE;  }  if( zFunctionName==0 ||      (xFunc && (xFinal || xStep)) ||       (!xFunc && (xFinal && !xStep)) ||      (!xFunc && (!xFinal && xStep)) ||      (nArg<-1 || nArg>127) ||      (255<(nName = strlen(zFunctionName))) ){    return SQLITE_ERROR;  }  #ifndef SQLITE_OMIT_UTF16  /* If SQLITE_UTF16 is specified as the encoding type, transform this  ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the  ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.  **  ** If SQLITE_ANY is specified, add three versions of the function  ** to the hash table.  */  if( enc==SQLITE_UTF16 ){    enc = SQLITE_UTF16NATIVE;  }else if( enc==SQLITE_ANY ){    int rc;    rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,         pUserData, xFunc, xStep, xFinal);    if( rc!=SQLITE_OK ) return rc;    rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,        pUserData, xFunc, xStep, xFinal);    if( rc!=SQLITE_OK ) return rc;    enc = SQLITE_UTF16BE;  }#else  enc = SQLITE_UTF8;#endif    /* Check if an existing function is being overridden or deleted. If so,  ** and there are active VMs, then return SQLITE_BUSY. If a function  ** is being overridden/deleted but there are no active VMs, allow the  ** operation to continue but invalidate all precompiled statements.  */  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 0);  if( p && p->iPrefEnc==enc && p->nArg==nArg ){    if( db->activeVdbeCnt ){      sqlite3Error(db, SQLITE_BUSY,         "Unable to delete/modify user-function due to active statements");      assert( !sqlite3MallocFailed() );      return SQLITE_BUSY;    }else{      sqlite3ExpirePreparedStatements(db);    }  }  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1);  if( p ){    p->flags = 0;    p->xFunc = xFunc;    p->xStep = xStep;    p->xFinalize = xFinal;    p->pUserData = pUserData;  }  return SQLITE_OK;}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:82,


示例23: sqlite3Step

/*** Execute the statement pStmt, either until a row of data is ready, the** statement is completely executed or an error occurs.**** This routine implements the bulk of the logic behind the sqlite_step()** API.  The only thing omitted is the automatic recompile if a ** schema change has occurred.  That detail is handled by the** outer sqlite3_step() wrapper procedure.*/static int sqlite3Step(Vdbe *p){  sqlite3 *db;  int rc;  /* Assert that malloc() has not failed */  assert( !sqlite3MallocFailed() );  if( p==0 || p->magic!=VDBE_MAGIC_RUN ){    return SQLITE_MISUSE;  }  if( p->aborted ){    return SQLITE_ABORT;  }  if( p->pc<=0 && p->expired ){    if( p->rc==SQLITE_OK ){      p->rc = SQLITE_SCHEMA;    }    rc = SQLITE_ERROR;    goto end_of_step;  }  db = p->db;  if( sqlite3SafetyOn(db) ){    p->rc = SQLITE_MISUSE;    return SQLITE_MISUSE;  }  if( p->pc<0 ){    /* If there are no other statements currently running, then    ** reset the interrupt flag.  This prevents a call to sqlite3_interrupt    ** from interrupting a statement that has not yet started.    */    if( db->activeVdbeCnt==0 ){      db->u1.isInterrupted = 0;    }#ifndef SQLITE_OMIT_TRACE    /* Invoke the trace callback if there is one    */    if( db->xTrace && !db->init.busy ){      assert( p->nOp>0 );      assert( p->aOp[p->nOp-1].opcode==OP_Noop );      assert( p->aOp[p->nOp-1].p3!=0 );      assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );      sqlite3SafetyOff(db);      db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3);      if( sqlite3SafetyOn(db) ){        p->rc = SQLITE_MISUSE;        return SQLITE_MISUSE;      }    }    if( db->xProfile && !db->init.busy ){      double rNow;      sqlite3OsCurrentTime(&rNow);      p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;    }#endif    /* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned    ** on in debugging mode.    */#ifdef SQLITE_DEBUG    if( (db->flags & SQLITE_SqlTrace)!=0 ){      sqlite3DebugPrintf("SQL-trace: %s/n", p->aOp[p->nOp-1].p3);    }#endif /* SQLITE_DEBUG */    db->activeVdbeCnt++;    p->pc = 0;  }#ifndef SQLITE_OMIT_EXPLAIN  if( p->explain ){    rc = sqlite3VdbeList(p);  }else#endif /* SQLITE_OMIT_EXPLAIN */  {    rc = sqlite3VdbeExec(p);  }  if( sqlite3SafetyOff(db) ){    rc = SQLITE_MISUSE;  }#ifndef SQLITE_OMIT_TRACE  /* Invoke the profile callback if there is one  */  if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){    double rNow;    u64 elapseTime;    sqlite3OsCurrentTime(&rNow);    elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;    assert( p->nOp>0 );//.........这里部分代码省略.........
开发者ID:Bracket-,项目名称:psp-ports,代码行数:101,


示例24: sqlite3RunParser1

int sqlite3RunParser1(Parse *pParse, const char *zSql, int sqlLen, char **pzErrMsg) {  int nErr = 0;  int i;  void *pEngine;  int tokenType;  int lastTokenParsed = -1; // sqlite3 *db = pParse->db;  extern void *sqlite3ParserAlloc(void*(*)(int));  extern void sqlite3ParserFree(void*, void(*)(void*));  extern int sqlite3Parser(void*, int, Token, Parse*);  //db->flags &= ~SQLITE_Interrupt;  pParse->flags &= ~SQLITE_Interrupt;  pParse->rc = SQLITE_OK;  i = 0;  pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);  if( pEngine==0 ){    return SQLITE_NOMEM;  }  assert( pParse->sLastToken.dyn==0 );  assert( pParse->pNewTable==0 );  assert( pParse->pNewTrigger==0 );  assert( pParse->nVar==0 );  assert( pParse->nVarExpr==0 );  assert( pParse->nVarExprAlloc==0 );  assert( pParse->apVarExpr==0 );  pParse->zTail = pParse->zSql = zSql;  while( !sqlite3MallocFailed() && /*zSql[i]!=0*/ i < sqlLen ){    assert( i>=0 );    pParse->sLastToken.z = (u8*)&zSql[i];    assert( pParse->sLastToken.dyn==0 );    pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);    i += pParse->sLastToken.n;        if (tokenType != TK_SPACE) {        TokenItem tokenItem;        tokenItem.token = pParse->sLastToken;        tokenItem.tokenType = tokenType;        sqlite3TokenArrayAppend(&pParse->tokens, &tokenItem);    }    switch( tokenType ){      case TK_SPACE:      case TK_COMMENT: {        //if( (db->flags & SQLITE_Interrupt)!=0 ){        if( (pParse->flags & SQLITE_Interrupt)!=0 ){          pParse->rc = SQLITE_INTERRUPT;          sqlite3SetString(pzErrMsg, "interrupt", (char*)0);          goto abort_parse;        }        break;      }      case TK_ILLEGAL: {        if( pzErrMsg ){          sqliteFree(*pzErrMsg);          *pzErrMsg = sqlite3MPrintf("unrecognized token: /"%T/"",                          &pParse->sLastToken);        }        nErr++;        goto abort_parse;      }      case TK_SEMI: {        pParse->zTail = &zSql[i];        /* Fall thru into the default case */      }      default: {        sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);        lastTokenParsed = tokenType;        if( pParse->rc!=SQLITE_OK ){          goto abort_parse;        }        break;      }    }  }abort_parse:    while(!sqlite3MallocFailed() && i < sqlLen) {        pParse->sLastToken.z = (u8*)&zSql[i];        assert( pParse->sLastToken.dyn==0 );        pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);        i += pParse->sLastToken.n;        if (tokenType != TK_SPACE) {            TokenItem tokenItem;            tokenItem.token = pParse->sLastToken;            tokenItem.tokenType = tokenType;            sqlite3TokenArrayAppend(&pParse->tokens, &tokenItem);        }    }    if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){    if( lastTokenParsed!=TK_SEMI ){      sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);      pParse->zTail = &zSql[i];    }    sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);  }  sqlite3ParserFree(pEngine, sqlite3FreeX);  if( sqlite3MallocFailed() ){    pParse->rc = SQLITE_NOMEM;//.........这里部分代码省略.........
开发者ID:Matrix0xCC,项目名称:lemon,代码行数:101,


示例25: sqlite3RunVacuum

//.........这里部分代码省略.........      "|| ' SELECT * FROM ' || quote(name) || ';' "      "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';"  );  if( rc!=SQLITE_OK ) goto end_of_vacuum;  /* Copy the triggers from the main database to the temporary database.  ** This was deferred before in case the triggers interfered with copying  ** the data. It's possible the indices should be deferred until this  ** point also.  */  rc = execExecSql(db,       "SELECT 'CREATE TRIGGER  vacuum_db.' || substr(sql, 16, 1000000) "      "FROM sqlite_master WHERE type='trigger'"  );  if( rc!=SQLITE_OK ) 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 one of the execSql() calls above returned SQLITE_NOMEM, then the  ** mallocFailed flag will be clear (because execSql() calls sqlite3_exec()).  ** Fix this so the flag and return code match.  */  if( rc==SQLITE_NOMEM ){    sqlite3MallocFailed();  }  if( zTemp ){    sqlite3OsDelete(zTemp);    sqliteFree(zTemp);  }  sqliteFree( zSql );  sqlite3ResetInternalSchema(db, 0);#endif  return rc;}
开发者ID:vijayskumar,项目名称:dcmpi,代码行数:101,


示例26: sqlite3FinishTrigger

/*** This routine is called after all of the trigger actions have been parsed** in order to complete the process of building the trigger.*/void sqlite3FinishTrigger(  Parse *pParse,          /* Parser context */  TriggerStep *pStepList, /* The triggered program */  Token *pAll             /* Token that describes the complete CREATE TRIGGER */){  Trigger *pTrig = 0;     /* The trigger whose construction is finishing up */  sqlite3 *db = pParse->db;  /* The database */  DbFixer sFix;  int iDb;                   /* Database containing the trigger */  pTrig = pParse->pNewTrigger;  pParse->pNewTrigger = 0;  if( pParse->nErr || !pTrig ) goto triggerfinish_cleanup;  iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema);  pTrig->step_list = pStepList;  while( pStepList ){    pStepList->pTrig = pTrig;    pStepList = pStepList->pNext;  }  if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &pTrig->nameToken)           && sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){    goto triggerfinish_cleanup;  }  /* if we are not initializing, and this trigger is not on a TEMP table,   ** build the sqlite_master entry  */  if( !db->init.busy ){    static const VdbeOpList insertTrig[] = {      { OP_NewRowid,   0, 0,  0          },      { OP_String8,    0, 0,  "trigger"  },      { OP_String8,    0, 0,  0          },  /* 2: trigger name */      { OP_String8,    0, 0,  0          },  /* 3: table name */      { OP_Integer,    0, 0,  0          },      { OP_String8,    0, 0,  "CREATE TRIGGER "},      { OP_String8,    0, 0,  0          },  /* 6: SQL */      { OP_Concat,     0, 0,  0          },       { OP_MakeRecord, 5, 0,  "aaada"    },      { OP_Insert,     0, 0,  0          },    };    int addr;    Vdbe *v;    /* Make an entry in the sqlite_master table */    v = sqlite3GetVdbe(pParse);    if( v==0 ) goto triggerfinish_cleanup;    sqlite3BeginWriteOperation(pParse, 0, iDb);    sqlite3OpenMasterTable(pParse, iDb);    addr = sqlite3VdbeAddOpList(v, ArraySize(insertTrig), insertTrig);    sqlite3VdbeChangeP3(v, addr+2, pTrig->name, 0);     sqlite3VdbeChangeP3(v, addr+3, pTrig->table, 0);     sqlite3VdbeChangeP3(v, addr+6, (char*)pAll->z, pAll->n);    sqlite3ChangeCookie(db, v, iDb);    sqlite3VdbeAddOp(v, OP_Close, 0, 0);    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0,        sqlite3MPrintf("type='trigger' AND name='%q'", pTrig->name), P3_DYNAMIC);  }  if( db->init.busy ){    int n;    Table *pTab;    Trigger *pDel;    pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,                      pTrig->name, strlen(pTrig->name), pTrig);    if( pDel ){      assert( sqlite3MallocFailed() && pDel==pTrig );      goto triggerfinish_cleanup;    }    n = strlen(pTrig->table) + 1;    pTab = sqlite3HashFind(&pTrig->pTabSchema->tblHash, pTrig->table, n);    assert( pTab!=0 );    pTrig->pNext = pTab->pTrigger;    pTab->pTrigger = pTrig;    pTrig = 0;  }triggerfinish_cleanup:  sqlite3DeleteTrigger(pTrig);  assert( !pParse->pNewTrigger );  sqlite3DeleteTriggerStep(pStepList);}
开发者ID:9iky6,项目名称:amxmodx,代码行数:85,


示例27: sqlite3AlterBeginAddColumn

/*** This function is called by the parser after the table-name in** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument ** pSrc is the full-name of the table being altered.**** This routine makes a (partial) copy of the Table structure** for the table being altered and sets Parse.pNewTable to point** to it. Routines called by the parser as the column definition** is parsed (i.e. sqlite3AddColumn()) add the new Column data to ** the copy. The copy of the Table structure is deleted by tokenize.c ** after parsing is finished.**** Routine sqlite3AlterFinishAddColumn() will be called to complete** coding the "ALTER TABLE ... ADD" statement.*/void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){  Table *pNew;  Table *pTab;  Vdbe *v;  int iDb;  int i;  int nAlloc;  /* Look up the table being altered. */  assert( pParse->pNewTable==0 );  if( sqlite3MallocFailed() ) goto exit_begin_add_column;  pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);  if( !pTab ) goto exit_begin_add_column;#ifndef SQLITE_OMIT_VIRTUALTABLE  if( IsVirtual(pTab) ){    sqlite3ErrorMsg(pParse, "virtual tables may not be altered");    goto exit_begin_add_column;  }#endif  /* Make sure this is not an attempt to ALTER a view. */  if( pTab->pSelect ){    sqlite3ErrorMsg(pParse, "Cannot add a column to a view");    goto exit_begin_add_column;  }  assert( pTab->addColOffset>0 );  iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);  /* Put a copy of the Table struct in Parse.pNewTable for the  ** sqlite3AddColumn() function and friends to modify.  */  pNew = (Table *)sqliteMalloc(sizeof(Table));  if( !pNew ) goto exit_begin_add_column;  pParse->pNewTable = pNew;  pNew->nRef = 1;  pNew->nCol = pTab->nCol;  assert( pNew->nCol>0 );  nAlloc = (((pNew->nCol-1)/8)*8)+8;  assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );  pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc);  pNew->zName = sqliteStrDup(pTab->zName);  if( !pNew->aCol || !pNew->zName ){    goto exit_begin_add_column;  }  memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);  for(i=0; i<pNew->nCol; i++){    Column *pCol = &pNew->aCol[i];    pCol->zName = sqliteStrDup(pCol->zName);    pCol->zColl = 0;    pCol->zType = 0;    pCol->pDflt = 0;  }  pNew->pSchema = pParse->db->aDb[iDb].pSchema;  pNew->addColOffset = pTab->addColOffset;  pNew->nRef = 1;  /* Begin a transaction and increment the schema cookie.  */  sqlite3BeginWriteOperation(pParse, 0, iDb);  v = sqlite3GetVdbe(pParse);  if( !v ) goto exit_begin_add_column;  sqlite3ChangeCookie(pParse->db, v, iDb);exit_begin_add_column:  sqlite3SrcListDelete(pSrc);  return;}
开发者ID:3rdexp,项目名称:jezzitest,代码行数:83,


示例28: sqlite3DeleteFrom

/*** Generate code for a DELETE FROM statement.****     DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;**                 /________/       /________________/**                  pTabList              pWhere*/void sqlite3DeleteFrom(  Parse *pParse,         /* The parser context */  SrcList *pTabList,     /* The table from which we should delete things */  Expr *pWhere           /* The WHERE clause.  May be null */){  Vdbe *v;               /* The virtual database engine */  Table *pTab;           /* The table from which records will be deleted */  const char *zDb;       /* Name of database holding pTab */  int end, addr = 0;     /* A couple addresses of generated code */  int i;                 /* Loop counter */  WhereInfo *pWInfo;     /* Information about the WHERE clause */  Index *pIdx;           /* For looping over indices of the table */  int iCur;              /* VDBE Cursor number for pTab */  sqlite3 *db;           /* Main database structure */  AuthContext sContext;  /* Authorization context */  int oldIdx = -1;       /* Cursor for the OLD table of AFTER triggers */  NameContext sNC;       /* Name context to resolve expressions in */  int iDb;               /* Database number */  int memCnt = 0;        /* Memory cell used for change counting */#ifndef SQLITE_OMIT_TRIGGER  int isView;                  /* True if attempting to delete from a view */  int triggers_exist = 0;      /* True if any triggers exist */#endif  sContext.pParse = 0;  if( pParse->nErr || sqlite3MallocFailed() ){    goto delete_from_cleanup;  }  db = pParse->db;  assert( pTabList->nSrc==1 );  /* Locate the table which we want to delete.  This table has to be  ** put in an SrcList structure because some of the subroutines we  ** will be calling are designed to work with multiple tables and expect  ** an SrcList* parameter instead of just a Table* parameter.  */  pTab = sqlite3SrcListLookup(pParse, pTabList);  if( pTab==0 )  goto delete_from_cleanup;  /* Figure out if we have any triggers and if the table being  ** deleted from is a view  */#ifndef SQLITE_OMIT_TRIGGER  triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0);  isView = pTab->pSelect!=0;#else# define triggers_exist 0# define isView 0#endif#ifdef SQLITE_OMIT_VIEW# undef isView# define isView 0#endif  if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){    goto delete_from_cleanup;  }  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);  assert( iDb<db->nDb );  zDb = db->aDb[iDb].zName;  if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){    goto delete_from_cleanup;  }  /* If pTab is really a view, make sure it has been initialized.  */  if( sqlite3ViewGetColumnNames(pParse, pTab) ){    goto delete_from_cleanup;  }  /* Allocate a cursor used to store the old.* data for a trigger.  */  if( triggers_exist ){     oldIdx = pParse->nTab++;  }  /* Resolve the column names in the WHERE clause.  */  assert( pTabList->nSrc==1 );  iCur = pTabList->a[0].iCursor = pParse->nTab++;  memset(&sNC, 0, sizeof(sNC));  sNC.pParse = pParse;  sNC.pSrcList = pTabList;  if( sqlite3ExprResolveNames(&sNC, pWhere) ){    goto delete_from_cleanup;  }  /* Start the view context  */  if( isView ){    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);  }//.........这里部分代码省略.........
开发者ID:3rdexp,项目名称:jezzitest,代码行数:101,


示例29: openDatabase

/*** This routine does the work of opening a database on behalf of** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"  ** is UTF-8 encoded.*/static int openDatabase(  const char *zFilename, /* Database filename UTF-8 encoded */  sqlite3 **ppDb         /* OUT: Returned database handle */){  sqlite3 *db;  int rc;  CollSeq *pColl;  assert( !sqlite3MallocFailed() );  /* Allocate the sqlite data structure */  db = sqliteMalloc( sizeof(sqlite3) );  if( db==0 ) goto opendb_out;  db->priorNewRowid = 0;  db->magic = SQLITE_MAGIC_BUSY;  db->nDb = 2;  db->aDb = db->aDbStatic;  db->autoCommit = 1;  db->flags |= SQLITE_ShortColNames;  sqlite3HashInit(&db->aFunc, SQLITE_HASH_STRING, 0);  sqlite3HashInit(&db->aCollSeq, SQLITE_HASH_STRING, 0);  /* Add the default collation sequence BINARY. BINARY works for both UTF-8  ** and UTF-16, so add a version for each to avoid any unnecessary  ** conversions. The only error that can occur here is a malloc() failure.  */  if( createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc) ||      createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc) ||      createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc) ||      (db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0   ){    assert( sqlite3MallocFailed() );    db->magic = SQLITE_MAGIC_CLOSED;    goto opendb_out;  }  /* Also add a UTF-8 case-insensitive collation sequence. */  createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc);  /* Set flags on the built-in collating sequences */  db->pDfltColl->type = SQLITE_COLL_BINARY;  pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0);  if( pColl ){    pColl->type = SQLITE_COLL_NOCASE;  }  /* Open the backend database driver */  rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);  if( rc!=SQLITE_OK ){    sqlite3Error(db, rc, 0);    db->magic = SQLITE_MAGIC_CLOSED;    goto opendb_out;  }#ifndef SQLITE_OMIT_PARSER  db->aDb[0].pSchema = sqlite3SchemaGet(db->aDb[0].pBt);  db->aDb[1].pSchema = sqlite3SchemaGet(0);#endif  if( db->aDb[0].pSchema ){    ENC(db) = SQLITE_UTF8;  }  /* The default safety_level for the main database is 'full'; for the temp  ** database it is 'NONE'. This matches the pager layer defaults.    */  db->aDb[0].zName = "main";  db->aDb[0].safety_level = 3;#ifndef SQLITE_OMIT_TEMPDB  db->aDb[1].zName = "temp";  db->aDb[1].safety_level = 1;#endif  /* Register all built-in functions, but do not attempt to read the  ** database schema yet. This is delayed until the first time the database  ** is accessed.  */  if( !sqlite3MallocFailed() ){    sqlite3RegisterBuiltinFunctions(db);    sqlite3Error(db, SQLITE_OK, 0);  }  db->magic = SQLITE_MAGIC_OPEN;opendb_out:  if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){    sqlite3_close(db);    db = 0;  }  *ppDb = db;  return sqlite3ApiExit(0, rc);}
开发者ID:BackupTheBerlios,项目名称:sqlitepp-svn,代码行数:95,



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


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