Re: Comparing RECORD's
Posted in 1994
: >From: root@candle.pha.pa.us (Bruce Momjian)
: >Subject: Comparing RECORD's
: >Date: Tue, 14 Jun 1994 04:05:20 GMT
: >X-Informix-List-Id: <news.7206>
: >
: >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?
Another way to compare is to use a temp table and let the engine do the work.
This may or may not suit your application, and it is optimized for ease of
implementation, not use of system resources.
At the start of your program:
If your input array matches a table row in your database then you can create an
empty table with the code --
select * from tablea where rowid=0 into temp junkYou can check the sqlca.sqlerrd record to make sure there are no records, and
delete them if there are, but this should work since rowid is not supposed to
be 0.
If your input array does not match a table row, use the code that defined
your input array to create a temp table with rows that look like the
rows in your array.
Before row:
insert into junk values (input_row[screen_pos].*)
After row:
insert into junk values (input_row[screen_pos].*)
select distinct * from junk into temp morejunk
if (sqlca.sqlerrd[3] > 1) then
# after_row is not the same as before_row
# so do what you wanted to do when the row is changed
end if
delete from junk where 1=1
drop table morejunk
Remember to drop the junk table when the program is done.
Once we encountered a bug that had to do with multiple drop and creates of
the same temp table name in one program session. We haven't had any
problems in awhile since an upgrade, but if you choose this method you might
want to try the after row stuff ten or twelve times in a row (so to speak)
to see if the bug doesn't bite.