c#

位置:IT落伍者 >> c# >> 浏览文章

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


发布日期:2020年06月12日
 
C#使用BerkeleyDB操作简介[3]

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());

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

               

上一篇:ADO.NET实用技巧两则

下一篇:C#使用BerkeleyDB操作简介[2]