C# Class Upscaledb.Database

A Database class
Inheritance: IDisposable
显示文件 Open project: cruppstahl/upscaledb Class Usage Examples

Public Methods

Method Description
AddCursor ( Cursor c ) : void

Adds a Cursor to the Cursor list

Close ( ) : void

Closes the Database

This method wraps the native ups_db_close function.
Before closing the Database, the cache is flushed to Disk.

Database ( ) : System

Default Constructor

Dispose ( ) : void

Closes the Database

Erase ( Transaction txn, byte key ) : void

Erases a Database Item

This method wraps the native ups_db_erase function.
This function erases a Database item. If the item with the specified key does not exist in the Database, error code UpsConst.UPS_KEY_NOT_FOUND is thrown.
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 Cursor.Erase to erase a specific duplicate key.

Erase ( byte key ) : void

Erases a Database Item

Find ( Transaction txn, byte key ) : byte[]

Searches an item in the Database, returns the record

Find ( Transaction txn, byte &key, int flags ) : byte[]

Searches an item in the Database, returns the record

This method wraps the native ups_db_find function.

This function searches the Database for a key. If the key is found, the method will return the record of this item.
Database.Find can not search for duplicate keys. If the key has multiple duplicates, only the first duplicate is returned.

Find ( byte key ) : byte[]

Searches an item in the Database, returns the record

GetCount ( ) : System.Int64

Returns the number of keys in this Database

GetCount ( Transaction txn, int flags ) : System.Int64

Returns the number of keys in this Database

This method wraps the native ups_db_count function.
You can specify UPS_SKIP_DUPLICATES if you do now want to include any duplicates in the count.

GetCount ( int flags ) : System.Int64

Returns the number of keys in this Database

GetLastError ( ) : int

Returns the last error code

This method wraps the native ups_db_get_error function.

GetVersion ( ) : Version

Returns the upscaledb.dll version

Insert ( Transaction txn, byte key, byte record ) : void

Inserts a Database item

This is an overloaded function for Database.Insert(txn, key, record, 0).

Insert ( Transaction txn, byte key, byte record, int flags ) : void

Inserts a Database Item

This method wraps the native ups_db_insert function.
This function inserts a key/record pair as a new Database item.
If the key already exists in the Database, error code UpsConst.UPS_DUPLICATE_KEY is thrown.
If you wish to overwrite an existing entry specify the flag UpsConst.UPS_OVERWRITE
If you wish to insert a duplicate key specify the flag UpsConst.UPS_DUPLICATE. (Note that the Database has to be created with the flag UpsConst.UPS_ENABLE_DUPLICATE_KEYS in order to use duplicate keys.) The duplicate key is inserted after all other duplicate keys (see UpsConst.UPS_DUPLICATE_INSERT_LAST).

Insert ( byte key, byte record ) : void

Inserts a Database item

This is an overloaded function for Database.Insert(null, key, record, 0).

Insert ( byte key, byte record, int flags ) : void

Inserts a Database item

This is an overloaded function for Database.Insert(null, key, record, flags).

InsertRecNo ( Transaction txn, byte record, int flags ) : byte[]

Inserts a Database Item into a Record Number Database

This method wraps the native ups_db_insert function.
This function inserts a record as a new Database item.

InsertRecNo ( byte record ) : byte[]

Inserts a Database Item into a Record Number Database

This is an overloaded function for Database.InsertRecNo(null, record, 0).

InsertRecNo ( byte record, int flags ) : byte[]

Inserts a Database Item into a Record Number Database

This is an overloaded function for Database.InsertRecNo(null, record, flags).

RegisterCompare ( String name, CompareFunc foo ) : void

Registers a global compare function.

This method wraps the native ups_register_compare function.

RemoveCursor ( Cursor c ) : void

Removes a Cursor from the Cursor list

SetCompareFunc ( CompareFunc foo ) : void

Sets the comparison function

This method wraps the native ups_db_set_compare_func function.

The CompareFunc delegate compares two index keys. It returns -1 if the first key is smaller, +1 if the second key is smaller or 0 if both keys are equal.

If foo is null, upscaledb will use the default compare function (which is based on memcmp(3)).

SetErrorHandler ( ErrorHandler eh ) : void

Sets the global error handler

This method wraps the native ups_set_error_handler function.

This handler will receive all debug messages that are emitted by upscaledb. You can install the default handler by setting eh to null.

Protected Methods

Method Description
Dispose ( bool all ) : void

Closes the Database

Private Methods

Method Description
AppendNullParameter ( Parameter parameters ) : Upscaledb.Parameter[]
Database ( IntPtr handle ) : System

Method Details

AddCursor() public method

Adds a Cursor to the Cursor list
public AddCursor ( Cursor c ) : void
c Cursor
return void

Close() public method

Closes the Database
This method wraps the native ups_db_close function.
Before closing the Database, the cache is flushed to Disk.
public Close ( ) : void
return void

Database() public method

Default Constructor
public Database ( ) : System
return System

Dispose() public method

Closes the Database
public Dispose ( ) : void
return void

Dispose() protected method

Closes the Database
protected Dispose ( bool all ) : void
all bool
return void

Erase() public method

Erases a Database Item
This method wraps the native ups_db_erase function.
This function erases a Database item. If the item with the specified key does not exist in the Database, error code UpsConst.UPS_KEY_NOT_FOUND is thrown.
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 Cursor.Erase to erase a specific duplicate key.
/// /// /// if the key was not found /// /// if you tried to insert a key in a read-only Database /// ///
public Erase ( Transaction txn, byte key ) : void
txn Transaction The optional Transaction
key byte The key of the item to delete
return void

Erase() public method

Erases a Database Item
public Erase ( byte key ) : void
key byte
return void

