diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-04-20 15:22:42 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-04-20 15:46:32 +0300 |
commit | e05e92d4ed7df7c60a422a7a3495b7f8cc0a1075 (patch) | |
tree | 7f052b6fed4248b64abb027bdbbffb87e777e475 /lib/backend | |
parent | d8d63645a0307e05af1e11f98a3bc237d1561c77 (diff) | |
download | librpm-tizen-e05e92d4ed7df7c60a422a7a3495b7f8cc0a1075.tar.gz librpm-tizen-e05e92d4ed7df7c60a422a7a3495b7f8cc0a1075.tar.bz2 librpm-tizen-e05e92d4ed7df7c60a422a7a3495b7f8cc0a1075.zip |
And another foot deeper...
- Inline dbiGet(), dbiPut(), dbiDel() and dbiCount() implementations
to the new interface
Diffstat (limited to 'lib/backend')
-rw-r--r-- | lib/backend/db3.c | 141 |
1 files changed, 56 insertions, 85 deletions
diff --git a/lib/backend/db3.c b/lib/backend/db3.c index b948025fe..44c06ac30 100644 --- a/lib/backend/db3.c +++ b/lib/backend/db3.c @@ -274,133 +274,104 @@ static int dbiCopen(dbiIndex dbi, DBC ** dbcp, unsigned int dbiflags) return rc; } -/* Store (key,data) pair in index database. */ -static int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data, - unsigned int flags) +dbiCursor dbiCursorInit(dbiIndex dbi, unsigned int flags) { - int rc = EINVAL; - - assert(key->data != NULL && key->size > 0 && data->data != NULL && data->size > 0); - - if (dbcursor) { - rpmswEnter(&dbi->dbi_rpmdb->db_putops, (ssize_t) 0); - - rc = dbcursor->c_put(dbcursor, key, data, DB_KEYLAST); - rc = cvtdberr(dbi, "dbcursor->c_put", rc, _debug); + dbiCursor dbc = NULL; + DBC * cursor = NULL; - rpmswExit(&dbi->dbi_rpmdb->db_putops, (ssize_t) data->size); + if (dbi && dbiCopen(dbi, &cursor, flags) == 0) { + dbc = xcalloc(1, sizeof(*dbc)); + dbc->cursor = cursor; + dbc->dbi = dbi; } + return dbc; +} - return rc; +dbiCursor dbiCursorFree(dbiCursor dbc) +{ + if (dbc) { + dbiCclose(dbc->dbi, dbc->cursor, 0); + } + return NULL; } -static int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data, - unsigned int flags) +int dbiCursorPut(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { int rc = EINVAL; - assert(key->data != NULL && key->size > 0); + assert(key->data != NULL && key->size > 0 && data->data != NULL && data->size > 0); - if (dbcursor) { - int _printit; - rpmswEnter(&dbi->dbi_rpmdb->db_delops, 0); + if (dbc) { + DBC * cursor = dbc->cursor; + rpmdb rdb = dbc->dbi->dbi_rpmdb; + rpmswEnter(&rdb->db_putops, (ssize_t) 0); - /* XXX TODO: insure that cursor is positioned with duplicates */ - rc = dbcursor->c_get(dbcursor, key, data, DB_SET); - /* XXX DB_NOTFOUND can be returned */ - _printit = (rc == DB_NOTFOUND ? 0 : _debug); - rc = cvtdberr(dbi, "dbcursor->c_get", rc, _printit); + rc = cursor->c_put(cursor, key, data, DB_KEYLAST); + rc = cvtdberr(dbc->dbi, "dbcursor->c_put", rc, _debug); - if (rc == 0) { - rc = dbcursor->c_del(dbcursor, flags); - rc = cvtdberr(dbi, "dbcursor->c_del", rc, _debug); - } - rpmswExit(&dbi->dbi_rpmdb->db_delops, data->size); + rpmswExit(&rdb->db_putops, (ssize_t) data->size); } - return rc; } -/* Retrieve (key,data) pair from index database. */ -static int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data, - unsigned int flags) +int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { int rc = EINVAL; assert((flags == DB_NEXT) || (key->data != NULL && key->size > 0)); - if (dbcursor) { + if (dbc) { + DBC * cursor = dbc->cursor; + rpmdb rdb = dbc->dbi->dbi_rpmdb; int _printit; - rpmswEnter(&dbi->dbi_rpmdb->db_getops, 0); + rpmswEnter(&rdb->db_getops, 0); /* XXX db4 does DB_FIRST on uninitialized cursor */ - rc = dbcursor->c_get(dbcursor, key, data, flags); + rc = cursor->c_get(cursor, key, data, flags); /* XXX DB_NOTFOUND can be returned */ _printit = (rc == DB_NOTFOUND ? 0 : _debug); - rc = cvtdberr(dbi, "dbcursor->c_get", rc, _printit); + rc = cvtdberr(dbc->dbi, "dbcursor->c_get", rc, _printit); - rpmswExit(&dbi->dbi_rpmdb->db_getops, data->size); + rpmswExit(&rdb->db_getops, data->size); } - return rc; } -static int dbiCount(dbiIndex dbi, DBC * dbcursor, - unsigned int * countp, - unsigned int flags) -{ - db_recno_t count = 0; - int rc = 0; - - flags = 0; - rc = dbcursor->c_count(dbcursor, &count, flags); - rc = cvtdberr(dbi, "dbcursor->c_count", rc, _debug); - if (rc) return rc; - if (countp) *countp = count; - - return rc; -} - -dbiCursor dbiCursorInit(dbiIndex dbi, unsigned int flags) +int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) { - dbiCursor dbc = NULL; - DBC * cursor = NULL; + int rc = EINVAL; - if (dbi && dbiCopen(dbi, &cursor, flags) == 0) { - dbc = xcalloc(1, sizeof(*dbc)); - dbc->cursor = cursor; - dbc->dbi = dbi; - } - return dbc; -} + assert(key->data != NULL && key->size > 0); -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); -} + DBC * cursor = dbc->cursor; + int _printit; + rpmdb rdb = dbc->dbi->dbi_rpmdb; + rpmswEnter(&rdb->db_delops, 0); -int dbiCursorGet(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) -{ - return dbiGet(dbc->dbi, dbc->cursor, key, data, flags); -} + /* XXX TODO: insure that cursor is positioned with duplicates */ + rc = cursor->c_get(cursor, key, data, DB_SET); + /* XXX DB_NOTFOUND can be returned */ + _printit = (rc == DB_NOTFOUND ? 0 : _debug); + rc = cvtdberr(dbc->dbi, "dbcursor->c_get", rc, _printit); -int dbiCursorDel(dbiCursor dbc, DBT * key, DBT * data, unsigned int flags) -{ - return dbiDel(dbc->dbi, dbc->cursor, key, data, flags); + if (rc == 0) { + rc = cursor->c_del(cursor, flags); + rc = cvtdberr(dbc->dbi, "dbcursor->c_del", rc, _debug); + } + rpmswExit(&rdb->db_delops, data->size); + } + return rc; } unsigned int dbiCursorCount(dbiCursor dbc) { db_recno_t count = 0; - dbiCount(dbc->dbi, dbc->cursor, &count, 0); + if (dbc) { + DBC * cursor = dbc->cursor; + int rc = cursor->c_count(cursor, &count, 0); + cvtdberr(dbc->dbi, "dbcursor->c_count", rc, _debug); + } return count; } |