Page 1 of 1

Comparing Oracle Objects

Posted: Wed 17 Dec 2014 15:44
by m.ghilardi
Is there a general way to Compare the contents of two TOraObjects?

Here is what I do now

Code: Select all

bool isObjectEqual(TOraObject* obj1, TOraObject* obj2)
{
	bool isEqual = obj1->ObjectType->Name.Compare(obj2->ObjectType->Name) == 0;
	isEqual = isEqual && (obj1->IsNull == obj2->IsNull);
	if (isEqual && !obj1->IsNull)
	{
		if (obj1->ObjectType->Name.CompareIC(L"mytype")==0)
		{
			isEqual = isEqual && (obj1->AttrAsLargeInt[L"attr1"] == obj2->AttrAsLargeInt[L"attr1"]);
			isEqual = isEqual && (obj1->AttrAsString[L"attr2"] == obj2->AttrAsString[L"attr2"]);
		}
		else
		{
			//throw exception obj1->ObjectType->Name not supported
		}
	}
	return isEqual;
}
Basically, for each object type i have to write another "else if" segment, it is a pain!
The Attribute list is not accessible, and there is no AttrAsVariant function, so I have to explicitly list all the attributes with the correct attribute type.

Re: Comparing Oracle Objects

Posted: Thu 18 Dec 2014 09:12
by AlexP
Hello,

Since objects can have a rather complicated structure, nesting, descend from other objects, etc., then it is quite difficult to create a "universal" object comparison method. Therefore you will have to use different comparison algorithms for different objects.
For access to an attribute by index, you can use AttributeCount methods and the Attributes indexer.

Code: Select all

for i := 0 to OraObject.ObjectType.AttributeCount - 1 do begin
  OraObject.ObjectType.Attributes[i]. .....
....
end;

Re: Comparing Oracle Objects

Posted: Thu 08 Jan 2015 08:39
by m.ghilardi
Hello AlexP,

I agree, writing such a method would be quite difficult.

ObjectType->Attributes returns a TAttribute*, which is the definition of the Attribute (not the instance I need) so I have to extract the Name from it, the type, and then call the correct method on the OraObject.
So it would be something like this (pseudo code)

Code: Select all

for i:=0 to AttributeCount-1 
  name := obj.ObjectType.Attributes[i].Name;
  type := obj.ObjectType.Attributes[i].DataType;
  
  switch (type)
  case string: obj.AttrAsString(name)...
  case largeint: obj.AttrAsLargeInt(name)
  case object: //recursion?
  case integer://...and so on
What I dream of is instead

Code: Select all

for i:=0 to AttributeCount-1 do begin
  if not(obj1.Attributes[i].isObject) then
    result:= obj1.Attributes[i].Value = obj2.Attributes[i].Value
  else
    result:= isObjectEqual(obj1.Attributes[i].AsObject,obj2.Attributes[i].AsObject);
end;

Re: Comparing Oracle Objects

Posted: Mon 12 Jan 2015 09:18
by AlexP
As I wrote you earlier, implementation of such comparison is difficult. Therefore you can use any implementation suiting your purposes.