[GRASS-dev] d.vect -a shows only some elements

Martin Landa landa.martin at gmail.com
Sat Oct 21 03:49:20 EDT 2006


Hi,

2006/10/21, Moritz Lennert <mlennert at club.worldonline.be>:

[snip]

> > you are right (if I understand well), adding
> >
> > db_CatValArray_sort (&cvarr_rgb);
> >
> > should solve the problem. I wonder why db_select_CatValArray sorts
> > cvarr->value by category number only for data type int or double...
> > (?), see
> >
> > 00300     if ( type == DB_C_TYPE_INT )
> > 00301         qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
> > cmpcat);
> > 00302     else if ( type == DB_C_TYPE_DOUBLE )
> > 00303         qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal),
> > cmpcat);
> >
>
> Applying below patch directly to db_select_CatValArray solves the problem
> for me, but I don't know if this might cause other problems, even though I
> doubt it.
>
> Any ideas ?
>
> Moritz
>
> Index: lib/db/dbmi_client/select.c
> ===================================================================
> RCS file: /grassrepository/grass6/lib/db/dbmi_client/select.c,v
> retrieving revision 1.8
> diff -u -r1.8 select.c
> --- lib/db/dbmi_client/select.c 14 Jul 2006 16:41:22 -0000      1.8
> +++ lib/db/dbmi_client/select.c 20 Oct 2006 23:22:26 -0000
> @@ -297,10 +297,7 @@
>      db_close_cursor(&cursor);
>      db_free_string ( &stmt );
>
> -    if ( type == DB_C_TYPE_INT )
> -        qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal), cmpcat);
> -    else if ( type == DB_C_TYPE_DOUBLE )
> -        qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal), cmpcat);
> +    db_CatValArray_sort ( cvarr );
>
>      return (nrows);
>  }

in this case the array is sorted twice for datatype DB_C_TYPE_INT and
DB_C_TYPE_DOUBLE, I suggest

Index: lib/db/dbmi_client/select.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/db/dbmi_client/select.c,v
retrieving revision 1.8
diff -u -r1.8 select.c
--- lib/db/dbmi_client/select.c	14 Jul 2006 16:41:22 -0000	1.8
+++ lib/db/dbmi_client/select.c	21 Oct 2006 07:43:35 -0000
@@ -297,9 +297,8 @@
     db_close_cursor(&cursor);
     db_free_string ( &stmt );

-    if ( type == DB_C_TYPE_INT )
-        qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal), cmpcat);
-    else if ( type == DB_C_TYPE_DOUBLE )
+    if ( type == DB_C_TYPE_INT || type == DB_C_TYPE_DOUBLE ||
+	 type == DB_C_TYPE_STRING )
         qsort( (void *) cvarr->value, nrows, sizeof(dbCatVal), cmpcat);

     return (nrows);

Not sure if you need to check "type" here (what about DB_C_TYPE_DATETIME)??

Best, Martin

-- 
Martin Landa <landa.martin at gmail.com> * http://gama.fsv.cvut.cz/~landa *




More information about the grass-dev mailing list