🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#43
From: MR
Date: Fri, 22 Jun 2007 09:03
78 lines
2850 bytes
How to create (dynamically) a primary index with *more than one
field*?

I tried the following:

    TTable *table; 
    table=new TTable(NULL);
    table->Active=false;
    table->TableType=ttDefault; // uses adequate table-type (e.g.
ttParadox, ttDBase) automatically, dependent on the file-extention
    table->TableType=ttParadox;
    table->TableName=EditBDETableName->Text;
    table->FieldDefs->Clear();
    table->FieldDefs->Add("Id", ftString, 10, FALSE);
    ...
    table->FieldDefs->Add("State", ftString, 25, FALSE);
    table->IndexDefs->Clear();

and than

    table->IndexDefs->Add("", "Id;Remark",
TIndexOptions()<<ixPrimary);

or instead

  table->IndexDefs->AddIndexDef()->Name="";
  table->IndexDefs->AddIndexDef()->Fields="Id"/*";Remark"*/;

table->IndexDefs->AddIndexDef()->Options=TIndexOptions()<<ixPrimary/*<<ixUnique*/;

and finally 

    table->CreateTable();
    table->Free();

When CreateTable() is executed I got an -exception
  'Zahl au�erhalb des g�ltigen Bereichs
   Tabelle nicht vorhanden 
   Tabelle: ...
translated
  'Number outside the valid range
   Table not available
   Table: ...

What did I do wrong?

Thanks,

Michael
I do not get this exception when using

    table->IndexDefs->Add("", "Id", TIndexOptions()<<ixPrimary);

, but unfortunatly 'Id' is not sufficent (i.e. there might be more
than one db-entry with the same id)




    /*  { Indizes der neuen Tabelle definieren }
        IndexDefs.Clear;
        with IndexDefs.AddIndexDef do begin
          Name := '';
          Fields := 'First';
          Options := [ixPrimary];
        end;
    */
    // table->IndexDefs->AddIndexDef()->Name="";
    // table->IndexDefs->AddIndexDef()->Fields="Id"/*";Remark"*/;
    //
table->IndexDefs->AddIndexDef()->Options=TIndexOptions()<<ixPrimary;

    // table->IndexDefs->Add("", "Id;Remark",
TIndexOptions()<<ixPrimary/*<<ixUnique*/);

    table->CreateTable();
    table->Free();
  }
Technical Details
Message-ID: <rf3n7353bhv32tvgdbcip16bgsbt0apt89@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.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

Show Full Headers
Complete Article Headers
X-Google-Thread: fb4e2,19b113387146ab80,start
X-Google-Attributes: gidfb4e2,public,usenet
X-Google-Language: ENGLISH,ASCII
From: <MR>
Newsgroups: borland.public.cppbuilder.database.dbexpress
Subject: How to create (dynamically) a primary index with more than one field?
Date: Fri, 22 Jun 2007 11:03:15 +0200
Message-ID: <rf3n7353bhv32tvgdbcip16bgsbt0apt89@4ax.com>
X-Newsreader: Forte Free Agent 3.3/32.846
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 88.64.9.118
X-Trace: newsgroups.borland.com 1182502994 88.64.9.118 (22 Jun 2007 02:03:14 -0700)
Lines: 78
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.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