Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 9 of 9 total |
Indexes deleted on altertable? |
Mon, Mar 10 2014 6:34 PM | Permanent Link |
F. van Daalen | Version 4.37 Build 3
Adding a field to a table and then adding a an index will delete all indexes? with FieldDefs do begin update; if IndexOf('Norm_Id')=-1 then Begin Altered :=true; Add('Norm_Id',ftLargeInt); End; end; if Altered then altertable; With IndexDefs do Begin update; If IndexOf('ByNorm')=-1 then Begin Add('ByNorm','Norm_Id',[],'',icNone); Altered := true; end; end; If Altered then AlterTable(); after this all indexes except the newly created one are deleted? |
Mon, Mar 10 2014 6:42 PM | Permanent Link |
F. van Daalen | PS Not doing the altertable after adding the field generate an error when generating the index as the field doesn't exist yet?
|
Mon, Mar 10 2014 7:13 PM | Permanent Link |
F. van Daalen | Ok the workaround is to add an IndexDefs.Update; statement BEFORE adding the field. Then after the field is added call altertable and then the index can be added.....
pwhuhhh |
Mon, Mar 10 2014 7:45 PM | Permanent Link |
Raul Team Elevate | On 3/10/2014 7:13 PM, F. van Daalen wrote:
> Ok the workaround is to add an IndexDefs.Update; statement BEFORE adding the field. Then after the field is added call altertable and then the index can be added..... This is not a workaround - this is by design and always has been. You must call Update on both FieldDefs and IndexDefs if you wish to retain them. Altertable has no way of know what you wish to alter so it always alters both. Raul |
Tue, Mar 11 2014 4:42 AM | Permanent Link |
F. van Daalen | Raul wrote:
This is not a workaround - this is by design and always has been. You must call Update on both FieldDefs and IndexDefs if you wish to retain them. Altertable has no way of know what you wish to alter so it always alters both. Raul If it's by design then it's inconsistent by design. When adding only an index without the fieldsdef.update then after the altertabel the fields aren't deleted. |
Tue, Mar 11 2014 4:51 AM | Permanent Link |
F. van Daalen | If it's by design then it's inconsistent by design. When adding only an index without the fieldsdef.update then after the altertabel the fields aren't deleted.
or add only fields without an index and without the indexdefs.update will also not delete any indexes. So only when doing both you must first do a indexdefs.update before touching the fields. |
Wed, Mar 19 2014 9:35 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Frans,
You don't need two AlterTable calls here, just one: FieldDefs.Update; IndexDefs.Update; with FieldDefs do begin if IndexOf('Norm_Id')=-1 then Begin Altered :=true; Add('Norm_Id',ftLargeInt); End; end; With IndexDefs do Begin If IndexOf('ByNorm')=-1 then Begin Add('ByNorm','Norm_Id',[],'',icNone); Altered := true; end; end; If Altered then AlterTable(); Tim Young Elevate Software www.elevatesoft.com |
Wed, Mar 19 2014 9:38 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Frans,
<< Ok the workaround is to add an IndexDefs.Update; statement BEFORE adding the field. Then after the field is added call altertable and then the index can be added..... >> See the example in my reply to your original post. You're just approaching the alteration in the wrong way - the alteration is a *table-wide* operation, meaning that all structure information (FieldDefs and IndexDefs) must be populated before calling AlterTable, whether that is done manually or automatically via the relevant Update calls. Any structure information not present at the time of the AlterTable call will be removed by DBISAM in the actual table. Tim Young Elevate Software www.elevatesoft.com |
Wed, Mar 19 2014 9:41 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Frans,
<< If it's by design then it's inconsistent by design. When adding only an index without the fieldsdef.update then after the altertabel the fields aren't deleted. >> How are you "adding the index" ? If you call IndexDefs.Update, DBISAM automatically calls FieldDefs.Update because it needs the field definitions in order to process the index definitions. This is *not* the case with the field definitions, nor would it make sense to have FieldDefs.Update automatically update the index definitions. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Wednesday, April 24, 2024 at 11:07 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |