Compare Blob data type!

praneesh

New Member
Hi There,

Please help me!!
I need to compare two objects which are blob data type.

eg: defined two temp-tables such as

define temp-table tt-table1 no-undo
field tt-bfield1 as blob.

define temp-table tt-table2 no-undo
field tt-bfield2 as blob.

copied some images to these two tables using copy-lob.
now i need to execute some code only if there any difference between these two fields.

ie,
for each tt-table1:
find first tt-table2.
if tt-bfield1 <> tt-bfield2 then
message "Here it goes" view-as alert-box.
end.

this statement is success only if the image loaded into both the table are different.

I have loaded same image with some changes, say content is changed slightly in one.
In this case the code is failing. So please suggest me how to compare the blob objects?
I can not use memptr and compare each byte because the image size may be 512 kb.

Thanks in advance,
Praneesh
 

bulklodd

Member
I'm not sure but how about that

Code:
DEFINE VARIABLE c1 AS LONGCHAR  NO-UNDO.
DEFINE VARIABLE c2 AS LONGCHAR  NO-UNDO.
 
COPY-LOB FROM tt-bfield1  TO c1.
COPY-LOB FROM tt-bfield2  TO c2.
 
if с1 <> с2 then
message "Here it goes" view-as alert-box.
   VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "DEBUG".
 

bulklodd

Member
... but I'm sure the following snippet will work

Code:
[LEFT]DEFINE VARIABLE c1 AS MEMPTR NO-UNDO.
DEFINE VARIABLE c2 AS MEMPTR  NO-UNDO.[/LEFT]
 
[LEFT]COPY-LOB FROM tt-bfield1  TO c1.
COPY-LOB FROM tt-bfield2  TO c2.[/LEFT]
 
[LEFT]if NOT MemptrEQ(c1,c2) then
message "Here it goes" view-as alert-box.
 VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "DEBUG".[/LEFT]
 
[LEFT]FUNCTION MemptrEQ RETURNS LOGICAL (c1 AS MEMPTR,
                                   c2 AS MEMPTR):
   DEFINE VARIABLE i AS INTEGER    NO-UNDO.
   IF GET-SIZE(c1) <> GET-SIZE(c2) THEN
      RETURN NO.
   DO i = 1 TO GET-SIZE(c1):
      IF GET-BYTE(c1,i) <> GET-BYTE(c2,i)THEN 
         RETURN NO.
   END.
   RETURN YES.
END FUNCTION.
[/LEFT]
 

praneesh

New Member
Hi bulklodd,

Thanks.
I've done somthing like this using get-string(memptr,i). But it was taking long time to execute because my image size may varry from 1 kb to 1000kb. I am afraid that the code you are mentioned is something like this. So please suggest me any other way without checking each byte?
 

bulklodd

Member
What's wrong with my code in the post #2? if the code works it'll be one of the best ways. however, any way of comparison includes full data scan.
You can try to calculate something like CRC but you need to do full scan anyway.
 

praneesh

New Member
Hi,
I am sorry. No problem in the code which you are suggested. But my problem is some thing like this,

Image size is 692 KB (708,608 bytes).
So my repeat loop will execute 708,608 times, if no difference found. The system we are working is littile slow and this code takes 4-6 minutes to complete. So I was looking for some simple statement to replace this.

Thanks,
Praneesh
 

bulklodd

Member
Hi,
I am sorry. No problem in the code which you are suggested. But my problem is some thing like this,

Image size is 692 KB (708,608 bytes).
So my repeat loop will execute 708,608 times, if no difference found. The system we are working is littile slow and this code takes 4-6 minutes to complete. So I was looking for some simple statement to replace this.

Thanks,
Praneesh

:) Ok, i can repeat, my first snippet was

Code:
[LEFT]DEFINE VARIABLE c1 AS LONGCHAR  NO-UNDO.
DEFINE VARIABLE c2 AS LONGCHAR  NO-UNDO.[/LEFT]
 
[LEFT]COPY-LOB FROM tt-bfield1  TO c1.
COPY-LOB FROM tt-bfield2  TO c2.[/LEFT]
 
[LEFT]if с1 <> с2 then
message "Here it goes" view-as alert-box.
  VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "DEBUG".[/LEFT]

There's no loops here as you can see for progress itself compares LOBs. but i'm not sure it will work okay. I think if that code works it'll be the best way.
 

doreynie

Member
Hi there,

