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

Berkeley DB Reference Guide: Access Methods



:

Partial Record Storing and Retrieval



PIt is possible to both store and retrieve parts of data items in all Berkeley DBtaccess methods. This is done by specifying the DB_DBT_PARTIAL>flag to the DBT structure passed to the Berkeley DB interface.

tThe DB_DBT_PARTIAL flag is based on the values of two elements6of the DBT structure, dlen and doff. The value@of dlen is the number of bytes of the record in which theGapplication is interested. The value of doff is the offset from7the beginning of the data item where those bytes start.

EFor example, if the data item were ABCDEFGHIJKL, a doff?value of 3 would indicate that the bytes of interest started atDD, and a dlen value of 4 would indicate that the bytesof interest were DEFG.

BWhen retrieving a data item from a database, the dlen bytesIstarting doff bytes from the beginning of the record are returned,Gas if they comprised the entire record. If any or all of the specifiedGbytes do not exist in the record, the retrieval is still successful and-the existing bytes or nul bytes are returned.

AWhen storing a data item into the database, the dlen bytesDstarting doff bytes from the beginning of the specified key'sCdata record are replaced by the data specified by the data and sizeDstructure elements. If dlen is smaller than size, theDrecord will grow, and if dlen is larger than size, theHrecord will shrink. If the specified bytes do not exist, the record willGbe extended using nul bytes as necessary, and the store call will stillsucceed.

:The following are various examples of the put case for thetDB_DBT_PARTIAL flag. In all examples, the initial data item is20 bytes in length:

ABCDEFGHIJ0123456789

    

  1. 

  2. 

  3. 

  4. 

  5. 

  6. 

  7. 



JAGÿÿ