📄 tcfdb.3
字号:
.TH "TCFDB" 3 "2008-06-18" "Man Page" "Tokyo Cabinet".SH NAMEtcfdb \- the fixed-length database API.SH DESCRIPTION.PPFixed\-length database is a file containing an array of fixed\-length elements and is handled with the fixed\-length database API. See `\fBtcfdb.h\fR' for entire specification..PPTo use the fixed\-length database API, include `\fBtcutil.h\fR', `\fBtcfdb.h\fR', and related standard header files. Usually, write the following description near the front of a source file..PP.RS.br\fB#include <tcutil.h>\fR.br\fB#include <tcfdb.h>\fR.br\fB#include <stdlib.h>\fR.br\fB#include <stdbool.h>\fR.br\fB#include <stdint.h>\fR.RE.PPObjects whose type is pointer to `\fBTCFDB\fR' are used to handle fixed\-length databases. A fixed\-length database object is created with the function `\fBtcfdbnew\fR' and is deleted with the function `\fBtcfdbdel\fR'. To avoid memory leak, it is important to delete every object when it is no longer in use..PPBefore operations to store or retrieve records, it is necessary to open a database file and connect the fixed\-length database object to it. The function `\fBtcfdbopen\fR' is used to open a database file and the function `\fBtcfdbclose\fR' is used to close the database file. To avoid data missing or corruption, it is important to close every database file when it is no longer in use..SH API.PPThe function `tcfdberrmsg' is used in order to get the message string corresponding to an error code..PP.RS.br\fBconst char *tcfdberrmsg(int \fIecode\fB);\fR.RS`\fIecode\fR' specifies the error code..RE.RSThe return value is the message string of the error code..RE.RE.PPThe function `tcfdbnew' is used in order to create a fixed\-length database object..PP.RS.br\fBTCFDB *tcfdbnew(void);\fR.RSThe return value is the new fixed\-length database object..RE.RE.PPThe function `tcfdbdel' is used in order to delete a fixed\-length database object..PP.RS.br\fBvoid tcfdbdel(TCFDB *\fIfdb\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object..RE.RSIf the database is not closed, it is closed implicitly. Note that the deleted object and its derivatives can not be used anymore..RE.RE.PPThe function `tcfdbecode' is used in order to get the last happened error code of a fixed\-length database object..PP.RS.br\fBint tcfdbecode(TCFDB *\fIfdb\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object..RE.RSThe return value is the last happened error code..RE.RSThe 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..RE.RE.PPThe function `tcfdbsetmutex' is used in order to set mutual exclusion control of a fixed\-length database object for threading..PP.RS.br\fBbool tcfdbsetmutex(TCFDB *\fIfdb\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object which is not opened..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the mutual exclusion control is needed if the object is shared by plural threads and this function should should be called before the database is opened..RE.RE.PPThe function `tcfdbtune' is used in order to set the tuning parameters of a fixed\-length database object..PP.RS.br\fBbool tcfdbtune(TCFDB *\fIfdb\fB, int32_t \fIwidth\fB, int64_t \fIlimsiz\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object which is not opened..RE.RS`\fIwidth\fR' specifies the width of the value of each record. If it is not more than 0, the default value is specified. The default value is 255..RE.RS`\fIlimsiz\fR' specifies the limit size of the database file. If it is not more than 0, the default value is specified. The default value is 268435456..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the tuning parameters should be set before the database is opened..RE.RE.PPThe function `tcfdbopen' is used in order to open a database file and connect a fixed\-length database object..PP.RS.br\fBbool tcfdbopen(TCFDB *\fIfdb\fB, const char *\fIpath\fB, int \fIomode\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object which is not opened..RE.RS`\fIpath\fR' specifies the path of the database file..RE.RS`\fIomode\fR' specifies the connection mode: `FDBOWRITER' as a writer, `FDBOREADER' as a reader. If the mode is `FDBOWRITER', the following may be added by bitwise or: `FDBOCREAT', which means it creates a new database if not exist, `FDBOTRUNC', which means it creates a new database regardless if one exists. Both of `FDBOREADER' and `FDBOWRITER' can be added to by bitwise or: `FDBONOLCK', which means it opens the database file without file locking, or `FDBOLCKNB', which means locking is performed without blocking..RE.RSIf successful, the return value is true, else, it is false..RE.RE.PPThe function `tcfdbclose' is used in order to close a fixed\-length database object..PP.RS.br\fBbool tcfdbclose(TCFDB *\fIfdb\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object..RE.RSIf successful, the return value is true, else, it is false..RE.RSUpdate 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..RE.RE.PPThe function `tcfdbput' is used in order to store a record into a fixed\-length database object..PP.RS.br\fBbool tcfdbput(TCFDB *\fIfdb\fB, int64_t \fIid\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIid\fR' specifies the ID number. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDPREV', the number less by one than the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified. If it is `FDBIDNEXT', the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value. If the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, it is overwritten..RE.RE.PPThe function `tcfdbput2' is used in order to store a record with a decimal key into a fixed\-length database object..PP.RS.br\fBbool tcfdbput2(TCFDB *\fIfdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the decimal key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value. If the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, it is overwritten..RE.RE.PPThe function `tcfdbput3' is used in order to store a string record with a decimal key into a fixed\-length database object..PP.RS.br\fBbool tcfdbput3(TCFDB *\fIfdb\fB, const char *\fIkstr\fB, const void *\fIvstr\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the decimal key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, it is overwritten..RE.RE.PPThe function `tcfdbputkeep' is used in order to store a new record into a fixed\-length database object..PP.RS.br\fBbool tcfdbputkeep(TCFDB *\fIfdb\fB, int64_t \fIid\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIid\fR' specifies the ID number. It should be more than 0. If it is `FDBIDMIN', the minimum ID number of existing records is specified. If it is `FDBIDPREV', the number less by one than the minimum ID number of existing records is specified. If it is `FDBIDMAX', the maximum ID number of existing records is specified. If it is `FDBIDNEXT', the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value. If the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, this function has no effect..RE.RE.PPThe function `tcfdbputkeep2' is used in order to store a new record with a decimal key into a fixed\-length database object..PP.RS.br\fBbool tcfdbputkeep2(TCFDB *\fIfdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the decimal key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value. If the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, this function has no effect..RE.RE.PPThe function `tcfdbputkeep3' is used in order to store a new string record with a decimal key into a fixed\-length database object..PP.RS.br\fBbool tcfdbputkeep3(TCFDB *\fIfdb\fB, const char *\fIkstr\fB, const void *\fIvstr\fB);\fR.RS`\fIfdb\fR' specifies the fixed\-length database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the decimal key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, this function has no effect..RE.RE.PPThe function `tcfdbputcat' is used in order to concatenate a value at the end of the existing record in a fixed\-length database object..PP.RS.br\fBbool tcfdbputcat(TCFDB *\fIfdb\fB, int64_t \fIid\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -