Esempio n. 1
0
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 );
}
Esempio n. 2
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 );
}
Esempio n. 3
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;
    IIAPI_QUERYPARM	queryParm;
    IIAPI_GETDESCRPARM	getDescrParm;
    IIAPI_GETCOLPARM	getColParm;
    IIAPI_CLOSEPARM	closeParm;
    IIAPI_CANCELPARM	cancelParm;
    IIAPI_WAITPARM	waitParm = { -1 };
    IIAPI_DATAVALUE	DataBuffer[ 1 ];
    int			i;
    char		var1[33];

    if ( argc != 2 )
    {
	printf( "usage: apissell [vnode::]dbname[/server_class]\n" );
	exit( 0 );
    }

    IIdemo_init(); 
    IIdemo_conn(argv[1],&connHandle);

    /*
    **  Issue query
    */
    printf( "apissell: select table names\n" );

    queryParm.qy_genParm.gp_callback = NULL;
    queryParm.qy_genParm.gp_closure = NULL;
    queryParm.qy_connHandle = connHandle;
    queryParm.qy_queryType = IIAPI_QT_QUERY;
    queryParm.qy_queryText = queryText;
    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 query result descriptors
    */
    printf( "apissell: get descriptors\n" );

    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 );

    /*
    **  Get query results
    */
    printf( "apissell: get results\n" );

    getColParm.gc_genParm.gp_callback = NULL;
    getColParm.gc_genParm.gp_closure = NULL;
    getColParm.gc_rowCount = 1;
    getColParm.gc_columnCount = 1;
    getColParm.gc_rowsReturned = 0;
    getColParm.gc_columnData =  DataBuffer;
    getColParm.gc_columnData[0].dv_value = var1; 
    getColParm.gc_stmtHandle = stmtHandle;
    getColParm.gc_moreSegments = 0;

    for( i = 0; i < 5; i++ )
    {
	IIapi_getColumns( &getColParm );
        
        while( getColParm.gc_genParm.gp_completed == FALSE )
	    IIapi_wait( &waitParm );

	if ( getColParm.gc_genParm.gp_status >= IIAPI_ST_NO_DATA )
	    break; 

	var1[ DataBuffer[0].dv_length ] = '\0';
	printf( "\t%s = %s  \n", 
	    getDescrParm.gd_descriptor[0].ds_columnName, var1 );

    };

    /*
    **  Cancel query processing.
    */
    printf( "apissell: cancel query\n" );

    cancelParm.cn_genParm.gp_callback = NULL;
    cancelParm.cn_genParm.gp_closure = NULL;
    cancelParm.cn_stmtHandle = stmtHandle;

    IIapi_cancel(&cancelParm );

    while( cancelParm.cn_genParm.gp_completed == FALSE )
	IIapi_wait( &waitParm);

    /*
    **  Free query resources.
    */
    printf( "apissell: free query resources\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 );
}
Esempio n. 4
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		envHandle = (II_PTR)NULL;
    IIAPI_CONNPARM	connParm;
    IIAPI_AUTOPARM	autoparm;
    IIAPI_QUERYPARM	queryParm;
    IIAPI_GETDESCRPARM	getDescrParm;
    IIAPI_GETCOLPARM	getColParm;
    IIAPI_GETQINFOPARM	getQInfoParm;
    IIAPI_CLOSEPARM	closeParm;
    IIAPI_WAITPARM	waitParm = { -1 };
    IIAPI_DESCRIPTOR	DescrBuffer[ 5 ];
    IIAPI_DATAVALUE	DataBuffer[ 5 ];
    char		var[5][129];
    short		i, len;

    IIdemo_init(&envHandle);

    /*
    **  Connect to local Name Server
    */
    printf( "apisname: establishing connection to Name Server\n" );

    connParm.co_genParm.gp_callback = NULL;
    connParm.co_genParm.gp_closure = NULL;
    connParm.co_target =  NULL;   
    connParm.co_type   =  IIAPI_CT_NS;   
    connParm.co_connHandle = envHandle; 
    connParm.co_tranHandle = NULL;
    connParm.co_username = NULL;
    connParm.co_password = NULL;
    connParm.co_timeout = -1;

    IIapi_connect( &connParm );
    
    while( connParm.co_genParm.gp_completed == FALSE )
         IIapi_wait( &waitParm );

    connHandle = connParm.co_connHandle;
    tranHandle = connParm.co_tranHandle;
    
    /*
    **  Enable autocommit
    */
    printf( "apisauto: enable autocommit\n" );

    autoparm.ac_genParm.gp_callback = NULL;
    autoparm.ac_genParm.gp_closure  = NULL;
    autoparm.ac_connHandle = connHandle;
    autoparm.ac_tranHandle = NULL;

    IIapi_autocommit( &autoparm );

    while( autoparm.ac_genParm.gp_completed == FALSE )
       IIapi_wait( &waitParm );

    tranHandle = autoparm.ac_tranHandle;

    /*
    **  Execute 'show' statement.
    */
    printf( "apisname: retrieving VNODE connection info\n");

    queryParm.qy_genParm.gp_callback = NULL;
    queryParm.qy_genParm.gp_closure = NULL;
    queryParm.qy_connHandle = connHandle;
    queryParm.qy_queryType = IIAPI_QT_QUERY;
    queryParm.qy_queryText = showText;
    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 );

    stmtHandle = queryParm.qy_stmtHandle;

    /*
    **  Get result row descriptors.
    */
    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 );

    /*
    **  Retrieve result rows.
    */
    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_stmtHandle = stmtHandle;
    getColParm.gc_moreSegments = 0;

    for( i = 0; i < getDescrParm.gd_descriptorCount; i++ )
	getColParm.gc_columnData[i].dv_value = var[i]; 

    do 
    {
	IIapi_getColumns( &getColParm );
        
        while( getColParm.gc_genParm.gp_completed == FALSE )
	    IIapi_wait( &waitParm );

	if ( getColParm.gc_genParm.gp_status >= IIAPI_ST_NO_DATA )
	    break; 

        for( i = 0; i < getDescrParm.gd_descriptorCount; i++ ) 
        {
	    if ( getDescrParm.gd_descriptor[i].ds_dataType == IIAPI_VCH_TYPE )
	    {
		memcpy( (char *)&len, var[i], 2 );
		var[i][ len + 2 ] = '\0';
		strcpy( var[i], &var[i][2] );
	    }
	    else
	    {
		var[i][ getColParm.gc_columnData[ i ].dv_length ] = '\0';
	    }

        }

	printf( "\tG/P = %s vnode = %s host = %s prot = %s addr = %s\n", 
		var[0],var[1],var[2],var[3],var[4]);

    } while (1); 

    /*
    **  Get query 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 );
          
    /*
    **  Close query.
    */
    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 );

    /*
    **  Disable autocommit.
    */
    printf( "apisname: disable autocommit\n" );

    autoparm.ac_connHandle = NULL;
    autoparm.ac_tranHandle = tranHandle;

    IIapi_autocommit( &autoparm );
    
    while( autoparm.ac_genParm.gp_completed == FALSE )
       IIapi_wait( &waitParm );

    IIdemo_disconn(&connHandle);
    IIdemo_term(&envHandle);

    return( 0 );
}