1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
|
# Implement common methods for access to data
#
class BDB::Common
class << self
#open the database
#
#* <em>name</em>
# The argument name is used as the name of a single physical
# file on disk that will be used to back the database.
#
#* <em>subname</em>
# 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.
#
#* <em>flags</em>
# 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
#
# * <em>BDB::CREATE</em>
# 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.
#
# * <em>BD::EXCL</em>
# 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.
#
# * <em>BDB::NOMMAP</em>
# Do not map this database into process memory.
#
# * <em>BDB::RDONLY</em>
# 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.
#
# * <em>BDB::TRUNCATE</em>
# 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.
#
#* <em>options</em>
# Hash, Possible options are (see the documentation of Berkeley DB
# for more informations)
#
# * <em>store_nil_as_null</em>: if `true' will store `nil' as `\000', otherwise as an empty string (default `false')
# * <em>set_array_base</em>: base index for BDB::Recno, BDB::Queue or BDB::Btree (with BDB::RECNUM). Must be 0 or 1
# * <em>set_bt_compare</em> : specify a Btree comparison function
# * <em>set_bt_minkey</em> : set the minimum number of keys per Btree page
# * <em>set_bt_prefix</em> : specify a Btree prefix comparison function
# * <em>set_cachesize</em> : set the database cache size
# * <em>set_dup_compare</em> : specify a duplicate comparison function
# * <em>set_store_key</em> : specify a Proc called before a key is stored
# * <em>set_fetch_key</em> : specify a Proc called after a key is read
# * <em>set_store_value</em> : specify a Proc called before a value is stored
# * <em>set_fetch_value</em> : specify a Proc called after a value is read
# * <em>set_flags</em> : general database configuration
# * <em>set_h_ffactor</em> : set the Hash table density
# * <em>set_h_hash</em> : specify a hashing function (due to bdb internals, the result will be truncated at 32 bits)
# * <em>set_h_nelem</em> : set the Hash table size
# * <em>set_lorder</em> : set the database byte order
# * <em>set_pagesize</em> : set the underlying database page size
# * <em>set_re_delim</em> : set the variable-length record delimiter
# * <em>set_re_len</em> : set the fixed-length record length
# * <em>set_re_pad</em> : set the fixed-length record pad byte
# * <em>set_re_source</em> : set the backing Recno text file
# * <em>set_append_recno</em> : modify the stored data for <em>BDB::APPEND</em>
# * <em>set_encrypt</em> : set the password used
# * <em>set_feedback</em> : set the function to monitor some operations
# * <em>env</em> : open the database in the environnement given as the value
# * <em>txn</em> : open the database in the transaction given as the value
#
# <em>set_append_recno</em> will be called with (key, value) and
# it must return <em>nil</em> or the modified value
#
# <em>set_encrypt</em> take an Array as arguments with the values
# [password, flags], where flags can be 0 or <em>BDB::ENCRYPT_AES</em>
#
# Proc given to <em>set_bt_compare</em>, <em>set_bt_prefix</em>,
# <em>set_dup_compare</em>, <em>set_h_hash</em>, <em>set_store_key</em>
# <em>set_fetch_key</em>, <em>set_store_value</em>, <em>set_fetch_value</em>
# <em>set_feedback</em> and <em>set_append_recno</em>
# can be also specified as a method (replace the prefix <em>set_</em>
# with <em>bdb_</em>)
#
# 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 <em> open</em>
def create(name = nil, subname = nil, flags = 0, mode = 0, options = {})
end
#same than <em> open</em>
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 <em> remove</em>
def db_remove(name, subname = nil)
end
#same than <em> remove</em>
def unlink(name, subname = nil)
end
#Upgrade the database
#
def upgrade(name)
end
#same than <em> upgrade</em>
def db_upgrade(name)
end
end
#Returns the value corresponding the <em>key</em>
#
def [](key)
end
#associate a secondary index db
#
#<em>flag</em> can have the value <em>BDB::RDONLY</em>
#
#The block must return the new key, or <em>Qfalse</em> 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 <em>BDB::PRIORITY_VERY_LOW</em>,
#<em>BDB::PRIORITY_LOW</em>, <em>BDB::PRIORITY_DEFAULT</em>,
#<em>BDB::PRIORITY_HIGH</em> or <em>BDB::PRIORITY_VERY_HIGH</em>
#
def cache_priority=value
end
#create a new sequence (see also <em>open_sequence</em>)
#
#equivalent to
#<em>open_sequence(key, BDB::CREATE|BDB::EXCL, init, options)</em>
#
#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)
#
#<em>key</em> : key for the sequence
#
#<em>flags</em> : flags can have BDB::CREATE, BDB::EXCL, BDB::AUTO_COMMIT,
#BDB::THREAD
#
#<em>init</em> : initial value for the sequence
#
#<em>options</em> : 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 <em>key</em>
#
#<em>flags</em> can have the values <em>BDB::GET_BOTH</em>,
#<em>BDB::SET_RECNO</em> or <em>BDB::RMW</em>
#
#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 <em> get</em>
def db_get(key, flags = 0)
end
#same than <em> get</em>
def fetch(key, flags = 0)
end
#Returns the primary key and the value corresponding to <em>key</em>
#in the secondary index
#
#only with >= 3.3.11
#
def pget(key, flags = 0)
end
#Stores the <em>value</em> associating with <em>key</em>
#
#If <em>nil</em> is given as the value, the association from the key will be
#removed.
#
def []=(key, value)
end
#Stores the <em>value</em> associating with <em>key</em>
#
#If <em>nil</em> is given as the value, the association from the <em>key</em>
#will be removed. It return the object deleted or <em>nil</em> if the
#specified key don't exist.
#
#<em>flags</em> can have the value <em>DBD::NOOVERWRITE</em>, in this case
#it will return <em>nil</em> if the specified key exist, otherwise <em>true</em>
#
def put(key, value, flags = 0)
end
#same than <em> put</em>
def db_put(key, value, flags = 0)
end
#same than <em> put</em>
def store(key, value, flags = 0)
end
#Append the <em>value</em> associating with <em>key</em>
#
def append(key, value)
end
#same than <em> append</em>
def db_append(key, value)
end
#Return if the underlying database is in host order
#
def byteswapped?
end
#same than <em> byteswapped?</em>
def get_byteswapped
end
#Clear partial set.
#
def clear_partial
end
#same than <em> clear_partial</em>
def partial_clear
end
#Closes the file.
#
def close(flags = 0)
end
#same than <em> close</em>
def db_close(flags = 0)
end
#Only for Btree and Recno (DB VERSION >= 4.4)
#
#* <em>start</em> 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.
#
#* <em>stop</em> 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
#
#* <em>options</em> hash with the possible keys
#
# * <em>flags</em> with the value 0, <em>BDB::FREELIST_ONLY</em>, or
# <em>BDB::FREE_SPACE</em>
#
# * <em>compact_fillpercent</em>the goal for filling pages, specified as a
# percentage between 1 and 100.
#
# * <em>compact_timeout</em> the lock timeout set for implicit transactions,
# in microseconds.
#
def compact(start = nil, stop = nil, options = nil)
end
#Return the count of duplicate for <em>key</em>
#
def count(key)
end
#same than <em> count</em>
def dup_count(key)
end
#Open a new cursor.
#
def cursor(flags = 0)
end
#same than <em> cursor</em>
def db_cursor(flags = 0)
end
#Open a new cursor with the flag <em>BDB::WRITECURSOR</em>
#
def cursor_write()
end
#same than <em> cursor_write</em>
def db_cursor_write(flags = 0)
end
#Return the subname
#
def database()
end
#same than <em> database</em>
def subname()
end
#Removes the association from the key.
#
#It return the object deleted or <em>nil</em> if the specified
#key don't exist.
#
def delete(key)
end
#same than <em> delete</em>
def db_del(key)
end
#Deletes associations if the evaluation of the block returns true.
#
#<em>set</em>
#
def delete_if(set = nil)
yield key, value
end
#same than <em> delete_if</em>
def reject!(set = nil)
yield key, value
end
#Return an array of all duplicate associations for <em>key</em>
#
#if <em>assoc</em> is <em>false</em> return only the values.
#
def duplicates(key , assoc = true)
end
#Iterates over associations.
#
#<em>set</em> <em>bulk</em>
#
def each(set = nil, bulk = 0, "flags" => 0)
yield key, value
end
#same than <em> each</em>
def each_pair(set = nil, bulk = 0)
yield key, value
end
#iterate over associations, where the key begin with
#<em>prefix</em>
def each_by_prefix(prefix = nil)
yield key, value
end
#Iterates over each duplicate associations for <em>key</em>
#
#<em>bulk</em>
#
def each_dup(key, bulk = 0)
yield key, value
end
#Iterates over each duplicate values for <em>key</em>
#
#<em>bulk</em>
#
def each_dup_value(key, bulk = 0)
yield value
end
#Iterates over keys.
#
#<em>set</em> <em>bulk</em>
#
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.
#
#<em>set</em> <em>bulk</em>
#
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 <em>key</em> exists.
#
def has_key?(key)
end
#same than <em> has_key?</em>
def key?(key)
end
#same than <em> has_key?</em>
def include?(key)
end
#same than <em> has_key?</em>
def member?(key)
end
#Returns true if the association from <em>key</em> is <em>value</em>
#
def has_both?(key, value)
end
#same than <em> has_both?</em>
def both?(key, value)
end
#Returns true if the association to the <em>value</em> exists.
#
def has_value?(value)
end
#same than <em> has_value?</em>
def value?(value)
end
#Returns the first <em>key</em> associated with <em>value</em>
#
def index(value)
end
#Returns the <em>keys</em> associated with <em>value1, value2, ...</em>
#
def indexes(value1, value2, )
end
#Perform a join. <em>cursor</em> is an array of <em>BDB::Cursor</em>
#
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 <em> length </em>
def size
end
#
#The <em>log_register</em> function registers a file <em>name</em>.
#
def log_register(name)
end
#
#The <em>log_unregister</em> 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
#
#<em>set</em>
#
def reverse_each(set = nil)
yield key, value
end
#same than <em> reverse_each</em>
def reverse_each_pair(set = nil)
yield key, value
end
#iterate over associations in reverse order, where the key begin with
#<em>prefix</em>
def reverse_each_by_prefix(prefix = nil)
yield key, value
end
#Iterates over keys in reverse order
#
#<em>set</em>
#
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.
#
#<em>set</em>
#
def reverse_each_value(set = nil)
yield value
end
#Set the partial value <em>len</em> and <em>offset</em>
#
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 <em> truncate</em>
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 <em>file</em> (file must respond to #to_io)
#
def verify(file = nil, flags = 0)
end
end
|