Re: rgetmsg
Posted in 1998
On Tue, 20 Oct 1998, John H. Frantz wrote:
> finderr 100 shows me the duplicate value message.
> finderr -100 also shows me this.
Unless you put an explicit + in front of the number, finderr interprets
numbers as error numbers, and hence as negative.
> finderr +100 shows me a no matching record message (i.e. not found).
It could, equivalently, have shown the duplicate value message.
C-ISAM can return iserrno = +100 for the duplicate value error.
Note that finderr simply (well, not all that simply) greps through a
text file to produce the text of an error message. By contrast, rgetmsg()
goes to the actual iem-file for the raw message.
> Apparently finderr assumes a negative value unless otherwise specified.
Yes.
> I'm not sure about rgetmsg() but if it accepts the message number as an
> integer then it may always assume a negative number, dealing only with
> messages categorized as errors.
No! rgetmsg() interprets the number you supply as the number you supply.
Internally, Informix code uses positive numbers for messages (including
things like menu options), and negative numbers for errors.
> Art S. Kagel wrote:
> > Henry A.L. Wollman wrote:
> > > How come rgetmsg returns the wrong description for an error code 100? It
> > > should be "not found" but instead returns something about a duplicate
> > > value on insert or update of a unique key.
> > >
> > > Are there other error codes for which rgetmsg returns the wrong
> > > description? It seems that even the manual as far back as several years
> > > ago has the wrong message for a 100. Aren't these things ever fixed? Is
> > > rgetmsg not a reliable function? Must I write my own?
> >
> > There is nothing to fix since nothing is broken!
> >
> > Rgetmsg does not return the wrong message. SQLNOTFOUND, or 100 is NOT
> > an error, however, there IS an ISAM error -100 which is described as:
> >
> > -100 ISAM error: duplicate value for a record with a unique key.
> >
> > It is a convenience that finderr and rgetmsg return the message whether
> > you enter the message number as positive or negative, but remember that
> > ALL error message numbers are negative! SQLNOTFOUND is an INDICATOR
> > that there is no more data to fetch NOT and error caused by fetching
> > beyond the end of the select set.
I threatened to send a chkmsg() program to c.d.i; I'm now carrying out that
threat. I'm not all that keen on the way it uses getopt(), but it more or
less works. To compile:
esql -o chkmsg chkmsg.ec range2.c stderr.c
To use:
chkmsg 100
chkmsg +100
chkmsg -100
chkmsg -100:+100
chkmsg -100..+100
This is a direct interface to rgetmsg(), so you can see what messages are
really in the message files. You might care to note that both +100 and
-100 produce the same message text:
-100: ISAM error: duplicate value for a record with unique key.
100: ISAM error: duplicate value for a record with unique key.
Yours,
Jonathan Leffler (jleffler@informix.com) #include <witticism.h>
Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN
Informix IDN for D4GL & Linux -- http://www.informix.com/idn
PS: I think this might be useful in the IIUG software archives.
: "@(#): shar.sh,v 2.1 1998/06/02 17:13:43 jleffler Exp $"
#! /bin/sh
#
# This is a shell archive.
# Remove everything above this line and run sh on the resulting file.
# If this archive is complete, you will see this message at the end:
# "All files extracted"
#
# Created on: Tue Oct 20 09:20:00 PDT 1998
# Created by: jleffler at Informix Software Inc.
#
# Files archived in this archive:
# chkmsg.ec
# getopt.h
# range.h
# range2.c
# stderr.c
# stderr.h
#
#--------------------
if [ -f chkmsg.ec -a "$1" != "-c" ]
then echo shar: chkmsg.ec already exists
else
echo 'x - chkmsg.ec (2190 characters)'
sed -e 's/^X//' >chkmsg.ec <<'SHAR-EOF'
X/*
X@(#)File: $RCSfile: chkmsg.ec,v $
X@(#)Version: $Revision: 1.1 $
X@(#)Last changed: $Date: 1997/03/28 14:28:12 $
X@(#)Purpose: Check specified message numbers
X@(#)Author: J Leffler
X@(#)Copyright: (C) JLSS 1997
X*/
X
X/*TABSTOP=4*/
X
X#define MAIN_PROGRAM
X#include <stdio.h>
X#include <stdlib.h>
X#include "stderr.h"
X#include "getopt.h"
X#include "range.h"
X
X#define NIL(x) ((x)0)
X
X/* -- Declarations */
X
Xstatic const char usestr[] = "[-qV] lo[-hi] ...";
X
X#ifndef lint
Xstatic const char sccs[] = "@(#)$Id: chkmsg.ec,v 1.1 1997/03/28 14:28:12 johnl Exp $";
X#endif
X
Xstatic int chkmsg(char *arg, int qflag)
X{
X int estat = EXIT_SUCCESS;
X long lo;
X long hi;
X char *endp;
X long msg;
X
X endp = numeric_range(arg, &lo, &hi);
X if (endp == arg || *endp != '\\0')
X err_report(ERR_ERR, ERR_STAT,
X "Non-numeric character after range '%s'\\n", arg);
X
X for (msg = lo; msg <= hi; msg++)
X {
X int actlen;
X long err;
X char buffer[BUFSIZ];
X if ((err = rgetlmsg(msg, buffer, sizeof(buffer), &actlen)) != 0)
X {
X err_report(ERR_REM, ERR_STAT,
X "cannot locate message %ld -- error %ld\\n", msg, err);
X estat = EXIT_FAILURE;
X }
X else if (qflag == 0)
X {
X printf("%ld: %s", msg, buffer);
X if (actlen >= sizeof(buffer))
X putchar('\\n');
X }
X }
X return(estat);
X}
X
Xint main(int argc, char **argv)
X{
X int i;
X int opt;
X int nstat;
X int estat = EXIT_SUCCESS;
X int qflag = 0;
X int nflag = 0;
X
X setarg0(argv[0]);
X
X while ((opt = getopt(argc, argv, "qV0:1:2:3:4:5:6:7:8:9:")) != EOF)
X {
X switch (opt)
X {
X case 'q':
X qflag = 1;
X break;
X case 'V':
X version("CHKMSG", "$Revision: 1.1 $ ($Date: 1997/03/28 14:28:12 $)");
X break;
X
X case '0':
X case '1':
X case '2':
X case '3':
X case '4':
X case '5':
X case '6':
X case '7':
X case '8':
X case '9':
X /* GETOPT() is probably not the right tool for this job! */
X nstat = chkmsg(optarg-2, qflag);
X if (estat == EXIT_SUCCESS)
X estat = nstat;
X nflag = 1;
X break;
X
X default:
X usage(usestr);
X break;
X }
X }
X
X if (optind >= argc && nflag == 0)
X usage(usestr);
X
X for (i = optind; i < argc; i++)
X {
X nstat = chkmsg(argv[i], qflag);
X if (estat == EXIT_SUCCESS)
X estat = nstat;
X }
X
X return(estat);
X}
SHAR-EOF
chmod 444 chkmsg.ec
if [ `wc -c <chkmsg.ec` -ne 2190 ]
then echo shar: chkmsg.ec unpacked with wrong size
fi
# end of overwriting check
fi
#--------------------
if [ -f getopt.h -a "$1" != "-c" ]
then echo shar: getopt.h already exists
else
echo 'x - getopt.h (1772 characters)'
sed -e 's/^X//' >getopt.h <<'SHAR-EOF'
X/*
X@(#)File: $RCSfile: getopt.h,v $
X@(#)Version: $R