Solved

BDE Field Sorting

Posted on 1998-07-19
14
302 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now