/I:Berkeley DB Reference Guide: Access Methods[P4

Berkeley DB Reference Guide: Access Methods



A

Logically renumbering records (DB_RENUMBER)



HRecords stored in the Recno access method are accessed by logical recordEnumber. By default, these record numbers are not mutable. What that>means is if you delete record number 5, record number 6 is notEautomatically renumbered to be record number 5 and 7 renumbered to beFrecord number 6 and so on. For the same reason, new records cannot be,inserted inbetween already existing records.

GIt is possible to make the logical record numbers mutable by specifyingothe DB_RENUMBER flag in the DB_INFO structure during theedb_open call to open the database. This means that the recordFnumbers may change change as records are added to and deleted from the database.

FFor example, the deletion of record number 4 causes records numbered 5Gand greater to be renumbered downward by 1. If a cursor was positionedFto record number 4 before the deletion, it will suddenly reference theHnew record number 4, if any such record exists, after the deletion. If aHcursor was positioned after record number 4 before the deletion, it willFbe shifted downward 1 logical record, continuing to reference the samerecord as it did before.

ESimilarly, if a created record is not at the end of the database, allHrecords following the new record will be automatically renumbered upwardIby 1. For example, the creation of a new record numbered 8 causes recordsDnumbered 8 and greater to be renumbered upward by 1. If a cursor wasIpositioned to record number 8 or greater before the insertion, it will beHshifted upward 1 logical record, continuing to reference the same recordas it did before.

AFor these reasons, concurrent access to a Recno database with thevDB_RENUMBER flag specified may be largely meaningless, althoughit is supported.

DIn the case of Recno databases where record numbers are not mutable,Fany attempt to retrieve deleted records will result in a special errorreturn, DB_KEYEMPTY.

JWhen using both mutable and immutable record numbers, creating new recordsHwill cause the creation of multiple records if the record number is moreGthan one greater than the largest record currently in the database. ForEexample, creating record number 28, when record 25 was previously theIlast record in the database, will create records 26 and 27 as well as 28.

HFirst, last, next and previous cursor operations will automatically skipHover implicitly created records. For example, if record number 5 is theFonly record the application has created, implicitly creating records 1–through 4, the DBcursor->c_get interface with the DB_FIRST flagIwill return record number 5, not record number 1. Attempts to explicitlyJretrieve records that were created in this manner will result in a specialerror return, DB_KEYEMPTY.

KAJÿÿ