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

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

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

   if (keyBufferLength < keySize)
   {
   keyStreamSetLength(keySize);
   key = DbEntryOut(keyStreamGetBuffer());
   }
   if (dataBufferLength < dataSize)
   {
   dataStreamSetLength(dataSize);
   data = DbEntryOut(dataStreamGetBuffer());
   }
   continue;
   case ReadStatusSuccess:
   dataStreamPosition = ;
   dataStreamSetLength(dataSize);
   cust = (IPut)formatterDeserialize(dataStream);
   return true;
   default:
   return false;
   }
   } while (true);
   }
   }

  調用方法

  首先要有一個寫入的實體類必須可以序列化並且實現IPut接口

   [Serializable()]
   class Item : IPut
   {
   public string Name { get; set; }
   public string Text { get; set; }
   public int ID { get; set; }
  
   public override string ToString()
   {
   return stringFormat(ID:{} Key:{} ID Name);
   }
  
   public string Key
   {
   get { return Name; }
   }
   }

  操作

   using (BDBManager manager = new BDBManager(db dbdat))
   {
   bool success = managerSet(new Item() { ID = Name = TestText = });
   ConsoleWriteLine(stringFormat(set is {} success));
   }
  
   using (BDBManager manager = new BDBManager(db dbdat))
   {
   IPut put = new Item() { Name = Test };
   bool success = managerGet(ref put);
   ConsoleWriteLine(stringFormat(read is {}item : {} success putToString()));
   }
  
   using (BDBManager manager = new BDBManager(db dbdat))
   {
   IPut put = new Item() { Name = Test };
   bool success = managerRemove(put);
   ConsoleWriteLine(stringFormat(remove is {}item : {} success putToString()));
   }
  
   using (BDBManager manager = new BDBManager(db dbdat))
   {
   List<IPut> list = managerFind();
   foreach (var item in list)
   {
   ConsoleWriteLine(itemToString());
   }
   }
   ConsoleWriteLine(end);
   ConsoleReadKey();

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


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