bsddb185 question

T

thakadu

I have an application that needs to create and delete
records in a Berkeley DB version 1.85 database.
If I use the bsdddb185 module I dont see any
of the record manipulation methods in there that
are available in the newer bsddb module.
(put(), get(), pop() etc)

I know the docs say that one should always use
the newer bsddb module however it appears that the bsddb module
is unable to open version 1.85 databases.

So it seems I am forced to use the bsddb185 module
which does not have convenient record level methods.
Am I missing something here or have others eperienced
tha same?
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

thakadu said:
So it seems I am forced to use the bsddb185 module
which does not have convenient record level methods.
Am I missing something here or have others eperienced
tha same?

I think you are missing that bsddb185 implements the
dictionary interface. So you can use [key] to access
the value for a certain key.

Regards,
Martin
 
T

thakadu

It seems it doesnt implement ALL of the dictionary interface though.
dir({}) yields many more methods than dir(bsddb185.open(f)).
So bsddb185 is missing many of the methods that I am used
to in bsddb. I mentioned some above that are missing, pop()
in particular would be useful in my situation but there are
others as well.
From a java perspective I believe that its not possible to omit certain
methods when implementing an interface, I am not sure about Python
though.
 
S

skip

thakadu> It seems it doesnt implement ALL of the dictionary interface
thakadu> though. dir({}) yields many more methods than
thakadu> dir(bsddb185.open(f)). So bsddb185 is missing many of the
thakadu> methods that I am used to in bsddb. I mentioned some above that
thakadu> are missing, pop() in particular would be useful in my
thakadu> situation but there are others as well. From a java
thakadu> perspective I believe that its not possible to omit certain
thakadu> methods when implementing an interface, I am not sure about
thakadu> Python though.

The bsddb185 module is only there as a "rescue" module so that you can work
with old 1.85 files. You should never use it for new development, as the
1.85 version of Berkeley DB has known bugs that are only fixed in later
versions. As you noticed, those later versions will not read or write v1.85
files. Since the bsddb185 module is only there for compatibility and
emergencies, no new functionality is planned for it.

Skip
 
T

thakadu

Ok but if you read my original post I already said that! The issue is
that I have an application that needs to share data with
an existing Berekeley db 1.85 database and applications
in perl. Sure if I was creating the database myself I would use the
newer bsddbmodule but I can't require the perl code be rewritten, so is
there
any way in Python to read and write to a legacy 1.85 Berkely
db?
 
S

skip

thakadu> Ok but if you read my original post I already said that!

Sure, I did. I was recapping what the purpose of the bsddb185 module is and
why its API is not likely to change.

thadaku> The issue is that I have an application that needs to share
thakadu> data with an existing Berekeley db 1.85 database and
thakadu> applications in perl. Sure if I was creating the database
thakadu> myself I would use the newer bsddbmodule but I can't require
thakadu> the perl code be rewritten, so is there any way in Python to
thakadu> read and write to a legacy 1.85 Berkely db?

Yup. Use the bsddb185 module and suffer with the older API. Note that
part of the reason the API it exposes is so feeble is that the underlying
1.85 Berkeley DB library doesn't provide anything better. The API you've
become used to with the later bsddb module is only available because the
underlying library API is more complete.

Skip
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

thakadu said:
It seems it doesnt implement ALL of the dictionary interface though.
dir({}) yields many more methods than dir(bsddb185.open(f)).
So bsddb185 is missing many of the methods that I am used
to in bsddb. I mentioned some above that are missing, pop()
in particular would be useful in my situation but there are
others as well.

I see. But .pop can be easily emulated using getitem, then del:

def bsddb_pop(db, key):
result = db[key]
del db[key]
return result
methods when implementing an interface, I am not sure about Python
though.

In Python, I'm sure: it is possible.

Regards,
Martin
 
T

thakadu

Thanks Martin

However the line:
del db[key]
results in an error: (1, 'Operation not permitted')
(only tested on Python 2.3.5)
Could this be because the .del() method of the dictionary
has not been implemented either? In fact in my tests
any attempt at altering the db by use of normal dictionary
methods fails with the same error. e.g.
db['newkey']='newvalue' causes the same error.
(again, only tested on Python 2.3.5)
So it seems only those methods listed by dir()
have been implemented, which is what I would expect.

Thanks for your info on the rules for interface implementation
in Python. That is an interesting difference. I have grown to
like the rules for java interface implementation because you
are guaranteed that all defined methods for the interface have
been implemented. That is what is meant by "implementing" an
interface in java. Although I dont deny the Python way may also
have its advantages, just different ones!
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

thakadu said:
However the line:
del db[key]
results in an error: (1, 'Operation not permitted')
(only tested on Python 2.3.5)

Did you open the dbm file for read-write? This should work,
and is implemented.
Could this be because the .del() method of the dictionary
has not been implemented either? In fact in my tests
any attempt at altering the db by use of normal dictionary
methods fails with the same error. e.g.
db['newkey']='newvalue' causes the same error.

Ah, so you definitely should pass the "w" argument to the
open function.
Thanks for your info on the rules for interface implementation
in Python. That is an interesting difference. I have grown to
like the rules for java interface implementation because you
are guaranteed that all defined methods for the interface have
been implemented. That is what is meant by "implementing" an
interface in java.

In Python, there is also the notion of implementing an interface.
However, the interface is just specified in English text,
and the interpreter never checks whether all of them are
implemented. For mapping types,

http://www.python.org/doc/current/lib/typesmapping.html

gives the list of operations they ought to support.

Regards,
Martin
 
T

thakadu

Martin you are great!

If I had just opened the file with f=bsddb185.hashopen('filename',''w')
it would have worked the first time.
So now I will create wrapper classes around the file classes of
bsddb185 and create the methods that I need to keep it consistent
with bsddb. Another small difference I noted is that bsddb seems
to auto sync() while bsddb185 does not, this is not a big issue though.

Thanks very much for all your input!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,353
Members
48,038
Latest member
HunterDela

Latest Threads

Top