void UnqliteCursor::remove() { int rc = unqlite_kv_cursor_delete_entry(this->_cursor); if (rc != UNQLITE_OK) throw UnqliteException(rc, this->_db); }
/* * Drop a collection from the KV storage engine and the underlying * unqlite VM. */ UNQLITE_PRIVATE int unqliteDropCollection(unqlite_col *pCol) { unqlite_vm *pVm = pCol->pVm; jx9_int64 nId; int rc; /* Reset the cursor */ unqlite_kv_cursor_reset(pCol->pCursor); /* Seek the cursor to the desired location */ rc = unqlite_kv_cursor_seek(pCol->pCursor, SyStringData(&pCol->sName),SyStringLength(&pCol->sName), UNQLITE_CURSOR_MATCH_EXACT ); if( rc == UNQLITE_OK ){ /* Remove the record from the storage engine */ rc = unqlite_kv_cursor_delete_entry(pCol->pCursor); } if( rc != UNQLITE_OK ){ unqliteGenErrorFormat(pCol->pVm->pDb, "Cannot remove collection '%z' due to a read-only Key/Value storage engine", &pCol->sName ); return rc; } /* Drop collection records */ for( nId = 0 ; nId < pCol->nLastid ; ++nId ){ unqliteCollectionDropRecord(pCol,nId,0,0); } /* Cleanup */ CollectionCacheRelease(pCol); SyBlobRelease(&pCol->sHeader); SyBlobRelease(&pCol->sWorker); SyMemBackendFree(&pVm->sAlloc,(void *)SyStringData(&pCol->sName)); unqliteReleaseCursor(pVm->pDb,pCol->pCursor); /* Unlink */ if( pCol->pPrevCol ){ pCol->pPrevCol->pNextCol = pCol->pNextCol; }else{ sxu32 iBucket = pCol->nHash & (pVm->iColSize - 1); pVm->apCol[iBucket] = pCol->pNextCol; } if( pCol->pNextCol ){ pCol->pNextCol->pPrevCol = pCol->pPrevCol; } MACRO_LD_REMOVE(pVm->pCol,pCol); pVm->iCol--; SyMemBackendPoolFree(&pVm->sAlloc,pCol); return UNQLITE_OK; }
/* * Drop a record from a given collection. */ UNQLITE_PRIVATE int unqliteCollectionDropRecord( unqlite_col *pCol, /* Target collection */ jx9_int64 nId, /* Unique ID of the record to be droped */ int wr_header, /* True to alter collection header */ int log_err /* True to log error */ ) { SyBlob *pWorker = &pCol->sWorker; int rc; /* Reset the working buffer */ SyBlobReset(pWorker); /* Prepare the unique ID for this record */ SyBlobFormat(pWorker,"%z_%qd",&pCol->sName,nId); /* Reset the cursor */ unqlite_kv_cursor_reset(pCol->pCursor); /* Seek the cursor to the desired location */ rc = unqlite_kv_cursor_seek(pCol->pCursor, SyBlobData(pWorker),SyBlobLength(pWorker), UNQLITE_CURSOR_MATCH_EXACT ); if( rc != UNQLITE_OK ){ return rc; } /* Remove the record from the storage engine */ rc = unqlite_kv_cursor_delete_entry(pCol->pCursor); /* Finally, Remove the record from the cache */ unqliteCollectionCacheRemoveRecord(pCol,nId); if( rc == UNQLITE_OK ){ pCol->nTotRec--; if( wr_header ){ /* Relect in the collection header */ rc = CollectionSetHeader(0,pCol,-1,pCol->nTotRec,0); } }else if( rc == UNQLITE_NOTIMPLEMENTED ){ if( log_err ){ unqliteGenErrorFormat(pCol->pVm->pDb, "Cannot delete record from collection '%z' due to a read-only Key/Value storage engine", &pCol->sName ); } } return rc; }