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