mco_uda_lookup

Perform a database lookup.

Prototype

 
    MCO_RET mco_uda_lookup(	/*IN*/ mco_trans_h t,
                  /*IN*/ unsigned short struct_no,
                  /*IN*/ unsigned short index_no,
                  /*IN*/ MCO_OPCODE op, 
                  /*IN*/ const mco_uda_value_t * keys,
                   /*IN*/ unsigned short keys_count, 
                  /*OUT*/ mco_cursor_t * cursor );
 

Arguments

t The transaction handle

struct_no

The structure/class number (must be between 0 and mco_dict_struct_count() - 1)

index_no

The index number (must be between 0 and struct_info.index_count - 1)

op

The opcode (MCO_LT, MCO_LE, MCO_EQ, MCO_GE, MCO_GT)

Note that a hash index only allows MCO_EQ

keys

An array of search keys

keys_count

The length of the search keys array. Note that the number of keys, their order and types must correspond to the DDL description for the index

cursor

The cursor handle

Description

Perform a database lookup. The function positions the cursor at the first object that satisfies the search criteria. The object handle can then be received using the mco_uda_from_cursor() API.

Return Codes

MCO_S_OK

Object found

MCO_E_UDA_STRUCT_NOTFOUND Invalid struct_no

MCO_E_UDA_STRUCT_NOT_CLASS

Invalid struct_no (not a class)

MCO_E_UDA_INDEX_NOTFOUND

Invalid index_no

MCO_E_UDA_WRONG_KEY_NUM

Mismatch between keys_count and actual number of keys defined in the index

MCO_E_UDA_WRONG_KEY_TYPE

Key type mismatch

MCO_E_UDA_WRONG_OPCODE

Invalid opcode (must be MCO_LT, MCO_LE, MCO_EQ, MCO_GE, or MCO_GT; and only MCO_EQ for a hash index)

Example

 
    Application snippet:
        
     
    int main(int argc, char* argv[])
    {
        MCO_RET rc;
        mco_db_h db;
        mco_trans_h t;
        mco_cursor_t csr;
        mco_uda_value_t keys[1];
        unsigned short struct_no = 1;
        unsigned short index_no = 2;
        mco_uda_object_handle_t uda_obj;
        ...
 
        rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
        if ( MCO_S_OK == rc)
        {
            ...
            keys[0].type = MCO_DD_UINT4;
            keys[0].u4   = 120;
            /* Lookup the first object with id >= 120. */
            rc = mco_uda_lookup(t, Record_struct_no, index_no, MCO_GE, 
                        keys, 1, &csr); 
            if ( MCO_S_OK == rc) 
            {
                mco_uda_from_cursor(t, &csr, &uda_obj); /* get the handle */
                ...
            }
        }
        ...
    }
     
     
 

Files

Header file:
mcouda.h
Source file:
mcouda.c
Library:
libmcouda.a