熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#使用BerkeleyDB操作簡介[6]

2022-06-13   來源: .NET編程 

   public bool Remove(IPut put)
   {
   Reset();
  
   keyStreamPosition = ;
   formatterSerialize(keyStream putKey);
   DbEntry key = DbEntryInOut(keyStreamGetBuffer() (int)keyStreamPosition);
   DeleteStatus status = btreeDelete(txn ref key);
   switch (status)
   {
   case DeleteStatusNotFound:
   case DeleteStatusSuccess:
   return true;
   case DeleteStatusKeyEmpty:
   default:
   return false;
   }
   }
  
   public void Dispose()
   {
   if (!iscomit)
   Commit();
   dbClose();
   dbClose();
   }
  
   private void Reset()
   {
   iscomit = false;
   }
  
   private void Init()
   {
   env = new Env(EnvCreateFlagsNone);
   EnvOpenFlags envFlags =
   EnvOpenFlagsCreate |
   EnvOpenFlagsInitLock |
   EnvOpenFlagsInitLog |
   EnvOpenFlagsInitMPool |
   EnvOpenFlagsInitTxn |
   EnvOpenFlagsRecover;
   envOpen(directory envFlags );
   txn = envTxnBegin(null TxnBeginFlagsNone);
   db = envCreateDatabase(DbCreateFlagsNone);
   btree = (DbBTree)dbOpen(txn dbName null DbTypeBTree DbOpenFlagsCreate );
   }
  
   private void StreamInit()
   {
   formatter = new BinaryFormatter();
   keyStream = new MemoryStream();
   dataStream = new MemoryStream();
   }
  
   private bool GetNextRecord(DbBTreeCursor cursor ref IPut cust)
   {
   ReadStatus status;
   keyStreamSetLength(keyStreamCapacity);
   dataStreamSetLength(dataStreamCapacity);
   DbEntry key = DbEntryOut(keyStreamGetBuffer());
   DbEntry data = DbEntryOut(dataStreamGetBuffer());
   do
   {
   status = cursorGet(ref key ref data DbFileCursorGetModeNext DbFileCursorReadFlagsNone);
   switch (status)
   {
   case ReadStatusNotFound: return false;
   case ReadStatusKeyEmpty: continue; // skip deleted records
   case ReadStatusBufferSmall:

[]  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/14798.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.