sqlite .AsDateTime error cannot access field as type DateTime

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
irwanto
Posts: 5
Joined: Fri 09 Jan 2015 17:27

sqlite .AsDateTime error cannot access field as type DateTime

Post by irwanto » Thu 11 Jun 2015 07:21

hi help me,


when i use .AsDateTime get error "cannot access field as type DateTime"
here my code :

Code: Select all

 FConnection_SQLITE.Database := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + 'smart_sfa.db3';
  FConnection_SQLITE.Connect;

  FQueryUniv.Close;
  FQueryUniv.SQL.Text := 'select max(tgl) as tgl, nm_hari from tblclosing left outer join tblhari on (strftime(''%w'', tblclosing.tgl)+1 = tblhari.kd_hari)';
  FQueryUniv.Open;

  if FQueryUniv.RecordCount <= 0 then
  begin
    raise Exception.Create('Tanggal transaksi di table closing kosong');
  end;

  ShowMessage(FQueryUniv.FieldByName('tgl').AsString);
  ShowMessage(DateToStr(FQueryUniv.FieldByName('tgl').AsDateTime)); /// <======== error here
SQLITE Direct Mode

Delphi XE5
UNIDAC 6.1.3
Windows 8.1

file test
http://www.filedropper.com/zzzz

Image

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: sqlite .AsDateTime error cannot access field as type DateTime

Post by AlexP » Thu 11 Jun 2015 07:51

Hello,

If you are using concatenation, aggregating functions (MAX, AVG, ...), etc., SQLite returns the Unknown type for such fields. For correct data display, you should use DataTypeMapping https://www.devart.com/unidac/docs/#dat ... apping.htm .

irwanto
Posts: 5
Joined: Fri 09 Jan 2015 17:27

Re: sqlite .AsDateTime error cannot access field as type DateTime

Post by irwanto » Thu 11 Jun 2015 08:26

thanks,,
working...

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: sqlite .AsDateTime error cannot access field as type DateTime

Post by AlexP » Thu 11 Jun 2015 08:59

Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.

Post Reply