# RPMDB.

## Data Structures

struct | rpmdb_s
| Describes the collection of index databases used by rpm. More...

## Files

file | rpmlib.h
file | dbconfig.c
file | rpmdb.c
file | rpmdb.h
| Access RPM indices using Berkeley DB interface(s).

## Enumerations

enum | rpmdbFlags { RPMDB_FLAG_JUSTCHECK = (1 << 0), RPMDB_FLAG_MINIMAL = (1 << 1), RPMDB_FLAG_CHROOT = (1 << 2) }

## Functions

int | rpmdbFindFpList (rpmdb db, fingerPrint *fpList, dbiIndexSet *matchList, int numItems)
| Find fingerprint matches in database.
unsigned int | rpmdbGetIteratorFileNum (rpmdbMatchIterator mi)

## RPMDB

typedef struct rpmdb_s * | rpmdb
typedef struct _dbiIndexSet * | dbiIndexSet
typedef struct _rpmdbMatchIterator * | rpmdbMatchIterator
int * | dbiTags
| Tags for which rpmdb indices will be built.
int | rpmdbOpen (const char *prefix, rpmdb *dbp, int mode, int perms)
| Open rpm database.
int | rpmdbInit (const char *prefix, int perms)
| Initialize database.
int | rpmdbVerify (const char *prefix)
| Verify database components.
int | rpmdbClose (rpmdb db)
| Close all database indices and free rpmdb.
int | rpmdbSync (rpmdb db)
| Sync all database indices.
int | rpmdbOpenAll (rpmdb db)
| Open all database indices.
int | rpmdbCountPackages (rpmdb db, const char *name)
| Return number of instances of package in rpm database.
rpmdbMatchIterator | rpmdbFreeIterator (rpmdbMatchIterator mi)
| Destroy rpm database iterator.
rpmdb | rpmdbGetIteratorRpmDB (rpmdbMatchIterator mi)
| Return rpm database used by iterator.
unsigned int | rpmdbGetIteratorOffset (rpmdbMatchIterator mi)
| Return join key for current position of rpm database iterator.
int | rpmdbGetIteratorCount (rpmdbMatchIterator mi)
| Return number of elements in rpm database iterator.
int | rpmdbAppendIterator (rpmdbMatchIterator mi, const int *hdrNums, int nHdrNums)
| Append items to set of package instances to iterate.
int | rpmdbPruneIterator (rpmdbMatchIterator mi, int *hdrNums, int nHdrNums, int sorted)
| Remove items from set of package instances to iterate.
int | rpmdbSetIteratorRE (rpmdbMatchIterator mi, rpmTag tag, rpmMireMode mode, const char *pattern)
| Add pattern to iterator selector.
int | rpmdbSetIteratorVersion (rpmdbMatchIterator mi, const char *version)
| Modify iterator to filter out headers that do not match version.
int | rpmdbSetIteratorRelease (rpmdbMatchIterator mi, const char *release)
| Modify iterator to filter out headers that do not match release.
int | rpmdbSetIteratorRewrite (rpmdbMatchIterator mi, int rewrite)
| Prepare iterator for lazy writes.
int | rpmdbSetIteratorModified (rpmdbMatchIterator mi, int modified)
| Modify iterator to mark header for lazy write.
Header | rpmdbNextIterator (rpmdbMatchIterator mi)
| Return next package header from iteration.
rpmdbMatchIterator | rpmdbInitIterator (rpmdb db, int rpmtag, const void *keyp, size_t keylen)
| Return database iterator.
int | rpmdbAdd (rpmdb db, int iid, Header h)
| Add package header to rpm database and indices.
int | rpmdbRemove (rpmdb db, int rid, unsigned int hdrNum)
| Remove package header from rpm database and indices.
int | rpmdbRebuild (const char *prefix)
| Rebuild database indices from package headers.

## Typedef Documentation

typedef struct _dbiIndexSet* dbiIndexSet

Definition at line 674 of file rpmlib.h.

typedef struct rpmdb_s* rpmdb

Definition at line 670 of file rpmlib.h.

typedef struct _rpmdbMatchIterator* rpmdbMatchIterator

Definition at line 754 of file rpmlib.h.

## Enumeration Type Documentation

