Assign an optional name
You can obtain access to a prepared statement through its statement descriptor. However, other SQL statements that need to reference the prepared statement cannot use a statement descriptor. Therefore, you can assign an optional string name to a prepared SQL statement. Specify a name as the third argument of the mi_prepare() function.
WHERE CURRENT OF cursor_name
SELECT customer_num, company FROM customer
WHERE customer_num = 104 FOR UPDATE OF company;
SELECT customer_num, company FROM customer
WHERE customer_num = 104;
For more information about the FOR UPDATE keywords of SELECT with databases that are ANSI compliant and not ANSI compliant, see Define a cursor mode.
/* Prepare the FOR UPDATE statement */
if ( (stmt1 = mi_prepare(conn,
"select * from tab1 for update;",
"curs1")) == NULL )
return MI_ERROR;
/* Open the cursor */
if ( mi_open_prepared_statement(stmt1, MI_BINARY,
MI_QUERY_BINARY, num_params, values, lengths, nulls,
types, NULL, 0, NULL) != MI_OK )
return MI_ERROR;
/* Fetch the 5th row */
if ( mi_fetch_statement(stmt1, MI_CURSOR_NEXT, 0, 5)
!= MI_OK )
return MI_ERROR;
/* Get values from 5th row */
if ( mi_get_result(conn) != MI_ROWS
|| mi_next_row(conn, &res) == NULL )
return MI_ERROR;
/* Update 5th row */
if ( mi_exec("update tab1 set int_col = int_col + 2 \
where current of curs1;", NULL) != MI_OK )
return MI_ERROR;
/* Clean up */
if ( mi_close_statement(stmt1) != MI_OK )
return MI_ERROR;
if ( mi_drop_prepared_statement(stmt1) != MI_OK )
return MI_ERROR;
The mi_open_prepared_statement() function also provides the ability to name the cursor. However, if you specify a cursor name in mi_prepare(), make sure that you pass a NULL-valued pointer as the cursor name to mi_open_prepared_statement(). Conversely, if you want to specify the cursor name in mi_open_prepared_statement(), use a NULL-valued pointer as the cursor name in mi_prepare(). If you specify a cursor name in both mi_prepare() and mi_open_prepared_statement(), the DataBlade® API uses the cursor name that mi_open_prepared_statement() provides.
If your prepared statement does not fetch rows, pass a NULL-valued pointer as the third argument to mi_prepare().