Move through a cursor
mi_collection_fetch(conn, coll_desc, MI_CURSOR_FIRST, 0,
coll_element, element_len);
if ( ((mi_integer)coll_element != 1) ||
(element_len != sizeof(mi_integer)) )
/* raise an error */
- Sequential collection cursors, if the cursor position does not move backward
- Scroll collection cursors
Only scroll cursors provide the ability to move the cursor position forward and backward.
mi_collection_fetch(conn, coll_desc, MI_CURSOR_NEXT, 0,
coll_element, element_len);
mi_collection_fetch(conn, coll_desc, MI_CURSOR_RELATIVE, 3,
coll_element, element_len);
The preceding mi_collection_fetch() call is valid only if the collection is a LIST. Only LIST collections are ordered. Therefore relative fetches, which specify the number of elements to move forward or backward, can only be used on LIST collections. If you try to perform a relative fetch on a SET or MULTISET, mi_collection_fetch() generates an error.
mi_collection_fetch(conn, coll_desc, MI_CURSOR_RELATIVE, -2,
coll_element, element_len);
Because the preceding mi_collection_fetch() call moves the cursor position backward, the call is valid only if the collection cursor is a scroll cursor. When you open a collection with mi_collection_open(), you get a read/write scroll collection cursor. However, if you open the collection with mi_collection_open_with_options() and the MI_COLL_NOSCROLL option, mi_collection_fetch() generates an error.
mi_collection_fetch(conn, coll_desc, MI_CURSOR_ABSOLUTE, 6,
coll_element, element_len);
The preceding mi_collection_fetch() call is valid only if the collection is a LIST. Because absolute fetches specify a position within the collection by number, they can only be used on an ordered collection (a LIST). If you try to perform an absolute fetch on a SET or MULTISET, mi_collection_fetch() generates an error.
mi_collection_fetch(conn, coll_desc, MI_CURSOR_LAST, 0,
coll_element, element_len);
The fetch last is useful when you do not know the number of elements in a collection and want to obtain the last one.