Board index » delphi » ttable.fielddefs.update doesn't update deleted fields

ttable.fielddefs.update doesn't update deleted fields

Hello All.

i do the following on a ttable with interbase local :

active:=false;
fielddefs.clear
fielddefs.update (fielddefs.count is now 9)
tmpsql:=Tquery.create(self);
tmpsql.add('alter table %s drop %s',tablename,'myfield');
tmpsql.execsql;
tmpsql.free;
{at this point i can see from other apps, that the field is gone in the table}
dataevent(depropertychange,0); {attempt to circumvent VCL doing nothing due to
fielddefs.fupdated=true}
fielddefs.clear
fielddefs.update (fielddefs.count is now STIlL 9 WHY???)
active:=true; (exception is raised with field Fname not found, when in
tdataset.internalopen updatebuffercount tries to load values from the deleted
field)

the above code removes a field from the table,
then updates fielddefs,
and lastly opens the table, which fails
The field that was dropped is still in fielddefs. Why?

When i re-run the program, and open the table  again, the fielddefs will update
correctly, with one field less.

Is it safe just to delete the field from fielddefs? i guess not, cause it will
probably come back next time fielddefs.update is called.
How do i kickstart the dbengine so it takes in the real field values for the
table?

i tried to trick the bde into updating the fielddefs by calling
DataEvent(depropertyChange,0) to force fielddefs.fupdated to false (it's
private so i have to call something that changes it). The problem is, that
even when the vcl is tricked to actually ask BDE, BDE returns the wrong
(deleted) fielddesc in response. Same is hapening when adding fields. the field
just added is not returned and count is not increased.

When the application starts next time - the correct values are returned from
BDE. so the problem must me somewhere in the BDE.

the error seems to be that in tdataset.internalopen a call to dbigetcursorprops
the returned cursorprops.ifields is not with an updated value.
This leads to confusion.
It seems that borland BDE doesn't check the database
to see if the fieldstructure has changed.

Does ANYONE have a fix or suggestion for avoiding this problem. Have anyone
successfully deleted a field from a table, and the being able to continue to
use the table afterwarsd, without closing the application ?

Please, Borland, add a AddField method to Your tables. Just like you have
AddIndex.

Oh yes.. Newest build of delphi from the delphi 2 client/server cd was used.
Fant...@image.dk

 

Re:ttable.fielddefs.update doesn't update deleted fields


Quote
Fant...@image.dk wrote:

...
Quote
> the above code removes a field from the table,
> then updates fielddefs,
> and lastly opens the table, which fails
> The field that was dropped is still in fielddefs. Why?

...
Well I can't be sure why, but do you have Interbase Schema Caching
turned on?  If you do it really stuffs things up in development, since
it will (obviously) keep some field information about in the schema.  I
find the only solution is not to have Schema Caching turned on during
development.

Oliver Townshend
oliv...@zip.com.au

Other Threads