diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-06-01 09:02:12 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-06-01 09:02:12 +0800 |
commit | 8f183d269e13e528442def98657e040b3728597d (patch) | |
tree | b6de7454fd22221b7e49bf7b8a408424fb8af6b5 /e-util/e-dbhash.c | |
parent | 9d1e57701a113ad29c920cfa26b9966115570f08 (diff) | |
download | gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.tar.gz gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.tar.zst gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.zip |
Included information about db3.
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* README: Included information about db3.
* acconfig.h: Added HAVE_DB_H and HAVE_DB3_DB_H.
* configure.in: Added various checks for db3 libraries and
includes. Of note are the new configure options
--with-db3-includes=PREFIX and --with-db3-libs=PREFIX to specify
the location for your db3 library.
From addressbook/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* backend/pas/Makefile.am (INCLUDES): Added db3 cflags.
* backend/pas/pas-backend-file.c: Updated this to use db3.
From e-util/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* Makefile.am (INCLUDES): Added db3 cflags.
* e-dbhash.c: Made this use db3.
* e-db3-utils.c, e-db3-utils.h: New files with some helper
functions.
From wombat/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* Makefile.am (wombat_LDADD): Added db3 libs.
svn path=/trunk/; revision=10077
Diffstat (limited to 'e-util/e-dbhash.c')
-rw-r--r-- | e-util/e-dbhash.c | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/e-util/e-dbhash.c b/e-util/e-dbhash.c index e286500066..a61318e7ab 100644 --- a/e-util/e-dbhash.c +++ b/e-util/e-dbhash.c @@ -7,19 +7,19 @@ */ #include <config.h> + +#include "e-dbhash.h" + #include <string.h> #include <fcntl.h> -#ifdef HAVE_DB_185_H -#include <db_185.h> -#else -#ifdef HAVE_DB1_DB_H -#include <db1/db.h> -#else #include <db.h> -#endif -#endif #include "md5-utils.h" -#include "e-dbhash.h" + +#if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 +#error Including wrong DB3. Need libdb 3.1.17. +#endif struct _EDbHashPrivate { @@ -31,20 +31,37 @@ e_dbhash_new (const char *filename) { EDbHash *edbh; DB *db; + int rv; + + int major, minor, patch; + + db_version (&major, &minor, &patch); + + if (major != 3 || + minor != 1 || + patch != 17) { + g_warning ("Wrong version of libdb."); + return NULL; + } /* Attempt to open the database */ - db = dbopen (filename, O_RDWR, 0666, DB_HASH, NULL); - if (db == NULL) { - db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + rv = db_create (&db, NULL, 0); + if (rv != 0) { + return NULL; + } + + rv = db->open (db, filename, NULL, DB_HASH, 0, 0666); + if (rv != 0) { + rv = db->open (db, filename, NULL, DB_HASH, DB_CREATE, 0666); - if (db == NULL) + if (rv != 0) return NULL; } - + edbh = g_new (EDbHash, 1); edbh->priv = g_new (EDbHashPrivate, 1); edbh->priv->db = db; - + return edbh; } @@ -86,7 +103,7 @@ e_dbhash_add (EDbHash *edbh, const gchar *key, const gchar *data) md5_to_dbt (local_hash, &ddata); /* Add to database */ - db->put (db, &dkey, &ddata, 0); + db->put (db, NULL, &dkey, &ddata, 0); } void @@ -105,7 +122,7 @@ e_dbhash_remove (EDbHash *edbh, const char *key) string_to_dbt (key, &dkey); /* Remove from database */ - db->del (db, &dkey, 0); + db->del (db, NULL, &dkey, 0); } void @@ -114,6 +131,7 @@ e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) DB *db; DBT dkey; DBT ddata; + DBC *dbc; int db_error = 0; g_return_if_fail (edbh != NULL); @@ -122,13 +140,20 @@ e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) db = edbh->priv->db; - db_error = db->seq(db, &dkey, &ddata, R_FIRST); + db_error = db->cursor (db, NULL, &dbc, 0); + + if (db_error != 0) { + return; + } + + db_error = dbc->c_get(dbc, &dkey, &ddata, DB_FIRST); while (db_error == 0) { (*func) ((const char *)dkey.data, user_data); - db_error = db->seq(db, &dkey, &ddata, R_NEXT); + db_error = dbc->c_get(dbc, &dkey, &ddata, DB_NEXT); } + dbc->c_close (dbc); } EDbHashStatus @@ -151,7 +176,7 @@ e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data) /* Lookup in database */ memset (&ddata, 0, sizeof (DBT)); - db->get (db, &dkey, &ddata, 0); + db->get (db, NULL, &dkey, &ddata, 0); /* Compare */ if (ddata.data) { @@ -191,10 +216,8 @@ e_dbhash_destroy (EDbHash *edbh) db = edbh->priv->db; /* Close datbase */ - db->close (db); + db->close (db, 0); g_free (edbh->priv); g_free (edbh); } - - |