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
Solved

BDE Field Sorting

Posted on 1998-07-19
14
304 Views
Last Modified: 2013-11-23
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
Comment
Question by:k6__
  • 6
  • 4
  • 4
14 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1358229
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
 
LVL 2

Author Comment

by:k6__
ID: 1358230
I use TTable... Does TTable Accepts SQL Commands ?

0
 

Expert Comment

by:aksystem
ID: 1358231
Create a temporary index on your field
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 3

Expert Comment

by:Matvey
ID: 1358232
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
 
LVL 2

Author Comment

by:k6__
ID: 1358233
well i want a PERMANT SORT!... and please post some code =)
i don't have a clue about indexes =)

0
 
LVL 3

Expert Comment

by:Matvey
ID: 1358234
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
 

Expert Comment

by:aksystem
ID: 1358235
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
 
LVL 3

Expert Comment

by:Matvey
ID: 1358236
Yes, of course it's possible to create indexes in run-time, but mostly useless in my opinion. Just some cases require this...
0
 

Expert Comment

by:aksystem
ID: 1358237
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
 
LVL 3

Expert Comment

by:Matvey
ID: 1358238
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
 
LVL 2

Author Comment

by:k6__
ID: 1358239
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
 
LVL 2

Author Comment

by:k6__
ID: 1358240
btw .. will those indexes speed up things like eg :
Table1.Locate('Field', Edit1.text , []);

btw : Thanx my friends for all your helps =)

0
 

Accepted Solution

by:
aksystem earned 50 total points
ID: 1358241
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
 
LVL 3

Expert Comment

by:Matvey
ID: 1358242
k6, yes, it should speed up any sorting/searching.
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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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