I am a long time user of Delphi and a beginner in Lazarus.
Currently I am using Lazarus 1.8.4 in Windows7.
I found a weird behaviour of component TSQLQuery.
It seems a bug to me, but I would like to discuss the question here.
say you have
qry:TSQLQuery;
IBConnection:TIBConnection;
trRead:TSQLTransaction;
I use these components to access a Firebird v. 2.5 DB.
I wrote the code below (please read the code at the bottom of this message).
When the program reaches the last line
a:=qry.FieldByName('id_cst').IsNull;
an exception is raised saying 'field ID_CST not found'.
It took a while to me to realize that I assigned the query SQL in
qry.SQL.Text:='select * from tb_cst';
without closing the query first. The correct code would be:
qry.Close;
qry.SQL.Text:='select * from tb_cst';
However Delphi does not allow to assign the SQL of an open query and the exception would have been raised in this line
qry.SQL.Text:='select * from tb_cst';
What Delphi does seems the correct way to go. At least, I would have spared a long time trying to understand the problem.
Should I report a bug? Or maybe this behaviour has been corrected in the most recent versions?
Thank you
Peppe Polpo
var
a:boolean;
begin
// access the DB
try
IBConnection.Connected:=true;
except
ShowMessage('Cannot connect to the server');
Close;
Exit;
end;
qry.Close;
qry.SQL.Text:='select * from tb_dpt';
(*
structure is
CREATE TABLE TB_DPT (
ID_DPT CHAR( 36 ) NOT NULL,
COD_DPT VARCHAR( 13 ) NOT NULL,
PRIMARY KEY ( ID_DPT )
)
*)
qry.Open;
qry.First;
a:=qry.FieldByName('id_dpt').IsNull; // check for field ID_DPT: OK
qry.SQL.Text:='select * from tb_cst';
(*
structure is
CREATE TABLE TB_CST (
ID_CST CHAR( 36 ) NOT NULL,
COD_CST VARCHAR( 13 ) NOT NULL,
PRIMARY KEY ( ID_CST )
)
*)
qry.Open;
qry.First;
a:=qry.FieldByName('id_cst').IsNull; // check for field ID_CST: an exception is raised here
I use