[comp.databases] Informix messages in ESQL/C

chris@vision.uucp (Chris Davies) (03/14/91)

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.

Alas, there doesn't seem to be any way of doing this, and it does seem rather
antiquated to tell the user "look the error number up in the book...".

I can see the error messages (they're in the .iem files in $INFORMIXDIR/msg)
but I cannot work out the file structure  :-)

I don't want to re-enter the messages into my program (or a file of my own
doing), since Informix Software Inc could
	(a) complain about breaches of copyright on the messages
	(b) change the messages or create new ones

and either of these situations would be problematical(!).

Can anyone help shed some light on how I would go about getting these error
messages?  A portable solution (ie works on any platform with an Informix
database on it) would be preferable.

Informix UK say "it can't be done", but then UK bits of other US companies
always say that when something's not in the manuals...  :-(

Ta,
    Chris
-- 
VISIONWARE LTD         | UK: chris@vision.uucp    JANET: chris%vision.uucp@ukc
57 Cardigan Lane       | US: chris@vware.mn.org   BANGNET: ...!ukc!vision!chris
LEEDS LS4 2LE, England | VOICE:  +44 532 788858   FAX:  +44 532 304676
-------------- "VisionWare:   The home of DOS/UNIX/X integration" -------------

barrym@informix.com (Barry Mednick) (03/15/91)

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.
>
>Alas, there doesn't seem to be any way of doing this, and it does seem rather
>antiquated to tell the user "look the error number up in the book...".
>
See the function rgetmsg(), as defined in Chapter 5 of the ESQL/C 4.00
manual.  It does exactly what you described.

barton@cbnewsk.att.com (jim.m.barton) (03/15/91)

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).

kelly@bellahs.UUCP (Kelly Kingdon) (03/15/91)

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.
>
>	[ text deleted ]

	I don't know about earlier versions but in Informix On-line there is a
	function, rgetmsg() that does exactly what you are looking for.  It is
	in chap 5, library functions in the esql/c manual.


===========================================================================
=  Kelly Kingdon 		Bell Atlantic Healthcare Systems          =
=  Phone: (415) 925-0121        Greenbrae, CA.                            =
=                                                                         =
=  E-mail: uunet!bellahs!kelly  uunet!kelly@bellahs.UUCP                  =

eric@cinnet.com (Eric Bardes) (03/18/91)

>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.

rgetmsg() often stores a '%s' to passed memory buffer.  The sqlerrm field
of the sqlca structure has, in every case I can think of, contained
the proper value for the %s.  Informix documentation says reserved for future
use.

It's useful, but use at your own confidence.

Eric

chris@vision.uucp (Chris Davies) (03/18/91)

In article <1991Mar13.171305.16997@vision.uucp> I wrote,
>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 an undocumented (in v2.xx) Informix library call which will do
exactly what I want:
    rgetmsg( code, buf, buffer_length )
    long    code;
    char    *buffer;
    int     buffer_length;

which returns a format string in 'buf[0..buffer_length]' corresponding to the
error number given by 'code'.

Some format strings require a parameter (such as the table name) and this
can be obtained from sqlca.sqlerrm.

Thus
	char	errtxt[256];
	char	emessage[256];

	rgetmsg(sqlca.sqlcode, errtxt, sizeof(errtxt));
	sprintf(emessage, errtxt, sqlca.sqlerrm);

	printf("Error %ld: %s\n", sqlca.sqlcode, emessage);

Thanks to all who pointed this out.  If only Informix had documented this in
version 2...

Chris
-- 
VISIONWARE LTD         | UK: chris@vision.uucp    JANET: chris%vision.uucp@ukc
57 Cardigan Lane       | US: chris@vware.mn.org   BANGNET: ...!ukc!vision!chris
LEEDS LS4 2LE, England | VOICE:  +44 532 788858   FAX:  +44 532 304676
-------------- "VisionWare:   The home of DOS/UNIX/X integration" -------------