Re: Checksum on row

From: Michel Cadot <micadot_at_netcourrier.com>
Date: Mon, 25 Oct 1999 15:04:43 +0200
Message-ID: <7v1kk2$ojt$1_at_oceanite.cybercable.fr>


You can add a trigger on insert and update to calculate your checksum:

create or replace trigger tr_ud before insert or update on <table> for each row
declare

   chksum number;
begin

   /* calculate the checksum using :NEW.col1, :NEW.col2, :NEW.col3, ... */    chksum := <my function> (:NEW.col1, :NEW.col2, ...);    /* set the checksum column of the inserted or updated row */    :NEW.checksumcol := chksum;
end;
/

When you add or update a row, the checksum is then calculated and the checksum column is set.

To check the row on the select statement, you have to create a function to verify the checksum, something like that:

create or replace function check_t (id rowid) return number is

   /* return 1 if checksum OK, 0 otherwise */    row <table>%rowtype;
   chksum number;
begin

   select * into row from <table> where rowid=id;    /* calculate chksum using row.col1, row.col2, ... */    chksum := <my function> (row.col1, row.col2, ...);    if ( chksum = row.checksumcol ) then

      return 1;
   else

      return 0;
   end if;
end;
/

and then

select * from <table> where ... and check_t(rowid) = 1;

--
Have a nice day
Michel


Remco Moolenaar <remco_at_scc.nl> a écrit dans le message :
381442E8.56A83152_at_scc.nl...

> Good afternoon,
>
> I want to do the following on rows of a table:
> - When a row is added calculate some sort of checksum (MD5?) of the
> contents of the row.
> - Save this value in a dedicated column of the same row.
> - Use this checksum to calculate the correctness of the row (including
> detail rows).
>
> How do I do this using standard methods. This is for a international
> project, so I need standard tools (like MD5).
>
> Thanks in advance,
>
> Remco Moolenaar
>
> --
> Remco Moolenaar mailto:remco_at_scc.nl
> SCC Internetworking & Databases http://www.scc.nl/
> Amsterdam, The Netherlands mailto:remco_at_bsdapps.org
>
> Maintainer of the BSD Applications database at http://www.bsdapps.org/
>
>
Received on Mon Oct 25 1999 - 15:04:43 CEST

Original text of this message