Execute the mi_next_row() loop

The mi_next_row() function is usually the middle loop of row-retrieval code. In the mi_next_row() loop, each call to mi_next_row() returns one query row from the cursor that is associated with the current statement. This query row is the current row only until the next iteration of the loop, when mi_next_row() retrieves another row from the cursor. This loop terminates when mi_next_row() returns a NULL-valued pointer and its error argument is zero. These conditions indicate either that no more rows exist in the cursor or that the cursor is empty. Think of the mi_next_row() loop as an iteration over the matching rows of the query.

The contents of a row structure become invalid as soon as you fetch a new row into it with mi_next_row(). If you want to save the row values that you obtain with mi_value() or mi_value_by_name(), copy the values that these functions pass back before the next call to mi_next_row().
Tip: If your DataBlade® API module requires simultaneous access to several rows at a time, you can use a save set to hold rows. Save sets are useful for comparing or processing multiple rows.

The mi_next_row() function allocates memory for the row structure that it returns. To free this row structure, you must complete the query.

As long as rows remain to be retrieved from the cursor, the mi_get_result() function returns a statement status of MI_ROWS. Therefore, you cannot exit the mi_get_result() loop until one of the following actions occurs:
  • The mi_next_row() loop continues until no more rows exist in the cursor. That is, mi_next_row() returns a NULL-valued pointer.
  • You terminate the mi_get_result() loop prematurely with a call to mi_query_finish() or mi_query_interrupt().