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

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

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

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;
   }
   }
   }

  遍歷 

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;
   }
  
   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:
   if (keyBufferLength < keySize)
   {
   keyStreamSetLength(keySize);
   key = DbEntryOut(keyStreamGetBuffer());

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


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