Variant trouble

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
erikfandersen
Posts: 9
Joined: Tue 26 Sep 2006 12:17

Variant trouble

Post by erikfandersen » Tue 03 Oct 2006 07:47

Hello!

I have code that depends heavily on reading and writing database fields as variants. It appears that ODAC lacks some support in this area and I'm now trying to work around this.

Take for instance the TOraTimeStampField class. It is only possible to read the value as a variant. There is no functionality to write the value as a variant. There is however a function to write the value as a string so I think this is just a omission that one cannot write the value as a variant as well.

I have worked around this problem by defining my own descendant on TOraTimeStampField that implements the function SetVarValue. I have also written my own descendant of TSmartQuery that overrides the function GetFieldClass.

My question is if my changes are "safe". That is will it break other functionality in ODAC?

My changes are:

function TMySmartQuery.GetFieldClass(FieldType: TFieldType): TFieldClass;
begin
result := inherited GetFieldClass(FieldType);
if (result = TOraTimeStampField) then
result := TMyOraTimeStampField;
end;

procedure TMyOraTimeStampField.SetVarValue(const Value: Variant);
begin
case VarType(Value) of
varString{$IFNDEF CLR},varOleStr{$ENDIF}{$IFDEF CLR}, varChar{$ENDIF}:
AsString := Value;
varDate:
AsDateTime := Value;
else
raise EConvertError.Create(SCannotConvertType);
end;
end;

Regards,
Erik

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 04 Oct 2006 09:15

The changes you have made are correct. We will add feature of setting TOraTimeStampField and TOraIntervalField as variant in the next build of ODAC.

Post Reply