[pybsddb] BDB Indexing and Joined Cursor issue

phu kungphu at gmail.com
Tue Oct 21 16:30:27 CEST 2008


Taken from working code... this is probably not the only or best way to
handle it; it's just one way to handle it that does work.

        for keyword in keywords:
            cursors[keyword] = dbhandle.cursor()
            if cursors[keyword].set(keyword, DB_SET) == None:
                del(cursors[keyword])
        if len(cursors) == 0:
            return []
        cursor = dbhandle.join(cursors.values())
        dbresult = cursor.get(DB_JOIN_ITEM)
        while dbresult:
            results.append(self.get(dbresult[0]))
            dbresult = cursor.get(DB_JOIN_ITEM)

On Tue, Oct 21, 2008 at 12:43 AM, Sury Soni <ssoni at nextdigital.com> wrote:

>  Sorry for not properly expressing my question.
>
> My question is how I determine if individual cursor is non-empty or cursor
> set to particular record. Once that determined, it can be put on a common
> list and join() them all together, which is what I am doing in my previous
> email code.
>
> So, to determine individual cursor, I tried using count() which was
> throwing exception and same with get_current_size(), as before calling
> these functions, I am using pget() for each individual cursor to point to
> first matching record on BTREE. So if records are not found for my pattern
> key, then pointer on cursor is not set to any record.*** How could I
> determine, if cursor is not yet positioned to some specific record*,
> before I can use that cursor to check count() or get_current_size() and
> later use join().
>
> I hope, I made my question clearer this time?
>
> Regards,
>
> Sury
>
>  *****From:* pybsddb-bounces at argo.es [mailto:pybsddb-bounces at argo.es<pybsddb-bounces at argo.es>
> ]***** On Behalf Of* phu
> ****
> *Sent:* Tuesday, 21 October 2008 4:30 PM
> *****To:* Python bindings for Oracle Berkeley DB
> *****Subject:* Re: [pybsddb] BDB Indexing and Joined Cursor issue
>
> If your question is how to avoid joining empty cursors, just create an
> empty list and append your non-zero-count cursors to it; if you end up with
> at least one cursor in your list, you can run your join (joining one cursor
> should not cause errors, but you can either do that or just use the single
> cursor, whichever you prefer).  If you end up with an empty list, then you
> know you have no cursors which return values, and should not attempt to
> either join or get from your cursors.  pget will not be an option once you
> have joined, as joined cursors only support get and close.
>
> _______________________________________________
> pybsddb mailing list
> pybsddb at argo.es
> http://mailman.argo.es/listinfo/pybsddb
> http://www.argo.es/~jcea/programacion/pybsddb.htm<http://www.argo.es/%7Ejcea/programacion/pybsddb.htm>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.jcea.es/pipermail/pybsddb/attachments/20081021/828b4c3d/attachment.htm>


More information about the pybsddb mailing list