IBM Support

ISAM error in ODBC -- How to get it.

Troubleshooting


Problem

How to get the ISAM error from ODBC. Includes a sample ODBC program which demonstrates the technique.

Resolving The Problem


Sometimes when an error occurs while executing a SQL statement with an IBM Informix engine, a secondary error called the ISAM error will be generated in addition to the normal SQL error number. The ISAM error gives additional information about why the SQL error occurred.

The IBM Informix ODBC Driver returns the ISAM error in the SQL_DIAG_ISAM_ERROR field of the diagnostic record. To get the error, make a call to the SQLGetDiagField ODBC function using the following syntax:

    SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 1,
 SQL_DIAG_ISAM_ERROR,(SQLPOINTER)&errornum,
SQL_IS_INTEGER, NULL);
    hstmt
      This is a valid ODBC statement handle.

    errornum
      This is an integer variable. The ISAM error will be placed in errornum. A value of zero returned in errornum indicates there was no ISAM error.


SAMPLE PROGRAM

This sample program connects to the stores demo database and tries to insert a value that is already in the table. It then uses the technique described above to get the ISAM error generated. The ISAM error returned will be -100.
    isamex.c.txt


Compiling

In order to use isamex.c do the following.

1. Copy the file isamex.c.txt given above to a working directory.

2. Rename the file isamex.c

3. Edit isamex.c to change the variables in the section marked with the following comment:
      /***** Change these values *****/
    Modify the variables to reflect the proper data source name, user name, and password.

4. Compile and run isamex.c as you would any other ODBC program. Use the option -DNO_WIN32 if not compiling on Windows.


Sample compile and run

On Unix/Linux:
    $ cc -I${INFORMIXDIR}/incl/cli -DNO_WIN32 isamex.c -o isamex -L${INFORMIXDIR}/lib/cli -lifcli -lifdmr -lm -lnsl

    $  ./isamex
    SQLAllocEnv successfull
    SQLAllocConnect successfull
    SQLConnect successfull
    SQLAllocStmt successfull
    Error in SQLExecDirect
    ERROR: -268 : 23000 : [Informix][Informix ODBC  Driver][Informix]Unique constraint (informix.u105_16) violated.
    ISAM Error: -100


On Microsoft Windows:
    C:\testing>cl -I"%INFORMIXDIR%/incl/cli" isamex.c odbc32.lib
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
    Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

    isamex.c
    Microsoft (R) Incremental Linker Version 6.00.8447
    Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

    /out:isamex.exe
    isamex.obj
    odbc32.lib

    C:\testing>isamex.exe
    SQLAllocEnv successfull
    SQLAllocConnect successfull
    SQLConnect successfull
    SQLAllocStmt successfull
    Error in SQLExecDirect
    ERROR: -268 : 23000 : [Informix][Informix ODBC Driver][Informix]Unique constraint (informix.u105_16) violated.
    ISAM Error: -100

[{"Product":{"code":"SSVT2J","label":"Informix Tools"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Informix Client Software Development Kit (CSDK)","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF025","label":"Platform Independent"},{"code":"PF008","label":"DYNIX\/ptx"},{"code":"PF010","label":"HP-UX"},{"code":"PF015","label":"IRIX"},{"code":"PF016","label":"Linux"},{"code":"PF026","label":"Reliant UNIX"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"1.0;1.1;1.2;1.3;1.4;1.5;1.6;2.0;2.1;2.2;2.3;2.4;2.5;2.6;2.7;2.8;2.9;3.0;4.0;4.1;4.2;5.1;6.0;7.2;7.3","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21083308