Class | TokyoCabinet::TDB |
In: |
tokyocabinet.c
tokyocabinet-doc.rb |
Parent: | Object |
Table database is a file containing records composed of the primary keys and arbitrary columns and is handled with the table database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the table database object to it. 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 multible database objects in a process to open the same database at the same time.%% Except for the interface below, methods compatible with the `Hash’ class are also provided; `[]’, `[]=’, `store’, `delete’, `fetch’, `has_key?’, `clear’, `length’, `empty?’, `each’, `each_key’, `each_value’, and `keys’.%%
ESUCCESS | = | INT2NUM(TCESUCCESS) | ||
ETHREAD | = | INT2NUM(TCETHREAD) | ||
EINVALID | = | INT2NUM(TCEINVALID) | ||
ENOFILE | = | INT2NUM(TCENOFILE) | ||
ENOPERM | = | INT2NUM(TCENOPERM) | ||
EMETA | = | INT2NUM(TCEMETA) | ||
ERHEAD | = | INT2NUM(TCERHEAD) | ||
EOPEN | = | INT2NUM(TCEOPEN) | ||
ECLOSE | = | INT2NUM(TCECLOSE) | ||
ETRUNC | = | INT2NUM(TCETRUNC) | ||
ESYNC | = | INT2NUM(TCESYNC) | ||
ESTAT | = | INT2NUM(TCESTAT) | ||
ESEEK | = | INT2NUM(TCESEEK) | ||
EREAD | = | INT2NUM(TCEREAD) | ||
EWRITE | = | INT2NUM(TCEWRITE) | ||
EMMAP | = | INT2NUM(TCEMMAP) | ||
ELOCK | = | INT2NUM(TCELOCK) | ||
EUNLINK | = | INT2NUM(TCEUNLINK) | ||
ERENAME | = | INT2NUM(TCERENAME) | ||
EMKDIR | = | INT2NUM(TCEMKDIR) | ||
ERMDIR | = | INT2NUM(TCERMDIR) | ||
EKEEP | = | INT2NUM(TCEKEEP) | ||
ENOREC | = | INT2NUM(TCENOREC) | ||
EMISC | = | INT2NUM(TCEMISC) | ||
TLARGE | = | INT2NUM(TDBTLARGE) | ||
TDEFLATE | = | INT2NUM(TDBTDEFLATE) | ||
TBZIP | = | INT2NUM(TDBTBZIP) | ||
TTCBS | = | INT2NUM(TDBTTCBS) | ||
OREADER | = | INT2NUM(TDBOREADER) | ||
OWRITER | = | INT2NUM(TDBOWRITER) | ||
OCREAT | = | INT2NUM(TDBOCREAT) | ||
OTRUNC | = | INT2NUM(TDBOTRUNC) | ||
ONOLCK | = | INT2NUM(TDBONOLCK) | ||
OLCKNB | = | INT2NUM(TDBOLCKNB) | ||
OTSYNC | = | INT2NUM(TDBOTSYNC) | ||
ITLEXICAL | = | INT2NUM(TDBITLEXICAL) | ||
ITDECIMAL | = | INT2NUM(TDBITDECIMAL) | ||
ITTOKEN | = | INT2NUM(TDBITTOKEN) | ||
ITQGRAM | = | INT2NUM(TDBITQGRAM) | ||
ITVOID | = | INT2NUM(TDBITVOID) | ||
ITKEEP | = | INT2NUM(TDBITKEEP) | ||
ESUCCESS | = | 0 | error code: success | |
ETHREAD | = | 1 | error code: threading error | |
EINVALID | = | 2 | error code: invalid operation | |
ENOFILE | = | 3 | error code: file not found | |
ENOPERM | = | 4 | error code: no permission | |
EMETA | = | 5 | error code: invalid meta data | |
ERHEAD | = | 6 | error code: invalid record header | |
EOPEN | = | 7 | error code: open error | |
ECLOSE | = | 8 | error code: close error | |
ETRUNC | = | 9 | error code: trunc error | |
ESYNC | = | 10 | error code: sync error | |
ESTAT | = | 11 | error code: stat error | |
ESEEK | = | 12 | error code: seek error | |
EREAD | = | 13 | error code: read error | |
EWRITE | = | 14 | error code: write error | |
EMMAP | = | 15 | error code: mmap error | |
ELOCK | = | 16 | error code: lock error | |
EUNLINK | = | 17 | error code: unlink error | |
ERENAME | = | 18 | error code: rename error | |
EMKDIR | = | 19 | error code: mkdir error | |
ERMDIR | = | 20 | error code: rmdir error | |
EKEEP | = | 21 | error code: existing record | |
ENOREC | = | 22 | error code: no record found | |
EMISC | = | 9999 | error code: miscellaneous error | |
TLARGE | = | 1 << 0 | tuning option: use 64-bit bucket array | |
TDEFLATE | = | 1 << 1 | tuning option: compress each record with Deflate | |
TBZIP | = | 1 << 2 | tuning option: compress each record with BZIP2 | |
TTCBS | = | 1 << 3 | tuning option: compress each record with TCBS | |
OREADER | = | 1 << 0 | open mode: open as a reader | |
OWRITER | = | 1 << 1 | open mode: open as a writer | |
OCREAT | = | 1 << 2 | open mode: writer creating | |
OTRUNC | = | 1 << 3 | open mode: writer truncating | |
ONOLCK | = | 1 << 4 | open mode: open without locking | |
OLCKNB | = | 1 << 5 | open mode: lock without blocking | |
OTSYNC | = | 1 << 6 | open mode: synchronize every transaction | |
ITLEXICAL | = | 0 | index type: lexical string | |
ITDECIMAL | = | 1 | index type: decimal string | |
ITTOKEN | = | 2 | index type: token inverted index | |
ITQGRAM | = | 3 | index type: q-gram inverted index | |
ITOPT | = | 9998 | index type: optimize | |
ITVOID | = | 9999 | index type: void | |
ITKEEP | = | 1 << 24 | index type: keep existing index |
Add a real number to a record.%% `key’ specifies the primary key.%% `num’ specifies the additional value.%% If successful, the return value is the summation value, else, it is `nil’.%% The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.%%
# File tokyocabinet-doc.rb, line 1157 1157: def adddouble(pkey, num) 1158: # (native code) 1159: end
Add an integer to a record.%% `pkey’ specifies the primary key.%% `num’ specifies the additional value.%% If successful, the return value is the summation value, else, it is `nil’.%% The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored.%%
# File tokyocabinet-doc.rb, line 1149 1149: def addint(pkey, num) 1150: # (native code) 1151: end
Close the database file.%% 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.%%
# File tokyocabinet-doc.rb, line 1079 1079: def close() 1080: # (native code) 1081: end
Copy the database file.%% `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 method is useful to create a backup file of the database file.%%
# File tokyocabinet-doc.rb, line 1185 1185: def copy(path) 1186: # (native code) 1187: end
Get the last happened error code.%% The return value is the last happened error code.%% The following error codes are defined: `TokyoCabinet::TDB::ESUCCESS’ for success, `TokyoCabinet::TDB::ETHREAD’ for threading error, `TokyoCabinet::TDB::EINVALID’ for invalid operation, `TokyoCabinet::TDB::ENOFILE’ for file not found, `TokyoCabinet::TDB::ENOPERM’ for no permission, `TokyoCabinet::TDB::EMETA’ for invalid meta data, `TokyoCabinet::TDB::ERHEAD’ for invalid record header, `TokyoCabinet::TDB::EOPEN’ for open error, `TokyoCabinet::TDB::ECLOSE’ for close error, `TokyoCabinet::TDB::ETRUNC’ for trunc error, `TokyoCabinet::TDB::ESYNC’ for sync error, `TokyoCabinet::TDB::ESTAT’ for stat error, `TokyoCabinet::TDB::ESEEK’ for seek error, `TokyoCabinet::TDB::EREAD’ for read error, `TokyoCabinet::TDB::EWRITE’ for write error, `TokyoCabinet::TDB::EMMAP’ for mmap error, `TokyoCabinet::TDB::ELOCK’ for lock error, `TokyoCabinet::TDB::EUNLINK’ for unlink error, `TokyoCabinet::TDB::ERENAME’ for rename error, `TokyoCabinet::TDB::EMKDIR’ for mkdir error, `TokyoCabinet::TDB::ERMDIR’ for rmdir error, `TokyoCabinet::TDB::EKEEP’ for existing record, `TokyoCabinet::TDB::ENOREC’ for no record found, and `TokyoCabinet::TDB::EMISC’ for miscellaneous error.%%
# File tokyocabinet-doc.rb, line 1034 1034: def ecode() 1035: # (native code) 1036: end
Get the message string corresponding to an error code.%% `ecode’ specifies the error code. If it is not defined or negative, the last happened error code is specified.%% The return value is the message string of the error code.%%
# File tokyocabinet-doc.rb, line 1028 1028: def errmsg(ecode) 1029: # (native code) 1030: end
Get the size of the database file.%% The return value is the size of the database file or 0 if the object does not connect to any database file.%%
# File tokyocabinet-doc.rb, line 1218 1218: def fsiz() 1219: # (native code) 1220: end
Get forward matching primary keys.%% `prefix’ specifies the prefix of the corresponding keys.%% `max’ specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% The return value is a list object of the keys of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% Note that this method may be very slow because every key in the database is scanned.%%
# File tokyocabinet-doc.rb, line 1141 1141: def fwmkeys(prefix, max) 1142: # (native code) 1143: end
Retrieve a record.%% `pkey’ specifies the primary key.%% If successful, the return value is a hash of the columns of the corresponding record. `nil’ is returned if no record corresponds.%%
# File tokyocabinet-doc.rb, line 1115 1115: def get(pkey) 1116: # (native code) 1117: end
Initialize the iterator.%% If successful, the return value is true, else, it is false.%% The iterator is used in order to access the primary key of every record stored in a database.%%
# File tokyocabinet-doc.rb, line 1127 1127: def iterinit() 1128: # (native code) 1129: end
Get the next primary key of the iterator.%% If successful, the return value is the next primary key, else, it is `nil’. `nil’ 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. It is allowed to update or remove records whose keys are fetched while the iteration. 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.%%
# File tokyocabinet-doc.rb, line 1133 1133: def iternext() 1134: # (native code) 1135: end
Open a database file.%% `path’ specifies the path of the database file.%% `omode’ specifies the connection mode: `TokyoCabinet::TDB::OWRITER’ as a writer, `TokyoCabinet::TDB::OREADER’ as a reader. If the mode is `TokyoCabinet::TDB::OWRITER’, the following may be added by bitwise-or: `TokyoCabinet::TDB::OCREAT’, which means it creates a new database if not exist, `TokyoCabinet::TDB::OTRUNC’, which means it creates a new database regardless if one exists, `TokyoCabinet::TDB::OTSYNC’, which means every transaction synchronizes updated contents with the device. Both of `TokyoCabinet::TDB::OREADER’ and `TokyoCabinet::TDB::OWRITER’ can be added to by bitwise-or: `TokyoCabinet::TDB::ONOLCK’, which means it opens the database file without file locking, or `TokyoCabinet::TDB::OLCKNB’, which means locking is performed without blocking. If it is not defined, `TokyoCabinet::TDB::OREADER’ is specified.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 1073 1073: def open(path, omode) 1074: # (native code) 1075: end
Optimize the database file.%% `bnum’ specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.%% `apow’ specifies the size of record alignment by power of 2. If it is not defined or 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 not defined or negative, the current setting is not changed.%% `opts’ specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS’ specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.%% If successful, the return value is true, else, it is false.%% This method is useful to reduce the size of the database file with data fragmentation by successive updating.%%
# File tokyocabinet-doc.rb, line 1173 1173: def optimize(bnum, apow, fpow, opts) 1174: # (native code) 1175: end
Remove a record.%% `pkey’ specifies the primary key.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 1109 1109: def out(pkey) 1110: # (native code) 1111: end
Store a record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% 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.%%
# File tokyocabinet-doc.rb, line 1087 1087: def put(pkey, cols) 1088: # (native code) 1089: end
Concatenate columns of the existing record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% If successful, the return value is true, else, it is false.%% If there is no corresponding record, a new record is created.%%
# File tokyocabinet-doc.rb, line 1103 1103: def putcat(pkey, value) 1104: # (native code) 1105: end
Store a new record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, this method has no effect.%%
# File tokyocabinet-doc.rb, line 1095 1095: def putkeep(pkey, cols) 1096: # (native code) 1097: end
Get the number of records.%% The return value is the number of records or 0 if the object does not connect to any database file.%%
# File tokyocabinet-doc.rb, line 1213 1213: def rnum() 1214: # (native code) 1215: end
Set the caching parameters.%% `rcnum’ specifies the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.%% `lcnum’ specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 4096.%% `ncnum’ specifies the maximum number of non-leaf nodes to be cached. If it is not defined or 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 of the database should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 1052 1052: def setcache(rcnum, lcnum, ncnum) 1053: # (native code) 1054: end
Set the unit step number of auto defragmentation.%% `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 parameters should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 1066 1066: def setdfunit(dfunit) 1067: # (native code) 1068: end
Set a column index.%% `name’ specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.%% `type’ specifies the index type: `TokyoCabinet::TDB::ITLEXICAL’ for lexical string, `TokyoCabinet::TDB::ITDECIMAL’ for decimal string, `TokyoCabinet::TDB::ITTOKEN’ for token inverted index, `TokyoCabinet::TDB::ITQGRAM’ for q-gram inverted index. If it is `TokyoCabinet::TDB::ITOPT’, the index is optimized. If it is `TokyoCabinet::TDB::ITVOID’, the index is removed. If `TokyoCabinet::TDB::ITKEEP’ is added by bitwise-or and the index exists, this method merely returns failure.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 1225 1225: def setindex(name, type) 1226: # (native code) 1227: end
Set the size of the extra mapped memory.%% `xmsiz’ specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.%% If successful, the return value is true, else, it is false.%% Note that the mapping parameters should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 1059 1059: def setxmsiz(xmsiz) 1060: # (native code) 1061: end
Synchronize updated 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 connects the same database file.%%
# File tokyocabinet-doc.rb, line 1163 1163: def sync() 1164: # (native code) 1165: end
Abort the transaction.%% 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.%%
# File tokyocabinet-doc.rb, line 1203 1203: def tranabort() 1204: # (native code) 1205: end
Begin the transaction.%% 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. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly.%%
# File tokyocabinet-doc.rb, line 1191 1191: def tranbegin() 1192: # (native code) 1193: end
Commit the transaction.%% If successful, the return value is true, else, it is false.%% Update in the transaction is fixed when it is committed successfully.%%
# File tokyocabinet-doc.rb, line 1197 1197: def trancommit() 1198: # (native code) 1199: end
Set the tuning parameters.%% `bnum’ specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.%% `apow’ specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.%% `fpow’ specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.%% `opts’ specifies options by bitwise-or: `TokyoCabinet::TDB::TLARGE’ specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `TokyoCabinet::TDB::TDEFLATE’ specifies that each record is compressed with Deflate encoding, `TokyoCabinet::TDB::TDBZIP’ specifies that each record is compressed with BZIP2 encoding, `TokyoCabinet::TDB::TTCBS’ specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.%% If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened.%%
# File tokyocabinet-doc.rb, line 1043 1043: def tune(bnum, apow, fpow, opts) 1044: # (native code) 1045: end
Remove all records.%% If successful, the return value is true, else, it is false.%%
# File tokyocabinet-doc.rb, line 1178 1178: def vanish() 1179: # (native code) 1180: end