Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread AlterTable , EDatabaseError - Field '0' not found
Mon, Feb 9 2009 11:11 PMPermanent Link

Joel Schaubert

I am evaluating moving my product to DBISAM engine 4.
Currently I have this code which was working on engine 3 but now fails under 4.
(the code is only roughly the same due to changes regarding these api's).

   TDBISAMTable *OptionsTable=new TDBISAMTable(Application);
   OptionsTable->DatabaseName=DatabasePath;
   OptionsTable->TableName="options.dat";

   OptionsTable->Close();  //just to make sure
   OptionsTable->Exclusive = true;
   OptionsTable->FieldDefs->Update();
   OptionsTable->FieldDefs->Delete(1);
   OptionsTable->FieldDefs->Insert(1,2,"IMPFILENAM",ftString,250,false,"","","","");
   OptionsTable->FieldDefs->Delete(12);
   OptionsTable->FieldDefs->Insert(12,13,"TEMPDIR",ftString,250,false,"","","","");
   OptionsTable->IndexDefs->Clear();
   OptionsTable->IndexDefs->Add("","RecordID",TIndexOptions() << ixPrimary <<
ixUnique,icNone);
   OptionsTable->AlterTable(0,1,sver);
   OptionsTable->Close();
   OptionsTable->Exclusive = false;



On executing the AlterTable() function,  an error is thrown with the text

Field '0' not found.




For reference, I am posting the exact code that runs correctly with Engine 3 for comparison.

   TDBISAMTable *OptionsTable=new TDBISAMTable(Application);
   OptionsTable->DatabaseName=DatabasePath;
   OptionsTable->TableName="options.dat";

   OptionsTable->Close();  //just to make sure
   OptionsTable->Exclusive = true;
   OptionsTable->RestructureFieldDefs->Update();
   OptionsTable->RestructureFieldDefs->Delete(1);
  
OptionsTable->RestructureFieldDefs->Insert(1,2,"IMPFILENAM",ftString,250,false,"","","","");
   OptionsTable->RestructureFieldDefs->Delete(12);
  
OptionsTable->RestructureFieldDefs->Insert(12,13,"TEMPDIR",ftString,250,false,"","","","");
   OptionsTable->RestructureIndexDefs->Clear();
   OptionsTable->RestructureIndexDefs->Add("","RecordID",TIndexOptions() << ixPrimary <<
ixUnique,icNone);
   OptionsTable->RestructureTable(0,0,1,sver,false,"","Options table",512,false);
   OptionsTable->RepairTable();
   OptionsTable->Close();
   OptionsTable->Exclusive = false;
Mon, Feb 9 2009 11:20 PMPermanent Link

Joel Schaubert

I suspect it could be related to the first field being an ftAutoInc.
I noticed that dbsys.exe version 4 when it did a reverse engineer added an underbar
character for some reason to the name of that first field as shown in this dbsys generated
code below.



But in spite of suspecting the problem is related to the autoinc field, I do not know how
to correct the above alterTable code to make it work.


     if ( !TableToCreate->Exists )
        {
        TableToCreate->FieldDefs->Clear();
        TableToCreate->FieldDefs->Add("_RecordID",ftAutoInc);
        TableToCreate->FieldDefs->Add("IMPFILENAM",ftString,70);
        TableToCreate->FieldDefs->Add("IMPFILETYP",ftString,30);
        TableToCreate->FieldDefs->Add("MAILTYPE",ftString,1);
        TableToCreate->FieldDefs->Add("SMTPHOST",ftString,70);
        TableToCreate->FieldDefs->Add("SMTPUSER",ftString,70);
        TableToCreate->FieldDefs->Add("SMTPFROM",ftString,70);
        TableToCreate->FieldDefs->Add("SMTPPORT",ftInteger);
        TableToCreate->FieldDefs->Add("SMTPTIMOUT",ftInteger);
        TableToCreate->FieldDefs->Add("MAPILOGON",ftString,63);
        TableToCreate->FieldDefs->Add("MAPIACKNOW",ftBoolean);
        TableToCreate->FieldDefs->Add("AUTOFILLJUV",ftBoolean);
        TableToCreate->FieldDefs->Add("TEMPDIR",ftString,70);
        TableToCreate->FieldDefs->Add("NEXTJUVID",ftInteger);
        TableToCreate->FieldDefs->Add("LASTNSRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("FIRSTNSRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("FIRSTNCHAR",ftInteger);
        TableToCreate->FieldDefs->Add("SSNSRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("SEXSRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("RACESRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("BIRTHSRCH",ftBoolean);
        TableToCreate->FieldDefs->Add("ORGANIZATN",ftString,50);
        TableToCreate->FieldDefs->Add("LICENSECOD",ftString,16);
        TableToCreate->FieldDefs->Add("EXPIRE_DT",ftDate);
Mon, Feb 9 2009 11:37 PMPermanent Link

Joel Schaubert

-------------------- SOLVED

Well after 3 hours of chasing this, this just proves that spending the time to write up
the problem clearly enough to post does indeed make you smarter Wink


The problem was small differences in the arguments need to    IndexDefs->Add()

this fails
   StudentTempTable->IndexDefs->Add("","SEQNUM",TIndexOptions() << ixPrimary <<
ixUnique,icFull);
   StudentTempTable->IndexDefs->Add("Student ID","STUID",TIndexOptions() << ixUnique,icNone);

this works
   StudentTempTable->IndexDefs->Add("","SEQNUM",TIndexOptions() << ixPrimary <<
ixUnique,"",icFull);
   StudentTempTable->IndexDefs->Add("Student ID","STUID",TIndexOptions() << ixUnique);


Notice the extra  ,""    after ixUnique in the one the works.
re-examining the dbsys.exe generated code and comparing it to my schema altering code
revealed little differences like this between what works in engine 3 and engine 4.

Joel
Tue, Feb 10 2009 6:10 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Joel,

<< Well after 3 hours of chasing this, this just proves that spending the
time to write up the problem clearly enough to post does indeed make you
smarter Wink>>

Sorry I didn't get an answer to you in time.  Yes, there are small
differences in the handling of the FieldDefs and IndexDefs from DBISAM 3.x
to 4.x, so you need to make sure to account for them.

I'm glad that you found the problem,

--
Tim Young
Elevate Software
www.elevatesoft.com

Image