enum rpmdbFlags

Enumerator:

  RPMDB_FLAG_JUSTCHECK |
  RPMDB_FLAG_MINIMAL |
  RPMDB_FLAG_CHROOT |

Definition at line 338 of file rpmdb.h.

## Function Documentation

int rpmdbAdd | ( | rpmdb | db,
|  | int | iid,
|  | Header | h |
| ) |  |  |

Add package header to rpm database and indices.

Parameters:

  | db | rpm database
  | iid | install transaction id (iid = 0 or -1 to skip)
  | h | header

Returns:
  0 on success

Definition at line 2592 of file rpmdb.c.

int rpmdbAppendIterator | ( | rpmdbMatchIterator | mi,
|  | const int * | hdrNums,
|  | int | nHdrNums |
| ) |  |  |

Append items to set of package instances to iterate.

Parameters:

  | mi | rpm database iterator
  | hdrNums | array of package instances
  | nHdrNums | number of elements in array

Returns:
  0 on success, 1 on failure (bad args)

Definition at line 2217 of file rpmdb.c.

int rpmdbClose | ( | rpmdb | db | ) |

Close all database indices and free rpmdb.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 813 of file rpmdb.c.

int rpmdbCountPackages | ( | rpmdb | db,
|  | const char * | name |
| ) |  |  |

Return number of instances of package in rpm database.

Parameters:

  | db | rpm database
  | name | rpm package name

Returns:
  number of instances

Definition at line 1249 of file rpmdb.c.

int rpmdbFindFpList | ( | rpmdb | db,
|  | fingerPrint * | fpList,
|  | dbiIndexSet * | matchList,
|  | int | numItems |
| ) |  |  |

Find fingerprint matches in database.

Parameters:

  | db | rpm database
  | fpList | fingerprint array

Return values:

  | matchList | returned fingerprint matches

Parameters:

  | numItems | number of fingerprint items

Returns:
  0 always

Definition at line 2876 of file rpmdb.c.

rpmdbMatchIterator rpmdbFreeIterator | ( | rpmdbMatchIterator | mi | ) |

Destroy rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  NULL always

Definition at line 1548 of file rpmdb.c.

int rpmdbGetIteratorCount | ( | rpmdbMatchIterator | mi | ) |

Return number of elements in rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  number of elements

Definition at line 1618 of file rpmdb.c.

unsigned int rpmdbGetIteratorFileNum | ( | rpmdbMatchIterator | mi | ) |

Definition at line 1612 of file rpmdb.c.

unsigned int rpmdbGetIteratorOffset | ( | rpmdbMatchIterator | mi | ) |

Return join key for current position of rpm database iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  current join key

Definition at line 1606 of file rpmdb.c.

rpmdb rpmdbGetIteratorRpmDB | ( | rpmdbMatchIterator | mi | ) |

Return rpm database used by iterator.

Parameters:

  | mi | rpm database iterator

Returns:
  rpm database handle

Definition at line 1598 of file rpmdb.c.

int rpmdbInit | ( | const char * | prefix,
|  | int | perms |
| ) |  |  |

Initialize database.

Parameters:

  | prefix | path to top of install tree
  | perms | database permissions

Returns:
  0 on success

Definition at line 1067 of file rpmdb.c.

rpmdbMatchIterator rpmdbInitIterator | ( | rpmdb | db,
|  | int | rpmtag,
|  | const void * | keyp,
|  | size_t | keylen |
| ) |  |  |

Return database iterator.

Parameters:

  | db | rpm database
  | rpmtag | rpm tag
  | keyp | key data (NULL for sequential access)
  | keylen | key data length (0 will use strlen(keyp))

Returns:
  NULL on failure

Definition at line 2228 of file rpmdb.c.

Header rpmdbNextIterator | ( | rpmdbMatchIterator | mi | ) |

Return next package header from iteration.

Parameters:

  | mi | rpm database iterator

Returns:
  NULL on end of iteration.

Definition at line 2019 of file rpmdb.c.

int rpmdbOpen | ( | const char * | prefix,
|  | rpmdb * | dbp,
|  | int | mode,
|  | int | perms |
| ) |  |  |

Open rpm database.

Parameters:

  | prefix | path to top of install tree

