# mco_uda_pattern_next

> Move cursor position to the next match in the pattern search.

### Prototype

        MCO_RET mco_uda_pattern_next(	/*IN*/ mco_trans_h t,
                         /*INOUT*/ mco_cursor_t * cursor,
                         /*INOUT*/ void * allocated_pattern );

### Arguments

t | The transaction handle
cursor | A cursor handle
allocated_pattern | The search pattern

### Description

Move cursor position to the next match in the pattern search.

### Return Codes

MCO_S_OK | The cursor was positioned successfully
MCO_ERR_CURSOR | A cursor error occurred
MCO_S_CURSOR_END | The last matching value has been reached

### 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;

            /* 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