Open a collection with mi_collection_open_with_options()
When you open a collection with mi_collection_open_with_options(), you can override the cursor characteristics that mi_collection_open() uses.
Cursor attribute | Control flag | Valid operations |
---|---|---|
Read-only cursor | MI_COLL_READONLY | Fetch only |
Sequential (nonscrolling) cursor | MI_COLL_NOSCROLL | Fetch forward only (MI_CURSOR_NEXT) through the
collection elements Any fetch operation that moves the cursor position backward in the cursor is not valid. |
Most collections need the capabilities of the read/write scroll cursor that mi_collection_open() creates. However, the database server can perform a special optimization for a collection from a collection subquery if you use a read-only sequential cursor to hold the collection subquery. It can fetch each row of the subquery on demand. That is, you can fetch the elements one at a time with mi_collection_fetch(). You can use mi_collection_open() or mi_collection_open_with_options() to create some other type of cursor for a collection subquery. However, if a collection subquery is in some other type of cursor, the database server fetches all the rows of the subquery and puts them in the collection cursor.
SELECT check_orders(
MULTISET(SELECT ITEM order_num FROM orders
WHERE customer_num = 120))
FROM customer
WHERE customer_num = 120;
mi_collection_open_with_options(conn, coll_ptr,
(MI_COLL_READONLY | MI_COLL_NOSCROLL));