Return values:

  | dbp | address of rpm database

Parameters:

  | mode | open(2) flags: O_RDWR or O_RDONLY (O_CREAT also)
  | perms | database permissions

Returns:
  0 on success

Definition at line 1059 of file rpmdb.c.

int rpmdbOpenAll | ( | rpmdb | db | ) |

Open all database indices.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 796 of file rpmdb.c.

int rpmdbPruneIterator | ( | rpmdbMatchIterator | mi,
|  | int * | hdrNums,
|  | int | nHdrNums,
|  | int | sorted |
| ) |  |  |

Remove items from set of package instances to iterate.

Note:
  Sorted hdrNums are always passed in rpmlib.

Parameters:

  | mi | rpm database iterator
  | hdrNums | array of package instances
  | nHdrNums | number of elements in array
  | sorted | is the array sorted? (array will be sorted on return)

Returns:
  0 on success, 1 on failure (bad args)

Definition at line 2206 of file rpmdb.c.

int rpmdbRebuild | ( | const char * | prefix | ) |

Rebuild database indices from package headers.

Parameters:

  | prefix | path to top of install tree

Returns:
  0 on success

Definition at line 3230 of file rpmdb.c.

int rpmdbRemove | ( | rpmdb | db,
|  | int | rid,
|  | unsigned int | hdrNum |
| ) |  |  |

Remove package header from rpm database and indices.

Parameters:

  | db | rpm database
  | rid | remove transaction id (rid = 0 or -1 to skip)
  | hdrNum | package instance number in database

Returns:
  0 on success

Definition at line 2368 of file rpmdb.c.

int rpmdbSetIteratorModified | ( | rpmdbMatchIterator | mi,
|  | int | modified |
| ) |  |  |

Modify iterator to mark header for lazy write.

Parameters:

  | mi | rpm database iterator
  | modified | new value of modified

Returns:
  previous value

Definition at line 2004 of file rpmdb.c.

int rpmdbSetIteratorRE | ( | rpmdbMatchIterator | mi,
|  | rpmTag | tag,
|  | rpmMireMode | mode,
|  | const char * | pattern |
| ) |  |  |

Add pattern to iterator selector.

Parameters:

  | mi | rpm database iterator
  | tag | rpm tag
  | mode | type of pattern match
  | pattern | pattern to match

Returns:
  0 on success

Definition at line 1774 of file rpmdb.c.

int rpmdbSetIteratorRelease | ( | rpmdbMatchIterator | mi,
|  | const char * | release |
| ) |  |  |

Modify iterator to filter out headers that do not match release.

Deprecated:
  Use rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_DEFAULT, release) instead.

Todo:
  Eliminate from API.

Parameters:

  | mi | rpm database iterator
  | release | release to match (can be a regex pattern)

Returns:
  0 on success

Definition at line 1984 of file rpmdb.c.

int rpmdbSetIteratorRewrite | ( | rpmdbMatchIterator | mi,
|  | int | rewrite |
| ) |  |  |

Prepare iterator for lazy writes.

Note:
  Must be called before rpmdbNextIterator() in CDB model database.

Parameters:

  | mi | rpm database iterator
  | rewrite | new value of rewrite

Returns:
  previous value

Definition at line 1992 of file rpmdb.c.

int rpmdbSetIteratorVersion | ( | rpmdbMatchIterator | mi,
|  | const char * | version |
| ) |  |  |

Modify iterator to filter out headers that do not match version.

Deprecated:
  Use rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_DEFAULT, version) instead.

Todo:
  Eliminate from API.

Parameters:

  | mi | rpm database iterator
  | version | version to match (can be a regex pattern)

Returns:
  0 on success

Definition at line 1988 of file rpmdb.c.

int rpmdbSync | ( | rpmdb | db | ) |

Sync all database indices.

Parameters:

  | db | rpm database

Returns:
  0 on success

Definition at line 840 of file rpmdb.c.

int rpmdbVerify | ( | const char * | prefix | ) |

Verify database components.

Parameters:

  | prefix | path to top of install tree

Returns:
  0 on success

Definition at line 1088 of file rpmdb.c.

## Variable Documentation

int* dbiTags

Tags for which rpmdb indices will be built.

Definition at line 61 of file rpmdb.c.