void IIdemo_term_server( II_BOOL mode_abort, II_BOOL verbose ) { if ( mode_abort ) { printf( "\tAbort server connection\n" ); IIdemo_abort( &global.svr_connHandle, verbose ); } else { II_PTR nullHandle = NULL; char dropEvText[] = "drop dbevent %s"; char removeEvText[] = "remove dbevent %s"; char queryText[ 64 ]; printf( "\tDe-register DB Event\n" ); sprintf( queryText, removeEvText, IIdemo_eventName ); IIdemo_query( &global.svr_connHandle, &global.svr_tranHandle, queryText, verbose ); printf( "\tDestroying DB Event \n"); sprintf( queryText, dropEvText, IIdemo_eventName ); IIdemo_query( &global.svr_connHandle, &global.svr_tranHandle, queryText, verbose ); printf( "\tDisconnecting \n"); IIdemo_autocommit( &nullHandle, &global.svr_tranHandle, verbose ); IIdemo_disconn( &global.svr_connHandle, verbose ); } return; }
IIAPI_STATUS IIdemo_init_server( II_PTR env, char *dbname, II_BOOL verbose ) { IIAPI_SETENVPRMPARM setEnvPrmParm; IIAPI_STATUS status; /* ** Set the callback function for uncaught Database Events. */ setEnvPrmParm.se_envHandle = env; setEnvPrmParm.se_paramID = IIAPI_EP_EVENT_FUNC; setEnvPrmParm.se_paramValue = (void *)eventCallback; if ( verbose ) printf( "\t\tCalling IIapi_setEnvParam()\n" ); IIapi_setEnvParam( &setEnvPrmParm); if ( setEnvPrmParm.se_status != IIAPI_ST_SUCCESS ) return( setEnvPrmParm.se_status ); printf( "\tEstablishing Connection \n"); status = IIdemo_conn( env, dbname, &global.svr_connHandle, verbose ); if ( status == IIAPI_ST_SUCCESS ) { status = IIdemo_autocommit( &global.svr_connHandle, &global.svr_tranHandle, verbose ); if ( status == IIAPI_ST_SUCCESS ) { char creEvText[] = "create dbevent %s"; char regEvText[] = "register dbevent %s"; char queryText[512]; printf( "\tCreating DB Event \n"); sprintf( queryText, creEvText, IIdemo_eventName ); IIdemo_query( &global.svr_connHandle, &global.svr_tranHandle, queryText, verbose ); printf( "\tRegistering for DB Event \n"); sprintf( queryText, regEvText, IIdemo_eventName ); status = IIdemo_query( &global.svr_connHandle, &global.svr_tranHandle, queryText, verbose ); } if ( status != IIAPI_ST_SUCCESS ) IIdemo_abort( &global.svr_connHandle, verbose ); } return( status ); }
int main( int argc, char** argv ) { II_PTR connHandle = (II_PTR)NULL; II_PTR tranHandle = (II_PTR)NULL; II_PTR stmtHandle; IIAPI_QUERYPARM queryParm; IIAPI_SETDESCRPARM setDescrParm; IIAPI_PUTPARMPARM putParmParm; IIAPI_GETQINFOPARM getQInfoParm; IIAPI_CLOSEPARM closeParm; IIAPI_WAITPARM waitParm = { -1 }; if ( argc != 2 ) { printf( "usage: apiserr [vnode::]dbname[/server_class]\n" ); exit( 0 ); } IIdemo_init(); IIdemo_conn(argv[1],&connHandle); /* ** Valid query: no row count */ IIdemo_query(&connHandle, &tranHandle,"create table",createTBLText); /* ** Valid query: row count */ IIdemo_query(&connHandle, &tranHandle,"insert",insertText); /* ** Invalid query */ IIdemo_query(&connHandle, &tranHandle,"invalid column",invalidText); IIdemo_rollback(&tranHandle); IIdemo_disconn(&connHandle); IIdemo_term(); return( 0 ); }
int main( int argc, char** argv ) { II_PTR connHandle = (II_PTR)NULL; II_PTR tranHandle = (II_PTR)NULL; II_PTR stmtHandle = (II_PTR)NULL; II_PTR cursorID; IIAPI_QUERYPARM queryParm; IIAPI_SETDESCRPARM setDescrParm; IIAPI_PUTPARMPARM putParmParm; IIAPI_GETDESCRPARM getDescrParm; IIAPI_GETCOLPARM getColParm; IIAPI_GETQINFOPARM getQInfoParm; IIAPI_CLOSEPARM closeParm; IIAPI_WAITPARM waitParm = { -1 }; IIAPI_DESCRIPTOR DescrBuffer[ 1 ]; IIAPI_DATAVALUE DataBuffer[ 2 ]; IIAPI_DATAVALUE CursorBuffer[ 1 ]; char var1[33]; int var2; if ( argc != 2 ) { printf( "usage: apiscupd [vnode::]dbname[/server_class]\n" ); exit( 0 ); } IIdemo_init(); IIdemo_conn(argv[1],&connHandle); IIdemo_query(&connHandle, &tranHandle,"create table",createTBLText); IIdemo_query(&connHandle, &tranHandle,"prepare insert",prepText); IIdemo_insert(&connHandle,&tranHandle); /* ** Open cursor. */ printf( "apiscupd: open cursor\n"); queryParm.qy_genParm.gp_callback = NULL; queryParm.qy_genParm.gp_closure = NULL; queryParm.qy_connHandle = connHandle; queryParm.qy_queryType = IIAPI_QT_OPEN; queryParm.qy_queryText = openText; queryParm.qy_parameters = FALSE; queryParm.qy_tranHandle = tranHandle; queryParm.qy_stmtHandle = NULL; IIapi_query( &queryParm ); while( queryParm.qy_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); tranHandle = queryParm.qy_tranHandle; stmtHandle = queryParm.qy_stmtHandle; /* ** Get cursor row descriptor. */ getDescrParm.gd_genParm.gp_callback = NULL; getDescrParm.gd_genParm.gp_closure = NULL; getDescrParm.gd_stmtHandle = stmtHandle; getDescrParm.gd_descriptorCount = 0; getDescrParm.gd_descriptor = NULL; IIapi_getDescriptor( &getDescrParm ); while( getDescrParm.gd_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Position cursor on row. */ getColParm.gc_genParm.gp_callback = NULL; getColParm.gc_genParm.gp_closure = NULL; getColParm.gc_rowCount = 1; getColParm.gc_columnCount = getDescrParm.gd_descriptorCount; getColParm.gc_columnData = DataBuffer; getColParm.gc_columnData[0].dv_value = var1; getColParm.gc_columnData[1].dv_value = &var2; getColParm.gc_stmtHandle = stmtHandle; getColParm.gc_moreSegments = 0; do { printf( "apiscupd: next row\n" ); IIapi_getColumns( &getColParm ); while( getColParm.gc_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); if ( getColParm.gc_genParm.gp_status >= IIAPI_ST_NO_DATA ) break; /* ** Update using cursor. */ printf( "apiscupd: update row\n" ); queryParm.qy_genParm.gp_callback = NULL; queryParm.qy_genParm.gp_closure = NULL; queryParm.qy_connHandle = connHandle; queryParm.qy_queryType = IIAPI_QT_CURSOR_UPDATE; queryParm.qy_queryText = updateText; queryParm.qy_parameters = TRUE; queryParm.qy_tranHandle = tranHandle; queryParm.qy_stmtHandle = NULL; IIapi_query( &queryParm ); while( queryParm.qy_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Describe query parameters - cursor handle. */ setDescrParm.sd_genParm.gp_callback = NULL; setDescrParm.sd_genParm.gp_closure = NULL; setDescrParm.sd_stmtHandle = queryParm.qy_stmtHandle; setDescrParm.sd_descriptorCount = 1; setDescrParm.sd_descriptor = DescrBuffer; setDescrParm.sd_descriptor[0].ds_dataType = IIAPI_HNDL_TYPE; setDescrParm.sd_descriptor[0].ds_nullable = FALSE; setDescrParm.sd_descriptor[0].ds_length = sizeof( II_PTR ); setDescrParm.sd_descriptor[0].ds_precision = 0; setDescrParm.sd_descriptor[0].ds_scale = 0; setDescrParm.sd_descriptor[0].ds_columnType = IIAPI_COL_SVCPARM; setDescrParm.sd_descriptor[0].ds_columnName = NULL; IIapi_setDescriptor( &setDescrParm ); while( setDescrParm.sd_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Send query parameters - cursor handle. */ putParmParm.pp_genParm.gp_callback = NULL; putParmParm.pp_genParm.gp_closure = NULL; putParmParm.pp_stmtHandle = queryParm.qy_stmtHandle; putParmParm.pp_parmCount = setDescrParm.sd_descriptorCount; putParmParm.pp_parmData = CursorBuffer; putParmParm.pp_moreSegments = 0; putParmParm.pp_parmData[0].dv_null = FALSE; putParmParm.pp_parmData[0].dv_length = sizeof( II_PTR ); putParmParm.pp_parmData[0].dv_value = (II_PTR)&cursorID; cursorID = stmtHandle; IIapi_putParms( &putParmParm ); while( putParmParm.pp_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Get update statement results. */ getQInfoParm.gq_genParm.gp_callback = NULL; getQInfoParm.gq_genParm.gp_closure = NULL; getQInfoParm.gq_stmtHandle = queryParm.qy_stmtHandle; IIapi_getQueryInfo( &getQInfoParm ); while( getQInfoParm.gq_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Free update statement resources. */ closeParm.cl_genParm.gp_callback = NULL; closeParm.cl_genParm.gp_closure = NULL; closeParm.cl_stmtHandle = queryParm.qy_stmtHandle; IIapi_close( &closeParm ); while( closeParm.cl_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); } while( 1 ); /* ** Get cursor fetch results. */ getQInfoParm.gq_genParm.gp_callback = NULL; getQInfoParm.gq_genParm.gp_closure = NULL; getQInfoParm.gq_stmtHandle = stmtHandle; IIapi_getQueryInfo( &getQInfoParm ); while( getQInfoParm.gq_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); /* ** Free cursor resources. */ printf( "apiscupd: close cursor\n" ); closeParm.cl_genParm.gp_callback = NULL; closeParm.cl_genParm.gp_closure = NULL; closeParm.cl_stmtHandle = stmtHandle; IIapi_close( &closeParm ); while( closeParm.cl_genParm.gp_completed == FALSE ) IIapi_wait( &waitParm ); IIdemo_rollback(&tranHandle); IIdemo_disconn(&connHandle); IIdemo_term(); return( 0 ); }