Ejemplo n.º 1
0
        public void Put(byte[] key, byte[] value, PutOption option = PutOption.Unspecific)
        {
            IntPtr keyPtr   = Marshal.AllocHGlobal(key.Length);
            IntPtr valuePtr = Marshal.AllocHGlobal(value.Length);

            try
            {
                Marshal.Copy(key, 0, keyPtr, key.Length);
                Marshal.Copy(value, 0, valuePtr, value.Length);


                DbValue dbKey   = new DbValue(keyPtr, key.Length);
                DbValue dbValue = new DbValue(valuePtr, value.Length);
                Dbi.Put(_tran._txnPtr, _dbi, dbKey, dbValue, option);
            }
            finally
            {
                Marshal.FreeHGlobal(keyPtr);
                Marshal.FreeHGlobal(valuePtr);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Open a table in the environment.
 ///
 /// A table handle denotes the name and parameters of a table, independently
 /// of whether such a table exists. The table handle may be discarded by
 /// calling mdbx_dbi_close(). The old table handle is returned if the table
 /// was already open. The handle may only be closed once.
 ///
 /// The table handle will be private to the current transaction until
 /// the transaction is successfully committed. If the transaction is
 /// aborted the handle will be closed automatically.
 /// After a successful commit the handle will reside in the shared
 /// environment, and may be used by other transactions.
 ///
 /// This function must not be called from multiple concurrent
 /// transactions in the same process. A transaction that uses
 /// this function must finish (either commit or abort) before
 /// any other transaction in the process may use this function.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="option"></param>
 /// <returns></returns>
 public MdbxDatabase OpenDatabase(string name = null, DatabaseOption option = DatabaseOption.Unspecific)
 {
     return(new MdbxDatabase(_env, this, Dbi.Open(_txnPtr, name, option)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Drop this database
 /// </summary>
 public void Drop()
 {
     Dbi.Drop(_tran._txnPtr, _dbi, true);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// delete all keys in this database to empty it
 /// </summary>
 public void Empty()
 {
     Dbi.Drop(_tran._txnPtr, _dbi, false);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Close a database handle. Normally unnecessary.
 /// Closing a database handle is not necessary, but lets mdbx_dbi_open()
 /// reuse the handle value.  Usually it's better to set a bigger
 /// mdbx_env_set_maxdbs(), unless that value would be large.
 /// </summary>
 public void Close()
 {
     Dbi.Close(_env._envPtr, _dbi);
 }