bsddb : python, index, cursor and get

Pierre pierre.lebrech at laposte.net
Tue Nov 13 10:30:06 EST 2007


Hello,

I'm having problems to use the get method on a cursor with an index
(secondary database). I've read Oracle's docs but there are mainly in C,
JAVA and C++. So no python docs!

actually, that's what I'm trying to do :

ret = cursor.get(key='blabla', data='2007-10-30', flags=0, dlen=-1, 
doff=-1)

this does not work.


the code above this line is :

########################### snip
def getDate(priKey, priData):
    date = string.split(priData, ' ')[1]
    return date

TheDB = db.DB()
TheDB.open(filename_pri, None, db.DB_BTREE, db.DB_RDONLY)

TheIDX = db.DB()
TheIDX.open(filename_idx2, None, db.DB_BTREE, db.DB_RDONLY)

TheDB.associate(TheIDX, getDate)


# get database cursor and print out database content
cursor = TheIDX.cursor()
########################### snip

Does anybody have some sample code which performs a lookup in a database
with an index using a cursor in Python?

Thanks a lot



More information about the Python-list mailing list