[solved] Same sql, different result for SQLite table

The stable tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.
Post Reply
aducom
Zeos Dev Team
Zeos Dev Team
Posts: 67
Joined: 30.08.2005, 13:21

[solved] Same sql, different result for SQLite table

Post by aducom »

I must be seeing things wrong but I have the following two events:

Code: Select all


procedure TFDBView.ToolButton2Click(Sender: TObject);
begin
  ZQ.Close;
  ZQ.Connection := ZT.Connection;
  ZQ.SQL.Text := SQLEdit.Text;
  ZQ.Open;
  DS.Dataset := ZQ;
end;

procedure TFDBView.ToolButton3Click(Sender: TObject);
var vs : string;
begin
  ZQ.Close;
  ZQ.SQL.Text := 'select max(fversion) as v, * from phsp_files where fid=:f';
  ZQ.Open;
  vs := ZQ.FieldByName('v').AsString;
  showmessage(vs);
end;
               
the first event is linked to a dbgrid. The grid will show all the fields and display a 1 for the 'v' column. The second event is executing exactly the same sql statement but returns an empty string. Connections are the same etc. But the result is different, I would expect the second event to return 1...
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Same sql, different result for SQLite table

Post by marsupilami »

Hello aducom,

I might be wrong but in your second example I don't see where the parameter f is set. If you never set it to any value it might be null and any comparison with null will fail. As a conseqnece to this the Query ZQ might be empty and in that case the Field v will return null if you Call FieldByName().Value and an empty string if you call FieldByName().AsString.
Best regards,

Jan
aducom
Zeos Dev Team
Zeos Dev Team
Posts: 67
Joined: 30.08.2005, 13:21

Re: Same sql, different result for SQLite table

Post by aducom »

And I thought I was an experienced developer *g*.

Tnx, sooooo obvious.
Post Reply