mco_uda_pattern_size

Return the amount of memory required for this search pattern.

Prototype

 
    MCO_RET mco_uda_pattern_size(	/*IN*/ const mco_metadict_header_t * metadict, 
                     /*IN*/ unsigned short dict_no,
                     /*IN*/ unsigned short struct_no,  
                     /*IN*/ unsigned short index_no,
                      /*INOUT*/ const mco_uda_value_t * keys, 
                     /*IN*/ unsigned short keys_count, 
                     /*OUT*/ uint4 * memsize ); 
 

Arguments

metadict The address of an initialized mco_metadict_header_t structure

dict_no

The number of the dictionary (must be between 0 and mco_metadict_count() - 1)

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)

keys

An array of search keys

keys_count

The length of the search keys array

Note that the number of keys, their sequence and types must correspond to the DDL description for the index

memsize

The amount of memory required for this search pattern

Description

Returns the amount of memory required for this search pattern. This function is called before allocating the pattern to be passed to mco_uda_pattern_search().

Return Codes

MCO_S_OK The size was returned successfully

MCO_E_UDA_DICT_NOTFOUND

Invalid dict_no

MCO_E_ILLEGAL_PARAM

Invalid metadict or null address passed for count

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

Invalid keys_count value - doesn't match the index definition

Example

 
    Sample schema :
     
    class TestClass
    {
        string 		key;
        char<20> 	k2;
        int4 		k3;
        int4 		v1;
         
        tree <key,k2,k3> i1;
    };
     
    Application code snippet:
     
    MCO_RET psearch(mco_db_h db, char* pattern1, char* pattern2, int p3, mco_bool ignore_other_fields)
    {
        MCO_RET rc = MCO_S_OK;
        mco_trans_h trn;
        mco_cursor_t csr;
        mco_uda_object_handle_t obj;
        uint2 size1;
        uint4 bsize;
        char key[64], k2[64];
        int4 k3, v1;
        void * buf;
        mco_pattern_policy_t p;
        unsigned short s_no = get_struct_no("TestClass");
        unsigned short i_no = get_index_no(s_no, "i1");
        unsigned short f_no;
        mco_uda_value_t keys[3], value;
        mco_metadict_header_t *metadict;
         
         
         
        /* Get memory for set of patterns */
        keys[0].type = MCO_DD_STRING;
        keys[0].v.p.p.c = pattern1;
        keys[0].v.p.len = (uint2)strlen(pattern1);
        keys[1].type = MCO_DD_CHAR;
        keys[1].v.p.p.c = pattern2;
        keys[1].v.p.len = (uint2)strlen(pattern2);
         
        keys[2].type = MCO_DD_INT4;
        keys[2].v.i4   = p3;
        mco_uda_pattern_size(metadict, 0, s_no, i_no, keys, 3, &bsize);
        
        buf = malloc(bsize);
         
        /* start read-write transaction to change pattern policy */
        rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &trn);
        if ( MCO_S_OK == rc ) 
        {
            mco_get_pattern_policy(trn, &p);
            p.ignore_other_fields = ignore_other_fields; /* ignore fields other than char<n> or string */
            mco_set_pattern_policy(trn, &p);
            rc = mco_uda_cursor(trn, s_no, i_no, &csr);
            for (rc = mco_uda_pattern_search(trn, s_no, i_no, keys, 3, &csr, buf);
                rc == MCO_S_OK; rc = mco_uda_pattern_next(trn, &csr, buf))
            {
                mco_uda_from_cursor(trn, &csr, &test);
                /* Do something with the current UDA object */
                ...
            }
        }
    }
         
         
    int main(int argc, char** argv)
    {
        MCO_RET rc;
        ...
        char * pattern1 = "abc_1*";
        char * pattern2 = "??c_?2?";
        int    pattern3 = 1;
        ...
        rc = psearch(db, pattern1, pattern2, pattern3, MCO_NO);
        if (MCO_S_OK == rc) 
        {
            printf("\n\tStart search using all patterns and ignore other index components\n");
            psearch(db, pattern1, pattern2, pattern3, MCO_YES);
        }
        ...
    }
 

Files

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