🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.dbexpress
Article #49

Re: How to create (dynamically) a primary index with more than one field?

#49
From: Minas
Date: Wed, 27 Jun 2007 09:06
81 lines
3460 bytes
? <MR> wrote

> So inserting a FieldDef between Id and Remark in your sample will
> result in the same exception I described.
>
> Is this always the case or is this specific for the data-base type,
> i.e. Paradox.
>
> Or is there a way to allow non-subsequent fields being indexed too?
>

You are right.Key Fields for the primary index must be consecutive.I tried 
the same code
in a .mdb database and I get the same exception. To stop the exception I 
used
the other way ,
TFieldDef *fldDef = table->FieldDefs->AddFieldDef();

and I used FieldNo to specify the physical field order.
In this case , though , I got a mess in the fields of indices


    TTable *table;
    table=new TTable(NULL);
    table->Active=false;
    table->TableType=ttParadox;
    table->DatabaseName =  "C:\\TestDBTable";// Database1->DatabaseName;
    table->TableName= Edit1->Text;
    table->FieldDefs->Clear();
    //fields definition
    TFieldDef *fldDef = table->FieldDefs->AddFieldDef();
    fldDef->Name ="Id";
    fldDef->DataType = ftString;
    fldDef->Size =10;
    fldDef->Required =false;
    fldDef->FieldNo =1;

    fldDef = table->FieldDefs->AddFieldDef();
    fldDef->Name ="OtherFld";
    fldDef->DataType = ftString;
    fldDef->Size =25;
    fldDef->Required =false;
    fldDef->FieldNo =3;

    fldDef = table->FieldDefs->AddFieldDef();
    fldDef->Name ="State";
    fldDef->DataType = ftString;
    fldDef->Size =25;
    fldDef->Required =false;
    fldDef->FieldNo =4;

    fldDef = table->FieldDefs->AddFieldDef();
    fldDef->Name ="Remark";
    fldDef->DataType = ftInteger;
    fldDef->Size =0;
    fldDef->Required =false;
    fldDef->FieldNo =2;

    table->IndexDefs->Clear();
//    TIndexDef *idxDef = table->IndexDefs->AddIndexDef();
//    idxDef->Name="";
//    idxDef->Fields = "Id;Remark";
//    idxDef->Options << ixPrimary;
    // indices
    table->IndexDefs->Add("", "Id;Remark",TIndexOptions()<<ixPrimary);
    table->IndexDefs->Add("StateX", "State",TIndexOptions()<< 
ixCaseInsensitive);
    table->IndexDefs->Add("OtherX", "OtherFld",TIndexOptions()<< 
ixCaseInsensitive);
    table->CreateTable();
    delete table;

To get right results with no exception, Remark field must be defined next to
Id field definition .

Best Regards

_Minas Harokopos

------
"Only the virtue's conquests have certainty" Sofokleous Erephyle 
Technical Details
Message-ID: <46822904@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <rf3n7353bhv32tvgdbcip16bgsbt0apt89@4ax.com> <467e2a33@newsgroups.borland.com> <6524839q2n65if026g1nnsstepr570ft2l@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: fb4e2,19b113387146ab80
X-Google-Attributes: gidfb4e2,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Minas" <no email>
Newsgroups: borland.public.cppbuilder.database.dbexpress
References: <rf3n7353bhv32tvgdbcip16bgsbt0apt89@4ax.com> <467e2a33@newsgroups.borland.com> <6524839q2n65if026g1nnsstepr570ft2l@4ax.com>
Subject: Re: How to create (dynamically) a primary index with more than one field?
Date: Wed, 27 Jun 2007 12:06:45 +0300
Lines: 83
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 62.1.125.184
Message-ID: <46822904@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1182935300 62.1.125.184 (27 Jun 2007 02:08:20 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail