[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

BDE Field Sorting

Can somebody tell me how to sort my Database(Paradox using
BDE 4.51) by one Field ?

eg i want to sort by Database By the Field "NAME".
Thanx
0
k6__
Asked:
k6__
  • 6
  • 4
  • 4
1 Solution
 
MatveyCommented:
One way is to sort it phisically. Such procedure is available in the Database Desktop.
Another way is to create an index on the field "Name". You can create an index using Database Desktop and also from inside your program.
Another way is to use SQL:

SELECT * FROM <table_name> GROUP BY name;
0
 
k6__Author Commented:
I use TTable... Does TTable Accepts SQL Commands ?

0
 
aksystemCommented:
Create a temporary index on your field
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
MatveyCommented:
TTable doesn't allow SQL command. You can use TQuery component. It depands on the size of your table, but in most cases it's better to create an index on your field. I you create an index, the updates, deletes and appends to your table slow down. But if you don't have a big table, than you won't notice it. The SQL command can be made "live", and the TQuery can be used for updates too, but the command also takes time.
I must say that if you create an index on your field and then make an SQL call to your table that has already the index, the command will work super fast. So this is to say that you can combine the two things.
Anyway, I see that your task is only sorting, so as I said in most cases it's better just to make an index. How many records are stored in it?
0
 
k6__Author Commented:
well i want a PERMANT SORT!... and please post some code =)
i don't have a clue about indexes =)

0
 
MatveyCommented:
Open your table in DataBase Desktop and in the restructure dialog you can define indexes.
Then in your TTable component set the IndexName property to the index name you defined in Database Desktop.
Your table will appear sorted by the field you defined the index on.
0
 
aksystemCommented:
With the following codeexample you might be able to create a table with a primary and a secondary index:

Procedure CreateTable(Verzeichnis: TFileName);
var
      Table1: TTable;
begin
   Table1 := TTable.Create(Application);
   with Table1 do begin
      if not FileExists(Verzeichnis + '\DEMO.DB') then begin
         DataBaseName := Verzeichnis;
         Name := 'Table1';
         TableName := 'DEMO.DB';
         TableType := ttParadox;
         with FieldDefs do begin
            Clear;
            Add('Field1', ftString, 24, false);
            Add('Name',   ftString, 24, false);
            Add('Field2', ftString, 24, false);
            Add('Field3', ftString, 24, false);
            Add('Field4', ftString, 24, false);
            Add('Field5', ftString, 24, false);
            Add('Field6', ftString, 24, false);
            Add('Field7', ftString, 24, false);
            Add('Field8', ftString, 24, false);
         end;
         with IndexDefs do begin
            Clear;
            Add('Primary','Field1;Name', [ixPrimary, ixUnique]);
            Add('Name','Name', []);
         end;
         CreateTable;
      end;
      Free;
   end;
end;

In your Code you select the sort via:

   with Table1 do begin
      Active := False;
      IndexName := 'Name';
      Active := True;
   end;

There isn't more about indizes

Regards, Achim

0
 
MatveyCommented:
Yes, of course it's possible to create indexes in run-time, but mostly useless in my opinion. Just some cases require this...
0
 
aksystemCommented:
I don't think, it's useless.
1.) I seldom deliver the databases with my app. I create them and their indexes at runtime
2.) Creating an index at runtime enables me to sort a table temporary or pemanent on every field I want, i. e. if you click on a grid header (if the grid component supports that).
0
 
MatveyCommented:
I also use it sometimes, but as k6__ said - he wants a permenant sort. Writing lots of code for this is sure possible, but not very useful.
0
 
k6__Author Commented:
Ok but can you tell me how to Sort Via Database Desktop
Permant ?

as matvey said :

Open your table in DataBase Desktop and in the restructure dialog you can define indexes.

aksystem: very usuful code but as i said above i want to have
permant indexes .. not to create them at run time =-)...
sorry
 

ok .. i went to database desktop but i only found Secondary indexes!.. where are the primaries ? =)


0
 
k6__Author Commented:
btw .. will those indexes speed up things like eg :
Table1.Locate('Field', Edit1.text , []);

btw : Thanx my friends for all your helps =)

0
 
aksystemCommented:
There is no difference between permanent or temporary index. The temporary index you have to erase after using. If you don't erase it, its permanent.

You create the primary index during database-table creation by marking the main sort fields at the top of the table with a star. Or if you do that programatically:
            Add('Primary','Field1;Name', [ixPrimary, ixUnique]);

Each table should have a primary index.

0
 
MatveyCommented:
k6, yes, it should speed up any sorting/searching.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now