Subject Why to use Unprepare in this case ?
Author emgfyah2002
Using FireBird + IBO 4Hc + Delphi 6
I need to create a table at runtime, with the following structure:
TablePK as integer ( PK ) + 1 ... N fields as smallint +
TotalField as Integer, in which N depends of runtime variables.
Before each new table creation, I use a query with a 'drop table
MyTable' to remove the old one. It works perfectly.
I decided to use another IB_query, lets name it QueryGTotal, with
the SQL = 'select sum(Total) as GTotal from Mytable' to get the great
total (sum of all total fields ). It runs under the same
transaction used to create and operate with the table. It works but
with the following particularity:
1 - if I use just : QueryTotal.open;
MyGreattotal := QueryTotal.fieldbyname
('GTotal').asinteger;
Querytotal.close;
I get the Greattotal but if after that I try to drop Mytable I
get an error because the table is in use. ( if I did not get the
great total, the drop table SQL works without error)
2 - if after the Querytotal.close I put: QueryTotal.unprepare;
Everything works perfetly, with no errors!
I came to use the unprepare instruction by tentatives but I would
like to know why is it necessary to do that.
thank you
Edison