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

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

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

   keyStreamPosition = ;
   formatterSerialize(keyStream putKey);
   DbEntry key = DbEntryInOut(keyStreamGetBuffer() (int)keyStreamPosition);
   dataStreamPosition = ;
   formatterSerialize(dataStream put);
   DbEntry data = DbEntryInOut(dataStreamGetBuffer() (int)dataStreamPosition);
   WriteStatus status = btreePut(txn ref key ref data);
   switch (status)
   {
   case WriteStatusSuccess:
   return true;
   case WriteStatusNotFound:
   case WriteStatusKeyExist:
   default:
   return false;
   }
   }
  
   private bool iscomit = false;
   public void Commit()
   {
   txnCommit(TxnCommitModeNone);
   iscomit = true;
   }
  
   public List<IPut> Find()
   {
   List<IPut> custList = new List<IPut>();
   using (DbBTreeCursor cursor = btreeOpenCursor(txn DbFileCursorCreateFlagsNone))
   {
   IPut cust = null;
   while (GetNextRecord(cursor ref cust))
   custListAdd(cust);
   }
   return custList;
   }
  
   public bool Get(ref IPut put)
   {
   keyStreamPosition = ;
   formatterSerialize(keyStream putKey);
   DbEntry key = DbEntryInOut(keyStreamGetBuffer() (int)keyStreamPosition);
   dataStreamSetLength(dataStreamCapacity);
   DbEntry data = DbEntryOut(dataStreamGetBuffer());
  
   while (true)
   {
   ReadStatus status = btreeGet(txn ref key ref data DbFileReadFlagsNone);
  
   switch (status)
   {
   case ReadStatusSuccess:
   dataStreamPosition = ;
   dataStreamSetLength(dataSize);
   put = (IPut)formatterDeserialize(dataStream);
   return true;
   case ReadStatusBufferSmall: //擴容
   if (keyBufferLength < keySize)
   {
   keyStreamSetLength(keySize);
   key = DbEntryOut(keyStreamGetBuffer());
   }
   if (dataBufferLength < dataSize)
   {
   dataStreamSetLength(dataSize);
   data = DbEntryOut(dataStreamGetBuffer());
   }
   continue;
   case ReadStatusNotFound:
   case ReadStatusKeyEmpty:
   default:
   return false;
   }
   }
   }

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


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