Example #1
0
 /// <summary>
 /// Creates a new Cursor in a Transaction
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_cursor_create function.
 /// <br />
 /// Creates a new Database Cursor. Cursors can be used to traverse
 /// the Database from start to end or vice versa. Cursors can also
 /// be used to insert, delete or search Database items.
 ///
 /// A newly created Cursor does not point to any item in the Database.
 ///
 /// The application should close all Database Cursors before closing
 /// the Database.
 /// </remarks>
 /// <param name="db">The Database object</param>
 /// <param name="txn">The optional Transaction</param>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///   <item><see cref="HamConst.HAM_OUT_OF_MEMORY"/>
 ///     if the new structure could not be allocated</item>
 ///   </list>
 /// </exception>
 public void Create(Database db, Transaction txn)
 {
     this.db = db;
       lock (this.db) {
     int st = NativeMethods.CursorCreate(out handle, db.Handle,
         txn != null ? txn.Handle : IntPtr.Zero, 0);
     if (st != 0)
       throw new DatabaseException(st);
     db.AddCursor(this);
       }
 }
Example #2
0
 /// <summary>
 /// Constructor which creates a new Cursor in a Transaction
 /// </summary>
 public Cursor(Database db, Transaction txn)
 {
     Create(db, txn);
 }
Example #3
0
 /// <summary>
 /// Inserts a Database item
 /// </summary>
 /// <remarks>
 /// This is an overloaded function for 
 ///   Database.Insert(txn, key, record, 0).
 /// </remarks>
 public void Insert(Transaction txn, byte[] key, byte[] record)
 {
     Insert(txn, key, record, 0);
 }
Example #4
0
 /// <summary>
 /// Inserts a Database Item
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_insert function.
 /// <br />
 /// This function inserts a key/record pair as a new Database item.
 /// <br />
 /// If the key already exists in the Database, error code 
 /// <see cref="HamConst.HAM_DUPLICATE_KEY" /> is thrown.
 /// <br />
 /// If you wish to overwrite an existing entry specify the flag
 /// <see cref="HamConst.HAM_OVERWRITE"/>
 /// <br />
 /// If you wish to insert a duplicate key specify the flag 
 /// <see cref="HamConst.HAM_DUPLICATE" />. (Note that 
 /// the Database has to be created with the flag 
 /// <see cref="HamConst.HAM_ENABLE_DUPLICATES" /> in order
 /// to use duplicate keys.) 
 /// The duplicate key is inserted after all other duplicate keys (see
 /// <see cref="HamConst.HAM_DUPLICATE_INSERT_LAST" />).
 /// </remarks>
 /// <param name="txn">An optional Transaction object</param>
 /// <param name="key">The key of the new item</param>
 /// <param name="record">The record of the new item</param>
 /// <param name="flags">Optional flags for this operation. Possible
 /// flags are:
 /// <list type="bullet">
 ///   <item><see cref="HamConst.HAM_OVERWRITE"/> 
 ///         If the key already exists, the record is overwritten. 
 ///         Otherwise, the key is inserted.</item>
 ///   <item><see cref="HamConst.HAM_DUPLICATE"/> 
 ///         If the key already exists, a duplicate key is inserted. 
 ///         The key is inserted before the already existing duplicates.
 ///         </item>
 /// </list></param>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///     <item><see cref="HamConst.HAM_INV_PARAMETER"/>
 ///         if the flags HamConst.HAM_DUPLICATE <b>AND</b>
 ///         HamConst.HAM_OVERWRITE were specified, or if 
 ///         HamConst.HAM_DUPLICATE was specified but the Database
 ///         was not created with HamConst.HAM_ENABLE_DUPLICATES</item>
 ///     <item><see cref="HamConst.HAM_DB_READ_ONLY"/>
 ///         if you tried to insert a key in a read-only Database</item>
 ///     <item><see cref="HamConst.HAM_INV_KEYSIZE"/>
 ///         if key size is larger than the key size parameter 
 ///         specified for Database.Create, and variable
 ///         length keys are disabled (see 
 ///         <see cref="HamConst.HAM_DISABLE_VAR_KEYLEN" />).</item>
 ///   </list>
 /// </exception>
 public void Insert(Transaction txn, byte[] key, byte[] record, int flags)
 {
     int st;
     lock (this) {
         st = NativeMethods.Insert(handle, txn != null ? txn.Handle : IntPtr.Zero,
                                     key, record, flags);
     }
     if (st!=0)
         throw new DatabaseException(st);
 }
Example #5
0
 /// <summary>
 /// Returns the number of keys in this Database
 /// </summary>
 public Int64 GetKeyCount(Transaction txn)
 {
     return GetKeyCount(txn, 0);
 }
Example #6
0
 /// <summary>
 /// Returns the number of keys in this Database
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_get_key_count function.
 /// <br />
 /// You can specify HAM_SKIP_DUPLICATES if you do now want
 /// to include any duplicates in the count; if all you're after is
 /// a quick estimate, you can specify the flag HAM_FAST_ESTIMATE
 /// (which implies HAM_SKIP_DUPLICATES), which will improve the
 /// execution speed of this operation significantly.
 /// </remarks>
 public Int64 GetKeyCount(Transaction txn, int flags)
 {
     int st;
     Int64 count=0;
     lock (this)
     {
         st = NativeMethods.GetKeyCount(handle, txn != null ? txn.Handle : IntPtr.Zero,
                                     flags, out count);
     }
     if (st != 0)
         throw new DatabaseException(st);
     return count;
 }
