Example: The send_statement() function

The send_statement() function takes an existing open connection and an SQL statement string as arguments and sends the statement to the database server with the mi_exec() function. It specifies text representation for the query results.

/* FUNCTION: send_statement()
 * PURPOSE: To send an SQL statement to the database server for
 *          execution
 *
 * CALLED BY: Called from within a C user-defined function to
 *            execute a basic SQL statement
 */
 
mi_integer
send_statement(MI_CONNECTION *conn, mi_string *stmt)
{
   mi_integer count;
 
   /* Send the statement, specifying results be sent 
    * in their text representation (MI_QUERY_NORMAL)
    */
   if ( MI_ERROR == mi_exec(conn, stmt, MI_QUERY_NORMAL) )
      {
       mi_db_error_raise(conn, MI_EXCEPTION, 
         "mi_exec failed\n");
      }

   /* Get the results of the current statement */
   count = get_results(conn);

   /* Release statement resources */
   if ( mi_query_finish(conn) == MI_ERROR )
      {
      mi_db_error_raise(conn, MI_EXCEPTION, 
         "mi_query_finish failed\n");
      }

   return ( count );
}

The send_statement() function calls another user function, get_results(), to examine the status of the current statement.