0

We are using an old version of isql to connect to Informix DB from Linux (RHEL 6.10) The format we are using to run a select SQL is:

 isql -v -k $INX_DRIVER -x0xEC -b < ${sql_file} > ${out_file}

When there are errors while running the SQL, the above call does not end and infinitely keeps adding error message in the log file.

How can I specify during isql call to exit on error/exception?

The man page has this option which sound like should do the trick but the description is not clear enough for me to be sure.

-3     Use the ODBC 3 calls.

I think this option would end isql call if there are 3 errors/exceptions. Is my understanding correct?

300
  • 965
  • 1
  • 14
  • 53
  • 1
    AFAIK, Informix `isql` does not have a `-3` option to use ODBC — I suspect you are looking at the wrong manual, or using an `isql` other than the `isql` that comes with Informix-SQL. (I don't recognize the `-v`, `-k`, `-b` or `-x0xEC` options either, but it's a long time since I last studied the option parsing code in Informix's `isql`.) Usually, it's best to use DB-Access (`dbaccess`) instead; there is an environment variable `DBACCNOIGN` (it just needs to be set; the value doesn't matter, so use `1`) which tells DB-Access not to ignore errors. AFAIK, that isn't available in `isql`. – Jonathan Leffler May 25 '22 at 00:03
  • 1
    I think he is using UnixODBC's isql, not Informix-SQL's isql. UnixODBC isql is a basic tool that uses ODBC drivers and the UnixODBC driver manager to run SQL against databases. Looking at the isql code, there is a "-3" option to set SQL_ATTR_ODBC_VERSION=3, but I'm not sure how that would make any difference to what you want. Digging a little more, I see no option to abort (exit isql) if an SQLExecute() fails. It just keep processing the supplied SQL statements. If you are not scare of building from source, it should be a simple change to make it exit if the call failed. – jsagrera May 25 '22 at 07:34
  • Thank you Jonathan and jsagrera for you inputs. Yes, I am using UnixODBC's isql, not Informix-SQL's isql. @jsagrera I am open to trying out other options as well. Would you be able to share your thoughts on how I can make it exit on error/exception? I tried looking for isql we have installed and it's a binary so I couldn't see how it's setup or what it's doing. – 300 May 25 '22 at 16:08
  • 1
    You will need to download the source packge (http://www.unixodbc.org/download.html), extract it, and then build it. If you are on a "standard" platform, it should work "out of the box". Follow the steps in the previous link. It's just a matter of: extract, run "./configure", then "make" and finally "make install" to install it in your system. I suggest to try that before attempting to modify the isql.c source file to add your "abort if there was an error" change. – jsagrera May 26 '22 at 17:45
  • 1
    If you downloaded the latest version (unixODBC-2.3.11.tar.gz), the only changes need it to exit if there was an error are in the "exe/isql.c" file. In line 504 and 519 replace the `ExecuteSQL( hDbc, szSQL, cDelimiter, bColumnNames, bHTMLTable );` for `if (ExecuteSQL( hDbc, szSQL, cDelimiter, bColumnNames, bHTMLTable ) == 0) exit(-1);` . Then run `make clean` and `make` to rebuild the isql binary (which will be in `./exe/.libs`. – jsagrera May 26 '22 at 18:21
  • Thank you very much @jsagrera I'll see which way will be allowed by our network admins and will try that out. – 300 May 27 '22 at 19:14

0 Answers0