Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > GET DIAGNOSTICS >

The Contents of the CONNECTION_NAME Field

The CONNECTION_NAME field contains different information after you execute the following statements.

Executed Statement
CONNECTION_NAME Field Contents
CONNECT
Contains connection name specified in the CONNECT statement, to which you connect or fail to connect The field is blank for no current connection or a default connection.
SET CONNECTION
Contains the connection name specified in the CONNECT statement, to which you switch or fail to switch
DISCONNECT
Contains the connection name specified in the CONNECT statement, from which you disconnect or fail to disconnect If you disconnect, and then execute a DISCONNECT statement for a connection that is not current, the CONNECTION_NAME field remains unchanged.
DISCONNECT ALL
Contains no information if the statement executes successfully If the statement does not execute successfully, the CONNECTION_NAME field contains the names of all the connections specified in your CONNECT statement from which you did not disconnect. This information does not mean, however, that the connection still exists.

If CONNECT is successful, CONNECTION_NAME takes one of these values:

Using GET DIAGNOSTICS for Error Checking

GET DIAGNOSTICS returns values from various fields in the diagnostics area. For each field in the diagnostics area that you wish to access, you must supply a host variable of a compatible data type.

The following example illustrates how to use the GET DIAGNOSTICS statement to display error information. The example shows an ESQL/C error display routine called disp_sqlstate_err( ):

void disp_sqlstate_err()
{
int j;
EXEC SQL BEGIN DECLARE SECTION;
    int exception_count;
    char overflow[2];
    int exception_num=1;
    char class_id[255];
    char subclass_id[255];
    char message[255];
    int messlen;
    char sqlstate_code[6];
    int i;
EXEC SQL END DECLARE SECTION;
    printf("---------------------------------");
    printf("-------------------------\n");
    printf("SQLSTATE: %s\n",SQLSTATE);
    printf("SQLCODE: %d\n", SQLCODE);
    printf("\n");
    EXEC SQL get diagnostics :exception_count = NUMBER,
        :overflow = MORE;
    printf("EXCEPTIONS:  Number=%d\t", exception_count);
    printf("More? %s\n", overflow);
    for (i = 1; i <= exception_count; i++)
    {
        EXEC SQL get diagnostics  exception :i
            :sqlstate_code = RETURNED_SQLSTATE,
            :class_id = CLASS_ORIGIN, :subclass_id = SUBCLASS_ORIGIN,
            :message = MESSAGE_TEXT, :messlen = MESSAGE_LENGTH;
        printf("- - - - - - - - - - - - - - - - - - - -\n");
        printf("EXCEPTION %d: SQLSTATE=%s\n", i, sqlstate_code);
        message[messlen-1] ='\0';
        printf("MESSAGE TEXT: %s\n", message);
        j = stleng(class_id);
        while((class_id[j] == '\0') ||
              (class_id[j] == ' '))
            j--;
        class_id[j+1] = '\0';
        printf("CLASS ORIGIN: %s\n",class_id);
        j = stleng(subclass_id);
        while((subclass_id[j] == '\0') ||
              (subclass_id[j] == ' '))
            j--;
        subclass_id[j+1] = '\0';
        printf("SUBCLASS ORIGIN: %s\n",subclass_id);
    }
    printf("---------------------------------");
    printf("-------------------------\n");
}

Related Information

For a task-oriented discussion of error handling and the SQLSTATE variable, see the IBM Informix Guide to SQL: Tutorial. For a discussion of concepts related to the GET DIAGNOSTICS statement and the SQLSTATE variable, see the IBM Informix ESQL/C Programmer's Manual.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]