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.38; 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.10.15.03.47.33; 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 @
|
![]() ![]() ![]() |
The DBcursor->c_get function is the standard interface for retrieving records from the database with a cursor. The DBcursor->c_get function takes a flag which controls how the cursor is positioned within the database and returns the key/data item associated with that positioning. Similar to DB->get, DBcursor->c_get may also take a supplied key and retrieve the data associated with that key from the database. There are several flags that you can set to customize retrieval.
In all cases, the cursor is repositioned by a DBcursor->c_get operation to point to the newly-returned key/data pair in the database.
The following is a code example showing a cursor walking through a database and displaying the records it contains to the standard output:
int display(database) char *database; { DB *dbp; DBC *dbcp; DBT key, data; int close_db, close_dbc, ret;close_db = close_dbc = 0;
/* Open the database. */ if ((ret = db_create(&dbp, NULL, 0)) != 0) { fprintf(stderr, "%s: db_create: %s\n", progname, db_strerror(ret)); return (1); }
/* Turn on additional error output. */ dbp->set_errfile(dbp, stderr); dbp->set_errpfx(dbp, progname);
/* Open the database. */ if ((ret = dbp->open(dbp, database, NULL, DB_UNKNOWN, DB_RDONLY, 0)) != 0) { dbp->err(dbp, ret, "%s: DB->open", database); goto err; }
/* Acquire a cursor for the database. */ if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) { dbp->err(dbp, ret, "DB->cursor"); goto err; }
/* Initialize the key/data return pair. */ memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data));
/* Walk through the database and print out the key/data pairs. */ while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) printf("%.*s : %.*s\n", (int)key.size, (char *)key.data, (int)data.size, (char *)data.data); if (ret != DB_NOTFOUND) { dbp->err(dbp, ret, "DBcursor->get"); goto err; }
err: if (close_dbc && (ret = dbcp->c_close(dbcp)) != 0) dbp->err(dbp, ret, "DBcursor->close"); if (close_db && (ret = dbp->close(dbp, 0)) != 0) fprintf(stderr, "%s: DB->close: %s\n", progname, db_strerror(ret)); return (0); }
![]() ![]() ![]() |
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 a48 2
The DBcursor->c_get method is the standard interface for retrieving records from the database with a cursor. The DBcursor->c_get method takes a flag which d98 1 a98 1 dbp->open(dbp, NULL, database, NULL, DB_UNKNOWN, DB_RDONLY, 0)) != 0) { @ 1.1.1.4 log @Import: RPM 4.1 @ text @d1 2 a2 2 d4 1 d19 2 a20 2
The DBcursor->c_get function is the standard interface for retrieving records from the database with a cursor. The DBcursor->c_get function takes a flag which d99 1 a99 1 dbp->open(dbp, database, NULL, DB_UNKNOWN, DB_RDONLY, 0)) != 0) { @ 1.1.1.5 log @Import: RPM 4.1.1 @ text @d1 2 a2 2 a3 1 d18 2 a19 2
The DBcursor->c_get method is the standard interface for retrieving records from the database with a cursor. The DBcursor->c_get method takes a flag which d98 1 a98 1 dbp->open(dbp, NULL, database, NULL, DB_UNKNOWN, DB_RDONLY, 0)) != 0) { @