[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUe-dev] Proposal for specifying 'Sort-Order' in datasources

From: Johannes Vetter
Subject: [GNUe-dev] Proposal for specifying 'Sort-Order' in datasources
Date: Fri, 31 Dec 2004 17:11:15 +0100


I had a look at the current way to specify a sort-order for a given
datasource which is done by defining an 'order_by'-string
(comma-separated for multiple fields). 

<datasource name="dtsFoo" table="foo" order_by="foo,bar" />
<datasource name="dtsBar" table="bar" order_by="foo desc,bar" />

The latter example shows how we could define a 'descending' sort-order
for a given field. Since GNUe Application Server does not support this
'descending' option atm, I've thought about how to implement this
feature. Doing this, I've also considered a more 'general' way of
specifying sort-orders in common. So please feel free to add comments
about my suggestions:

I.) Define 'sorting' via XML-tag:

The following pieces of XML-code would be equivalent to the examples
given above.

<datasource name="dtsFoo" table="foo">
    <field name="foo" />
    <field name="bar" />

<datasource name="dtsBar" table="bar">
    <field name="foo" descending="True" />
    <field name="bar" />

Of course this is a bit more code, but it's very straight forward. As
you can read from this code, having ascending order would be the

To accomplish sorting according to the above xml-code in gnue.common I
think the following changes would be needed:


I think having a property "order" (or something like that) which is a
sequence of tuples would be nice. Each such a tuple holds the fieldname
and a boolean flag, specifiying wether the order is ascending (False) or
descending (True). To stick with my examples these 'order' property
would look like this:

dtsFoo.order = [(foo, False), (bar, False)]
dtsBar.order = [(foo, True), (bar, False)]

Now, having the sorting defined in such a general and easy to use
structure all db-drivers can easily transform it to fit their needs. Ok,
but now to the real changes in code:

1. extend primaryInit () of GDataSource

Here we would build the tuple-sequence from <sorting>-tags. (all fields
specified will be implicitly added to the fieldReferences-dictionary).
If *no* <sorting>-tag is given but an "order_by" attribute set in the
<datasource>-tag, a depreciation-waring will be printed *and* the
tuple-sequence will be generated too.

If a datasource has both, an 'order_by'-attribute and a 'sorting'-tag, a
MarkupError will be raised.

2. triggerGetOrderBy/triggerSetOrderBy

These functions are currently mapped into trigger-namespace (as
properties). "triggerSetOrderBy" could be changed to work with both (a
string-based, and a sequence-based) argument giving also
depreciation-warnings if a string is passed in. "triggerGetOrderBy" is a
bit tricky then. To keep compatibility we would have to return a string
here, but i dislike this ...

III) datasource.drivers.DBSIG2:

Change DataObject._buildQuery () to use the tuple-sequence instead of
the order_by string. This would be a quite easy task.

Besides this one would have to check the odbc/wodbc-driver too. I think
this needs the same change as DBSIG2.DataObject

With these changes datasources should work as they do now.

IV) Support for (descending) sorting in Application Server:

The application server has to be changed on the following points:

1. API-Change: geasSession.request ()

The parameter 'sortorder' is a sequence of tuples (as described in II.),
but we could be nice and also accept a sequence of field-names, assuming
'ascending' order for all given fields.


in _createDataSource () we would have to pass a sort-sequence to the
DataSourceWrapper instance.

3. geasList.__sortBatch ():

this function needs some changes to take care of fields ordered

Ok, that's it (I think :). Please feel free to give me some feedback.


BYTEWISE Software GmbH          Tel +43 (5577) 89877-0
i.A. Johannes Vetter            Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2
Wir bieten die Installation von Debian GNU/Linux auf
Servern für kleinere Netzwerke zum Pauschalpreis an.
Mehr dazu unter

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

reply via email to

[Prev in Thread] Current Thread [Next in Thread]