From owner-freebsd-database Mon Aug 10 04:45:11 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA27160 for freebsd-database-outgoing; Mon, 10 Aug 1998 04:45:11 -0700 (PDT) (envelope-from owner-freebsd-database@FreeBSD.ORG) Received: from teel.info-noire.com (XP11-1-3-02.interlinx.qc.ca [207.253.79.62]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA27155 for ; Mon, 10 Aug 1998 04:45:07 -0700 (PDT) (envelope-from alex@gel.usherb.ca) Received: from localhost (alex@localhost) by teel.info-noire.com (8.8.8/8.8.8) with SMTP id BAA12487; Mon, 10 Aug 1998 01:07:37 -0400 (EDT) (envelope-from alex@teel.info-noire.com) Date: Mon, 10 Aug 1998 01:07:37 -0400 (EDT) From: Alex Boisvert Reply-To: boia01@gel.usherb.ca To: Marc Tardif cc: freebsd-database@FreeBSD.ORG Subject: Re: db(3) help In-Reply-To: <35CB3BAE.6C24C0FD@cam.org> Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1258050431-902725657=:11653" Sender: owner-freebsd-database@FreeBSD.ORG Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --0-1258050431-902725657=:11653 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 --0-1258050431-902725657=:11653 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="dbread.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: I2luY2x1ZGUgPHN5cy9zdGF0Lmg+DQojaW5jbHVkZSA8ZGIuaD4NCiNpbmNs dWRlIDxmY250bC5oPg0KI2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8 c3RkbGliLmg+DQoNCg0KaW50IG1haW4oaW50IGFyZ2MsIGNoYXIqIGFyZ3Zb XSkNCnsNCglEQiAqZGI7DQoJREJUIGRhdGEsIGtleTsNCglpbnQgcmV0Ow0K DQoJaWYgKGFyZ2MgIT0gMikgew0KCQlwcmludGYoIlVzYWdlOiAgZGJyZWFk IDxmaWxlbmFtZT5cbiIpOw0KCX0NCglpZighKGRiID0gZGJvcGVuKGFyZ3Zb MV0sIE9fQ1JFQVR8T19FWExPQ0t8T19SRFdSLA0KCQkJCQkJCQkJIDAsIERC X0JUUkVFLCBOVUxMKSkpIHsNCgkJZXJyKDEsICIlcyIsIGFyZ3ZbMV0pOw0K CX0NCg0KCWtleS5zaXplID0gZGF0YS5zaXplID0gMDsNCglrZXkuZGF0YSA9 IGRhdGEuZGF0YSA9IE5VTEw7DQoNCgl3aGlsZSAoMSkgew0KCQlpZiAoZGIt PnNlcShkYiwgJmtleSwgJmRhdGEsIFJfTkVYVCkgIT0gMCkgew0KCQkJYnJl YWs7DQoJCX0NCgkJcHJpbnRmKCJLZXk6ICVzXG4iLCBrZXkuZGF0YSk7DQoJ ICBwcmludGYoIkRhdGE6ICVzXG4iLCBkYXRhLmRhdGEpOw0KCX0NCg0KCSh2 b2lkKShkYi0+Y2xvc2UpKGRiKTsNCn0NCg== --0-1258050431-902725657=:11653-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-database" in the body of the message From owner-freebsd-database Fri Aug 14 14:27:27 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA16515 for freebsd-database-outgoing; Fri, 14 Aug 1998 14:27:27 -0700 (PDT) (envelope-from owner-freebsd-database@FreeBSD.ORG) Received: from skylink.skylink.net (skylink.skylink.net [206.25.34.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA16510 for ; Fri, 14 Aug 1998 14:27:24 -0700 (PDT) (envelope-from animal@skylink.net) Received: from shell.skylink.net (animal@shell.skylink.net [206.25.34.5]) by skylink.skylink.net (8.8.8/8.8.8) with SMTP id OAA19304 for ; Fri, 14 Aug 1998 14:26:55 -0700 (PDT) Date: Fri, 14 Aug 1998 14:26:55 -0700 (PDT) From: animal To: freebsd-database@FreeBSD.ORG Subject: .dir .pag .db Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-database@FreeBSD.ORG Precedence: bulk I am for one haveing a hard time even getiing any documentation on all of these.... When i create a database with perl it makes a .db..... but i am trying to compile a c prog that will add keys to a data base... can you tell me what i am doing wrong.... I use this to create the database...... #include #include #include main() { DBM *db; db = dbm_open("/usr/local/radius/users",O_CREAT,0000664); dbm_close(db); } and then i am trying to add data to it by.......... #include #include #include main() { DBM *db datum kename,whatto; db = dbm_open("/usr/local/radius/users",O_WRONLY,0000664); kename.dptr = "animal"; kename.dsize = strlen(kename.dptr)+1; whatto.dptr = "Data to be stored in database"; kename.dsize = strlen(whatto.dptr)+1; if (dbm_store(db,kename,whatto,DBM_INSERT) < 0) { printf("Insert messed up"); } dbm_close(db); } both progs compile correctly and the create one works fine gives me a file of -rw-r--r-- 1 root wheel 0 Aug 14 14:24 users.db but when i run the second one to insert a key and some data..... i get Segmentation fault (core dumped) any suggestions..... i am probably even in the wrong mailing list... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-database" in the body of the message From owner-freebsd-database Fri Aug 14 16:15:55 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA11309 for freebsd-database-outgoing; Fri, 14 Aug 1998 16:15:55 -0700 (PDT) (envelope-from owner-freebsd-database@FreeBSD.ORG) Received: from misery.sdf.com (misery.sdf.com [204.244.213.49]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id QAA11303 for ; Fri, 14 Aug 1998 16:15:49 -0700 (PDT) (envelope-from tom@sdf.com) Received: from tom by misery.sdf.com with smtp (Exim 1.82 #3) id 0z7SW8-0002Pd-00; Fri, 14 Aug 1998 15:40:16 -0700 Date: Fri, 14 Aug 1998 15:40:15 -0700 (PDT) From: Tom To: animal cc: freebsd-database@FreeBSD.ORG Subject: Re: .dir .pag .db In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-database@FreeBSD.ORG Precedence: bulk On Fri, 14 Aug 1998, animal wrote: > > I am for one haveing a hard time even getiing any documentation on all of > these.... > > When i create a database with perl it makes a .db..... > > but i am trying to compile a c prog that will add keys to a data base... > > can you tell me what i am doing wrong.... > > I use this to create the database...... > > #include > #include > #include > > main() { > > DBM *db; > > db = dbm_open("/usr/local/radius/users",O_CREAT,0000664); > > dbm_close(db); > } > > > > and then i am trying to add data to it by.......... > > #include > #include > #include > > > main() { > > DBM *db > datum kename,whatto; > > db = dbm_open("/usr/local/radius/users",O_WRONLY,0000664); > > kename.dptr = "animal"; > kename.dsize = strlen(kename.dptr)+1; > > whatto.dptr = "Data to be stored in database"; > kename.dsize = strlen(whatto.dptr)+1; This is a bit of problem. You are setting kename.dsize twice, and the second time to the length of whatto.dptr, so dbm_store will read beyond the end of kename.dptr. > if (dbm_store(db,kename,whatto,DBM_INSERT) < 0) { > printf("Insert messed up"); > } > > dbm_close(db); > } Tom To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-database" in the body of the message From owner-freebsd-database Sat Aug 15 16:02:30 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA28143 for freebsd-database-outgoing; Sat, 15 Aug 1998 16:02:30 -0700 (PDT) (envelope-from owner-freebsd-database@FreeBSD.ORG) Received: from skylink.skylink.net (skylink.skylink.net [206.25.34.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA28128 for ; Sat, 15 Aug 1998 16:02:27 -0700 (PDT) (envelope-from animal@skylink.net) Received: from shell.skylink.net (animal@shell.skylink.net [206.25.34.5]) by skylink.skylink.net (8.8.8/8.8.8) with SMTP id QAA06626; Sat, 15 Aug 1998 16:01:52 -0700 (PDT) Date: Sat, 15 Aug 1998 16:01:52 -0700 (PDT) From: animal To: Tom cc: freebsd-database@FreeBSD.ORG Subject: Re: .dir .pag .db In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-database@FreeBSD.ORG Precedence: bulk that was a mistake in typing only..... it should look like this.... kename.dptr = "animal"; kename.dsize = strlen(kename.dptr)+1; whatto.dptr = "Data to store"; whatto.dsize = strlen(whatto.dptr)+1; On Fri, 14 Aug 1998, Tom wrote: > > On Fri, 14 Aug 1998, animal wrote: > > > > > I am for one haveing a hard time even getiing any documentation on all of > > these.... > > > > When i create a database with perl it makes a .db..... > > > > but i am trying to compile a c prog that will add keys to a data base... > > > > can you tell me what i am doing wrong.... > > > > I use this to create the database...... > > > > #include > > #include > > #include > > > > main() { > > > > DBM *db; > > > > db = dbm_open("/usr/local/radius/users",O_CREAT,0000664); > > > > dbm_close(db); > > } > > > > > > > > and then i am trying to add data to it by.......... > > > > #include > > #include > > #include > > > > > > main() { > > > > DBM *db > > datum kename,whatto; > > > > db = dbm_open("/usr/local/radius/users",O_WRONLY,0000664); > > > > kename.dptr = "animal"; > > kename.dsize = strlen(kename.dptr)+1; > > > > whatto.dptr = "Data to be stored in database"; > > kename.dsize = strlen(whatto.dptr)+1; > > This is a bit of problem. You are setting kename.dsize twice, and the > second time to the length of whatto.dptr, so dbm_store will read beyond > the end of kename.dptr. > > > if (dbm_store(db,kename,whatto,DBM_INSERT) < 0) { > > printf("Insert messed up"); > > } > > > > dbm_close(db); > > } > > Tom > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-database" in the body of the message