Exemple #1
0
/*
** 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 **NotUsed){
  InitData *pData = (InitData*)pInit;
  sqlite3 *db = pData->db;
  int iDb = pData->iDb;

  assert( argc==3 );
  UNUSED_PARAMETER2(NotUsed, argc);
  assert( sqlite3_mutex_held(db->mutex) );
  DbClearProperty(db, iDb, DB_Empty);
  if( db->mallocFailed ){
    corruptSchema(pData, argv[0], 0);
    return 1;
  }

  assert( iDb>=0 && iDb<db->nDb );
  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */
  if( argv[1]==0 ){
    corruptSchema(pData, argv[0], 0);
  }else if( sqlite3_strnicmp(argv[2],"create ",7)==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.
    */
    int rc;
    u8 saved_iDb = db->init.iDb;
    sqlite3_stmt *pStmt;
    TESTONLY(int rcp);            /* Return code from sqlite3_prepare() */

    assert( db->init.busy );
    db->init.iDb = iDb;
    db->init.newTnum = sqlite3Atoi(argv[1]);
    db->init.orphanTrigger = 0;
    TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
    rc = db->errCode;
    assert( (rc&0xFF)==(rcp&0xFF) );
    db->init.iDb = saved_iDb;
    assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
    if( SQLITE_OK!=rc ){
      if( db->init.orphanTrigger ){
        assert( iDb==1 );
      }else{
        pData->rc = rc;
        if( rc==SQLITE_NOMEM ){
          sqlite3OomFault(db);
        }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
          corruptSchema(pData, argv[0], sqlite3_errmsg(db));
        }
      }
    }
    sqlite3_finalize(pStmt);
  }else if( argv[0]==0 || (argv[2]!=0 && argv[2][0]!=0) ){
Exemple #2
0
int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed) {
    InitData *pData = (InitData*)pInit;
    sqlite3 *db = pData->db;
    int iDb = pData->iDb;

    assert( argc==3 );
    UNUSED_PARAMETER2(NotUsed, argc);
    assert( sqlite3_mutex_held(db->mutex) );
    DbClearProperty(db, iDb, DB_Empty);
    if( db->mallocFailed ) {
        corruptSchema(pData, argv[0], 0);
        return 1;
    }

    assert( iDb>=0 && iDb<db->nDb );
    if( argv==0 ) return 0;
    if( argv[1]==0 ) {
        corruptSchema(pData, argv[0], 0);
    } else if( argv[2] && argv[2][0] ) {
        int rc;
        sqlite3_stmt *pStmt;
        TESTONLY(int rcp);

        assert( db->init.busy );
        db->init.iDb = iDb;
        db->init.newTnum = sqlite3Atoi(argv[1]);
        db->init.orphanTrigger = 0;
        TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
        rc = db->errCode;
        assert( (rc&0xFF)==(rcp&0xFF) );
        db->init.iDb = 0;
        if( SQLITE_OK!=rc ) {
            if( db->init.orphanTrigger ) {
                assert( iDb==1 );
            } else {
                pData->rc = rc;
                if( rc==SQLITE_NOMEM ) {
                    db->mallocFailed = 1;
                } else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ) {
                    corruptSchema(pData, argv[0], sqlite3_errmsg(db));
                }
            }
        }
        sqlite3_finalize(pStmt);
    } else if( argv[0]==0 ) {