/* ** Title: DataBladeAPI ** SCCSid: %W% %E% %U% ** CCid: %W% %E% %U% ** Author: Informix Software, Inc. ** Created: 06/11/1998 14:50 ** Description: This is the generated 'C' file for the DataBladeAPI DataBlade. ** Comments: Generated for project DataBladeAPI.3.6 */ /* ** The following is placed here to insure ** that name "mangling" does not occur. */ #ifdef __cplusplus extern "C" { #endif /* Standard library includes. */ #include #include #include #include /* Used by Informix GLS routines. */ #include /* Include when accessing the Informix API. */ #include /* This is the project include file. */ #include "DataBladeAPI.h" /* {{FUNCTION(3147d4d0-1364-11d1-80af-0800095a455b) (MergeSection) */ /**************************************************************** ** ** Function name: ** ** CIter ** ** Description: ** ** Special Comments: ** ** Entrypoint for the SQL routine CIter (boolean) returns set (money not null). ** ** Parameters: ** ** Return value: ** ** set (money not null) ** ** History: ** ** 06/11/1998 - Generated by BladeSmith Version 3.60.TC1B1. ** ** Identification: ** ** NOTE: ** ** BladeSmith will add and remove parameters from the function prototype, ** and will generate tracing calls. ONLY EDIT code in blocks marked ** Your_
. Any other modifications will require manual merging. ** ***************************************************************** */ MI_COLLECTION * CIter ( mi_integer bool_col, MI_FPARAM * Gen_fparam /* Standard info - see DBDK docs.*/ ) { MI_CONNECTION * Gen_Con; /* The connection handle. */ MI_COLLECTION * Gen_RetVal; /* The return value wrapper. */ MI_COLL_DESC * Gen_OutCollDesc; /* The collection descriptor. */ MI_TYPEID * Gen_TypeId; /* The collection's type ID. */ MI_DATUM * Gen_Value; /* Insert this collection value. */ mi_integer Gen_Result; /* The return value. */ mi_lvarchar * Gen_InData; /* The data value. */ /* ------ {{Your_Declarations (PreserveSection) BEGIN ------ */ mi_integer ret; mi_integer len; MI_ROW * row = NULL; char cmd_buffer[256]; /* buffer used for SQL statements */ /* ------ }}Your_Declarations (#0000) END ------ */ /* Get the current connection handle. */ Gen_Con = mi_open( NULL, NULL, NULL ); /* Verify that the connection has been established. */ if( Gen_Con == 0 ) { /* ** Opening the current connection has failed ** so issue the following message and quit. ** ** "Connection has failed in CIter." */ DBDK_TRACE_ERROR( "CIter", ERRORMESG1, 10 ); /* not reached */ } /* Get the type ID for the given collection type. */ Gen_TypeId = mi_typestring_to_id( Gen_Con, "set (money not null)" ); /* Validate the type ID. */ if( Gen_TypeId == NULL ) { /* ** Insertion into the collection has failed ** so issue the following message and quit. ** ** "Insertion into the collection ** has failed in CIter." */ DBDK_TRACE_ERROR( "CIter", ERRORMESG16, 10 ); /* not reached */ } /* Create the collection. */ Gen_RetVal = mi_collection_create( Gen_Con, Gen_TypeId ); /* Check for a successful creation. */ if ( Gen_RetVal == NULL ) { /* ** Collection creation has failed so ** issue the following message and quit. ** ** "Collection creation has failed in CIter." */ DBDK_TRACE_ERROR( "CIter", ERRORMESG15, 10 ); /* not reached */ } /* Open the collection for use and get a handle to it. */ Gen_OutCollDesc = mi_collection_open( Gen_Con, Gen_RetVal ); /* Insure that the open operation was successful. */ if ( Gen_OutCollDesc == NULL ) { /* ** Collection creation has failed so ** issue the following message and quit. ** ** "Collection creation has failed in CIter." */ DBDK_TRACE_ERROR( "CIter", ERRORMESG15, 10 ); /* not reached */ } /* ------ {{Your_Code (PreserveSection) BEGIN ------ */ /* PROGRAMMER's NOTE: As a first step, we will create the view from which we will query for the data that we are going to return ret=mi_exec(Gen_Con, "create view blt_view as select * from blt_tab;", MI_QUERY_NORMAL); */ if (ret == MI_ERROR) { /* PROGRAMMER's NOTE: We are assuming here that the reason for failure is always the pre-existance of the view and so we will not throw an error. Any other error will be caught again while executing the query. mi_db_error_raise( NULL, MI_FATAL, "Fatal Error : Cannot Create View"); */ } /* PROGRAMMER's NOTE: Next we execute construct and query whose results we want to return as the collection. */ if ( bool_col == MI_TRUE ) sprintf(cmd_buffer, "select money_col from blt_view where bool_col = \'t\';"); else sprintf(cmd_buffer, "select money_col from blt_view where bool_col = \'f\';"); /* PROGRAMMER's NOTE: The Query is executed in binary mode, because we need the binary value of the column and not the string representation. */ ret = mi_exec( Gen_Con, cmd_buffer, MI_QUERY_BINARY ); if( ret == MI_ERROR ) { mi_db_error_raise( NULL , MI_FATAL, "Fatal Error: Error executing query" ); } /* PROGRAMMER's NOTE /* Now process the results. If rows were returned, one of the results will be MI_ROWS, so, we loop through all the results to see if we got an MI_ROWS as result. */ ret = mi_get_result(Gen_Con ); if( ret != MI_ROWS ) /* PROGRAMMER's NOTE: No rows were returned, return is null */ { /* Close the open collection. */ mi_collection_close( Gen_Con, Gen_OutCollDesc ); mi_fp_setreturnisnull( Gen_fparam, 0 , 0 ); /* PROGRAMMER's NOTE: See note at bottom about dropping views */ return Gen_RetVal; } /* PROGRAMMER's NOTE: We need not allocate memory for each element as the mi_value LibDMI call will allocate the value for you. Gen_InData = (mi_money *)mi_alloc( sizeof( mi_money ) ); */ row = mi_next_row( Gen_Con, &ret ); while( row != NULL ) /* PROGRAMMER's NOTE: there are more rows */ { ret = mi_value( row, 0 , (void **)&Gen_InData , &len ); if( ret != MI_NORMAL_VALUE ) { mi_db_error_raise( NULL, MI_FATAL, "Fatal Error: Illegal value returned by" "mi_value()"); /* not reached */ } /* PROGRAMMER's NOTE: Insert the value into the collection. */ Gen_Result = mi_collection_insert( Gen_Con, Gen_OutCollDesc, (MI_DATUM)Gen_InData, MI_CURSOR_NEXT, 0 ); /* Check for a successful insertion. */ if( Gen_Result != MI_OK ) { /* ** Insertion into the collection has failed ** so issue the following message and quit. ** ** "Insertion into the collection ** has failed in CIter." */ DBDK_TRACE_ERROR( "CIter", ERRORMESG16, 10 ); /* not reached */ } row = mi_next_row( Gen_Con, &ret ); } if( ret == MI_ERROR ) { mi_db_error_raise( NULL, MI_FATAL, "Error: fetching next row" ); } /* PROGRAMMER's NOTE: NOTE: We are not dropping the view we created because, the drop view is a DDL statement that is not legal in select and update statements because if modifies the schema. Note, also that the create view, although a DDL is valid. */ /* ** Write to the trace file indicating ** that CIter has successfully exited. */ DBDK_TRACE_EXIT( "CIter" ); /* ------ }}Your_Code (#9JIR) END ------ */ /* Close the open collection. */ mi_collection_close( Gen_Con, Gen_OutCollDesc ); /* Close the connection. */ mi_close( Gen_Con ); /* Return the function's return value. */ return Gen_RetVal; } /* }}FUNCTION (#HLNQ) */ #ifdef __cplusplus } #endif