Solved

BDE Field Sorting

Posted on 1998-07-19
14
299 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

16 Experts available now in Live!

Get 1:1 Help Now