c#

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

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


发布日期:2020年02月18日
 
C#使用BerkeleyDB操作简介[6]

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:

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

               

上一篇:C#使用BerkeleyDB操作简介[4]

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