Date: Mon, 10 Aug 1998 01:07:37 -0400 (EDT) From: Alex Boisvert <alex@gel.usherb.ca> To: Marc Tardif <intmktg@cam.org> Cc: freebsd-database@FreeBSD.ORG Subject: Re: db(3) help Message-ID: <Pine.BSF.3.95q.980810004918.11653A-200000@teel.info-noire.com> In-Reply-To: <35CB3BAE.6C24C0FD@cam.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Fri, 7 Aug 1998, Marc Tardif wrote:
> 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.
Salut Marc,
The program you supplied is correct. It does create a new entry in
the database having the key "key" and data "dat".
When you run btreeop(1) without any action argument, it displays only the
data portions of the entries in the database. You probably think/expect
btreeop(1) to display both the key and data portions.
This is (probably) because the database format created/used by btreeop(1)
is "mis-documented". Say you create a database with btreeop, something
like:
% btreeop -C
key1 data1
key2 data2
^D
You'll get entries in the database looking like:
Entry# Key Data
====== ===== =======
1 key1 key1 data1
2 key2 key2 data2
As you can see, with btreeop(1) the key part is repeated in the data
portion of the entry.
I have attached to this email a program which displays both the key and
the data portions of a database.
Regards,
Alex Boisvert
---
FreeBSD: Decouvrez la puissance de votre PC! www.freebsd.org
[-- Attachment #2 --]
#include <sys/stat.h>
#include <db.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
DB *db;
DBT data, key;
int ret;
if (argc != 2) {
printf("Usage: dbread <filename>\n");
}
if(!(db = dbopen(argv[1], O_CREAT|O_EXLOCK|O_RDWR,
0, DB_BTREE, NULL))) {
err(1, "%s", argv[1]);
}
key.size = data.size = 0;
key.data = data.data = NULL;
while (1) {
if (db->seq(db, &key, &data, R_NEXT) != 0) {
break;
}
printf("Key: %s\n", key.data);
printf("Data: %s\n", data.data);
}
(void)(db->close)(db);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95q.980810004918.11653A-200000>
