Re: Problems with ESQL/C function rgetmsg
Posted in 1996
>From: tim@windy.ftc.nrcs.usda.gov (Tim Maloney) >Date: 17 Jan 1996 23:43:36 GMT >X-Informix-List-Id: <news.20349> > >I have several questions concerning the ESQL/C function rgetmsg. I am using >UNIX System V, Release 4.2, UnixWare version 1.1.2 on a 386, and I am using >version 5.02.UC6 of Informix-SE and Informix ESQL/C. > >For several "error message numbers" between -200 and -999, rgetmsg returns >strings that contain a "%s". For an "error message number" of -533, rgetmsg >returns a string with a "%d". A coworker of mine discovered that for a -217 >error, the value that would belong in the "%s" was in "sqlca.sqlerrm". (By >the way, in "sqlca.h" the comment "/* error message parameters */" is next to >sqlerrm.) The following are some questions about these messages with "%s" or >"%d". > Is rgetmsg working correctly when, in some cases, rgetmsg returns a string > that can be used as an sprintf format string with a conversion > specification such as "%s" or "%d"? Yes, that is the intention. > Will the argument that should replace the "%s" or "%d" always be in > "sqlca.sqlerrm"? For a single %s, yes. The source for '%d' is indeterminate -- it varies. In the case of error -533, it should be a hard-wired constant of some sort. DB-Access seems to manage to handle this; my own code does not. > What is in "sqlca.sqlerrm" when no "%s" or "%d" is in the rgetmsg message > string? It doesn't matter -- and the answer is generally nothing. > When the rgetmsg message string contains a "%d", is the number stored in > "sqlca.sqlerrm" as a string or as an int? The output of rgetmsg() is generally intended to be the format specified for a call to printf(), sprintf() or fprintf(). Therefore, when a %d is specified, you need to provide printf() with an int (not long). However, it is far from clear to me that the value that goes in %d is stored anywhere useful. > Can an rgetmsg message string have more than one conversion specification, > and if so, how are the arguments separated in "sqlca.sqlerrm"? Yes. However, such messages should not be returned to you. One case in point is the incompatible p-code version message (I forget the number). It takes two %d formats. > Does any value in the sqlca structure indicate whether or not an rgetmsg > message string contains a conversion specification? No. >When 100 (SQLNOTFOUND) is the error message number passed into rgetmsg, the > message for -100 is returned. For 1 <= error_message_number <= 199, the > error message for -error_message_number is returned. Is this an rgetmsg > problem, or something else? Something else. SQLNOTFOUND is not an error indication, and therefore should not be processed by by rgetmsg(). Errors are negative. >Is it correct that, when using ESQL/C, if the error message number passed into > rgetmsg is only either (1) sqlca.sqlcode or (2) sqlca.sqlerrd[1] when > sqlca.sqlcode != 0, and is cast as a short, that rgetmsg will only be called > with an error message number in the range (-999) - 100? No. It is trivial to get error numbers in the -25000 range if your machine is not correctly set up for network operations and you try to access a network connection. And date conversion errors are in the -1200 range. And one of the errors from rgetmsg() is -1232, and the text for that should be retrievable using rgetmsg(). >Is it correct that when sqlca.sqlcode != 0, and no ISAM error occurred, that > "sqlca.sqlerrd[1]" is always 0? Yes. >The description of rgetmsg mentions the function rgetlmsg. Is rgetlmsg the > same as rgetmsg, except for msgnum being of type long instead of short? More or less. It also has an extra output parameter, an int pointer, which returns the actual length of the error message. It is set even if an error is returned indicating that the message was truncated. The 7.10 ESQL/C manual gives the function spec (except it doesn't use a prototype): int rgetlmsg(long msgnum, char *msgstr, int lenmsgstr, int *msglen) >Is rgetlmsg available? Yes, though in some versions it is rget_lmsg(). >Would it ever be appropriate to use rgetlmsg in an ESQL/C program? Yes! Use rgetlmsg() unless it is not available; then try rget_lmsg(); only then fall back on rgetmsg(). Note that in 6.00 and above (maybe even 5.00 and above), the error message files can use error numbers outside the range +/- 32767 which can fail with rgetmsg() in 16-bit environments. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>