[Back]

API of Depot


use Depot;
Module `Depot' should be loaded in application codes. An instance of the class `Depot' is used as a database handle.
$Depot::errmsg;
Global Variable: The message of the last happened error.
$depot = new Depot($name, $omode, $bnum);
Constructor: Get the database handle. `$name' specifies the name of a database file. `$omode' specifies the connection mode: `Depot::OWRITER' as a writer, `Depot::OREADER' as a reader. If the mode is `Depot::OWRITER', the following may be added by bitwise or: `Depot::OCREAT', which means it creates a new database if not exist, `Depot::OTRUNC', which means it creates a new database regardless if one exists. Both of `Depot::OREADER' and `Depot::OWRITER' can be added to by bitwise or: `Depot::ONOLCK', which means it opens a database file without file locking, or `Depot::OLCKNB', which means locking is performed without blocking. `Depot::OCREAT' can be added to by bitwise or: `Depot::OSPARSE', which means it creates a database file as a sparse file. If it is undef, `Depot::OREADER' is specified. `$bnum' specifies the number of elements of the bucket array. If it is undef or not more than 0, the default value is specified. The size of a bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of a bucket array is about from 0.5 to 4 times of the number of all records to store. The return value is the database handle or undef if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. If `Depot::ONOLCK' is used, the application is responsible for exclusion control.
$bool = $depot->close();
Method: Close the database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
$bool = $depot->put($key, $val, $dmode);
Method: Store a record. `$key' specifies a key. If it is undef, this method has no effect. `$val' specifies a value. If it is undef, this method has no effect. `$dmode' specifies behavior when the key overlaps, by the following values: `Depot::DOVER', which means the specified value overwrites the existing one, `Depot::DKEEP', which means the existing value is kept, `Depot::DCAT', which means the specified value is concatenated at the end of the existing value. If it is undef, `Depot::DOVER' is specified. If successful, the return value is true, else, it is false.
$bool = $depot->out($key);
Method: Delete a record. `$key' specifies a key. If it is undef, this method has no effect. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key.
$str = $depot->get($key, $start, $max);
Method: Retrieve a record. `$key' specifies a key. If it is undef, this method has no effect. `$start' specifies the offset address of the beginning of the region of the value to be read. If it is negative or undef, the offset is specified as 0. `$max' specifies the max size to be read. If it is negative or undef, the size to read is unlimited. If successful, the return value is a scalar of the value of the corresponding record, else, it is undef. undef is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `$start'.
$num = $depot->vsiz($key);
Method: Get the size of the value of a record. `$key' specifies a key. If it is undef, this method has no effect. If successful, the return value is the size of the value of the corresponding record, else, it is -1. Because this method does not read the entity of a record, it is faster than `get'.
$bool = $depot->iterinit();
Method: Initialize the iterator of the database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access the key of every record stored in a database.
$str = $depot->iternext();
Method: Get the next key of the iterator. If successful, the return value is a scalar of the value of the next key, else, it is undef. undef is returned when no record is to be get out of the iterator. It is possible to access every record by iteration of calling this method. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
$bool = $depot->setalign($align);
Method: Set alignment of the database handle. `$align' specifies the basic size of alignment. If it is undef, alignment is cleared. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.
$bool = $depot->setfbpsiz($size);
Method: Set the size of the free block pool. `$size' specifies the size of the free block pool. If it is undef, the free block pool is not used. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.
$bool = $depot->sync();
Method: Synchronize updating contents with the file and the device. If successful, the return value is true, else, it is false. This method is useful when another process uses the connected database file.
$bool = $depot->optimize($bnum);
Method: Optimize the database. `$bnum' specifies the number of the elements of the bucket array. If it is undef or not more than 0, the default value is specified. If successful, the return value is true, else, it is false. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This method is useful to do away with them.
$num = $depot->fsiz();
Method: Get the size of the database file. If successful, the return value is the size of the database file, else, it is -1.
$num = $depot->bnum();
Method: Get the number of the elements of the bucket array. If successful, the return value is the number of the elements of the bucket array, else, it is -1.
$num = $depot->rnum();
Method: Get the number of the records stored in the database. If successful, the return value is the number of the records stored in the database, else, it is -1.
$bool = $depot->writable();
Method: Check whether the database handle is a writer or not. The return value is true if the handle is a writer, false if not.
$bool = $depot->fatalerror();
Method: Check whether the database has a fatal error or not. The return value is true if the database has a fatal error, false if not.
Called automatically by the garbage collector.
Destructor: DESTROY: Release the resources. If the database handle is not closed yet, it is closed.
$depot = tie(%hash, "Depot", $name, $omode, $bnum);
Tying Function: TIEHASH: Get the database handle.
$bool = ($hash{$key} = $val);
Tying Function: STORE: Store a record with overwrite.
$bool = delete($hash{$key});
Tying Function: DELETE: Delete a record.
$bool = (%hash = ());
Tying Function: CLEAR: Delete all records.
$str = $hash{$key};
Tying Function: FETCH: Retrieve whole value of a record.
$bool = exists($hash{$val});
Tying Function: EXISTS: Check whether a record exists or not.
Called automatically by keys(), each(), and so on.
Tying Function: FIRSTKEY: Get the first key.
Called automatically by keys(), each(), and so on.
Tying Function: NEXTKEY: Get the next key.
$func = $depot->filter_store_key(\&nf);
Method: set a filter invoked when writing a key. `\&nf' specifies the reference of a filter function proofing `$_'. If it is undef, the current filter function is cleared. The return value is the old filter function.
$func = $depot->filter_store_value(\&nf);
Method: set a filter invoked when writing a value. `\&nf' specifies the reference of a filter function proofing `$_'. If it is undef, the current filter function is cleared. The return value is the old filter function.
$func = $depot->filter_fetch_key(\&nf);
Method: set a filter invoked when reading a key. `\&nf' specifies the reference of a filter function proofing `$_'. If it is undef, the current filter function is cleared. The return value is the old filter function.
$func = $depot->filter_fetch_value(\&nf);
Method: set a filter invoked when reading a value. `\&nf' specifies the reference of a filter function proofing `$_'. If it is undef, the current filter function is cleared. The return value is the old filter function.

Generated by mypldoc, 2007/03/05.