# Implement common methods for access to data # class BDB::Common class << self #open the database # #* name # The argument name is used as the name of a single physical # file on disk that will be used to back the database. # #* subname # The subname argument allows applications to have # subdatabases, i.e., multiple databases inside of a single physical # file. This is useful when the logical databases are both # numerous and reasonably small, in order to avoid creating a large # number of underlying files. It is an error to attempt to open a # subdatabase in a database file that was not initially # created using a subdatabase name. # #* flags # The flags must be the string "r", "r+", "w", "w+", "a", "a+" or # and integer value. # # The flags value must be set to 0 or by bitwise inclusively # OR'ing together one or more of the following values # # * BDB::CREATE # Create any underlying files, as necessary. If the files # do not already exist and the DB_CREATE flag is not # specified, the call will fail. # # * BD::EXCL # Return an error if the database already exists. Underlying # filesystem primitives are used to implement this # flag. For this reason it is only applicable to the # physical database file and cannot be used to test if a # subdatabase already exists. # # * BDB::NOMMAP # Do not map this database into process memory. # # * BDB::RDONLY # Open the database for reading only. Any attempt to # modify items in the database will fail regardless of the # actual permissions of any underlying files. # # * BDB::TRUNCATE # Physically truncate the underlying database file, # discarding all previous subdatabases or databases. # Underlying filesystem primitives are used to implement # this flag. For this reason it is only applicable to the # physical database file and cannot be used to discard # subdatabases. # # The DB_TRUNCATE flag cannot be transaction protected, # and it is an error to specify it in a transaction # protected environment. # #* options # Hash, Possible options are (see the documentation of Berkeley DB # for more informations) # # * store_nil_as_null: if `true' will store `nil' as `\000', otherwise as an empty string (default `false') # * set_array_base: base index for BDB::Recno, BDB::Queue or BDB::Btree (with BDB::RECNUM). Must be 0 or 1 # * set_bt_compare : specify a Btree comparison function # * set_bt_minkey : set the minimum number of keys per Btree page # * set_bt_prefix : specify a Btree prefix comparison function # * set_cachesize : set the database cache size # * set_dup_compare : specify a duplicate comparison function # * set_store_key : specify a Proc called before a key is stored # * set_fetch_key : specify a Proc called after a key is read # * set_store_value : specify a Proc called before a value is stored # * set_fetch_value : specify a Proc called after a value is read # * set_flags : general database configuration # * set_h_ffactor : set the Hash table density # * set_h_hash : specify a hashing function # * set_h_nelem : set the Hash table size # * set_lorder : set the database byte order # * set_pagesize : set the underlying database page size # * set_re_delim : set the variable-length record delimiter # * set_re_len : set the fixed-length record length # * set_re_pad : set the fixed-length record pad byte # * set_re_source : set the backing Recno text file # * set_append_recno : modify the stored data for BDB::APPEND # * set_encrypt : set the password used # * set_feedback : set the function to monitor some operations # * env : open the database in the environnement given as the value # * txn : open the database in the transaction given as the value # # set_append_recno will be called with (key, value) and # it must return nil or the modified value # # set_encrypt take an Array as arguments with the values # [password, flags], where flags can be 0 or BDB::ENCRYPT_AES # # Proc given to set_bt_compare, set_bt_prefix, # set_dup_compare, set_h_hash, set_store_key # set_fetch_key, set_store_value, set_fetch_value # set_feedback and set_append_recno # can be also specified as a method (replace the prefix set_ # with bdb_) # # For example # # module BDB # class Btreesort < Btree # def bdb_bt_compare(a, b) # b.downcase <=> a.downcase # end # end # end # def open(name = nil, subname = nil, flags = 0, mode = 0, options = {}) end #same than open def create(name = nil, subname = nil, flags = 0, mode = 0, options = {}) end #same than open def new(name = nil, subname = nil, flags = 0, mode = 0, options = {}) end #Removes the database (or subdatabase) represented by the #name and subname combination. # #If no subdatabase is specified, the physical file represented by name #is removed, incidentally removing all subdatabases that it contained. # def remove(name, subname = nil) end #same than remove def db_remove(name, subname = nil) end #same than remove def unlink(name, subname = nil) end #Upgrade the database # def upgrade(name) end #same than upgrade def db_upgrade(name) end end #Returns the value corresponding the key # def [](key) end #associate a secondary index db # #flag can have the value BDB::RDONLY # #The block must return the new key, or Qfalse in this case the #secondary index will not contain any reference to key/value # def associate(db, flag = 0) yield db, key, value end #return the current priority value # def cache_priority end #set the priority value : can be BDB::PRIORITY_VERY_LOW, #BDB::PRIORITY_LOW, BDB::PRIORITY_DEFAULT, #BDB::PRIORITY_HIGH or BDB::PRIORITY_VERY_HIGH # def cache_priority=value end #create a new sequence (see also open_sequence) # #equivalent to #open_sequence(key, BDB::CREATE|BDB::EXCL, init, options) # #return (or yield) an object BDB::Sequence def create_sequence(key, init = nil, options = {}) yield sequence end #create or open a sequence (see BDB::Sequence) # #key : key for the sequence # #flags : flags can have BDB::CREATE, BDB::EXCL, BDB::AUTO_COMMIT, #BDB::THREAD # #init : initial value for the sequence # #options : hash with the possible keys "set_cachesize", #"set_flags" and "set_range" # #return (or yield) an object BDB::Sequence def open_sequence(key, flags = 0, init = nil, options = {}) yield sequence end # #monitor the progress of some operations # def feedback=(proc) end #Returns the value correspondind the key # #flags can have the values BDB::GET_BOTH, #BDB::SET_RECNO or BDB::RMW # #In presence of duplicates it will return the first data item, use ##duplicates if you want all duplicates (see also #each_dup) # def get(key, flags = 0) end #same than get def db_get(key, flags = 0) end #same than get def fetch(key, flags = 0) end #Returns the primary key and the value corresponding to key #in the secondary index # #only with >= 3.3.11 # def pget(key, flags = 0) end #Stores the value associating with key # #If nil is given as the value, the association from the key will be #removed. # def []=(key, value) end #Stores the value associating with key # #If nil is given as the value, the association from the key #will be removed. It return the object deleted or nil if the #specified key don't exist. # #flags can have the value DBD::NOOVERWRITE, in this case #it will return nil if the specified key exist, otherwise true # def put(key, value, flags = 0) end #same than put def db_put(key, value, flags = 0) end #same than put def store(key, value, flags = 0) end #Append the value associating with key # def append(key, value) end #same than append def db_append(key, value) end #Return if the underlying database is in host order # def byteswapped? end #same than byteswapped? def get_byteswapped end #Clear partial set. # def clear_partial end #same than clear_partial def partial_clear end #Closes the file. # def close(flags = 0) end #same than close def db_close(flags = 0) end #Only for Btree and Recno (DB VERSION >= 4.4) # #* start starting point for compaction in a Btree or Recno database. # Compaction will start at the smallest key greater than or equal to the # specified key. # #* stop the stopping point for compaction in a Btree or Recno database. # Compaction will stop at the page with the smallest key greater # than the specified key # #* options hash with the possible keys # # * flags with the value 0, BDB::FREELIST_ONLY, or # BDB::FREE_SPACE # # * compact_fillpercentthe goal for filling pages, specified as a # percentage between 1 and 100. # # * compact_timeout the lock timeout set for implicit transactions, # in microseconds. # def compact(start = nil, stop = nil, options = nil) end #Return the count of duplicate for key # def count(key) end #same than count def dup_count(key) end #Open a new cursor. # def cursor(flags = 0) end #same than cursor def db_cursor(flags = 0) end #Open a new cursor with the flag BDB::WRITECURSOR # def cursor_write() end #same than cursor_write def db_cursor_write(flags = 0) end #Return the subname # def database() end #same than database def subname() end #Removes the association from the key. # #It return the object deleted or nil if the specified #key don't exist. # def delete(key) end #same than delete def db_del(key) end #Deletes associations if the evaluation of the block returns true. # #set # def delete_if(set = nil) yield key, value end #same than delete_if def reject!(set = nil) yield key, value end #Return an array of all duplicate associations for key # #if assoc is false return only the values. # def duplicates(key , assoc = true) end #Iterates over associations. # #set bulk # def each(set = nil, bulk = 0, "flags" => 0) yield key, value end #same than each def each_pair(set = nil, bulk = 0) yield key, value end #iterate over associations, where the key begin with #prefix def each_by_prefix(prefix = nil) yield key, value end #Iterates over each duplicate associations for key # #bulk # def each_dup(key, bulk = 0) yield key, value end #Iterates over each duplicate values for key # #bulk # def each_dup_value(key, bulk = 0) yield value end #Iterates over keys. # #set bulk # def each_key(set = nil, bulk = 0) yield key end #Iterates over secondary indexes and give secondary key, primary key #and value # def each_primary(set = nil) yield skey, pkey, pvalue end #Iterates over values. # #set bulk # def each_value(set = nil, bulk = 0) yield value end #Returns true if the database is empty. # def empty?() end #Return the name of the file # def filename() end #Returns true if the association from the key exists. # def has_key?(key) end #same than has_key? def key?(key) end #same than has_key? def include?(key) end #same than has_key? def member?(key) end #Returns true if the association from key is value # def has_both?(key, value) end #same than has_both? def both?(key, value) end #Returns true if the association to the value exists. # def has_value?(value) end #same than has_value? def value?(value) end #Returns the first key associated with value # def index(value) end #Returns the keys associated with value1, value2, ... # def indexes(value1, value2, ) end #Perform a join. cursor is an array of BDB::Cursor # def join(cursor , flag = 0) yield key, value end #Returns the array of the keys in the database # def keys end #Returns the number of association in the database. # def length end #same than length def size end # #The log_register function registers a file name. # def log_register(name) end # #The log_unregister function unregisters a file name. # def log_unregister() end #Create an hash without the associations if the evaluation of the #block returns true. # def reject yield key, value end #Iterates over associations in reverse order # #set # def reverse_each(set = nil) yield key, value end #same than reverse_each def reverse_each_pair(set = nil) yield key, value end #iterate over associations in reverse order, where the key begin with #prefix def reverse_each_by_prefix(prefix = nil) yield key, value end #Iterates over keys in reverse order # #set # def reverse_each_key(set = nil) yield key end #Iterates over secondary indexes in reverse order and give secondary #key, primary key and value # def reverse_each_primary(set = nil) yield skey, pkey, pvalue end #Iterates over values in reverse order. # #set # def reverse_each_value(set = nil) yield value end #Set the partial value len and offset # def set_partial(len, offset) end #Return database statistics. # def stat end #Return an array of all associations [key, value] # def to_a end #Return an hash of all associations {key => value} # def to_hash end #Empty a database # def truncate end #same than truncate def clear end #Returns the array of the values in the database. # def values end #Verify the integrity of the DB file, and optionnally output the #key/data to file (file must respond to #to_io) # def verify(file = nil, flags = 0) end end