head 1.2; access; symbols RPM_4_2_1:1.1.1.5 RPM_4_2:1.1.1.5 RPM_4_1_1:1.1.1.5 RPM_4_1:1.1.1.4 RPM_4_0_5:1.1.1.3 RPM_4_0_4:1.1.1.2 RPM_4_0_3:1.1.1.1 RPM:1.1.1; locks; strict; comment @# @; 1.2 date 2008.01.02.09.54.42; author rse; state dead; branches; next 1.1; commitid z4cpSiAhOCXk5PLs; 1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.07.23.20.45.37; author rse; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 2002.01.08.00.30.11; author rse; state Exp; branches; next 1.1.1.3; 1.1.1.3 date 2003.01.18.13.49.01; author rse; state Exp; branches; next 1.1.1.4; 1.1.1.4 date 2001.07.23.20.09.17; author rse; state Exp; branches; next 1.1.1.5; 1.1.1.5 date 2003.01.18.14.04.59; author rse; state Exp; branches; next ; desc @@ 1.2 log @remove the ancient RPM 4.2.1 source tree copy @ text @ Berkeley DB Reference Guide: Retrieving Btree records by logical record number

Berkeley DB Reference Guide:
Access Methods

PrevRefNext

Retrieving Btree records by logical record number

The Btree access method optionally supports retrieval by logical record numbers. To configure a Btree to support record numbers, call the DB->set_flags function with the DB_RECNUM flag.

Configuring a Btree for record numbers should not be done lightly. While often useful, it may significantly slow down the speed at which items can be stored into the database, and can severely impact application throughput. Generally it should be avoided in trees with a need for high write concurrency.

To retrieve by record number, use the DB_SET_RECNO flag to the DB->get and DBcursor->c_get functions. The following is an example of a routine that displays the data item for a Btree database created with the DB_RECNUM option.

int
rec_display(dbp, recno)
	DB *dbp;
	db_recno_t recno;
{
	DBT key, data;
	int ret;

memset(&key, 0, sizeof(key)); key.data = &recno; key.size = sizeof(recno); memset(&data, 0, sizeof(data));

if ((ret = dbp->get(dbp, NULL, &key, &data, DB_SET_RECNO)) != 0) return (ret); printf("data for %lu: %.*s\n", (u_long)recno, (int)data.size, (char *)data.data); return (0); }

To determine a key's record number, use the DB_GET_RECNO flag to the DBcursor->c_get function. The following is an example of a routine that displays the record number associated with a specific key.

int
recno_display(dbp, keyvalue)
	DB *dbp;
	char *keyvalue;
{
	DBC *dbcp;
	DBT key, data;
	db_recno_t recno;
	int ret, t_ret;

/* Acquire a cursor for the database. */ if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) { dbp->err(dbp, ret, "DB->cursor"); goto err; }

/* Position the cursor. */ memset(&key, 0, sizeof(key)); key.data = keyvalue; key.size = strlen(keyvalue); memset(&data, 0, sizeof(data)); if ((ret = dbcp->c_get(dbcp, &key, &data, DB_SET)) != 0) { dbp->err(dbp, ret, "DBC->c_get(DB_SET): %s", keyvalue); goto err; }

/* * Request the record number, and store it into appropriately * sized and aligned local memory. */ memset(&data, 0, sizeof(data)); data.data = &recno; data.ulen = sizeof(recno); data.flags = DB_DBT_USERMEM; if ((ret = dbcp->c_get(dbcp, &key, &data, DB_GET_RECNO)) != 0) { dbp->err(dbp, ret, "DBC->c_get(DB_GET_RECNO)"); goto err; }

printf("key for requested key was %lu\n", (u_long)recno);

err: /* Close the cursor. */ if ((t_ret = dbcp->c_close(dbcp)) != 0) { if (ret == 0) ret = t_ret; dbp->err(dbp, ret, "DBC->close"); } return (ret); }


PrevRefNext

Copyright Sleepycat Software @ 1.1 log @Initial revision @ text @d1 1 a1 1 @ 1.1.1.1 log @Import: RPM 4.0.3 @ text @@ 1.1.1.2 log @Import: RPM 4.0.4 @ text @d1 1 a1 1 @ 1.1.1.3 log @Import: RPM 4.0.5 @ text @d1 2 a2 2 a3 1 d20 1 a20 1 DB->set_flags method with the DB_RECNUM flag. d27 1 a27 1 DB->get and DBcursor->c_get methods. The following is an example of d50 1 a50 1 to the DBcursor->c_get method. The following is an example of a routine that @ 1.1.1.4 log @Import: RPM 4.1 @ text @d1 2 a2 2 d4 1 d21 1 a21 1 DB->set_flags function with the DB_RECNUM flag. d28 1 a28 1 DB->get and DBcursor->c_get functions. The following is an example of d51 1 a51 1 to the DBcursor->c_get function. The following is an example of a routine that @ 1.1.1.5 log @Import: RPM 4.1.1 @ text @d1 2 a2 2 a3 1 d20 1 a20 1 DB->set_flags method with the DB_RECNUM flag. d27 1 a27 1 DB->get and DBcursor->c_get methods. The following is an example of d50 1 a50 1 to the DBcursor->c_get method. The following is an example of a routine that @