/* ** This function is invoked by the vdbe to call the xDestroy method ** of the virtual table named zTab in database iDb. This occurs ** when a DROP TABLE is mentioned. ** ** This call is a no-op if zTab is not a virtual table. */ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ int rc = SQLITE_OK; Table *pTab; pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); if( pTab!=0 && ALWAYS(pTab->pVTable!=0) ){ VTable *p; int (*xDestroy)(sqlite3_vtab *); for(p=pTab->pVTable; p; p=p->pNext){ assert( p->pVtab ); if( p->pVtab->nRef>0 ){ return SQLITE_LOCKED; } } p = vtabDisconnectAll(db, pTab); xDestroy = p->pMod->pModule->xDestroy; assert( xDestroy!=0 ); /* Checked before the virtual table is created */ rc = xDestroy(p->pVtab); /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ if( rc==SQLITE_OK ){ assert( pTab->pVTable==p && p->pNext==0 ); p->pVtab = 0; pTab->pVTable = 0; sqlite3VtabUnlock(p); } } return rc; }
/* Walk the tree can call xDestroy on each node */ static void closureAvlDestroy(closure_avl *p, void (*xDestroy)(closure_avl*)){ if( p ){ closureAvlDestroy(p->pBefore, xDestroy); closureAvlDestroy(p->pAfter, xDestroy); xDestroy(p); } }
static xkern_return_t bidClose( XObj self) { XObj myProtl = xMyProtl(self); PState *ps = (PState *)myProtl->state; SState *ss = (SState *)self->state; XObj lls; Part_s part; xTrace0(bidp, TR_MAJOR_EVENTS, "bid Close"); lls = xGetDown(self, 0); if ( mapRemoveBinding(ps->activeMap, self->binding) == XK_FAILURE ) { xAssert(0); return XK_FAILURE; } partInit(&part, 1); partPush(part, &ss->peer, sizeof(ss->peer)); if ( xOpenDisable(myProtl, myProtl, xGetDown(myProtl, BID_CTL_I), &part) == XK_FAILURE ) { xTrace0(bidp, TR_ERRORS, "bidClose couldn't openDisable cntrl protl"); } xAssert(xIsSession(lls)); xClose(lls); xDestroy(self); return XK_SUCCESS; }
/* ** The actual function that does the work of creating a new module. ** This function implements the sqlite3_create_module() and ** sqlite3_create_module_v2() interfaces. */ static int createModule( sqlite3 *db, /* Database in which module is registered */ const char *zName, /* Name assigned to this module */ const sqlite3_module *pModule, /* The definition of the module */ void *pAux, /* Context pointer for xCreate/xConnect */ void (*xDestroy)(void *) /* Module destructor function */ ){ int rc = SQLITE_OK; sqlite3_mutex_enter(db->mutex); if( sqlite3HashFind(&db->aModule, zName) ){ rc = SQLITE_MISUSE_BKPT; }else{ (void)sqlite3VtabCreateModule(db, zName, pModule, pAux, xDestroy); } rc = sqlite3ApiExit(db, rc); if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux); sqlite3_mutex_leave(db->mutex); return rc; }
/* ** The actual function that does the work of creating a new module. ** This function implements the sqlite3_create_module() and ** sqlite3_create_module_v2() interfaces. */ static int createModule( sqlite3 *db, /* Database in which module is registered */ const char *zName, /* Name assigned to this module */ const sqlite3_module *pModule, /* The definition of the module */ void *pAux, /* Context pointer for xCreate/xConnect */ void (*xDestroy)(void *) /* Module destructor function */ ){ int rc = SQLITE_OK; int nName; sqlite3_mutex_enter(db->mutex); nName = sqlite3Strlen30(zName); if( sqlite3HashFind(&db->aModule, zName) ){ rc = SQLITE_MISUSE_BKPT; }else{ Module *pMod; pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); if( pMod ){ Module *pDel; char *zCopy = (char *)(&pMod[1]); memcpy(zCopy, zName, nName+1); pMod->zName = zCopy; pMod->pModule = pModule; pMod->pAux = pAux; pMod->xDestroy = xDestroy; pMod->pEpoTab = 0; pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod); assert( pDel==0 || pDel==pMod ); if( pDel ){ db->mallocFailed = 1; sqlite3DbFree(db, pDel); } } } rc = sqlite3ApiExit(db, rc); if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux); sqlite3_mutex_leave(db->mutex); return rc; }
/* ** This function is invoked by the vdbe to call the xDestroy method ** of the virtual table named zTab in database iDb. This occurs ** when a DROP TABLE is mentioned. ** ** This call is a no-op if zTab is not a virtual table. */ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab) { int rc = SQLITE_OK; Table *pTab; pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); assert(pTab); if( pTab->pVtab ){ int (*xDestroy)(sqlite3_vtab *pVTab) = pTab->pMod->pModule->xDestroy; rc = sqlite3SafetyOff(db); assert( rc==SQLITE_OK ); if( xDestroy ){ rc = xDestroy(pTab->pVtab); } sqlite3SafetyOn(db); if( rc==SQLITE_OK ){ pTab->pVtab = 0; } } return rc; }
/* ** The actual function that does the work of creating a new module. ** This function implements the sqlite3_create_module() and ** sqlite3_create_module_v2() interfaces. */ static int createModule( sqlite3 *db, /* Database in which module is registered */ const char *zName, /* Name assigned to this module */ const sqlite3_module *pModule, /* The definition of the module */ void *pAux, /* Context pointer for xCreate/xConnect */ void (*xDestroy)(void *) /* Module destructor function */ ){ int rc, nName; Module *pMod; sqlite3_mutex_enter(db->mutex); nName = sqlite3Strlen30(zName); pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1); if( pMod ){ Module *pDel; char *zCopy = (char *)(&pMod[1]); memcpy(zCopy, zName, nName+1); pMod->zName = zCopy; pMod->pModule = pModule; pMod->pAux = pAux; pMod->xDestroy = xDestroy; pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod); if( pDel && pDel->xDestroy ){ pDel->xDestroy(pDel->pAux); } sqlite3DbFree(db, pDel); if( pDel==pMod ){ db->mallocFailed = 1; } sqlite3ResetInternalSchema(db, 0); }else if( xDestroy ){ xDestroy(pAux); } rc = sqlite3ApiExit(db, SQLITE_OK); sqlite3_mutex_leave(db->mutex); return rc; }
static XObj bidNewSessn( XObj self, XObj hlpRcv, XObj hlpType, ActiveKey *key, Path path) { XObj s, llpCtl; PState *ps = (PState *)self->state; SState *ss; Part_s part; IPhost peer; if ( xControl(key->lls, GETPEERHOST, (char *)&peer, sizeof(IPhost)) < (int)sizeof(IPhost) ) { return ERR_XOBJ; } s = xCreateSessn(getSessnFuncs, hlpRcv, hlpType, self, 1, &key->lls, path); if ( s == ERR_XOBJ ) { return ERR_XOBJ; } llpCtl = xGetDown(self, BID_CTL_I); partInit(&part, 1); partPush(part, &peer, sizeof(peer)); if ( ! (ss = pathAlloc(path, sizeof(SState))) ) { xTraceP0(self, TR_ERRORS, "allocation error"); return ERR_XOBJ; } ss->hdr.hlpNum = key->hlpNum; ss->hdr.srcBid = ps->myBid; #if BID_CHECK_CLUSTERID ss->hdr.srcCluster = ps->myCluster; #endif /* BID_CHECK_CLUSTERID */ ss->peer = peer; s->state = ss; if ( mapBind(ps->activeMap, key, s, &s->binding) != XK_SUCCESS ) { xDestroy(s); return ERR_XOBJ; } /* * Register this protocol's interest in this host with the control protocol */ if ( xOpenEnable(self, self, llpCtl, &part) == XK_SUCCESS ) { BidctlBootMsg msg; msg.h = peer; msg.id = 0; if ( xControl(llpCtl, BIDCTL_GET_PEER_BID, (char *)&msg, sizeof(msg)) == (int)sizeof(msg) ) { ss->hdr.dstBid = msg.id; if ( msg.id != 0 ) { activateSessn(s); } return s; } else { xTrace1(bidp, TR_ERRORS, "bid CreateSessn: couldn't get peer BID for %s", ipHostStr(&peer)); } partInit(&part, 1); partPush(part, &peer, sizeof(peer)); xOpenDisable(self, self, llpCtl, &part); } else { xTrace0(bidp, TR_ERRORS, "bidCreateSessn couldn't openEnable BIDCTL"); } xDestroy(s); return ERR_XOBJ; }