Documentation
Below documentation is part of the BeeBase dictribution and is also available in PDF.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
11. Order
For each table in your database you can specify in which order its records should be displayed. This chapter describes how you can specify an order and what consequences it has.
11.1 Empty order | If you don't want to order your records. | |
11.2 Order by fields | Easy ordering by comparing fields. | |
11.3 Order by a function | Customized ordering. | |
11.4 Changing orders | How to specify an order. | |
11.5 Reorder all records | If they ever become unsorted. |
11.1 Empty Order
By default each newly created table has an empty order. This means that if you enter a new record, the created record is inserted at the current position, that is, behind the current record of the table. If you change some fields of an existing record, the position of the record within the table stays unchanged.
11.2 Order by Fields
Sometimes it is useful to have the records sorted by a certain field, e.g. by the `Name' field if the table has one.
In BeeBase you can specify for each table a list of fields by which its records should be sorted. All records are first sorted by the first field in this list. If two records are equal in a field then the next field in the list determines the order. For each field you can specify if the records should be sorted ascending or descending.
For determining the order of fields the rules of the following table are used:
Type Order relation
Integer NIL < MIN_INT < ... < -1 < 0 < 1 < ... < MAX_INT
Choice (Choice values are treated as integers)
Real NIL < -HUGE_VAL < ... < -1.0 < 0.0 < 1.0 < ... < HUGE_VAL
String NIL < "" < ... < "a" < "AA" < "b" < ...
Memo (String comparison is done case insensitive)
Date NIL < 1.1.0000 < ... < 31.12.9999
Time NIL < 00:00:00 < ... < 596523:14:07
Boolean NIL < TRUE
Reference NIL < any_record
(Records itself are not comparable for ordering)
|
If you have specified an order for a table then the records are automatically rearranged whenever you add a new record or change an order-relevant field of a record.
11.3 Order by a Function
Sometimes you want a more complex ordering scheme than a simple field list as described in the last section. For example, a field list can't hold reference fields, so it is not possible to sort your records by a reference field. The reason for this is that with reference fields BeeBase is not able to keep your records ordered at all times (see Comparison function in the BeeBase programming chapter for more details).
However, BeeBase also offers the possibility to specify a comparison function for sorting your records. You can specify any function that you have written using the BeeBase program editor. The function will be called with two record pointers and the returned value should reflect the order of the two records. The function can use any operations for comparing the records, thus it can e.g. compare records using reference fields. For more information on this mechanism, see Comparison function.
If you decide to use a comparison function for ordering a table then please note that BeeBase cannot always detect when records of the table have to be reordered since the dependencies are unknown. Use menu item `Table - Reorder all records' when records are becoming unsorted.
11.4 Changing Orders
To specify an order for the current table select menu item `Table - Change order'. This will open a window containing
- the name of the table in the window title.
- a choice field `Type' where you specify
whether the table should be ordered by using an `Field list'
or by using a `Comparison function'.
Depending on the state of `Type' you can enter
data into the following items.
For an order using a field list, the following items exist:
- a list of all fields of the table that can be used in the
order list. This list is placed in the left part of the window.
If you double click a name then the name will be inserted
into the order list at the current cursor position.
- the current list of fields used for ordering.
This list is placed in the right part of the window.
The top item in this list is the first field of the
order list. You can rearrange items by dragging them to
other positions in the list. To add further fields drag them
from the field list to the order list.
You can remove a field from the order list
by dragging the item out of the order list and dropping it
onto the field list.
Each entry in the order list has an arrow symbol pointing up or down on the left side. You can toggle the state of the arrow by double-clicking it. If an arrow is pointing up then the sorting order for this field is done ascending, if it is pointing down, it is done descending.
For an order using a comparison function, there is the following item:
- a field `Function for comparing records'
where you can enter the name of a function that should be called
for comparing two records of the table.
You can use the pop-up button to the right of the string field for
choosing a name from a list of all function names.
If you leave the field empty then an empty order is used.
For more information on how to use a comparison function,
including the arguments that are passed to it, see Comparison function.
Furthermore, the following buttons exist:
- a `Clear' button that clears all fields for an empty order.
- two buttons `Ok' and `Cancel' for leaving the window.
To enter a new field order list, choose `Field list' in the `Type' field and press the `Clear' button. Then use drag & drop as described above to build up a new list of fields. If you want to have an empty order then just don't add any fields to the order list.
When you are done specifying the order, press the `Ok' button. BeeBase will then reorder all records of the table.
11.5 Reorder all Records
If you ever think that some records of a table became unsorted, e.g. when using a comparison function for ordering, then you can choose menu item `Table - Reorder all records' for sorting all records.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on September, 30 2024 using texi2html