Unix Programming - db shell

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > db shell





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author db shell
Ian Zimmerman

2004-06-26, 10:11 am


Hi, I am looking for a program to interactively retrieve and store
records in Berkeley DB files (actually, a similar program for an
equivalent database package like gdbm would do, as well; I just like DB
because of its wide and well documented API).

I have in mind something like the following hypothetical transcript.

$ bdbshell foo.db
BDB> get "foo"
BDB: foo.db: key "foo" not found
BDB> set "foo" "bar"
BDB> get "foo"
bar
BDB> set_multiline "foo"
bar
baz
^C
BDB> get "foo"
bar
baz

BDB>

You get the idea.

I think I need it because I want to access DB files from an interpreter
that cannot be extended with C code, but can communicate with spawned
subprocesses. If you have another suggestion how to achieve this,
I am listening.

I could also use sqlite but there will be no joins, so any relational
features are overkill.

Thanks. I have googled, without apparent success.

--
"It's not true or not." A reality show producer (real quote)
Keith Bostic

2004-06-26, 10:11 am

Ian Zimmerman <itz@buug.org> wrote in message news:<878yeg3xql.fsf@buug.org>...

> Hi, I am looking for a program to interactively retrieve and store
> records in Berkeley DB files (actually, a similar program for an
> equivalent database package like gdbm would do, as well; I just
> like DB because of its wide and well documented API).
>
> I have in mind something like the following hypothetical transcript.
>
> $ bdbshell foo.db
> BDB> get "foo"
> BDB: foo.db: key "foo" not found
> BDB> set "foo" "bar"
> BDB> get "foo"
> bar
> BDB> set_multiline "foo"
> bar
> baz
> ^C
> BDB> get "foo"
> bar
> baz
>
> BDB>
>
> You get the idea.


The are Berkeley DB APIs for most popular interpreted languages:
Perl, Tcl, Python and so on. Why not use one of those? You can
do almost exactly what you're describing in Tcl:

set e [berkdb env -home TESTDIR -create -txn -recover]
set d [berkdb open -create -btree -env $e -auto_commit a]
set t [$e txn]
$d put -txn $t aaa data
$d put -txn $t aab data
$d put -txn $t aac data
$d put -txn $t aad data
$t commit
$d close
$e close

Regards,
--keith

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic bostic@sleepycat.com
Sleepycat Software Inc. keithbosticim (ymsgid)
118 Tower Rd. +1-781-259-3139
Lincoln, MA 01773 http://www.sleepycat.com
Ian Zimmerman

2004-06-26, 10:11 am


Ian> $ bdbshell foo.db
Ian> BDB> get "foo"
Ian> BDB: foo.db: key "foo" not found
Ian> BDB> set "foo" "bar"
Ian> BDB> get "foo"
Ian> bar
Ian> BDB> set_multiline "foo"
Ian> bar
Ian> baz
Ian> ^C
Ian> BDB> get "foo"
Ian> bar
Ian> baz
Ian>
Ian> BDB>

Keith> The are Berkeley DB APIs for most popular interpreted languages:
Keith> Perl, Tcl, Python and so on. Why not use one of those?

The idea of generating PERL code reminds me of seeing _Quills_ last
weekend :-)

Tcl might be another matter. As for Python, that was actually my first
reaction, but I haven't found a DB binding. Can you point me to one?

Thanks.

--
"It's not true or not." A reality show producer (real quote)
William Park

2004-06-26, 10:11 am

Ian Zimmerman <itz@buug.org> wrote:
>
> Ian> $ bdbshell foo.db
> Ian> BDB> get "foo"
> Ian> BDB: foo.db: key "foo" not found
> Ian> BDB> set "foo" "bar"
> Ian> BDB> get "foo"
> Ian> bar
> Ian> BDB> set_multiline "foo"
> Ian> bar
> Ian> baz
> Ian> ^C
> Ian> BDB> get "foo"
> Ian> bar
> Ian> baz
> Ian>
> Ian> BDB>
>
> Keith> The are Berkeley DB APIs for most popular interpreted languages:
> Keith> Perl, Tcl, Python and so on. Why not use one of those?
>
> The idea of generating PERL code reminds me of seeing _Quills_ last
> weekend :-)
>
> Tcl might be another matter. As for Python, that was actually my first
> reaction, but I haven't found a DB binding. Can you point me to one?


Ref:
http://freshmeat.net/projects/bashdiff/
http://home.eol.ca/~parkw/index.html#bash

It has GDBM and SQLite. And, I'm working on PostgreSQL, now. Regarding
your example,
gdbm boo.db foo
gdbm boo.db foo bar --> store
gdbm boo.db foo
gdbm boo.db foo 'bar --> store string
baz'
gdbm boo.db foo

Yours truly,
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
No, I will not fix your computer! I'll reformat your harddisk, though.
Keith Bostic

2004-06-26, 10:11 am

Ian Zimmerman <itz@buug.org> wrote in message news:<87vfhj6jwt.fsf@buug.org>...

> Tcl might be another matter. As for Python, that was actually my first
> reaction, but I haven't found a DB binding. Can you point me to one?


The Tcl and PERL bindings are included in the Berkeley DB distribution.

PyBSDDB is a set of Python wrappers for the Berkeley DB library,
allowing the use of most of the features of DB from the Python language.
The DB objects can be used in a variety of ways, from simple persistent
dictionaries all the way up to full transaction-protected databases. The
Python wrappers allow you to store Python string objects of any length,
keyed either by strings or integers depending on the database access
method. With the use of another module in the package standard
shelve-like functionality is provided allowing you to store any pickable
Python object, allowing you to easily create an Object Database.

More information is available at:

http://pybsddb.sourceforge.net/

Other sites that have provided useful Python information and interfaces
include:

http://www.python.org

but we believe that the Sourceforge site is currently the most up-to-date.

Regards,
--keith

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic bostic@sleepycat.com
Sleepycat Software Inc. keithbosticim (ymsgid)
118 Tower Rd. +1-781-259-3139
Lincoln, MA 01773 http://www.sleepycat.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com