Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 Aug 1998 13:38:55 -0400
From:      Marc Tardif <intmktg@cam.org>
To:        freebsd-database@FreeBSD.ORG
Subject:   db(3) help
Message-ID:  <35CB3BAE.6C24C0FD@cam.org>

next in thread | raw e-mail | index | archive | help
Hi,
I'm struggling to understand the db(3) function. I am trying to create a
btree with a key and data, yet btreeop(1) only shows data for the
following program. I'd appreciate any help... really.
Marc

#include <sys/stat.h>

#include <db.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

#define PERM_SECURE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
#define MAX 12

int
main()
{
        DB *db;
        DBT data, key;
        char buf[MAX + 1], keybuf[MAX + 1];
        char dbtmp[MAX + 1], dbname[MAX + 1];

        (void)snprintf(dbtmp, sizeof(dbtmp), "dev.tmp");
        (void)snprintf(dbname, sizeof(dbtmp), "dev.db");
        if(!(db = dbopen(dbtmp, O_CREAT|O_EXLOCK|O_RDWR|O_TRUNC,
            PERM_SECURE, DB_BTREE, NULL)))
                err(1, "%s", dbtmp);


        key.data = keybuf;
        (void)strcpy(keybuf, "key");
        keybuf[3] = '\0';

        data.data = buf;
        (void)strcpy(buf, "dat");
        buf[3] = '\0';

        printf("%s\n%s\n", keybuf, buf);

        key.size = 4;
        data.size = 4;
        if ((db->put)(db, &key, &data, 0))
                err(1, "dbput %s", dbtmp);

        (void)(db->close)(db);
        if (rename(dbtmp, dbname))
                err(1, "rename %s to %s", dbtmp, dbname);
        exit(0);
}



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-database" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35CB3BAE.6C24C0FD>