cxflag203 / superobject

Automatically exported from code.google.com/p/superobject
0 stars 0 forks source link

Convert SQLTimestamp datafield value to SO is fail with "Unsupported variant data type" (XE5) #54

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Open a FireDAC query, which has an SQLTimeStamp field
2. Try to convert datafield value to SO, as 'SO(qry.Fields[x].Value)'
3. "Unsuported variant data type" exception will be raised

What is the expected output? What do you see instead?
The excepted result is, an SO object with DateTime value represented in 
datafield. The given result is the exception above.

What version of the product are you using? On what operating system?
Latest source from SVN. Windows8 / Delphi XE5.

Please provide any additional information below.
I made a fix, and post the critical code below.
(I also corrected a typo in the exception text 'suported' -> 'supported')
The affected unit is 'superobject.pas', the affected function is 'SO'.
The modified version of the function (see the modifications / comments at the 
end of the function):

function SO(const value: Variant): ISuperObject; overload;
begin
  with TVarData(value) do
  case VType of
    varNull:     Result := nil;
    varEmpty:    Result := nil;
    varSmallInt: Result := TSuperObject.Create(VSmallInt);
    varInteger:  Result := TSuperObject.Create(VInteger);
    varSingle:   Result := TSuperObject.Create(VSingle);
    varDouble:   Result := TSuperObject.Create(VDouble);
    varCurrency: Result := TSuperObject.CreateCurrency(VCurrency);
    varDate:     Result := TSuperObject.Create(DelphiToJavaDateTime(vDate));
    varOleStr:   Result := TSuperObject.Create(SOString(VOleStr));
    varBoolean:  Result := TSuperObject.Create(VBoolean);
    varShortInt: Result := TSuperObject.Create(VShortInt);
    varByte:     Result := TSuperObject.Create(VByte);
    varWord:     Result := TSuperObject.Create(VWord);
    varLongWord: Result := TSuperObject.Create(VLongWord);
    varInt64:    Result := TSuperObject.Create(VInt64);
    varString:   Result := TSuperObject.Create(SOString(AnsiString(VString)));
{$if declared(varUString)}
  {$IFDEF FPC}
    varUString:  Result := TSuperObject.Create(SOString(UnicodeString(VString)));
  {$ELSE}
    varUString:  Result := TSuperObject.Create(SOString(string(VUString)));
  {$ENDIF}
{$endif}
  else
    // ---- PL modification 2014.03.17 start ----
    // FireDAC gives back SQL TimeStamp data in SQLTimeStamp datafield, 
    // which value as Variant is 'VarSQLTimeStamp' (function call) type.
    // To handle this (SQLTimestamp datafield value -> Superobject)
    // need to modify the code here:
    if( VType = VarSQLTimeStamp ) then
    begin
      Result := 
        TSuperObject.Create(
          DelphiToJavaDateTime(
            SQLTimeStampToDateTime(
              VarToSQLTimeStamp(value))));
    end
    else
    // ---- PL modification 2014.03.17 end ----
      raise Exception.CreateFmt('Unsupported variant data type: %d', [VType]);
  end;
end;

Original issue reported on code.google.com by polyakl...@gmail.com on 18 Mar 2014 at 8:12