table of contents
TCBDB(3) | Tokyo Cabinet | TCBDB(3) |
NAME¶
tcbdb - the B+ tree database APIDESCRIPTION¶
B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. To use the B+ tree database API, include ` tcutil.h', `tcbdb.h', and related standard header files. Usually, write the following description near the front of a source file.API¶
The function `tcbdberrmsg' is used in order to get the message string corresponding to an error code.`ecode' specifies the error code.
The return value is the message string of the
error code.
The return value is the new B+ tree database
object.
`bdb' specifies the B+ tree database
object.
If the database is not closed, it is closed
implicitly. Note that the deleted object and its derivatives can not be used
anymore.
`bdb' specifies the B+ tree database
object.
The return value is the last happened error
code.
The following error codes are defined:
`TCESUCCESS' for success, `TCETHREAD' for threading error, `TCEINVALID' for
invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no
permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record
header, `TCEOPEN' for open error, `TCECLOSE' for close error, `TCETRUNC' for
trunc error, `TCESYNC' for sync error, `TCESTAT' for stat error, `TCESEEK' for
seek error, `TCEREAD' for read error, `TCEWRITE' for write error, `TCEMMAP'
for mmap error, `TCELOCK' for lock error, `TCEUNLINK' for unlink error,
`TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for rmdir
error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and
`TCEMISC' for miscellaneous error.
`bdb' specifies the B+ tree database
object which is not opened.
If successful, the return value is true, else,
it is false.
Note that the mutual exclusion control of the
database should be set before the database is opened.
`bdb' specifies the B+ tree database
object which is not opened.
`cmp' specifies the pointer to the
custom comparison function. It receives five parameters. The first parameter
is the pointer to the region of one key. The second parameter is the size of
the region of one key. The third parameter is the pointer to the region of the
other key. The fourth parameter is the size of the region of the other key.
The fifth parameter is the pointer to the optional opaque object. It returns
positive if the former is big, negative if the latter is big, 0 if both are
equivalent.
`cmpop' specifies an arbitrary pointer
to be given as a parameter of the comparison function. If it is not needed,
`NULL' can be specified.
If successful, the return value is true, else,
it is false.
The default comparison function compares keys
of two records by lexical order. The functions `tccmplexical' (default),
`tccmpdecimal', `tccmpint32', and `tccmpint64' are built-in. Note that the
comparison function should be set before the database is opened. Moreover,
user-defined comparison functions should be set every time the database is
being opened.
`bdb' specifies the B+ tree database
object which is not opened.
`lmemb' specifies the number of members
in each leaf page. If it is not more than 0, the default value is specified.
The default value is 128.
`nmemb' specifies the number of members
in each non-leaf page. If it is not more than 0, the default value is
specified. The default value is 256.
`bnum' specifies the number of elements
of the bucket array. If it is not more than 0, the default value is specified.
The default value is 16381. Suggested size of the bucket array is about from 1
to 4 times of the number of all pages to be stored.
`apow' specifies the size of record
alignment by power of 2. If it is negative, the default value is specified.
The default value is 8 standing for 2^8=256.
`fpow' specifies the maximum number of
elements of the free block pool by power of 2. If it is negative, the default
value is specified. The default value is 10 standing for 2^10=1024.
`opts' specifies options by bitwise-or:
`BDBTLARGE' specifies that the size of the database can be larger than 2GB by
using 64-bit bucket array, `BDBTDEFLATE' specifies that each page is
compressed with Deflate encoding, `BDBTBZIP' specifies that each page is
compressed with BZIP2 encoding, `BDBTTCBS' specifies that each page is
compressed with TCBS encoding.
If successful, the return value is true, else,
it is false.
Note that the tuning parameters should be set
before the database is opened.
`bdb' specifies the B+ tree database
object which is not opened.
`lcnum' specifies the maximum number of
leaf nodes to be cached. If it is not more than 0, the default value is
specified. The default value is 1024.
`ncnum' specifies the maximum number of
non-leaf nodes to be cached. If it is not more than 0, the default value is
specified. The default value is 512.
If successful, the return value is true, else,
it is false.
Note that the caching parameters should be set
before the database is opened.
`bdb' specifies the B+ tree database
object which is not opened.
`xmsiz' specifies the size of the extra
mapped memory. If it is not more than 0, the extra mapped memory is disabled.
It is disabled by default.
If successful, the return value is true, else,
it is false.
Note that the mapping parameters should be set
before the database is opened.
`bdb' specifies the B+ tree database
object which is not opened.
`dfunit' specifie the unit step number.
If it is not more than 0, the auto defragmentation is disabled. It is disabled
by default.
If successful, the return value is true, else,
it is false.
Note that the defragmentation parameter should
be set before the database is opened.
`bdb' specifies the B+ tree database
object which is not opened.
`path' specifies the path of the
database file.
`omode' specifies the connection mode:
`BDBOWRITER' as a writer, `BDBOREADER' as a reader. If the mode is
`BDBOWRITER', the following may be added by bitwise-or: `BDBOCREAT', which
means it creates a new database if not exist, `BDBOTRUNC', which means it
creates a new database regardless if one exists, `BDBOTSYNC', which means
every transaction synchronizes updated contents with the device. Both of
`BDBOREADER' and `BDBOWRITER' can be added to by bitwise-or: `BDBONOLCK',
which means it opens the database file without file locking, or `BDBOLCKNB',
which means locking is performed without blocking.
If successful, the return value is true, else,
it is false.
`bdb' specifies the B+ tree database
object.
If successful, the return value is true, else,
it is false.
Update of a database is assured to be written
when the database is closed. If a writer opens a database but does not close
it appropriately, the database will be broken.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`vbuf' specifies the pointer to the
region of the value.
`vsiz' specifies the size of the region
of the value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, it is overwritten.
`bdb' specifies the B+ tree database
object connected as a writer.
`kstr' specifies the string of the
key.
`vstr' specifies the string of the
value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, it is overwritten.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`vbuf' specifies the pointer to the
region of the value.
`vsiz' specifies the size of the region
of the value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, this function has no effect.
`bdb' specifies the B+ tree database
object connected as a writer.
`kstr' specifies the string of the
key.
`vstr' specifies the string of the
value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, this function has no effect.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`vbuf' specifies the pointer to the
region of the value.
`vsiz' specifies the size of the region
of the value.
If successful, the return value is true, else,
it is false.
If there is no corresponding record, a new
record is created.
`bdb' specifies the B+ tree database
object connected as a writer.
`kstr' specifies the string of the
key.
`vstr' specifies the string of the
value.
If successful, the return value is true, else,
it is false.
If there is no corresponding record, a new
record is created.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`vbuf' specifies the pointer to the
region of the value.
`vsiz' specifies the size of the region
of the value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, the new record is placed after the existing one.
`bdb' specifies the B+ tree database
object connected as a writer.
`kstr' specifies the string of the
key.
`vstr' specifies the string of the
value.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, the new record is placed after the existing one.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the common key.
`ksiz' specifies the size of the region
of the common key.
`vals' specifies a list object
containing values.
If successful, the return value is true, else,
it is false.
If a record with the same key exists in the
database, the new records are placed after the existing one.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is true, else,
it is false.
If the key of duplicated records is specified,
the first one is selected.
`bdb' specifies the B+ tree database
object connected as a writer.
`kstr' specifies the string of the
key.
If successful, the return value is true, else,
it is false.
If the key of duplicated records is specified,
the first one is selected.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is true, else,
it is false.
If the key of duplicated records is specified,
all of them are removed.
`bdb' specifies the B+ tree database
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the value of the corresponding record. `NULL' is returned if
no record corresponds.
If the key of duplicated records is specified,
the first one is selected. Because an additional zero code is appended at the
end of the region of the return value, the return value can be treated as a
character string. Because the region of the return value is allocated with the
`malloc' call, it should be released with the `free' call when it is no longer
in use.
`bdb' specifies the B+ tree database
object.
`kstr' specifies the string of the
key.
If successful, the return value is the string
of the value of the corresponding record. `NULL' is returned if no record
corresponds.
If the key of duplicated records is specified,
the first one is selected. Because the region of the return value is allocated
with the `malloc' call, it should be released with the `free' call when it is
no longer in use.
`bdb' specifies the B+ tree database
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the value of the corresponding record. `NULL' is returned if
no record corresponds.
If the key of duplicated records is specified,
the first one is selected. Because an additional zero code is appended at the
end of the region of the return value, the return value can be treated as a
character string. Because the region of the return value is volatile and it
may be spoiled by another operation of the database, the data should be copied
into another involatile buffer immediately.
`bdb' specifies the B+ tree database
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is a list
object of the values of the corresponding records. `NULL' is returned if no
record corresponds.
Because the object of the return value is
created with the function `tclistnew', it should be deleted with the function
`tclistdel' when it is no longer in use.
`bdb' specifies the B+ tree database
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is the number
of the corresponding records, else, it is 0.
`bdb' specifies the B+ tree database
object.
`kstr' specifies the string of the
key.
If successful, the return value is the number
of the corresponding records, else, it is 0.
`bdb' specifies the B+ tree database
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is the size of
the value of the corresponding record, else, it is -1.
If the key of duplicated records is specified,
the first one is selected.
`bdb' specifies the B+ tree database
object.
`kstr' specifies the string of the
key.
If successful, the return value is the size of
the value of the corresponding record, else, it is -1.
If the key of duplicated records is specified,
the first one is selected.
`bdb' specifies the B+ tree database
object.
`bkbuf' specifies the pointer to the
region of the key of the beginning border. If it is `NULL', the first record
is specified.
`bksiz' specifies the size of the
region of the beginning key.
`binc' specifies whether the beginning
border is inclusive or not.
`ekbuf' specifies the pointer to the
region of the key of the ending border. If it is `NULL', the last record is
specified.
`eksiz' specifies the size of the
region of the ending key.
`einc' specifies whether the ending
border is inclusive or not.
`max' specifies the maximum number of
keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the keys
of the corresponding records. This function does never fail. It returns an
empty list even if no record corresponds.
Because the object of the return value is
created with the function `tclistnew', it should be deleted with the function
`tclistdel' when it is no longer in use.
`bdb' specifies the B+ tree database
object.
`bkstr' specifies the string of the key
of the beginning border. If it is `NULL', the first record is specified.
`binc' specifies whether the beginning
border is inclusive or not.
`ekstr' specifies the string of the key
of the ending border. If it is `NULL', the last record is specified.
`einc' specifies whether the ending
border is inclusive or not.
`max' specifies the maximum number of
keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the keys
of the corresponding records. This function does never fail. It returns an
empty list even if no record corresponds.
Because the object of the return value is
created with the function `tclistnew', it should be deleted with the function
`tclistdel' when it is no longer in use.
`bdb' specifies the B+ tree database
object.
`pbuf' specifies the pointer to the
region of the prefix.
`psiz' specifies the size of the region
of the prefix.
`max' specifies the maximum number of
keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the
corresponding keys. This function does never fail. It returns an empty list
even if no key corresponds.
Because the object of the return value is
created with the function `tclistnew', it should be deleted with the function
`tclistdel' when it is no longer in use.
`bdb' specifies the B+ tree database
object.
`pstr' specifies the string of the
prefix.
`max' specifies the maximum number of
keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the
corresponding keys. This function does never fail. It returns an empty list
even if no key corresponds.
Because the object of the return value is
created with the function `tclistnew', it should be deleted with the function
`tclistdel' when it is no longer in use.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`num' specifies the additional
value.
If successful, the return value is the
summation value, else, it is `INT_MIN'.
If the corresponding record exists, the value
is treated as an integer and is added to. If no record corresponds, a new
record of the additional value is stored.
`bdb' specifies the B+ tree database
object connected as a writer.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
`num' specifies the additional
value.
If successful, the return value is the
summation value, else, it is Not-a-Number.
If the corresponding record exists, the value
is treated as a real number and is added to. If no record corresponds, a new
record of the additional value is stored.
`bdb' specifies the B+ tree database
object connected as a writer.
If successful, the return value is true, else,
it is false.
This function is useful when another process
connects to the same database file.
`bdb' specifies the B+ tree database
object connected as a writer.
`lmemb' specifies the number of members
in each leaf page. If it is not more than 0, the current setting is not
changed.
`nmemb' specifies the number of members
in each non-leaf page. If it is not more than 0, the current setting is not
changed.
`bnum' specifies the number of elements
of the bucket array. If it is not more than 0, the default value is specified.
The default value is two times of the number of pages.
`apow' specifies the size of record
alignment by power of 2. If it is negative, the current setting is not
changed.
`fpow' specifies the maximum number of
elements of the free block pool by power of 2. If it is negative, the current
setting is not changed.
`opts' specifies options by bitwise-or:
`BDBTLARGE' specifies that the size of the database can be larger than 2GB by
using 64-bit bucket array, `BDBTDEFLATE' specifies that each record is
compressed with Deflate encoding, `BDBTBZIP' specifies that each page is
compressed with BZIP2 encoding, `BDBTTCBS' specifies that each page is
compressed with TCBS encoding. If it is `UINT8_MAX', the current setting is
not changed.
If successful, the return value is true, else,
it is false.
This function is useful to reduce the size of
the database file with data fragmentation by successive updating.
`bdb' specifies the B+ tree database
object connected as a writer.
If successful, the return value is true, else,
it is false.
`bdb' specifies the B+ tree database
object.
`path' specifies the path of the
destination file. If it begins with `@', the trailing substring is executed as
a command line.
If successful, the return value is true, else,
it is false. False is returned if the executed command returns non-zero
code.
The database file is assured to be kept
synchronized and not modified while the copying or executing operation is in
progress. So, this function is useful to create a backup file of the database
file.
`bdb' specifies the B+ tree database
object connected as a writer.
If successful, the return value is true, else,
it is false.
The database is locked by the thread while the
transaction so that only one transaction can be activated with a database
object at the same time. Thus, the serializable isolation level is assumed if
every database operation is performed in the transaction. Because all pages
are cached on memory while the transaction, the amount of referred records is
limited by the memory capacity. If the database is closed during transaction,
the transaction is aborted implicitly.
`bdb' specifies the B+ tree database
object connected as a writer.
If successful, the return value is true, else,
it is false.
Update in the transaction is fixed when it is
committed successfully.
`bdb' specifies the B+ tree database
object connected as a writer.
If successful, the return value is true, else,
it is false.
Update in the transaction is discarded when it
is aborted. The state of the database is rollbacked to before
transaction.
`bdb' specifies the B+ tree database
object.
The return value is the path of the database
file or `NULL' if the object does not connect to any database file.
`bdb' specifies the B+ tree database
object.
The return value is the number of records or 0
if the object does not connect to any database file.
`bdb' specifies the B+ tree database
object.
The return value is the size of the database
file or 0 if the object does not connect to any database file.
`bdb' specifies the B+ tree database
object.
The return value is the new cursor
object.
Note that the cursor is available only after
initialization with the `tcbdbcurfirst' or the `tcbdbcurjump' functions and so
on. Moreover, the position of the cursor will be indefinite when the database
is updated after the initialization of the cursor.
`cur' specifies the cursor
object.
`cur' specifies the cursor
object.
If successful, the return value is true, else,
it is false. False is returned if there is no record in the database.
`cur' specifies the cursor
object.
If successful, the return value is true, else,
it is false. False is returned if there is no record in the database.
`cur' specifies the cursor
object.
`kbuf' specifies the pointer to the
region of the key.
`ksiz' specifies the size of the region
of the key.
If successful, the return value is true, else,
it is false. False is returned if there is no record corresponding the
condition.
The cursor is set to the first record
corresponding the key or the next substitute if completely matching record
does not exist.
`cur' specifies the cursor
object.
`kstr' specifies the string of the
key.
If successful, the return value is true, else,
it is false. False is returned if there is no record corresponding the
condition.
The cursor is set to the first record
corresponding the key or the next substitute if completely matching record
does not exist.
`cur' specifies the cursor
object.
If successful, the return value is true, else,
it is false. False is returned if there is no previous record.
`cur' specifies the cursor
object.
If successful, the return value is true, else,
it is false. False is returned if there is no next record.
`cur' specifies the cursor object of
writer connection.
`vbuf' specifies the pointer to the
region of the value.
`vsiz' specifies the size of the region
of the value.
`cpmode' specifies detail adjustment:
`BDBCPCURRENT', which means that the value of the current record is
overwritten, `BDBCPBEFORE', which means that the new record is inserted before
the current record, `BDBCPAFTER', which means that the new record is inserted
after the current record.
If successful, the return value is true, else,
it is false. False is returned when the cursor is at invalid position.
After insertion, the cursor is moved to the
inserted record.
`cur' specifies the cursor object of
writer connection.
`vstr' specifies the string of the
value.
`cpmode' specifies detail adjustment:
`BDBCPCURRENT', which means that the value of the current record is
overwritten, `BDBCPBEFORE', which means that the new record is inserted before
the current record, `BDBCPAFTER', which means that the new record is inserted
after the current record.
If successful, the return value is true, else,
it is false. False is returned when the cursor is at invalid position.
After insertion, the cursor is moved to the
inserted record.
`cur' specifies the cursor object of
writer connection.
If successful, the return value is true, else,
it is false. False is returned when the cursor is at invalid position.
After deletion, the cursor is moved to the
next record if possible.
`cur' specifies the cursor
object.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the key, else, it is `NULL'. `NULL' is returned when the
cursor is at invalid position.
Because an additional zero code is appended at
the end of the region of the return value, the return value can be treated as
a character string. Because the region of the return value is allocated with
the `malloc' call, it should be released with the `free' call when it is no
longer in use.
`cur' specifies the cursor
object.
If successful, the return value is the string
of the key, else, it is `NULL'. `NULL' is returned when the cursor is at
invalid position.
Because the region of the return value is
allocated with the `malloc' call, it should be released with the `free' call
when it is no longer in use.
`cur' specifies the cursor
object.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the key, else, it is `NULL'. `NULL' is returned when the
cursor is at invalid position.
Because an additional zero code is appended at
the end of the region of the return value, the return value can be treated as
a character string. Because the region of the return value is volatile and it
may be spoiled by another operation of the database, the data should be copied
into another involatile buffer immediately.
`cur' specifies the cursor
object.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the value, else, it is `NULL'. `NULL' is returned when the
cursor is at invalid position.
Because an additional zero code is appended at
the end of the region of the return value, the return value can be treated as
a character string. Because the region of the return value is allocated with
the `malloc' call, it should be released with the `free' call when it is no
longer in use.
`cur' specifies the cursor
object.
If successful, the return value is the string
of the value, else, it is `NULL'. `NULL' is returned when the cursor is at
invalid position.
Because the region of the return value is
allocated with the `malloc' call, it should be released with the `free' call
when it is no longer in use.
`cur' specifies the cursor
object.
`sp' specifies the pointer to the
variable into which the size of the region of the return value is
assigned.
If successful, the return value is the pointer
to the region of the value, else, it is `NULL'. `NULL' is returned when the
cursor is at invalid position.
Because an additional zero code is appended at
the end of the region of the return value, the return value can be treated as
a character string. Because the region of the return value is volatile and it
may be spoiled by another operation of the database, the data should be copied
into another involatile buffer immediately.
`cur' specifies the cursor
object.
`kxstr' specifies the object into which
the key is wrote down.
`vxstr' specifies the object into which
the value is wrote down.
If successful, the return value is true, else,
it is false. False is returned when the cursor is at invalid position.
SEE ALSO¶
tcbtest(1), tcbmttest(1), tcbmgr(1), tokyocabinet(3)2011-02-12 | Man Page |