[Back]

API of Villa


use Villa;
Module `Villa' should be loaded in application codes. An instance of the class `Villa' is used as a database handle.
$Villa::errmsg;
Global Variable: The message of the last happened error.
$villa = new Villa($name, $omode, $cmode);
Constructor: Get the database handle. `$name' specifies the name of a database file. `$omode' specifies the connection mode: `Villa::OWRITER' as a writer, `Villa::OREADER' as a reader. If the mode is `Villa::OWRITER', the following may be added by bitwise or: `Villa::OCREAT', which means it creates a new database if not exist, `Villa::OTRUNC', which means it creates a new database regardless if one exists, `Villa::OZCOMP', which means leaves in the database are compressed with ZLIB, `Villa::OYCOMP', which means leaves in the database are compressed with LZO, `Villa::OXCOMP', which means leaves in the database are compressed with BZIP2. Both of `Villa::OREADER' and `Villa::OWRITER' can be added to by bitwise or: `Villa::ONOLCK', which means it opens a database file without file locking, or `Villa::OLCKNB', which means locking is performed without blocking. If it is undef, `Villa::OREADER' is specified. `$cmode' specifies the comparing function: `Villa::CMPLEX' comparing keys in lexical order, `Villa::CMPDEC' comparing keys as decimal strings. The comparing function should be kept same in the life of a database. 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. `Villa::OZCOMP', `Villa::OYCOMP', and `Villa::OXCOMP' are available only if QDBM was built each with ZLIB, LZO, and BZIP2 enabled. If `Villa::ONOLCK' is used, the application is responsible for exclusion control.
$bool = $villa->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. If the transaction is activated and not committed, it is aborted.
$bool = $villa->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: `Villa::DOVER', which means the specified value overwrites the existing one, `Villa::DKEEP', which means the existing value is kept, `Villa::DCAT', which means the specified value is concatenated at the end of the existing value, `Villa::DDUP', which means duplication of keys is allowed and the specified value is added as the last one, `Villa::DDUPR', which means duplication of keys is allowed and the specified value is added as the first one. If it is undef, `Villa::DOVER' is specified. If successful, the return value is true, else, it is false. The cursor becomes unavailable due to updating database.
$bool = $villa->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. When the key of duplicated records is specified, the first record of the same key is deleted. The cursor becomes unavailable due to updating database.
$str = $villa->get($key);
Method: Retrieve a record. `$key' specifies a key. If it is undef, this method has no effect. 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. When the key of duplicated records is specified, the value of the first record of the same key is selected.
$num = $villa->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. The return value is the size of the value of the corresponding record. If no record corresponds, -1 is returned. If multiple records correspond, the size of the first is returned.
$num = $villa->vnum($key);
Method: Get the number of records corresponding a key. `$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 0.
$bool = $villa->curfirst();
Method: Move the cursor to the first record. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
$bool = $villa->curlast();
Method: Move the cursor to the last record. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
$bool = $villa->curprev();
Method: Move the cursor to the previous record. If successful, the return value is true, else, it is false. False is returned if there is no previous record.
$bool = $villa->curnext();
Method: Move the cursor to the next record. If successful, the return value is true, else, it is false. False is returned if there is no next record.
$bool = $villa->curjump($key, $jmode);
Method: Move the cursor to a position around a record. `$key' specifies a key. If it is undef, this method has no effect. `$jmode' specifies detail adjustment: `Villa::JFORWARD', which means that the cursor is set to the first record of the same key and that the cursor is set to the next substitute if completely matching record does not exist, `Villa::JBACKWARD', which means that the cursor is set to the last record of the same key and that the cursor is set to the previous substitute if completely matching record does not exist. If it is undef, `Villa::JFORWARD' is specified. If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.
$str = $villa->curkey();
Method: Get the key of the record where the cursor is. If successful, the return value is a scalar of the key of the corresponding record, else, it is undef. undef is returned when no record corresponds to the cursor.
$str = $villa->curval();
Method: Get the value of the record where the cursor is. 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 cursor.
$bool = $villa->curput($val, $cpmode);
Method: Insert a record around the cursor. `$val' specifies a value. If it is undef, this method has no effect. `$cpmode' specifies detail adjustment: `Villa::CPCURRENT', which means that the value of the current record is overwritten, `Villa::CPBEFORE', which means that a new record is inserted before the current record, `Villa::CPAFTER', which means that a new record is inserted after the current record. If it is undef, `Villa::CPCURRENT' is specified. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After insertion, the cursor is moved to the inserted record.
$bool = $villa->curout();
Method: Delete the record where the cursor is. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After deletion, the cursor is moved to the next record if possible.
$bool = $villa->settuning($lrecmax, $nidxmax, $lcnum, $ncnum);
Method: Set alignment of the database handle. `$lrecmax' specifies the max number of records in a leaf node of B+ tree. If it is undef or not more than 0, the default value is specified. `$nidxmax' specifies the max number of indexes in a non-leaf node of B+ tree. If it is undef or not more than 0, the default value is specified. `$lcnum' specifies the max number of caching leaf nodes. If it is undef or not more than 0, the default value is specified. `$ncnum' specifies the max number of caching non-leaf nodes. 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. The default setting is equivalent to `vlsettuning(49, 192, 1024, 512)'. Because tuning parameters are not saved in a database, you should specify them every opening a database.
$bool = $villa->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. This method should not be used while the transaction is activated.
$bool = $villa->optimize();
Method: Optimize the database. 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. This method should not be used while the transaction is activated.
$num = $villa->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. Because of the I/O buffer, the return value may be less than the real size.
$num = $villa->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 = $villa->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 = $villa->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.
$bool = $villa->tranbegin();
Method: Begin the transaction. If successful, the return value is true, else, it is false. Only one transaction can be activated with a database handle at the same time.
$bool = $villa->trancommit();
Method: Commit the transaction. If successful, the return value is true, else, it is false. Updating a database in the transaction is fixed when it is committed successfully.
$bool = $villa->tranabort();
Method: Abort the transaction. If successful, the return value is true, else, it is false. Updating a database in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
Called automatically by the garbage collector.
Destructor: DESTROY: Release the resources. If the database handle is not closed yet, it is closed.
$villa = tie(%hash, "Villa", $name, $omode, $cmp);
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 = $villa->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 = $villa->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 = $villa->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 = $villa->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, 2010/08/05.