Why not output to blob-data to temporary-files, to disk, and then run a os-file-compare on the two files. For example : fc in dos. You can use a binary compare option there which is very fast.

Then get the output of the command you execute and you will know if the files you are comparing are the same or not.
 

abl

New Member
This thread shows why you normally need to go to PEG.COM to get real answers.

Look at the buffer-compare method, set your mode to binary. no except-list, set the pairs list to "tt-bfield1,tt-bfield2" (and next time name the fields woth the same name and use table.field syntax -- this is a best practice so start following it), set no-lobs to true (which is the default, so you really don't need it).

Six days; if you had posted to PEG you probably would have gotten a good answer in six minutes.


Hi There,

Please help me!!
I need to compare two objects which are blob data type.

eg: defined two temp-tables such as

define temp-table tt-table1 no-undo
field tt-bfield1 as blob.

define temp-table tt-table2 no-undo
field tt-bfield2 as blob.

copied some images to these two tables using copy-lob.
now i need to execute some code only if there any difference between these two fields.

ie,
for each tt-table1:
find first tt-table2.
if tt-bfield1 <> tt-bfield2 then
message "Here it goes" view-as alert-box.
end.

this statement is success only if the image loaded into both the table are different.

I have loaded same image with some changes, say content is changed slightly in one.
In this case the code is failing. So please suggest me how to compare the blob objects?
I can not use memptr and compare each byte because the image size may be 512 kb.

Thanks in advance,
Praneesh
 

praneesh

New Member
Hi,

I've done it using buffer-compare. Adding the code snippet.

define temp-table tt1 no-undo
field f1 as character
field bfield as blob.

define temp-table tt2 no-undo
field f2 as character
field bfield as blob.

define variable s1 as character no-undo init "0123456789".
define variable s2 as character no-undo init "0123446789".

define variable mp as memptr no-undo.

define variable bh1 as handle no-undo.
define variable bh2 as handle no-undo.

assign
bh1 = temp-table tt1:default-buffer-handle
bh2 = temp-table tt2:default-buffer-handle
.

assign
set-size ( mp ) = 0
set-size ( mp ) = length ( s1, "raw" )
put-string ( mp, 1, get-size ( mp ) ) = s1
.
create tt1.
copy-lob from mp to tt1.bfield.

assign
set-size ( mp ) = 0
set-size ( mp ) = length ( s2, "raw" )
put-string ( mp, 1, get-size ( mp ) ) = s2
.

create tt2.
copy-lob from mp to tt2.bfield.


if tt1.bfield <> tt2.bfield then do:
message "the fields are different" view-as alert-box.
end.

if bh1:buffer-compare ( bh2, "binary", "f1,f2", "bfield,bfield", false )
eq false then do:
message "buffer compare say's the fields are different"

view-as alert-box.
end.


if temp-table tt1:default-buffer-handle:buffer-compare (
temp-table tt2:default-buffer-handle , "binary", "f1,f2" )
eq false then do:
message "notice this doesn't work though it should"

view-as alert-box.
end.


message "we're done" view-as alert-box.
 

Casper

ProgressTalk.com Moderator
Staff member
Well ok, I think and know you are right, but nevertheless there seems to be some competition going on which I don't understand and which I know you absolutely don't need. But ok, I must admit I had a real crappy day so had to say it.

Every questions which needs to be answered fast and is urgent, should be posted @peg (as well). And most times people are advised to do so.

Peg is proven to be a more active expert forum then this one. Nevertheless I like this forum. Here I got a chance to answer a question before someone else did it :) furthermore I like the forum style (webbased) and the search capabilty's which you probably have to admit as well are far more superior then the serach capabilities @ PEG.
I hope with the anounced improvements @peg this will change.

This is a much more laid back (and perhaps friendly forum) then the peg is. It took quite some time for me to dare ask a question @peg, but that probably has to do with my nature as well :D

But I'm way crossing my line know, who am I to argue with you. PEG has learned me so many things that I shouldn't complain or interphere with any of these things.

Regards,

Casper.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
i dont think its such a big deal, but i for one think it should have been said.

thats one of the great things about this place, you can say whatever you
want and you know what things have a way of settling themselves.

i can appreciate the added stakes when money is involved but i doubt
anything can shake pegs position, at least for a long while.

though its not the center of the world like most peggers think.

as for the site, i think, progresstalk is the perfect example of how a forum
should be and Casper is one of the guys who made what it is today.

btw i'm always having a bad day.
 
Top