diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-04-20 13:52:41 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-04-20 14:04:17 +0300 |
commit | fb548c0612c40502f668eca7b70b8447afccf6f1 (patch) | |
tree | bb5f074bceaa0b29279b1574da2030f4ce35c7aa /lib/backend | |
parent | 9ae37ce58ae68dc502b7f2d018df45dd9884c695 (diff) | |
download | librpm-tizen-fb548c0612c40502f668eca7b70b8447afccf6f1.tar.gz librpm-tizen-fb548c0612c40502f668eca7b70b8447afccf6f1.tar.bz2 librpm-tizen-fb548c0612c40502f668eca7b70b8447afccf6f1.zip |
Add a db cursor abstraction and interfaces for using it
- Callers are currently required to pass all sorts of unnecessary
gunk to the cursor operations just for performance statistics
etc, and the interface doesn't match the uses inside rpmdb.c
very well. This adds a more "rpm-style" interface around the
BDB API.
- Cursor open + close can only fail on invalid arguments (which would
be programmer errors), and various conditions on replication which
we dont care about. So we essentially ignore the errors, except
for cursor open which will return NULL to indicate an error.
- As an intermediate step, these are just wrappers to the older
dbiFoo interfaces to permit converting things to the new interfaces
piece by piece.
Diffstat (limited to 'lib/backend')
-rw-r--r-- | lib/backend/db3.c | 49 | ||||
-rw-r--r-- | lib/backend/dbi.h | 19 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lib/backend/db3.c b/lib/backend/db3.c index 0b364bde4..41c550db1 100644 --- a/lib/backend/db3.c +++ b/lib/backend/db3.c @@ -20,6 +20,11 @@ static int _debug = 1; /* XXX if < 0 debugging, > 0 unusual error returns */ static const char * _errpfx = "rpmdb"; +struct dbiCursor_s { + dbiIndex dbi; + DBC *cursor; +}; + static int dbapi_err(rpmdb rdb, const char * msg, int error, int printit) { if (printit && error) { @@ -269,7 +274,6 @@ int dbiCopen(dbiIndex dbi, DBC ** dbcp, unsigned int dbiflags) return rc; } - /* Store (key,data) pair in index database. */ int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data, unsigned int flags) @@ -357,6 +361,49 @@ int dbiCount(dbiIndex dbi, DBC * dbcursor, return rc; } +dbiCursor dbiCursorInit(dbiIndex dbi, unsigned int flags) +{ + dbiCursor dbc = NULL; + DBC * cursor = NULL; + + if (dbi && dbiCopen(dbi, &cursor, flags) == 0) { + dbc = xcalloc(1, sizeof(*dbc)); + dbc->cursor = cursor; + dbc->dbi = dbi; + } + return dbc; +} + +dbiCursor dbiCursorFree(dbiCursor dbc) +{ + if (dbc) { + dbiCclose(dbc->dbi, dbc->cursor, 0); + } + return NULL; +} + +int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) +{ + return dbiPut(dbc->dbi, dbc->cursor, key, data, flags); +} + +int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) +{ + return dbiGet(dbc->dbi, dbc->cursor, key, data, flags); +} + +int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) +{ + return dbiDel(dbc->dbi, dbc->cursor, key, data, flags); +} + +unsigned int dbiCursorCount(dbiCursor dbc) +{ + db_recno_t count = 0; + dbiCount(dbc->dbi, dbc->cursor, &count, 0); + return count; +} + int dbiByteSwapped(dbiIndex dbi) { DB * db = dbi->dbi_db; diff --git a/lib/backend/dbi.h b/lib/backend/dbi.h index 1e51a3a0b..249a35fa3 100644 --- a/lib/backend/dbi.h +++ b/lib/backend/dbi.h @@ -8,6 +8,7 @@ enum rpmdbFlags { }; typedef struct dbiIndex_s * dbiIndex; +typedef struct dbiCursor_s * dbiCursor; struct dbConfig_s { int db_mmapsize; /*!< (10Mb) */ @@ -263,6 +264,24 @@ int dbiFlags(dbiIndex dbi); RPM_GNUC_INTERNAL const char * dbiName(dbiIndex dbi); +RPM_GNUC_INTERNAL +dbiCursor dbiCursorInit(dbiIndex dbi, unsigned int flags); + +RPM_GNUC_INTERNAL +dbiCursor dbiCursorFree(dbiCursor dbc); + +RPM_GNUC_INTERNAL +int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags); + +RPM_GNUC_INTERNAL +int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags); + +RPM_GNUC_INTERNAL +int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags); + +RPM_GNUC_INTERNAL +unsigned int dbiCursorCount(dbiCursor dbc); + #ifdef __cplusplus } #endif |