Skip to content

4. Sample Programs#

This chapter provides sample programs in C that were written using Altibase Monitoring API.

Makefile#

This is an example Makefile to compile the sample programs provided in this chapter. It uses the altibase_env.mk file included in the Altibase package.

include $(ALTIBASE_HOME)/install/altibase_env.mk
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.$(OBJEXT))
BINS = $(SRCS:.c=$(BINEXT))

all : $(BINS)

sample_1 : sample_1.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_2 : sample_2.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_3 : sample_3.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_4 : sample_4.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_5 : sample_5.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_6 : sample_6.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_7 : sample_7.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_8 : sample_8.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_9 : sample_9.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
sample_10 : sample_10.$(OBJEXT)
    $(LD) $(LDOUT) $@ $^ $(LFLAGS) $(LIBOPT)altibaseMonitor$(LIBAFT) $(LIBOPT)odbccli$(LIBAFT) $(LIBS)
clean :
    $(RM) $(OBJS) $(BINS) *.log

sample_1.c#

This sample program uses the ABIGetVSession and ABIGetVSessionBySID functions to select the V$SESSION performance view.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printVSession( ABIVSession *aVSession, int aRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABIVSession *sVSession = NULL, *sVSessionBySID = NULL;
    int          sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        /*
           IF the second argument sets to
           0 - Return all session information.
           1 - Return executing session information only.
         */
        // Test ABIGetVSession
        sRc = ABIGetVSession( &sVSession, 0 );
        if( sRc >= 0 )
        {
            printf( "*******************************\n" );
            printf( "*          V$Session          *\n" );
            printf( "*******************************\n" );
            printVSession( sVSession, sRc );

            sVSession = NULL;
            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSession [ Active Only ]
        sRc = ABIGetVSession( &sVSession, 1 );
        if( sRc >= 0 )
        {
            printf( "***********************************************\n" );
            printf( "*          V$Session [ Active Only ]          *\n" );
            printf( "***********************************************\n" );
            printVSession( sVSession, sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSessionBySID
        sRc = ABIGetVSessionBySID( &sVSessionBySID, sVSession[0].mID );
        if( sRc >= 0 )
        {
            printf( "*************************************************\n" );
            printf( "*          V$Session [ specified SID ]          *\n" );
            printf( "*************************************************\n" );
            printVSession( sVSessionBySID, sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printVSession( ABIVSession *aVSession, int aRowCount )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "ID : %d\n", aVSession[sI].mID );
        printf( "TRANS_ID : %lld\n", aVSession[sI].mTransID );
        printf( "TASK_STATE : %s\n", aVSession[sI].mTaskState );
        printf( "COMM_NAME : %s\n", aVSession[sI].mCommName );
        printf( "XA_SESSION_FLAG : %d\n", aVSession[sI].mXASessionFlag );
        printf( "XA_ASSOCIATE_FLAG : %d\n", aVSession[sI].mXAAssociateFlag );
        printf( "QUERY_TIME_LIMIT : %d\n", aVSession[sI].mQueryTimeLimit );
        printf( "DDL_TIME_LIMIT : %d\n", aVSession[sI].mDdlTimeLimit );
        printf( "FETCH_TIME_LIMIT : %d\n", aVSession[sI].mFetchTimeLimit );
        printf( "UTRANS_TIME_LIMIT : %d\n", aVSession[sI].mUTransTimeLimit );
        printf( "IDLE_TIME_LIMIT : %d\n", aVSession[sI].mIdleTimeLimit );
        printf( "IDLE_START_TIME : %d\n", aVSession[sI].mIdleStartTime );
        printf( "ACTIVE_FLAG : %d\n", aVSession[sI].mActiveFlag );
        printf( "OPENED_STMT_COUNT : %d\n", aVSession[sI].mOpenedStmtCount );
        printf( "CLIENT_PACKAGE_VERSION : %s\n", aVSession[sI].mClientPackageVersion );
        printf( "CLIENT_PROTOCOL_VERSION : %s\n", aVSession[sI].mClientProtocolVersion );
        printf( "CLIENT_PID : %lld\n", aVSession[sI].mClientPID );
        printf( "CLIENT_TYPE : %s\n", aVSession[sI].mClientType );
        printf( "CLIENT_APP_INFO : %s\n", aVSession[sI].mClientAppInfo );
        printf( "CLIENT_NLS : %s\n", aVSession[sI].mClientNls );
        printf( "DB_USERNAME : %s\n", aVSession[sI].mDBUserName );
        printf( "DB_USERID : %d\n", aVSession[sI].mDBUserID );
        printf( "DEFAULT_TBSID : %lld\n", aVSession[sI].mDefaultTbsID );
        printf( "DEFAULT_TEMP_TBSID : %lld\n", aVSession[sI].mDefaultTempTbsID );
        printf( "SYSDBA_FLAG : %d\n", aVSession[sI].mSysDbaFlag );
        printf( "AUTOCOMMIT_FLAG : %d\n", aVSession[sI]. mAutoCommitFlag );
        printf( "SESSION_STATE : %s\n", aVSession[sI].mSessionState );
        printf( "ISOLATION_LEVEL : %d\n", aVSession[sI].mIsolationLevel );
        printf( "REPLICATION_MODE : %d\n", aVSession[sI].mReplicationMode );
        printf( "TRANSACTION_MODE : %d\n", aVSession[sI].mTransactionMode );
        printf( "COMMIT_WRITE_WAIT_MODE : %d\n", aVSession[sI].mCommitWriteWaitMode );
        printf( "OPTIMIZER_MODE : %d\n", aVSession[sI].mOptimizerMode );
        printf( "HEADER_DISPLAY_MODE : %d\n", aVSession[sI].mHeaderDisplayMode );
        printf( "CURRENT_STMT_ID : %d\n", aVSession[sI].mCurrentStmtID );
        printf( "STACK_SIZE : %d\n", aVSession[sI].mStackSize );
        printf( "DEFAULT_DATE_FORMAT : %s\n", aVSession[sI].mDefaultDateFormat );
        printf( "TRX_UPDATE_MAX_LOGSIZE : %lld\n", aVSession[sI].mTrxUpdateMaxLogSize );
        printf( "PARALLEL_DML_MODE : %d\n", aVSession[sI].mParallelDmlMode );
        printf( "LOGIN_TIME : %d\n", aVSession[sI].mLoginTime );
        printf( "FAILOVER_SOURCE : %s\n\n", aVSession[sI].mFailoverSource );
    }
    printf( "\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_2.c#

This sample program uses the ABIGetSessionCount function to select the total number of existing sessions and active sessions on the Altibase server. In addition, it retrieves the maximum number of clients that can connect to Altibase server using ABIGetMaxClientCount.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void errorHandling( int aErrCode );

int main()
{
    int         sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        /*
           IF the argument sets to
           0 - Return all session count.
           1 - Return executing session count only.
         */
        // Test ABIGetSessionCount
        sRc = ABIGetSessionCount( 0 );
        if( sRc >= 0 )
        {
            printf( "***********************************\n" );
            printf( "*          Session Count          *\n" );
            printf( "***********************************\n" );
            printf( "Session Count : %d\n\n\n", sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetSessionCount [ Active Only ]
        sRc = ABIGetSessionCount( 1 );
        if( sRc >= 0 )
        {
            printf( "***************************************************\n" );
            printf( "*          Session Count [ Active Only ]          *\n" );
            printf( "***************************************************\n" );
            printf( "Session Count : %d\n\n\n", sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetMaxClientCount
        sRc = ABIGetMaxClientCount();
        if( sRc >= 0 )
        {
            printf( "**************************************\n" );
            printf( "*          Max Client Count          *\n" );
            printf( "**************************************\n" );
            printf( "Max Client Count : %d\n\n\n", sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_3.c#

This sample program uses the ABIGetStatName, ABIGetVSysstat, ABIGetVSesstat, and ABIGetVSesstatBySID functions to select statistics on the Altibase system and its sessions.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printVSysstat( ABIVSysstat *aVSysstat, int aRowCount, ABIStatName *aStatName );
void printVSesstat( ABIVSesstat *aVSesstat, int aRowCount, ABIStatName *aStatName, int aStatNameRowCount );
void printStatName( ABIStatName *aStatName, int aStatNameRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABIVSysstat *sVSysstat = NULL;
    ABIVSesstat *sVSesstat = NULL;
    ABIStatName *sStatName = NULL;
    int          sStatNameRowCount = 0;
    int          sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        // Test ABIGetStatName
        sStatNameRowCount = ABIGetStatName( &sStatName );
        if( sStatNameRowCount >= 0 )
        {
            printf( "******************************\n" );
            printf( "*          StatName          *\n" );
            printf( "******************************\n" );
            printStatName( sStatName, sStatNameRowCount );
        }
        else
        {
            // Error handling
            errorHandling( sStatNameRowCount );
        }

        // Test ABIGetVSysstat
        sRc = ABIGetVSysstat( &sVSysstat );
        if( sRc >= 0 )
        {
            printf( "*******************************\n" );
            printf( "*          V$Sysstat          *\n" );
            printf( "*******************************\n" );
            printVSysstat( sVSysstat, sRc, sStatName );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSesstat
        sRc = ABIGetVSesstat( &sVSesstat, 0 );
        if( sRc >= 0 )
        {
            printf( "*******************************\n" );
            printf( "*          V$Sesstat          *\n" );
            printf( "*******************************\n" );
            printVSesstat( sVSesstat, sRc, sStatName, sStatNameRowCount );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSesstatBySID
        sRc = ABIGetVSesstatBySID( &sVSesstat, sVSesstat[0].mSID );
        if( sRc >= 0 )
        {
            printf( "*************************************************\n" );
            printf( "*          V$Sesstat [ specified SID ]          *\n" );
            printf( "*************************************************\n" );
            printVSesstat( sVSesstat, sRc, sStatName, sStatNameRowCount );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printVSysstat( ABIVSysstat *aVSysstat, int aRowCount, ABIStatName *aStatName )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "SEQNUM : %d\n", aStatName[sI].mSeqNum );
        printf( "NAME : %s\n", aStatName[sI].mName );
        printf( "VALUE : %lld\n\n", aVSysstat[sI].mValue );
    }
    printf( "\n" );
}

void printVSesstat( ABIVSesstat *aVSesstat, int aRowCount, ABIStatName *aStatName, int aStatNameRowCount )
{
    int sI, sJ;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        sJ = sI % aStatNameRowCount;

        printf( "SID : %d\n", aVSesstat[sI].mSID );
        printf( "SEQNUM : %d\n", aStatName[sJ].mSeqNum );
        printf( "NAME : %s\n", aStatName[sJ].mName );
        printf( "VALUE : %lld\n\n", aVSesstat[sI].mValue );
    }
    printf( "\n" );
}

void printStatName( ABIStatName *aStatName, int aStatNameRowCount )
{
    int sI;

    for( sI = 0; sI < aStatNameRowCount; sI++ )
    {
        printf( "SEQNUM : %d\n", aStatName[sI].mSeqNum );
        printf( "NAME : %s\n\n", aStatName[sI].mName );
    }
    printf( "\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_4.c#

This sample program uses the ABIGetEventName, ABIGetVSystemEvent, ABIGetVSessionEvent, and ABIGetVSessionEventBySID functions to select statistics on waits events of the Altibase system and its sessions.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printVSystemEvent( ABIVSystemEvent *aVSystemEvent, int aRowCount, ABIEventName *aEventName );
void printVSessionEvent( ABIVSessionEvent *aVSessionEvent, int aRowCount, ABIEventName *aEventName, int aEventNameRowCount );
void printEventName( ABIEventName *aEventName, int aEventNameRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABIVSystemEvent  *sVSystemEvent = NULL;
    ABIVSessionEvent *sVSessionEvent = NULL;
    ABIEventName     *sEventName = NULL;
    int               sEventNameRowCount = 0;
    int               sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        // Test ABIGetEventName
        sEventNameRowCount = ABIGetEventName( &sEventName );
        if( sEventNameRowCount >= 0 )
        {
            printf( "********************************\n" );
            printf( "*          Event Name          *\n" );
            printf( "********************************\n" );
            printEventName( sEventName, sEventNameRowCount );
        }
        else
        {
            // Error handling
            errorHandling( sEventNameRowCount );
        }

        // Test ABIGetVSystemEvent
        sRc = ABIGetVSystemEvent( &sVSystemEvent );
        if( sRc >= 0 )
        {
            printf( "************************************\n" );
            printf( "*          V$System_Event          *\n" );
            printf( "************************************\n" );
            printVSystemEvent( sVSystemEvent, sRc, sEventName );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSessionEvent
        sRc = ABIGetVSessionEvent( &sVSessionEvent );
        if( sRc >= 0 )
        {
            printf( "*************************************\n" );
            printf( "*          V$Session_Event          *\n" );
            printf( "*************************************\n" );
            printVSessionEvent( sVSessionEvent, sRc, sEventName, sEventNameRowCount );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSessionEventBySID
        sRc = ABIGetVSessionEventBySID( &sVSessionEvent, sVSessionEvent[0].mSID );
        if( sRc >= 0 )
        {
            printf( "*******************************************************\n" );
            printf( "*          V$Session_Event [ specified SID ]          *\n" );
            printf( "*******************************************************\n" );
            printVSessionEvent( sVSessionEvent, sRc, sEventName, sEventNameRowCount );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printVSystemEvent( ABIVSystemEvent *aVSystemEvent, int aRowCount, ABIEventName *aEventName )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "EVENT : %s\n", aEventName[sI].mEvent );
        printf( "TOTAL_WAITS : %lld\n", aVSystemEvent[sI].mTotalWaits );
        printf( "TOTAL_TIMEOUTS : %lld\n", aVSystemEvent[sI].mTotalTimeOuts );
        printf( "TIME_WAITED : %lld\n", aVSystemEvent[sI].mTimeWaited );
        printf( "AVERAGE_WAIT : %lld\n", aVSystemEvent[sI].mAverageWait );
        printf( "TIME_WAITED_MICRO : %lld\n", aVSystemEvent[sI].mTimeWaitedMicro );
        printf( "EVENT_ID : %d\n", aEventName[sI].mEventID );
        printf( "WAIT_CLASS_ID : %d\n", aEventName[sI].mWaitClassID );
        printf( "WAIT_CLASS : %s\n\n", aEventName[sI].mWaitClass );
    }
    printf( "\n" );
}

void printVSessionEvent( ABIVSessionEvent *aVSessionEvent, int aRowCount, ABIEventName *aEventName, int aEventNameRowCount )
{
    int sI, sJ;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        sJ = sI % aEventNameRowCount;

        printf( "SID : %d\n", aVSessionEvent[sI].mSID );
        printf( "EVENT : %s\n", aEventName[sJ].mEvent );
        printf( "TOTAL_WAITS : %lld\n", aVSessionEvent[sI].mTotalWaits );
        printf( "TOTAL_TIMEOUTS : %lld\n", aVSessionEvent[sI].mTotalTimeOuts );
        printf( "TIME_WAITED : %lld\n", aVSessionEvent[sI].mTimeWaited );
        printf( "AVERAGE_WAIT : %lld\n", aVSessionEvent[sI].mAverageWait );
        printf( "MAX_WAIT : %lld\n", aVSessionEvent[sI].mMaxWait );
        printf( "TIME_WAITED_MICRO : %lld\n", aVSessionEvent[sI].mTimeWaitedMicro );
        printf( "EVENT_ID : %d\n", aEventName[sJ].mEventID );
        printf( "WAIT_CLASS_ID : %d\n", aEventName[sJ].mWaitClassID );
        printf( "WAIT_CLASS : %s\n\n", aEventName[sJ].mWaitClass );
    }
    printf( "\n" );
}

void printEventName( ABIEventName *aEventName, int aEventNameRowCount )
{
    int sI;

    for( sI = 0; sI < aEventNameRowCount; sI++ )
    {
        printf( "EVENT_ID : %d\n", aEventName[sI].mEventID );
        printf( "EVENT : %s\n", aEventName[sI].mEvent );
        printf( "WAIT_CLASS_ID : %d\n", aEventName[sI].mWaitClassID );
        printf( "WAIT_CLASS : %s\n\n", aEventName[sI].mWaitClass );
    }
    printf( "\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_5.c#

This sample program uses the ABIGetSqlText, ABIGetLockPairBetweenSessions, and ABIGetLockWaitSessionCount functions.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printSqlText( ABISqlText *aSqlText );
void printLockPairBetweenSessions( ABILockPair *aLockPair, int aRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABISqlText  *sSqlText = NULL;
    ABILockPair *sLockPair = NULL;
    int          sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        // Test ABIGetSqlText
        sRc = ABIGetSqlText( &sSqlText, 2 );
        if( sRc >= 0 )
        {
            printf( "******************************\n" );
            printf( "*          SQL Text          *\n" );
            printf( "******************************\n" );
            printSqlText( sSqlText );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetLockPairBetweenSessions
        sRc = ABIGetLockPairBetweenSessions( &sLockPair );
        if( sRc >= 0 )
        {
            printf( "************************************************\n" );
            printf( "*          Lock Pair Between Sessions          *\n" );
            printf( "************************************************\n" );
            printLockPairBetweenSessions( sLockPair, sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetLockWaitSessionCount
        sRc = ABIGetLockWaitSessionCount();
        if( sRc >= 0 )
        {
            printf( "*********************************************\n" );
            printf( "*          Lock Wait Session Count          *\n" );
            printf( "*********************************************\n" );
            printf( "Lock Wait Session Count : %d\n\n\n", sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printSqlText( ABISqlText *aSqlText )
{
    printf( "SQL TEXT : %s\n", aSqlText->mSqlText );
    printf( "TEXT LENGTH : %d\n\n\n", aSqlText->mTextLength );
    printf( "QUERY START TIME : %d\n\n\n", aSqlText->mQueryStartTime );
    printf( "EXECUTE FLAG : %d\n\n\n", aSqlText->mExecuteFlag );
    printf( "PARSE TIME : %lld\n\n\n", aSqlText->mParseTime);
    printf( "SOFT PREPARE TIME : %lld\n\n\n", aSqlText->mSoftPrepareTime);
    printf( "LAST QUERY START TIME : %d\n\n\n", aSqlText->mLastQueryStartTime);
    printf( "EXECUTE TIME : %lld\n\n\n", aSqlText->mExecuteTime);
    printf( "FETCH TIME : %lld\n\n\n", aSqlText->mFetchTime);
    printf( "FETCH START TIME : %d\n\n\n", aSqlText->mFetchStartTime);
    printf( "TOTAL TIME : %lld\n\n\n", aSqlText->mTotalTime);
    printf( "VALIDATE TIME : %lld\n\n\n", aSqlText->mValidateTime);
    printf( "OPTIMIZE TIME : %lld\n\n\n", aSqlText->mOptimizeTime);
}

void printLockPairBetweenSessions( ABILockPair *aLockPair, int aRowCount )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "HOLDER : %d,\t\tWAITER : %d\n", aLockPair[sI].mHolderSID, aLockPair[sI].mWaiterSID );
    }
    printf( "\n\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_6.c#

This sample program uses the ABIGetDBInfo and ABIGetReadCount functions.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printDBInfo( ABIDBInfo *aDBInfo );
void printReadCount( ABIReadCount *aReadCount );
void errorHandling( int aErrCode );

int main()
{
    ABIDBInfo    *sDBInfo = NULL;
    ABIReadCount *sReadCount = NULL;
    int           sRc = 0;

    // Testing ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Testing ABICheckConnection()
    if( ABICheckConnection() != -1 )
    {
        // Testing ABIGetDBInfo
        sRc = ABIGetDBInfo( &sDBInfo );
        if( sRc >= 0 )
        {
            printf( "*****************************\n" );
            printf( "*          DB Info          *\n" );
            printf( "*****************************\n" );
            printDBInfo( sDBInfo );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Testing ABIGetReadCount
        sRc = ABIGetReadCount( &sReadCount );
        if( sRc >= 0 )
        {
            printf( "********************************\n" );
            printf( "*          Read Count          *\n" );
            printf( "********************************\n" );
            printReadCount( sReadCount );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Testing ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printDBInfo( ABIDBInfo *aDBInfo )
{
    printf( "DB NAME : %s\n", aDBInfo->mDBName );
    printf( "VERSION : %s\n\n\n", aDBInfo->mDBVersion );
}

void printReadCount( ABIReadCount *aReadCount )
{
    printf( "Logical Read Count : %d\n", aReadCount->mLogicalReadCount );
    printf( "Physical Read Count : %d\n\n\n", aReadCount->mPhysicalReadCount );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_7.c#

This sample program uses a global variable of the pthread_mutex_t type to synchronize the function calls of ABIGetVSession and ABIGetSessionCount.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <altibaseMonitor.h>

#define LOOP_COUNT 1000

pthread_mutex_t gMutex;

void *call_ABIGetVSession( void *aArgs );
void *call_ABIGetSessionCount( void *aArgs );
void errorHandling( int aErrCode );

int main()
{
    pthread_t sThread[2];
    int       sRc = 0;

    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    sRc = pthread_mutex_init( &gMutex, NULL );
    if( sRc != 0 )
    {
        printf( "Mutex init" );
        exit(1);
    }

    sRc = pthread_create( &( sThread[0] ), NULL, call_ABIGetVSession, NULL );
    if( sRc != 0 )
    {
        printf( "Create thread_1 [ Calling ABIGetVSession ]" );
        exit(1);
    }

    sRc = pthread_create( &( sThread[1] ), NULL, call_ABIGetSessionCount, NULL );
    if( sRc != 0 )
    {
        printf( "Create thread_2 [ Calling ABIGetSessionCount ]" );
        exit(1);
    }

    pthread_join( sThread[0], NULL );
    pthread_join( sThread[1], NULL );

    pthread_mutex_destroy( &gMutex );

    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void *call_ABIGetVSession( void *aArgs )
{
    ABIVSession *sVSession = NULL;
    int          sRc = 0;
    int          sI;

    for( sI = 0; sI < LOOP_COUNT; sI++ )
    {
        pthread_mutex_lock( &gMutex );

        sRc = ABIGetVSession( &sVSession, 1 );

        pthread_mutex_unlock( &gMutex );

        if( sRc < 0 )
        {
            // Error handling
            errorHandling( sRc );
        }

        sleep( 0.05 );
    }

    return NULL;
}

void *call_ABIGetSessionCount( void *aArgs )
{
    int sRc = 0;
    int sI;

    for( sI = 0; sI < LOOP_COUNT; sI++ )
    {
        pthread_mutex_lock( &gMutex );

        sRc = ABIGetSessionCount( 1 );

        pthread_mutex_unlock( &gMutex );

        if( sRc < 0 )
        {
            // Error handling
            errorHandling( sRc );
        }
    }

    return NULL;
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}


sample_8.c#

This sample program uses the ABIGetVSessionWait and ABIGetVSessionWaitBySID functions to select wait event information for sessions connected to the Altibase server.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printVSessionWait( ABIVSessionWait *aVSessionWait, int aRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABIVSessionWait *sVSessionWait = NULL, *sVSessionWaitBySID = NULL;
    int              sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        /*
           IF the second argument sets to
           0 - Return all session information.
           1 - Return executing session information only.
         */
        // Test ABIGetVSessionWait
        sRc = ABIGetVSessionWait( &sVSessionWait );
        if( sRc >= 0 )
        {
            printf( "************************************\n" );
            printf( "*          V$Session_Wait          *\n" );
            printf( "************************************\n" );
            printVSessionWait( sVSessionWait, sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetVSessionWaitBySID
        sRc = ABIGetVSessionWaitBySID( &sVSessionWaitBySID, sVSessionWait[0].mSID );
        if( sRc >= 0 )
        {
            printf( "******************************************************\n" );
            printf( "*          V$Session_Wait [ specified SID ]          *\n" );
            printf( "******************************************************\n" );
            printVSessionWait( sVSessionWaitBySID, sRc );

            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printVSessionWait( ABIVSessionWait *aVSessionWait, int aRowCount )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "SID : %d\n", aVSessionWait[sI].mSID );
        printf( "SEQNUM : %d\n", aVSessionWait[sI].mSeqNum );
        printf( "P1 : %lld\n", aVSessionWait[sI].mP1 );
        printf( "P2 : %lld\n", aVSessionWait[sI].mP2 );
        printf( "P3 : %lld\n", aVSessionWait[sI].mP3 );
        printf( "WAIT_CLASS_ID : %d\n", aVSessionWait[sI].mWaitClassID );
        printf( "WAIT_TIME : %lld\n", aVSessionWait[sI].mWaitTime );
        printf( "SECOND_IN_TIME : %lld\n\n", aVSessionWait[sI].mSecondInTime );
    }
    printf( "\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_9.c#

This sample program uses the ABIGetErrorMessage function to select an error message by its error code.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printErrorMessage( int aErrCode, const char *aErrMsg );
void errorHandling( int aErrCode );

int main()
{
    int         sI;
    int         sRc = 0;
    const char *sErrMsg = NULL;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        printf( "***********************************\n" );
        printf( "*          Error Message          *\n" );
        printf( "***********************************\n" );

        for( sI = -21; sI < 0; sI++ )
        {
            // Test ABIGetErrorMessage
            ABIGetErrorMessage( sI, &sErrMsg );
            printErrorMessage( sI, sErrMsg );
        }
        printf( "\n" );
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printErrorMessage( int aErrCode, const char *aErrMsg )
{
    printf( "Error Code : %d\n", aErrCode );
    printf( "%s\n\n", aErrMsg );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}

sample_10.c#

This program sample uses the ABIGetRepGap and ABIGetRepSentLogCount functions.

#include <stdio.h>
#include <stdlib.h>
#include <altibaseMonitor.h>

void printRepGap( ABIRepGap *aRepGap, int aRowCount );
void printRepSentLogCount( ABIRepSentLogCount *aRepSentLogCount, int aRowCount );
void errorHandling( int aErrCode );

int main()
{
    ABIRepGap          *sRepGap = NULL;
    ABIRepSentLogCount *sRepSentLogCount = NULL;
    int                 sRc = 0;

    // Test ABIInitialize
    sRc = ABIInitialize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    // Test ABICheckConnection
    if( ABICheckConnection() != -1 )
    {
        // Test ABIRepGap
        sRc = ABIGetRepGap( &sRepGap );
        if( sRc >= 0 )
        {
            printf( "*******************************\n" );
            printf( "*           RepGap            *\n" );
            printf( "*******************************\n" );
            printRepGap( sRepGap, sRc );
            sRepGap = NULL;
            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }

        // Test ABIGetRepSentLogCount
        sRc = ABIGetRepSentLogCount( &sRepSentLogCount );
        if( sRc >= 0 )
        {
            printf( "***********************************************\n" );
            printf( "*               RepSentLogCount               *\n" );
            printf( "***********************************************\n" );
            printRepSentLogCount( sRepSentLogCount, sRc );
            sRepSentLogCount = NULL;
            sRc = 0;
        }
        else
        {
            // Error handling
            errorHandling( sRc );
        }
    }
    else
    {
        // Exception handling
    }

    // Test ABIFinalize
    sRc = ABIFinalize();
    if( sRc < 0 )
    {
        // Error handling
        errorHandling( sRc );
    }

    return 0;
}

void printRepGap( ABIRepGap *aRepGap, int aRowCount )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "REP_NAME : %s\n", aRepGap[sI].mRepName );
        printf( "REP_GAP : %lld\n", aRepGap[sI].mRepGap );
    }
    printf( "\n" );
}

void printRepSentLogCount( ABIRepSentLogCount *aRepSentLogCount, int aRowCount )
{
    int sI;

    for( sI = 0; sI < aRowCount; sI++ )
    {
        printf( "REP_NAME : %s\n", aRepSentLogCount[sI].mRepName );
        printf( "TABLE_NAME : %s\n", aRepSentLogCount[sI].mTableName );
        printf( "INSERT_LOG_COUNT : %d\n", aRepSentLogCount[sI].mInsertLogCount );
        printf( "DELETE_LOG_COUNT : %d\n", aRepSentLogCount[sI].mDeleteLogCount );
        printf( "UPDATE_LOG_COUNT : %d\n", aRepSentLogCount[sI].mUpdateLogCount );
    }
    printf( "\n" );
}

void errorHandling( int aErrCode )
{
    const char *sErrMsg = NULL;

    ABIGetErrorMessage( aErrCode, &sErrMsg );
    printf( "%s\n\n\n", sErrMsg );
    exit(1);
}