Versions: 6.7, 6.8 and 2003
This tech tip will show a quick method to compare blobs. As a developer, you may want to track any changes that occur to records. Being able to compare blobs will provide a developer the means to track the slightest modification.
Let's begin with the most obvious change. If the sizes are different then you know there has been a modification. However, two blobs with the same size may contain different values. To detect this, you will need to compare each byte of the blob against the other. Here is a simple project method to compare two blobs:
`Method Name: compareBlob
`Description: This method will compare the content of two blobs
`Parameter:
` $1 = Blob; $2 = Blob
`Return Value:
` $0: True if equal, otherwise false
C_BLOB($1;$2)
C_BOOLEAN($0)
If (BLOB size($1)=BLOB size($2))
For ($vByte;0;BLOB size($1)-1)
If ($1{$vByte}#$2{$vByte})
$0:=False
$vByte:=BLOB size Else
$0:=True
$vByte:=BLOB size($1)
End if
End for
Else
$0:=False
End if
Method Call Example:
TEXT TO BLOB("hello world";vBlob1;3)
TEXT TO BLOB("hello World";vBlob2;3)
$var:=compareBlob (vBlob1;vBlob2)
In this example, I am using just a text comparison. This example method will create two BLOBs and pass them into the compareBlob method and return a Boolean. You will notice that the text is "hello world" in both cases, so the total blob size will be the same. But the second blob has a capitalized W, which will return false.