I am trying to query a database using FireDac. Here is my code;
procedure TfSMSViewer.LoadSMSFromDatabase(path: AnsiString);
var
con: TFDConnection;
query: TFDQuery;
LI: TListItem;
B: Int64;
begin
con := TFDConnection.Create(nil);
query := TFDQuery.Create(con);
con.LoginPrompt := False;
con.Open('DriverID=SQLite;Database=' + Path +' ;');
query.Connection := con;
query.SQL.Text := 'SELECT * FROM sms';
query.Open;
query.First;
While Not Query.EOF Do
Begin
LI := ListView1.Items.Add;
LI.Caption := inttostr(query.Fields[4].AsLargeInt); //This line
if query.FieldValues['type'] = 1 then
LI.SubItems.Add('Incoming')
else
LI.SubItems.Add('Outbound');
LI.SubItems.Add(query.FieldValues['address']);
LI.SubItems.Add(query.FieldValues['body']);
Query.Next;
End;
end;
However the line highlighted doesn't work correctly. In the database, an example value set in this column is 1418421520957 (a UNIX timestamp).
When that line of code is executed, the result is 1082313277.
The data type in the SQLite database is set to Integer. The freeware software I'm using to debug this shows the correct value. When debugging my code, the incorrect value is pulled from the database before any assignment is made.
Also some of the values populated in my TListView
are negated.
Does TFDQuery
not support large integers? How can I fix this?
Thanks
This is how I fixed it, with suggestions from TLama. Maybe this will be useful for someone, or my future self.
con := TFDConnection.Create(nil);
query := TFDQuery.Create(con);
with query.FormatOptions do begin
OwnMapRules := True;
with MapRules.Add do begin
SourceDataType := dtInt32;
TargetDataType := dtInt64;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With