[GRASS-dev] adding 'desc' to dbf sql driver

Daniel Calvelo dca.gis at gmail.com
Wed Sep 27 21:32:37 EDT 2006


Hi Moritz. See below

On 9/22/06, Moritz Lennert <mlennert at club.worldonline.be> wrote:
> Hi,
>
> Reworking on d.vect.chart I need to be able to sort the reults of a
> select in descending order. As the dbf driver doesn't allow this, I have
> been trying to see how to extend the driver.
>
> IIUC, it's "just" a question of conditionalising the qsort call on line
> 566 of db/drivers/dbf/dbfexe.c, and (would this be enough ?) use
>
> qsort(set, nset, sizeof(int), -cmp_row);

That might work. Although it would be much nicer to use an expression
as sorting order.

> if the desc keyword is present.
>
> However, I have some trouble understanding the parsing of the sql
> statement.
>
> If I understand correctly, we would need to extent the SQLPSTMT
> structure in include/sqlp.h to include a flag for 'desc' (and possible
> 'asc') and the parser to identify and set that flag.
>
> But this is as far as I get. Could someone help me with this ?

Quick shot: you need to

- change SQLPSTMT to have an "order"/"direction"/"sort_order"  element

- add ASC and DESC in lex.l as tokens

- change yac.y to stg like:

y_order: y_order_asc | y_order_desc ;
y_order_asc:
       NAME ASC { sqpOrderColumn( $1 ); sqpOrderDirection( 1 ); }
;
y_order_desc:
      NAME DESC { sqpOrderColumn( $1 );sqpOrderDirection( 2 );}
;

- add in sql.c a sqpOrderDirection() function that sets the element
you added to SQLPSTMT

(Alternatively, you can change sqpOrderColumn() to receive two
arguments, one being the sorting direction. I'd also rather #define
SORT_ASC and SORT_DESC instead of using magic numbers as above.)

- use that value in dbfexe.c to test the sorting direction.

HTH,

Daniel.

> Thanks,
>
> Moritz
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev
>


--
-- Daniel Calvelo Aros


-- 
-- Daniel Calvelo Aros




More information about the grass-dev mailing list