TCFDB(3)
β¨ NAME β¨
tcfdb β the fixed-length database API. Like, this whole page is TCFDB(3) from Tokyo Cabinet, bestie. π
π DESCRIPTION π
Okay so a fixed-length database is literally just a file containing an array of fixed-length elements, and you handle it with the fixed-length database API. No cap. π¦
To use the fixed-length database API, include tcutil.h, tcfdb.h, and related standard header files. Usually, write the following description near the front of a source file. β¨
#include <tcutil.h>
#include <tcfdb.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
Objects whose type is pointer to TCFDB are used to handle fixed-length databases. A fixed-length database object is created with the function tcfdbnew and is deleted with the function tcfdbdel. To avoid memory leak, it is important to delete every object when it is no longer in use. Memory leak is not the vibe, bestie. π
Before 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 tcfdbopen is used to open a database file and the function tcfdbclose 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. It is forbidden for multiple database objects in a process to open the same database at the same time. Like, do not do that. π«
π API π
Here's every function, every signature, every default, every error code, every warning. Periodt. π
β¨ tcfdberrmsg β¨
The function tcfdberrmsg is used in order to get the message string corresponding to an error code.
const char *tcfdberrmsg(int ecode);
ecodespecifies the error code.- The return value is the message string of the error code.
β¨ tcfdbnew β¨
The function tcfdbnew is used in order to create a fixed-length database object.
TCFDB *tcfdbnew(void);
- The return value is the new fixed-length database object.
β¨ tcfdbdel β¨
The function tcfdbdel is used in order to delete a fixed-length database object.
void tcfdbdel(TCFDB *fdb);
fdbspecifies the fixed-length 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.
β¨ tcfdbecode β¨
The function tcfdbecode is used in order to get the last happened error code of a fixed-length database object.
int tcfdbecode(TCFDB *fdb);
fdbspecifies the fixed-length database object.- The return value is the last happened error code.
The following error codes are defined:
TCESUCCESSfor successTCETHREADfor threading errorTCEINVALIDfor invalid operationTCENOFILEfor file not foundTCENOPERMfor no permissionTCEMETAfor invalid meta dataTCERHEADfor invalid record headerTCEOPENfor open errorTCECLOSEfor close errorTCETRUNCfor trunc errorTCESYNCfor sync errorTCESTATfor stat errorTCESEEKfor seek errorTCEREADfor read errorTCEWRITEfor write errorTCEMMAPfor mmap errorTCELOCKfor lock errorTCEUNLINKfor unlink errorTCERENAMEfor rename errorTCEMKDIRfor mkdir errorTCERMDIRfor rmdir errorTCEKEEPfor existing recordTCENORECfor no record foundTCEMISCfor miscellaneous error
β¨ tcfdbsetmutex β¨
The function tcfdbsetmutex is used in order to set mutual exclusion control of a fixed-length database object for threading.
bool tcfdbsetmutex(TCFDB *fdb);
fdbspecifies the fixed-length database object which is not opened.- If successful, the return value is true, else, it is false.
- Note that the mutual exclusion control is needed if the object is shared by plural threads and this function should be called before the database is opened.
β¨ tcfdbtune β¨
The function tcfdbtune is used in order to set the tuning parameters of a fixed-length database object.
bool tcfdbtune(TCFDB *fdb, int32_t width, int64_t limsiz);
fdbspecifies the fixed-length database object which is not opened.widthspecifies 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.limsizspecifies the limit size of the database file. If it is not more than 0, the default value is specified. The default value is 268435456.- If successful, the return value is true, else, it is false.
- Note that the tuning parameters should be set before the database is opened.
β¨ tcfdbopen β¨
The function tcfdbopen is used in order to open a database file and connect a fixed-length database object.
bool tcfdbopen(TCFDB *fdb, const char *path, int omode);
fdbspecifies the fixed-length database object which is not opened.pathspecifies the path of the database file.omodespecifies the connection mode:FDBOWRITERas a writer,FDBOREADERas a reader. If the mode isFDBOWRITER, 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,FDBOTSYNC, which means every transaction synchronizes updated contents with the device. Both ofFDBOREADERandFDBOWRITERcan be added to by bitwise-or:FDBONOLCK, which means it opens the database file without file locking, orFDBOLCKNB, which means locking is performed without blocking.- If successful, the return value is true, else, it is false.
β¨ tcfdbclose β¨
The function tcfdbclose is used in order to close a fixed-length database object.
bool tcfdbclose(TCFDB *fdb);
fdbspecifies the fixed-length 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.
β οΈ bestie, if a writer opens a database but does not close it appropriately, the database will be broken. That is not a drill. π
β¨ tcfdbput β¨
The function tcfdbput is used in order to store a record into a fixed-length database object.
bool tcfdbput(TCFDB *fdb, int64_t id, const void *vbuf, int
vsiz);
fdbspecifies the fixed-length database object connected as a writer.idspecifies the ID number. It should be more than 0. If it isFDBIDMIN, the minimum ID number of existing records is specified. If it isFDBIDPREV, the number less by one than the minimum ID number of existing records is specified. If it isFDBIDMAX, the maximum ID number of existing records is specified. If it isFDBIDNEXT, the number greater by one than the maximum ID number of existing records is specified.vbufspecifies the pointer to the region of the value.vsizspecifies 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.- 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.
β¨ tcfdbput2 β¨
The function tcfdbput2 is used in order to store a record with a decimal key into a fixed-length database object.
bool tcfdbput2(TCFDB *fdb, const void *kbuf, int ksiz, const void
*vbuf, int vsiz);
fdbspecifies the fixed-length database object connected as a writer.kbufspecifies 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.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies 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.- 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.
β¨ tcfdbput3 β¨
The function tcfdbput3 is used in order to store a string record with a decimal key into a fixed-length database object.
bool tcfdbput3(TCFDB *fdb, const char *kstr, const void *vstr);
fdbspecifies the fixed-length database object connected as a writer.kstrspecifies 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.vstrspecifies 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.
β¨ tcfdbputkeep β¨
The function tcfdbputkeep is used in order to store a new record into a fixed-length database object.
πΎ tcfdbputkeep
bool tcfdbputkeep(TCFDB *fdb, int64_t id, const void *vbuf, int vsiz);
okay so this one is the polite version of putting stuff in β it only writes if the seat is actually free. β¨
fdbβ the fixed-length database object, and bestie, it has to be connected as a writer. reader vibes will not cut it here.idβ the ID number. It should be more than0. And here's the fun part, it can also be one of these lil magic constants:FDBIDMINβ the minimum ID number of existing recordsFDBIDPREVβ the number less by one than the minimum ID number of existing recordsFDBIDMAXβ the maximum ID number of existing recordsFDBIDNEXTβ the number greater by one than the maximum ID number of existing records
vbufβ pointer to the region of the value.vsizβ size of the region of the value. π«Ά heads up: if the size of the value is greater than the width tuning parameter of the database, the size gets cut down to the width. no negotiating.
If it works, the return value is true; if not, it's false.
and the whole point of "keep": if a record with the same key already exists in the database, this function has no effect. it justβ¦ sits there. respectfully. π
π’ tcfdbputkeep2
bool tcfdbputkeep2(TCFDB *fdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
same energy as above, but the key comes in as a decimal key instead of a raw int. πΈ
fdbβ the fixed-length database object connected as a writer.kbufβ pointer to the region of the decimal key. It should be more than0. And yes, the magic words work here too, except as strings:"min"β the minimum ID number of existing records"prev"β the number less by one than the minimum ID number of existing records"max"β the maximum ID number of existing records"next"β the number greater by one than the maximum ID number of existing records
ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value. and again: if the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width. βοΈ
Success β true. Otherwise β false.
same rule, same drama: if a record with the same key exists in the database, this function has no effect. periodt.
π tcfdbputkeep3
bool tcfdbputkeep3(TCFDB *fdb, const char *kstr, const void *vstr);
the string-flavored twin. storing a new string record with a decimal key, bestie. π¦
fdbβ the fixed-length database object connected as a writer.kstrβ the string of the decimal key. It should be more than0. And the magic words:"min"β the minimum ID number of existing records"prev"β the number less by one than the minimum ID number of existing records"max"β the maximum ID number of existing records"next"β the number greater by one than the maximum ID number of existing records
vstrβ the string of the value.
Success β true, else β false.
and you already know: if a record with the same key exists in the database, this function has no effect. it's giving boundaries. π
β tcfdbputcat
bool tcfdbputcat(TCFDB *fdb, int64_t id, const void *vbuf, int vsiz);
this one concatenates a value onto the end of an existing record. like adding to the group chat instead of starting a new one. π¬
fdbβ the fixed-length database object connected as a writer.idβ the ID number. It should be more than0. magic constants:FDBIDMINβ the minimum ID number of existing recordsFDBIDPREVβ the number less by one than the minimum ID number of existing recordsFDBIDMAXβ the maximum ID number of existing recordsFDBIDNEXTβ the number greater by one than the maximum ID number of existing records
vbufβ pointer to the region of the value.vsizβ 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. same rules, every time. π )
Success β true, else β false.
plot twist tho: if there is no corresponding record, a new record is created. it said "fine, I'll do it myself." π
π’β tcfdbputcat2
bool tcfdbputcat2(TCFDB *fdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
concatenate a value with a decimal key. same vibe, different key type. β¨
fdbβ the fixed-length database object connected as a writer.kbufβ pointer to the region of the decimal key. It should be more than0. and the stringy magic words:"min"β the minimum ID number of existing records"prev"β the number less by one than the minimum ID number of existing records"max"β the maximum ID number of existing records"next"β the number greater by one than the maximum ID number of existing records
ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value. and if the size of the value is greater than the width tuning parameter of the database, the size is cut down to the width. π«Ά
Success β true, else β false.
and if there is no corresponding record, a new record is created. iconic behavior honestly.
πβ tcfdbputcat3
bool tcfdbputcat3(TCFDB *fdb, const char *kstr, const void *vstr);
concatenate a string value with a decimal key. the string trio is complete. π
fdbβ the fixed-length database object connected as a writer.kstrβ the string of the decimal key. It should be more than0. magic words:"min"β the minimum ID number of existing records"prev"β the number less by one than the minimum ID number of existing records"max"β the maximum ID number of existing records"next"β the number greater by one than the maximum ID number of existing records
vstrβ the string of the value.
Success β true, else β false.
and again, fr fr: if there is no corresponding record, a new record is created.
ποΈ tcfdbout
bool tcfdbout(TCFDB *fdb, int64_t id);
removing a record. it's giving unsubscribe. π
fdbβ the fixed-length database object connected as a writer.idβ the ID number. It should be more than0. and note that this one only takes two magic constants:FDBIDMINβ the minimum ID number of existing recordsFDBIDMAXβ the maximum ID number of existing records
noFDBIDPREV, noFDBIDNEXThere, bestie. don't try it. π
Success β true, else β false.
π’ποΈ tcfdbout2
bool tcfdbout2(TCFDB *fdb, const void *kbuf, int ksiz);
remove a record with a decimal key. same deletion energy, decimal key. β¨
fdbβ the fixed-length database object connected as a writer.kbufβ pointer to the region of the decimal key. It should be more than0. and only two magic words this time:"min"β the minimum ID number of existing records"max"β the maximum ID number of existing records
ksizβ size of the region of the key.
Success β true, else β false.
πποΈ tcfdbout3
bool tcfdbout3(TCFDB *fdb, const char *kstr);
remove a string record with a decimal key. last of the out squad. π«Ά
fdbβ the fixed-length database object connected as a writer.kstrβ the string of the decimal key. It should be more than0. and again, just the two:"min"β the minimum ID number of existing records"max"β the maximum ID number of existing records
Success β true, else β false.
π tcfdbget
and now for the moment we've all been waiting for β the function tcfdbget is used in order to retrieve a record in a fixed-length database object. π
πΈ tcfdbget β the classic getter
void *tcfdbget(TCFDB *fdb, int64_t id, int *sp);
Okay bestie, this is the one you'll be calling the most, so listen up π
fdbβ your fixed-length database object. The whole vibe.idβ the ID number you're hunting for. It should be more than 0. BUT!! if you passFDBIDMIN, you get the minimum ID number of the existing records instead, and if you passFDBIDMAX, you get the maximum ID number of the existing records. Literal "just give me the first/last one" energy πspβ a pointer to the variable where the size of the returned region gets dumped. It's giving "here's the receipt, keep it" π§Ύ
If it works, you get back the pointer to the region of the value of the matching record. If nothing matches, you get NULL. No record, no vibes, no nothing π
Heads up: there's an extra zero code appended at the end of the returned region, so you can absolutely treat the return value like a character string β¨
And because that region was allocated with the malloc call, you must release it with the free call once you're done with it. Not freeing it is not the move, bestie β that's a leak π
π tcfdbget2 β getter but the key is decimal
void *tcfdbget2(TCFDB *fdb, const void *kbuf, int ksiz, int *sp);
Same energy as tcfdbget, but this one retrieves a record with a decimal key in a fixed-length database object.
fdbβ the fixed-length database object, obviously πkbufβ pointer to the region of the decimal key. It should be more than 0. If you pass"min", you're asking for the minimum ID number of existing records; if you pass"max", you're asking for the maximum ID number of existing records. Sneaky little string keywords, we love to see it β¨ksizβ the size of the region of the key.spβ pointer to the variable that receives the size of the region of the return value.
Successful? You get the pointer to the region of the value of the corresponding record. No match? NULL. That's it, that's the deal π¦
Additional zero code gets appended at the end of the returned region, so string treatment is fully allowed π
And yeah β malloc allocated, so free it when you're done. Every single time. Periodt π
π¦ tcfdbget3 β string record, decimal key, pure convenience
char *tcfdbget3(TCFDB *fdb, const char *kstr);
This one retrieves a string record with a decimal key. It's the low-effort, high-reward version, and honestly? Iconic.
fdbβ your fixed-length database object.kstrβ the string of the decimal key. Should be more than 0. Pass"min"for the minimum ID number of existing records, pass"max"for the maximum ID number of existing records. Same rules, same magic words π₯
If it works you get the string of the value of the corresponding record. If not, NULL β no record corresponds, so sorry babe π
Yes, there's still that additional zero code at the end of the returned region, so you can treat it as a character string π
It's malloc-allocated. free it. You know the drill by now π«Ά
π
tcfdbget4 β write it straight into your own buffer
int tcfdbget4(TCFDB *fdb, int64_t id, void *vbuf, int max);
Not me giving you a getter that writes into your buffer instead of handing you a fresh malloc region β main character energy fr fr π
fdbβ the fixed-length database object.idβ the ID number. Should be more than 0.FDBIDMINgets you the minimum ID number of existing records,FDBIDMAXgets you the maximum ID number of existing records. (Yes, same deal astcfdbget, keep up bestie β¨)vbufβ pointer to the buffer where the value of the corresponding record gets written.maxβ the size of the buffer. Don't be cute with this one.
If it works, the return value is the size of the written data. If not, it's -1. And -1 is also what you get if no record corresponds to the specified key. Rude but consistent π
β οΈ IMPORTANT: an additional zero code is not appended at the end of the region of the writing buffer. So don't go treating vbuf like a string without doing that yourself. This is not the same as the other getters and you will get caught out πΈ
π tcfdbvsiz β just tell me how big it is
int tcfdbvsiz(TCFDB *fdb, int64_t id);
Want the size of the value of a record without actually grabbing the value? Vibe check only, no full download π
fdbβ the fixed-length database object.idβ the ID number. More than 0, please.FDBIDMINβ minimum ID number of existing records.FDBIDMAXβ maximum ID number of existing records. You know it π
If it works, you get the size of the value of the corresponding record. If not, -1. That's the whole function, she's simple and she's slaying β¨
β tcfdbvsiz2 β size check, decimal key edition
int tcfdbvsiz2(TCFDB *fdb, const void *kbuf, int ksiz);
Size of the value, but with a decimal key. Same plot, different key type π¦
fdbβ the fixed-length database object.kbufβ pointer to the region of the decimal key. Should be more than 0."min"for the minimum ID number of existing records,"max"for the maximum ID number of existing records. The keyword thing again, we stay consistent πksizβ the size of the region of the key.
Success β the size of the value of the corresponding record. Failure β -1. Short and sweet, love that for us π
π tcfdbvsiz3 β size of a string value, decimal key
int tcfdbvsiz3(TCFDB *fdb, const char *kstr);
Getting the size of the string value with a decimal key. The 3 of the vsiz family, and she delivers π₯
fdbβ the fixed-length database object.kstrβ the string of the decimal key. Should be more than 0."min"β minimum ID number of existing records."max"β maximum ID number of existing records. As always πΈ
Works β the size of the value of the corresponding record. Doesn't work β -1. Finishing strong π«Ά
π§ tcfdbiterinit β spin up the iterator
bool tcfdbiterinit(TCFDB *fdb);
Bestie, this initializes the iterator of a fixed-length database object. If you wanna walk through every record in the database, this is step one, no skips π
fdbβ the fixed-length database object.
Returns true if it worked, false if it didn't. That's it π
The iterator is the thing you use to access the key of every record stored in the database. It's your little tour guide π
π tcfdbiternext β next ID, let's go
uint64_t tcfdbiternext(TCFDB *fdb);
After you've hit tcfdbiterinit, you keep calling this to get the next ID number out of the iterator. Yes, in a loop. Yes, it works. Trust β¨
fdbβ the fixed-length database object.
Success β the next ID number of the iterator. Otherwise β 0. And 0 is also what you get when there's no record left to be gotten out of the iterator. So 0 means "we're done here", not "we found a record with ID 0" β read the room π
- It's possible to access every record by iterating this function. Full coverage, no record left behind π
- It is allowed to update or remove records whose keys are fetched while the iteration. Live editing, we love a flexible API π
- The order of this traversal access method is ascending of the ID number. Smallest to biggest, always π
π¦ tcfdbiternext2 β next decimal key, pointer style
void *tcfdbiternext2(TCFDB *fdb, int *sp);
The decimal-key sibling of tcfdbiternext. Same iteration energy, different return type π
fdbβ the fixed-length database object.spβ pointer to the variable into which the size of the region of the return value gets assigned.
Success β the pointer to the region of the next decimal key. Otherwise β NULL. And NULL is also what you get when there's no record to be gotten out of the iterator. Same "we're done" signal as before π
Additional zero code at the end of the returned region β string treatment is allowed, bestie π
malloc-allocated, so free it when it's no longer in use. Every time. No exceptions π«Ά
- Every record is accessible by iterating this function.
- Updating or removing records whose keys are fetched during the iteration? Totally allowed.
- Traversal order is ascending of the ID number. Ascending. Always ascending π₯
πΈ tcfdbiternext3 β next decimal key, string style
char *tcfdbiternext3(TCFDB *fdb);
The string-flavored one. No sp, no pointer math, just vibes and a char * π
fdbβ the fixed-length database object.
Success β the string of the next decimal key. Otherwise β NULL, and NULL also means no record is left to be gotten out of the iterator. When it's over, it's over π
malloc-allocated, sofreeit once it's no longer in use. You already knew that but I'm saying it anyway because I care π₯Ί
- Every record is reachable by iterating this function.
- Updating or removing records whose keys are fetched during the iteration is allowed.
- The order of this traversal access method is ascending of the ID number. Ascending, bestie. Ascending β
π tcfdbrange β range matching ID numbers
The function tcfdbrange is used in order to get range matching ID numbers in a fixed-length database object.
π¦ tcfdbrange
uint64_t *tcfdbrange(TCFDB *fdb, int64_t lower, int64_t upper, int max, int *np);
okay so this is THE "gimme every record in this range bestie" function and honestly? iconic. π
fdbβ the fixed-length database object. your main character.lowerβ the lower limit of the range. if you passFDBIDMINhere, it means "the minimum ID, pls and ty".upperβ the upper limit of the range. passFDBIDMAXand it means "the maximum ID, exactly".maxβ the max number of keys to be fetched. if it's negative, no limit at all, we go feral, we go unhinged. π₯npβ the pointer to the variable where the number of elements of the return value gets assigned.
if it works you get back a pointer to an array of ID numbers of the corresponding records. on failure you get NULL. but lowkey? this function does never fail. it returns an empty array even if no key corresponds. she's resilient like that. π
heads up bestie: the region of the return value is allocated with themalloccall, so it should be released with thefreecall when it is no longer in use. don't leave her hanging, she deserves closure. π«Ά
πΈ tcfdbrange2
the function tcfdbrange2 is used in order to get range matching decimal keys in a fixed-length database object.
TCLIST *tcfdbrange2(TCFDB *fdb, const void *lbuf, int lsiz, const void *ubuf, int usiz, int max);
fdbβ the fixed-length database object, obviously.lbufβ pointer to the region of the lower key. if it's"min", the minimum ID number of existing records is specified.lsizβ the size of the region of the lower key.ubufβ pointer to the region of the upper key. if it's"max", the maximum ID number of existing records is specified.usizβ the size of the region of the upper key.maxβ the max number of keys to be fetched. negative? no limit. we ball. π
the return value is a list object of the corresponding decimal keys. this function does never fail β it returns an empty list even if no key corresponds. no cap.
because the object of the return value is created with the functiontclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use. also pls note that this function may be very slow because every key in the database is scanned. she's thorough, not fast. π
π§ tcfdbrange3
the function tcfdbrange3 is used in order to get range matching decimal keys with strings in a fixed-length database object.
TCLIST *tcfdbrange3(TCFDB *fdb, const char *lstr, const char *ustr, int max);
fdbβ the fixed-length database object.lstrβ the string of the lower key. if it's"min", the minimum ID number of existing records is specified.ustrβ the string of the upper key. if it's"max", the maximum ID number of existing records is specified.maxβ the max number of keys to be fetched. negative means no limit, live your truth.
the return value is a list object of the corresponding decimal keys. this function does never fail. it returns an empty list even if no key corresponds. periodt.
created withtclistnewβ delete it withtclistdelwhen you're done, bestie. and yeah, this one may be very slow because every single key in the database gets scanned. every. single. one. π
π tcfdbrange4
the function tcfdbrange4 is used in order to get keys with an interval notation in a fixed-length database object.
TCLIST *tcfdbrange4(TCFDB *fdb, const void *ibuf, int isiz, int max);
fdbβ the fixed-length database object.ibufβ pointer to the region of the interval notation.isizβ the size of the region of the interval notation.maxβ max number of keys to be fetched. negative = no limit, no thoughts, head empty. β¨
the return value is a list object of the corresponding decimal keys. this function does never fail, she returns an empty list even if no key corresponds. obsessed.
the return value object is made withtclistnew, so delete it withtclistdelwhen it's no longer in use. and note that this function may be very slow because every key in the database is scanned. it's giving full-table-scan energy, iykyk.
β tcfdbrange5
the function tcfdbrange5 is used in order to get keys with an interval notation string in a fixed-length database object.
TCLIST *tcfdbrange5(TCFDB *fdb, const void *istr, int max);
fdbβ the fixed-length database object.istrβ pointer to the region of the interval notation string.maxβ max number of keys to be fetched. if it's negative, no limit, we simply do not cap. π
the return value is a list object of the corresponding decimal keys. this function does never fail β it returns an empty list even if no key corresponds, which is honestly so forgiving of her.
created viatclistnew, so clean up withtclistdelwhen you're done. and yes, she may be very slow because every key in the database is scanned. it is what it is. π
π tcfdbaddint
the function tcfdbaddint is used in order to add an integer to a record in a fixed-length database object. math girlies rise. π₯
int tcfdbaddint(TCFDB *fdb, int64_t id, int num);
fdbβ the fixed-length database object, connected as a writer. (writer only, bestie, don't try it as a reader.)idβ the ID number. it should be more than 0. and it can also be one of the cute special values:FDBIDMINβ the minimum ID number of existing records is specified.FDBIDPREVβ the number less by one than the minimum ID number of existing records is specified.FDBIDMAXβ the maximum ID number of existing records is specified.FDBIDNEXTβ the number greater by one than the maximum ID number of existing records is specified.
numβ the additional value.
if it works, the return value is the summation value. otherwise it's 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. so either way you're getting a number back. slay.
π tcfdbadddouble
the function tcfdbadddouble is used in order to add a real number to a record in a fixed-length database object.
double tcfdbadddouble(TCFDB *fdb, int64_t id, double num);
fdbβ the fixed-length database object, connected as a writer.idβ the ID number. should be more than 0. and again with the special values:FDBIDMINβ the minimum ID number of existing records is specified.FDBIDPREVβ the number less by one than the minimum ID number of existing records is specified.FDBIDMAXβ the maximum ID number of existing records is specified.FDBIDNEXTβ the number greater by one than the maximum ID number of existing records is specified.
numβ the additional value.
if it works, the return value is the summation value. if not, it's Not-a-Number. a whole NaN. not me getting a NaN from my database. π
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.
π tcfdbsync
the function tcfdbsync is used in order to synchronize updated contents of a fixed-length database object with the file and the device.
bool tcfdbsync(TCFDB *fdb);
fdbβ the fixed-length database object, connected as a writer.
if successful, the return value is true. otherwise, false. simple as.
this function is useful when another process connects to the same database file. sharing is caring, bestie. π«Ά
π tcfdboptimize
the function tcfdboptimize is used in order to optimize the file of a fixed-length database object. glow-up time. β¨
bool tcfdboptimize(TCFDB *fdb, int32_t width, int64_t limsiz);
fdbβ the fixed-length database object, connected as a writer.widthβ the width of the value of each record. if it's not more than 0, the current setting is not changed. (so 0 or below = "keep her as she is".)limsizβ the limit size of the database file. if it's not more than 0, the current setting is not changed either.
if successful, the return value is true. else, false.
π«Ά tcfdbvanish
the function tcfdbvanish is used in order to remove all records of a fixed-length database object.
bool tcfdbvanish(TCFDB *fdb);
fdbβ the fixed-length database object, connected as a writer.
if successful, the return value is true. else, false.
ok so this one literally makes everything disappear. poof. no takebacks. π»
π tcfdbcopy
the function tcfdbcopy is used in order to copy the database file of a fixed-length database object.
bool tcfdbcopy(TCFDB *fdb, const char *path);
fdbβ the fixed-length database object.pathβ the path of the destination file. and here's the cute part: if it begins with@, the trailing substring is executed as a command line. π
if successful, the return value is true. else, 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. she's literally the responsible friend who holds your stuff while you run around. π«Ά
π tcfdbtranbegin
the function tcfdbtranbegin is used in order to begin the transaction of a fixed-length database object.
okay bestie, last stretch, we're in the transaction-and-stats era of this page and honestly? it's giving β¨backend glitzβ¨ let's go π
π tcfdbtranbegin β start the β¨momentβ¨
bool tcfdbtranbegin(TCFDB *fdb);
fdbβ the fixed-length database object, and she MUST be connected as a writer. no reader energy allowed here π ββοΈ
Returns true if it worked, false if it didn't. that's it, that's the whole vibe check.
okay so the deets, because they matter π«Ά:
- the database gets locked by the thread for the whole transaction, so only one transaction can be active on a database object at a time. no sharing, no tag-teaming, she's monogamous π
- so if you do every database operation inside the transaction, you're lowkey getting serializable isolation level for free. iconic behavior, no cap.
- all the updated regions are tracked by write ahead logging while the transaction runs. she's keeping receipts π
- and if the database gets closed mid-transaction? the transaction is aborted implicitly. so rude, but also correct. don't close her while she's mid-sentence bestie π
π tcfdbtrancommit β say yes to the changes
use tcfdbtrancommit to commit the transaction of a fixed-length database object. periodt.
bool tcfdbtrancommit(TCFDB *fdb);
fdbβ the fixed-length database object, connected as a writer. again: writer only, bestie π- returns
trueon success,falseotherwise
the update inside the transaction gets locked in forever when it commits successfully. no take-backs, it's canon now π
π¦ tcfdbtranabort β nvm bestie, forget I said anything
use tcfdbtranabort to abort the transaction of a fixed-length database object. it's the "actually never mind π" of database ops.
bool tcfdbtranabort(TCFDB *fdb);
fdbβ the fixed-length database object, connected as a writer (you know the drill by now π )- returns
trueon success,falseotherwise
when it aborts, the update in the transaction is discarded. and the state of the database gets rolled back to before the transaction</straight>. so it's like it never even happened. we love a clean slate β¨
π tcfdbpath β where does she live
use tcfdbpath to get the file path of a fixed-length database object. lowkey just asking for her address π‘
const char *tcfdbpath(TCFDB *fdb);
fdbβ the fixed-length database object- returns the path of the database file, or
NULLif the object doesn't connect to any database file
πΈ tcfdbrnum β how many records, bestie
use tcfdbrnum to get the number of records in a fixed-length database object.
uint64_t tcfdbrnum(TCFDB *fdb);
fdbβ the fixed-length database object- returns the number of records, or
0if the object doesn't connect to any database file
yes, 0. so if you get a zero, check whether she's even connected before you spiral π
β tcfdbfsiz β how big is the file
use tcfdbfsiz to get the size of the database file of a fixed-length database object.
uint64_t tcfdbfsiz(TCFDB *fdb);
fdbβ the fixed-length database object- returns the size of the database file, or
0if the object doesn't connect to any database file
π SEE ALSO
and that's the whole page bestie, we ate and left absolutely zero crumbs π β¨
the page signs off as Man Page, version/date 2012-08-18, filed under TCFDB(3) β so go forth, connect as a writer, commit your little heart out, and remember: abort is always an option π«Άπππ¦πΈ
π¦ where this page comes from
- debian bookworm: libtokyocabinet-dev 1.4.48-15 Β· LGPL-2.1-or-later
- debian trixie: libtokyocabinet-dev 1.4.48-15.1+b1 Β· LGPL-2.1-or-later
- ubuntu jammy: libtokyocabinet-dev 1.4.48-14build1 Β· LGPL-2.1-or-later
- ubuntu noble: libtokyocabinet-dev 1.4.48-15.1build1 Β· LGPL-2.1-or-later
- ubuntu questing: libtokyocabinet-dev 1.4.48-15.1build2
- ubuntu resolute: libtokyocabinet-dev 1.4.48-15.1build3 Β· LGPL-2.1-or-later
- ubuntu stonking: libtokyocabinet-dev 1.4.48-15.1build3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms