Cursor.search

Locate the position of an object in the specified index.

For an overview see page Python Cursor Class

Prototype

 
    Cursor.search(cls, idx, op, value)
 

Arguments

cls The class to be searched
idx The index name used for the search
op

The compare operation to perform; one of the following (some are relevant only for RTree or Patricia indexes): LessThan, LessOrEquals, Equals, GreaterOrEquals, GreaterThan, Overlaps, Contains, ExactMatch, BestMatch, PrefixMatch, NextMatch, Neighbourhood, StrictEquals, IsPrefixOf

value The value to look up (if the index is a compound index, all of the values for the index components are passed as a tuple)

Description

This method locates the position of an object in the specified index idx applying the operation op with key value. It returns an object instance or None if not found.

Returns

Object An object of the specified class (if search is successful)
None No object found corresponding to the specified value

Example

     
    #
    # Search operation
    #
    conn.startTransaction(exdb.Transaction.MCO_READ_ONLY)
    cursor = conn.cursor()
    ret = cursor.search("Record", "by_i4", exdb.Operation.GreaterOrEquals, 2)
 
    if ret:
        rec = cursor.next()
        print "Object found: i4=%s,str=%s" % (rec.i4, rec.str)
 
        rec = cursor.next()
        print "Next object is: i4=%s,str=%s" % (rec.i4, rec.str)
    else:
        print "Object not found"
    print ""
 
    cursor.close()
    conn.commit()