Find() public method

Searches an item in the Database, returns the record
public Find ( Transaction txn, byte key ) : byte[]
txn Transaction
key byte
return byte[]

Find() public method

Searches an item in the Database, returns the record
This method wraps the native ups_db_find function.

This function searches the Database for a key. If the key is found, the method will return the record of this item.
Database.Find can not search for duplicate keys. If the key has multiple duplicates, only the first duplicate is returned.
/// /// /// if the item was not found /// ///
public Find ( Transaction txn, byte &key, int flags ) : byte[]
txn Transaction The optional Transaction
key byte The key of the item
flags int The flags of the operation
return byte[]

Find() public method

Searches an item in the Database, returns the record
public Find ( byte key ) : byte[]
key byte
return byte[]

GetCount() public method

Returns the number of keys in this Database
public GetCount ( ) : System.Int64
return System.Int64

GetCount() public method

Returns the number of keys in this Database
This method wraps the native ups_db_count function.
You can specify UPS_SKIP_DUPLICATES if you do now want to include any duplicates in the count.
public GetCount ( Transaction txn, int flags ) : System.Int64
txn Transaction
flags int
return System.Int64

GetCount() public method

Returns the number of keys in this Database
public GetCount ( int flags ) : System.Int64
flags int
return System.Int64

GetLastError() public method

Returns the last error code
This method wraps the native ups_db_get_error function.
public GetLastError ( ) : int
return int

GetVersion() public static method

Returns the upscaledb.dll version
public static GetVersion ( ) : Version
return Version

Insert() public method

Inserts a Database item
This is an overloaded function for Database.Insert(txn, key, record, 0).
public Insert ( Transaction txn, byte key, byte record ) : void
txn Transaction
key byte
record byte
return void

Insert() public method

Inserts a Database Item
This method wraps the native ups_db_insert function.
This function inserts a key/record pair as a new Database item.
If the key already exists in the Database, error code UpsConst.UPS_DUPLICATE_KEY is thrown.
If you wish to overwrite an existing entry specify the flag UpsConst.UPS_OVERWRITE
If you wish to insert a duplicate key specify the flag UpsConst.UPS_DUPLICATE. (Note that the Database has to be created with the flag UpsConst.UPS_ENABLE_DUPLICATE_KEYS in order to use duplicate keys.) The duplicate key is inserted after all other duplicate keys (see UpsConst.UPS_DUPLICATE_INSERT_LAST).
/// /// /// if the flags UpsConst.UPS_DUPLICATE AND /// UpsConst.UPS_OVERWRITE were specified, or if /// UpsConst.UPS_DUPLICATE was specified but the Database /// was not created with UpsConst.UPS_ENABLE_DUPLICATE_KEYS /// /// if you tried to insert a key in a read-only Database /// /// if key size is different than than the key size parameter /// specified for Database.Create. /// ///
public Insert ( Transaction txn, byte key, byte record, int flags ) : void
txn Transaction An optional Transaction object
key byte The key of the new item
record byte The record of the new item
flags int Optional flags for this operation. Possible /// flags are: /// /// /// If the key already exists, the record is overwritten. /// Otherwise, the key is inserted. /// /// If the key already exists, a duplicate key is inserted. /// The key is inserted before the already existing duplicates. /// ///
return void

Insert() public method

Inserts a Database item
This is an overloaded function for Database.Insert(null, key, record, 0).
public Insert ( byte key, byte record ) : void
key byte
record byte
return void

Insert() public method

Inserts a Database item
This is an overloaded function for Database.Insert(null, key, record, flags).
public Insert ( byte key, byte record, int flags ) : void
key byte
record byte
flags int
return void

InsertRecNo() public method

Inserts a Database Item into a Record Number Database
This method wraps the native ups_db_insert function.
This function inserts a record as a new Database item.
/// /// /// if you tried to insert a key in a read-only Database /// ///
public InsertRecNo ( Transaction txn, byte record, int flags ) : byte[]
txn Transaction An optional Transaction object
record byte The record of the new item
flags int Optional flags for this operation.
return byte[]

InsertRecNo() public method

Inserts a Database Item into a Record Number Database
This is an overloaded function for Database.InsertRecNo(null, record, 0).
public InsertRecNo ( byte record ) : byte[]
record byte
return byte[]

InsertRecNo() public method

Inserts a Database Item into a Record Number Database
This is an overloaded function for Database.InsertRecNo(null, record, flags).
public InsertRecNo ( byte record, int flags ) : byte[]
record byte
flags int
return byte[]

RegisterCompare() public static method

Registers a global compare function.
This method wraps the native ups_register_compare function.
public static RegisterCompare ( String name, CompareFunc foo ) : void
name String Descriptive name of the compare function
foo CompareFunc Delegate object
return void

RemoveCursor() public method

Removes a Cursor from the Cursor list
public RemoveCursor ( Cursor c ) : void
c Cursor
return void

SetCompareFunc() public method

Sets the comparison function
This method wraps the native ups_db_set_compare_func function.

The CompareFunc delegate compares two index keys. It returns -1 if the first key is smaller, +1 if the second key is smaller or 0 if both keys are equal.

If foo is null, upscaledb will use the default compare function (which is based on memcmp(3)).
public SetCompareFunc ( CompareFunc foo ) : void
foo CompareFunc The compare delegate, or null
return void

SetErrorHandler() public static method

Sets the global error handler
This method wraps the native ups_set_error_handler function.

This handler will receive all debug messages that are emitted by upscaledb. You can install the default handler by setting eh to null.
public static SetErrorHandler ( ErrorHandler eh ) : void
eh ErrorHandler The delegate which is called whenever an /// error message is emitted; set to null to set the default /// error handler
return void