Introduction to C # using BERKELEYDB operations

Source: Internet
Author: User
Tags versions zip

Berkeley DB is a long history of embedded database system, mainly used in Unix/linux operating system. The Berkeley DB Store is a Key/value key value pair that can be understood as a super hash table on a hard disk. It can manage 256TB of data and can support thousands of concurrent accesses. Currently Berkeley DB has C + + and Java versions. So, we need an intermediate conversion of access, and someone has already published the C # API. You can find it from Berkeley DB for. NET, and the latest version is version 0.95, which supports versions 4.3 and 4.5. This article will be the 4.5 version of the example. The BerkeleyDB version can be downloaded in http://www.oracle.com/technology/products/berkeley-db/index.html and the current version is 4.7. 4.5 C + + version of Berkeley DB can be downloaded here in http://www.oracle.com/technology/software/products/berkeley-db/db/index.html.

by birdshover@ Blog Park http://www.cnblogs.com/birdshover/

Download to Berkeley DB for. NET, you can start to use it after the api--libdb-dotnet_0_95.zip. First find Libdb_dotnet45.dll in the Libdb-dotnet_0_95.zip uncompressed Bin directory, which is the DLL used by version 4.5. New project, referencing this DLL. Note that compiling your own source code may be compiled, however, mainly because of inconsistent visibility of some of the delegate and delegate parameters. Use the class or struct of those parameters to public.

BerkeleyDB database operations require the help of dbbtree classes. Therefore, you need to get an instance of Dbbtree, but the Dbbtree class has dependencies on several other classes and must rely on several other classes to create.

The following code is a procedure for initializing a Dbbtree instance.

/// <summary>
/// 数据库目录
/// </summary>
private string directory;
/// <summary>
/// 数据库文件名
/// </summary>
private string dbName;

private DbBTree btree;
private Txn txn;
private Db db;
private Env env;
/// <summary>
/// 初始化
/// </summary>
private void Init()
{
env = new Env(EnvCreateFlags.None);
Env.OpenFlags envFlags =
Env.OpenFlags.Create |
Env.OpenFlags.InitLock |
Env.OpenFlags.InitLog |
Env.OpenFlags.InitMPool |
Env.OpenFlags.InitTxn |
Env.OpenFlags.Recover;
env.Open(directory, envFlags, 0);
txn = env.TxnBegin(null, Txn.BeginFlags.None);
db = env.CreateDatabase(DbCreateFlags.None);
btree = (DbBTree)db.Open(txn, dbName, null, DbType.BTree, Db.OpenFlags.Create, 0);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.