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

Glynn Clements glynn at gclements.plus.com
Mon Oct 9 06:34:06 EDT 2006

Moritz Lennert 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 won't work. It might compile, but you're essentially converting
the address of the cmp_row() function to an integer, negating it, then
converting it back to a pointer.

However, you can do:

	static int cmp_row_desc(const void *pa, const void *pb)
		return -cmp_row_asc(pa, pb);

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list