Update a collection

You update an element in an open collection with the mi_collection_update() function. You can perform an update operation only on a read/write cursor. An update is not valid on a read-only cursor.

The mi_collection_update() function uses an MI_DATUM value to represent the new value for the element it updates in a collection. The contents of this MI_DATUM structure depend on the passing mechanism that the function used, as follows:
  • In a C UDR, when mi_collection_update() updates an element value, it can pass the value by reference or by value, depending on the data type of the column value. If the function passes back the element value by value, the MI_DATUM structure contains the value. If the function passes back the element value by reference, the MI_DATUM structure contains a pointer to the value.
  • In a client LIBMI application, when mi_collection_update() updates an element value, it always passes the value by reference. Even for values that you can pass by value in a C UDR (such as an INTEGER value), these functions return the column value by reference. The MI_DATUM structure contains a pointer to the value.

The mi_collection_update() function updates the element at the location in the collection cursor that its action argument specifies. For a list of valid cursor-action flags, see Valid cursor-action constants.

Server only: The following code shows an example of using the mi_collection_update() function to update the first element in a collection:
/*
 * Update position 1 in the collection to contain 3.0
 * Note that single-precision value is passed by REFERENCE.
 */
   MI_CONNECTION *conn;
   MI_COLL_DESC *colldesc;
   MI_DATUM val;
   mi_integer ret, jump;
   mi_real value;

   /* Update 1st element to 3.0 */
   value = 3.0;
   val = (MI_DATUM)&value;
   jump = 1;
   DPRINTF("trc_class", 11, 
      ("Update set value %d @%d", value, jump));

   /* Pass single-precision values by reference */
   ret = mi_collection_update(conn, colldesc, val,
      MI_CURSOR_ABSOLUTE, jump);

   if ( ret != MI_OK )
      {
      DPRINTF("trc_class", 11, 
         ("Update @%d value %d MI_CURSOR_ABSOLUTE\
          failed", jump, value));
      }