Re: Comparing two records in 4gl
Posted in 1995
Srini Sunkaraneni (srini@eccs.com) wrote: : Hi Everybody! : : I am looking for ways to compare two records in 4gl and all : Iam interested is if they are equal or not. : : For eg: : : Say p_stdrec.* != r_stdrec.* : : I know that they can be compared field by field and I do : not want to do that because there are too many fields in the : table to compare. Also even if it can be done using ESQLC : I would like to know. : I had saved this posting. It addresses your question. --------------------------------------------------------------------------- From candle!jabber!dsinc!spool.mu.edu!sdd.hp.com!usc!elroy.jpl.nasa.gov!ames!pacbell.com!UB.com!wetware!cse Fri Jun 17 22:21:59 1994 Newsgroups: comp.databases.informix Path: candle!jabber!dsinc!spool.mu.edu!sdd.hp.com!usc!elroy.jpl.nasa.gov!ames!pacbell.com!UB.com!wetware!cse From: cse@wetware.com (Scott Ellard) Subject: Re: Comparing RECORD's Message-ID: <CrK9s4.Koq@wetware.com> Sender: news@wetware.com (Usenet News Account) Nntp-Posting-Host: wetware.wetware.com Organization: /usr/local/lib/rn/organization References: <CrDCow.E4D@candle.pha.pa.us> <CrJK72.CAy@wetware.com> Date: Fri, 17 Jun 1994 21:45:40 GMT Lines: 110 Status: OR In article <CrJK72.CAy@wetware.com> cse@wetware.com (Scott Ellard) writes: >In article <CrDCow.E4D@candle.pha.pa.us> root@candle.pha.pa.us (Bruce Momjian) writes: >>If I have two structures with idenical fields, is there an easy way to >>see if the values in each of the fields is the same, without comparing >>each and every field (with NULL checks too)? >> >>I need this because I am using a INPUT ARRAY statement, but want to >>record the date each row changes. I am going to store the record in a >>BEFORE ROW statement, and compare in an AFTER ROW statement. >> >>Is there a better way to do this? >>Bruce Momjian | 830 Blythe Avenue >>root@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026 >> + If your life is a hard drive, | (610) 353-9879(w) >> + Christ can be your backup. | (610) 853-3000(h) > >I wondered what a 4GL record comparison function might look like >using only published interfaces. Here is one possibility I put >together very quickly. (so be gentle :) >Scott (Rom10:9) It's funny how the light of a new day affects your perspective. Please forgive the wasted bandwidth from my previous post. Here is a revised version of the code I posted last night. Scott /*------------------------------------------------------------------------------ * * FUNCTION: fgl_reccmp.c * * AUTHOR: C. S. Ellard * * PURPOSE: compare two 4gl records for equality. * * USAGE: LET N = fgl_reccmp(rec1.*, rec2.*) * * N == 0, records compare equal * N != 0, records compare not equal at field number N * NOTES: * * 1. Nulls compare equal. * 2. Trailing spaces are not significant. * 3. Assumes Ifmx string conversions create equal strings for numerics. * 4. BLOBS aren't handled. * *------------------------------------------------------------------------------ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXARGSIZE (512) /* adjust to largest string expected */ int fgl_reccmp(nargs) int nargs; { char* *argvec; int i; if ((nargs <= 0) || ((nargs % 2) != 0)) { (void) fprintf(stderr, "fgl_reccmp: EINVAL = %d\\n", nargs); exit(1); } if ((argvec = (char**) malloc(nargs * sizeof(char**))) == 0) { (void) fprintf(stderr, "fgl_reccmp: ENOMEM\\n"); exit(1); } for (i = nargs-1; i >= 0; --i) { char buff[MAXARGSIZE+1]; /* +1 for the NULL */ char *p; popquote(buff, sizeof(buff)); if (*buff == 0) { argvec[i] = ""; continue; } /* trim trailing spaces */ for (p = buff + (sizeof(buff)-2); p >= buff && *p == ' '; --p) ; *(p+1) = 0; if ((argvec[i] = strdup(buff)) == 0) { (void) fprintf(stderr, "fgl_reccmp: ENOMEM\\n"); exit(1); } } for (nargs /= 2, i = 0; i < nargs; ++i) { if (strcmp(argvec[i], argvec[i+nargs]) != 0) break; } retint((i == nargs) ? 0 : ++i); /* adjust from origin 0 to origin 1 */ for (nargs *= 2, i = 0; i < nargs; ++i) { if (*argvec[i] != 0) free(argvec[i]); } free((char*)argvec); return(1); } -- Bruce Momjian | 830 Blythe Avenue root@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026 + If your life is a hard drive, | (610) 353-9879(w) + Christ can be your backup. | (610) 853-3000(h)