Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!att!att!cbnewsk!barton From: barton@cbnewsk.att.com (jim.m.barton) Newsgroups: comp.databases Subject: Re: Informix messages in ESQL/C Summary: use rgetmsg() sql library function Message-ID: <1991Mar14.222941.3459@cbnewsk.att.com> Date: 14 Mar 91 22:29:41 GMT References: <1991Mar13.171305.16997@vision.uucp> Organization: AT&T Bell Laboratories Lines: 43 In article <1991Mar13.171305.16997@vision.uucp>, chris@vision.uucp (Chris Davies) writes: > WRT Informix databases, at least version 2, probably OnLine/version 4 too... > > I have an application written with Informix's ESQL/C embedded SQL in C (not > the 4GL product). When an error occurs, the error number can be found from > the sqlca structure (in sqlca.sqlcode). What I would like to do is to be > able to obtain the error text associated with that error number. > There is a function provided in the INFORMIX-provided sql library: rgetmsg( code, buf, buffer_length ) long code; char *buffer; int buffer_length; rgetmsg() will populate a caller-provided character buffer, 'buffer' with the error message corresponding with database error code 'code'. The maximum length of 'buffer' is passed in as 'buffer_length'. Note: be sure that the value of code does not exceed the bounds for a short, (even though the argument is a long) - it will result in a core dump at least on my system. I also was told by INFORMIX support that there was no way to read those .iem files. I discovered rgetmsg() by disassembling some of the sql library functions. There is also a (apparently undocumented) method of getting values to substitite for format specifications found in some of the error messages, (e. g., name of table, to substitute for %s in: "The specified table (%s) is not in the database." [db error -206] When a error message contains a format specification, (%s or %d), you can get the ASCII string to substitute from sqlca.sqlerrm). I have only encountered at most one format specification and only %s and %d, but since this seems to be undocumented, code defensively for the unexpected, (e. g., check for a valid ASCII string in sqlca.sqlerrm before attempting to use it).