Example #7
0
 /// <summary>
 /// Searches an item in the Database, returns the record
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_find function.<br />
 /// <br />
 /// This function searches the Database for a key. If the key
 /// is found, the method will return the record of this item.
 /// <br />
 /// Database.Find can not search for duplicate keys. If the
 /// key has multiple duplicates, only the first duplicate is returned.
 /// </remarks>
 /// <param name="txn">The optional Transaction</param>
 /// <param name="key">The key of the item</param>
 /// <returns>The record of the item</returns>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///     <item><see cref="HamConst.HAM_KEY_NOT_FOUND"/>
 ///         if the item was not found</item>
 ///   </list>
 /// </exception>
 public byte[] Find(Transaction txn, byte[] key)
 {
     byte[] r;
     lock (this) {
         r = NativeMethods.Find(handle, txn != null ? txn.Handle : IntPtr.Zero, key, 0);
     }
     if (r == null)
         throw new DatabaseException(GetLastError());
     return r;
 }
Example #8
0
 /// <summary>
 /// Erases a Database Item
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_erase function.
 /// <br />
 /// This function erases a Database item. If the item with the 
 /// specified key does not exist in the Database, error code 
 /// <see cref="HamConst.HAM_KEY_NOT_FOUND" /> is thrown.
 /// <br />
 /// Note that this method can not erase a single duplicate key. 
 /// If the key has multiple duplicates, all duplicates of this key 
 /// will be erased. Use <see cref="Cursor.Erase" /> to erase a 
 /// specific duplicate key.
 /// </remarks>
 /// <param name="txn">The optional Transaction</param>
 /// <param name="key">The key of the item to delete</param>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///     <item><see cref="HamConst.HAM_KEY_NOT_FOUND"/>
 ///         if the key was not found</item>
 ///     <item><see cref="HamConst.HAM_DB_READ_ONLY"/>
 ///         if you tried to insert a key in a read-only Database</item>
 ///   </list>
 /// </exception>
 public void Erase(Transaction txn, byte[] key)
 {
     int st;
     lock (this) {
         st = NativeMethods.Erase(handle, txn != null ? txn.Handle : IntPtr.Zero, key, 0);
     }
     if (st != 0)
         throw new DatabaseException(st);
 }
Example #9
0
 /// <summary>
 /// Inserts a Database Item into a Record Number Database
 /// </summary>
 /// <returns name="key">The key of the new item</returns>
 /// <remarks>
 /// This method wraps the native ham_db_insert function.
 /// <br />
 /// This function inserts a record as a new Database item.
 /// <br />
 /// </remarks>
 /// <param name="txn">An optional Transaction object</param>
 /// <param name="record">The record of the new item</param>
 /// <param name="flags">Optional flags for this operation.</param>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///   <item><see cref="HamConst.HAM_WRITE_PROTECTED"/>
 ///     if you tried to insert a key in a read-only Database</item>
 ///   </list>
 /// </exception>
 public byte[] InsertRecNo(Transaction txn, byte[] record, int flags)
 {
     int st;
     byte[] key = null;
     lock (this)
     {
     st = NativeMethods.InsertRecNo(handle,
               txn != null ? txn.Handle : IntPtr.Zero,
               ref key, record, flags);
     }
     if (st != 0)
     throw new DatabaseException(st);
     return key;
 }
Example #10
0
 /// <summary>
 /// Searches an item in the Database, returns the record
 /// </summary>
 /// <remarks>
 /// This method wraps the native ham_db_find function.<br />
 /// <br />
 /// This function searches the Database for a key. If the key
 /// is found, the method will return the record of this item.
 /// <br />
 /// Database.Find can not search for duplicate keys. If the
 /// key has multiple duplicates, only the first duplicate is returned.
 /// </remarks>
 /// <param name="txn">The optional Transaction</param>
 /// <param name="key">The key of the item</param>
 /// <param name="flags">The flags of the operation</param>
 /// <returns>The record of the item</returns>
 /// <exception cref="DatabaseException">
 ///   <list type="bullet">
 ///   <item><see cref="HamConst.HAM_KEY_NOT_FOUND"/>
 ///     if the item was not found</item>
 ///   </list>
 /// </exception>
 public byte[] Find(Transaction txn, ref byte[] key, int flags)
 {
     byte[] record = null;
       lock (this) {
     int st = NativeMethods.Find(handle,
                 txn != null ? txn.Handle : IntPtr.Zero,
                 ref key, ref record, flags);
     if (st != 0)
       throw new DatabaseException(st);
       }
       return record;
 }
Example #11
0
 /// <summary>
 /// Searches an item in the Database, returns the record
 /// </summary>
 public byte[] Find(Transaction txn, byte[] key)
 {
     return Find(txn, ref key, 0);
 }