?
Solved

Secondary Index

Posted on 1997-12-10
8
Medium Priority
?
520 Views
Last Modified: 2010-04-04
How do I create a secondary index at runtime, I have checked addindex, but I get an error saying that I can't create it, what do I have to be aware of? Could anybody send me a example that works?
0
Comment
Question by:koger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1353294
Koger, please, what database are you using? Oracle is different from MS SQL Server is different from dBase is different from Sybase, etc, etc, etc. Is it a REAL database like MS SQL Server or a database-wanna-be like Paradox or dBase?

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353295
It's just a hunch, but for the AddIndex options paramater use [ixCaseInsensitive] without any other options.
E.g.  MyTable.AddIndex('NewIx', 'CustNum', [ixCaseInsensitive]);

JB
0
 
LVL 3

Expert Comment

by:d4jaj1
ID: 1353296
There is a quirk with index names:

 if IndexName = Fieldname then ixCaseSensitive is reqd (the default)
 if IndexName <> Fieldname then ixCaseInsensitive is reqd

Thus you need:

  table.AddIndex('cusname', 'name', [ixCaseInsensitive]);

or

  table.AddIndex('name', 'name', []);

Any questions, please add a comment.

Good Luck!
Jay
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:koger
ID: 1353297
I forgot to said that the database is paradox, here comes the code that I write:

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Form2.Table1 do
  begin
    with FieldDefs do
    begin
      Clear;
      Add('Name:', ftString, 50, False);
      //and alot more
    end;
    CreateTable;
    Form2.Table1.Open;
  end;
  Form2.Show;
end;



procedure TForm2.Button1Click(Sender: TObject);
begin
  Table1.Refresh;
// is this ok to save the table?
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  Table1.AddIndex('koger', 'Name:', []);
end;

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353298
Try this in Button2Click:
Table1.AddIndex('koger', 'Name:', [ixCaseInsensitive]);

0
 

Author Comment

by:koger
ID: 1353299
No, don't work, I get a error

Table is not indexed. Index: Koger
0
 

Author Comment

by:koger
ID: 1353300
Adjusted points to 100
0
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 400 total points
ID: 1353301
Sorry, I've been on vacation for a while and didn't see any of your comments.  All of the code above will work, but only in certain situations.  I'm willing to work with you until we get it solved.

At first sight, it appears the problem in your original statement (Table1.AddIndex('koger', 'Name:', []);)is the missing Index option ixcaseinsensitive.  In JimBob's solution, you can remove the Colon (:).  If you are trying to assign an index to the field Kroger, you MUST set it as the Primary Index FIRST.  The reason you are getting the error is you can't set a Secondary Index before you set a Primary Index. So try this,

Add('Kroger', 'Name', [ixPrimary, ixUnique]);

The code below may be a little better for you since it creates the table and its indexes all at the same time.

 with Table1 do
  begin
   Active := False;
   DatabaseName := 'DBDemo';
   TableName := 'Your_Table_Name';
   TableType := ttParadox;
   with FieldDefs do
    begin
     Clear;
     Add('Name', ftString, 30, False);
    end;
   with IndexDefs do
    begin
    Clear;
    Add('Name', 'Name', [ixPrimary, ixUnique]);  //or 'Kroger' then 'Name'
   end;
  end;
  table1.CreateTable;
 end;
end;

Any more questions, please add a comment - I'm sure we can work it out.

Good Luck!
Jay
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question