/**** isamex.c *********************************************** This program makes an odbc connection and returns the ISAM error, which should be -100 in this case. Be sure to change the values in the "Change these values" section to set up the connection. -- If you do not already have a "state" table, use this SQL -- to create one: create table state ( code char(2), sname char(15), primary key (code) ); insert into state values('KS', 'Kansas'); ****/ /* Be sure to specify -DNO_WIN32 if not compiling on Windows */ #ifndef NO_WIN32 #include #include #include #endif /*NO_WIN32*/ #include #include "infxcli.h" /***** Change these values *****/ char dsn[31] = "dsnstores7"; /* datasource name */ char user[31] = "informix"; /* username */ char pwd[31] = "xxxxxxxx"; /* password */ /* Sql statement to run to hopefully get an ISAM error****/ char sql[255] = "insert into state values('KS', 'Kansas')"; /***** *****/ #define ErrMsgLen 255 UCHAR ErrMsg[ErrMsgLen]; void checkError(RETCODE rcode, HENV henv, HDBC hdbc, HSTMT hstmt, char *sqlState, char *context) { RETCODE rc = SQL_NO_DATA_FOUND; SWORD pcbErrorMsgLen = 0; SDWORD pfNativeError; int ISAMerror = 0; short i; if (rcode == SQL_SUCCESS || rcode == SQL_SUCCESS_WITH_INFO) { fprintf(stdout, "%s successfull\n", context); } else { fprintf(stdout, "Error in %s\n", context); /* Get the SQL error and message */ rc = SQLError(henv, hdbc, hstmt, (UCHAR *)sqlState, &pfNativeError, (UCHAR *)ErrMsg, ErrMsgLen, &pcbErrorMsgLen); if( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO ) { fprintf(stdout, "ERROR: %d : %s : %s \r\n", pfNativeError, sqlState, ErrMsg ); } else { fprintf(stdout, "ERROR: Severe Error in ODBC Driver\n" ); } /* Check for the ISAM error */ if (hstmt != NULL) { /* This is the actual call that returns the ISAM error */ rc = SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 1, SQL_DIAG_ISAM_ERROR, (SQLPOINTER)&ISAMerror, SQL_IS_INTEGER, NULL); if (ISAMerror) fprintf(stdout, "ISAM Error: %d\n", ISAMerror); } exit(1); /* exit the program */ } } int main() { RETCODE rc; HENV henv = NULL; HDBC hdbc = NULL; HSTMT hstmt = NULL; char sqlState[6]; rc = SQLAllocEnv(&henv); checkError(rc, henv, hdbc, hstmt, sqlState, "SQLAllocEnv"); rc = SQLAllocConnect(henv, &hdbc); checkError(rc, henv, hdbc, hstmt, sqlState, "SQLAllocConnect"); rc = SQLConnect(hdbc, (UCHAR*)dsn, SQL_NTS, (UCHAR*)user, SQL_NTS, (UCHAR*)pwd, SQL_NTS); checkError(rc, henv, hdbc, hstmt, sqlState, "SQLConnect"); rc = SQLAllocStmt(hdbc, &hstmt); checkError(rc, henv, hdbc, hstmt, sqlState, "SQLAllocStmt"); rc = SQLExecDirect(hstmt, (UCHAR*)sql, SQL_NTS); checkError(rc, henv, hdbc, hstmt, sqlState, "SQLExecDirect"); SQLFreeStmt(hstmt, SQL_DROP); SQLFreeConnect(hdbc); SQLFreeEnv(henv); printf("Done with program\n"); } /**** end isamex.c *******************************/