Re: dynamic referencing of fields in a record
Posted in 1996
I've done that sort of thing, in pretty much the way you did. It was more complex -- I had to worry about nulls. The code fragment below doesn't take note when rec1.a is null and rec2.a is not, or vice versa, but it probably should! A couple of years ago, Scott Ellard (cse@wetware.com) posted an I4GL record comparison routine, coded in C. It works as long as the two records passed do in fact have the same number of elements; it would get badly confused if recordA had 2 elements and recordB had 4, because it would compare recordB.field1 with recordB.field4 but they would not, in general, be the same type, let alone the same value! But, within the constraints of I4GL, it is as good as you can do. It should be kicking around in the news archives; the X-Informix-List-Id was <news.7255> and it was dated 17th June 1994 -- I have a copy which I can repost if absolutely necessary. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> PS: Actually, I was dealing with large records (72 elements), so I ended up writing a shell script which automatically wrote the record comparison code, and I bundled it into a source file which could be run through the shell to update itself or run through the I4GL compiler to generate an object file! }From: dennisl@acay.com.au }Date: Fri, 01 Nov 1996 18:46:53 GMT }X-Informix-List-Id: <news.30011> } }just a passing thought ... } }if I have 2 records of the same table, how do I compare the fields }within the records, without having to explicitly name the fields? }(i.e. only fields with different values are of interest to me) } }at the moment, I compare each field with an if statement, i.e. } } IF rec1.a <> rec2.a THEN } -- take note } END IF } IF rec1.b <> rec2.b THEN } -- take note } END IF } ... } IF rec1.z <> rec2.z THEN } -- take note } END IF } }anybody ever had to do a similar thing, and wondered if there }was a better way of doing this?