On 03/04/09 08:43, Markus Neteler wrote:
On Thu, Apr 2, 2009 at 6:37 PM, Moritz Lennert
<[email protected]> wrote:
On 02/04/09 18:12, Moritz Lennert wrote:
On 02/04/09 16:58, Markus Neteler wrote:
On Thu, Apr 2, 2009 at 4:51 PM, Moritz Lennert
On 02/04/09 16:00, Markus Neteler wrote:
On Thu, Apr 2, 2009 at 1:43 PM, Markus Neteler <[email protected]>
On Wed, Apr 1, 2009 at 6:05 PM, Paolo Cavallini
v.dissolve input=reg...@nuovo layer=1 column=REGIAO output=reg_diss
dbmi: Protocol error
...
Offlist we figured it out:
If the "REGIAO" column field value is empty, then it fails.
...
BAD happens when Null is found here.
And that's arguably a correct behaviour as how should NULL be handled in
such a comparison ? Don't know how it is dealt with in other DBMS...
Yes, I also don't know...
So, before we fix this in any way, we should probably agree to how to
handle it. One possible way would be to check for nulls and if there are any
to assign a return value according to our choice as to where to sort nulls
to. Don't know how to check for an uninitialised char variable in C, but I
imagine that it should be possible.
Actually, you should be able to check
tbl->rows[*row1].values[cur_cmp_ocol].is_null
and deal with the values accordingly, but from a casual glimpse I cannot
find the possible values of is_null... I suppose 0 for false and 1 for true,
but not sure...Use your example to check, with something like
fprintf(stdout, "row 1 null status = %i\n",
tbl->rows[*row1].values[cur_cmp_ocol].is_null);
echo "SELECT cat, REGIAO FROM regiao ORDER BY REGIAO" | db.select
D0/0: case DBF_CHAR: c1 = ALTO PORTUGAL, c2 = ALTO PORTUGAL
D0/0: case DBF_CHAR: row 1 null status = 0
D0/0: case DBF_CHAR: c1 = NOROESTE CISMONTANO, c2 = ALTO PORTUGAL
D0/0: case DBF_CHAR: row 1 null status = 0
D0/0: case DBF_CHAR: c1 = NOROESTE CISMONTANO, c2 = ALTO PORTUGAL
D0/0: case DBF_CHAR: row 1 null status = 0
D0/0: case DBF_CHAR: c1 = NOROESTE CISMONTANO, c2 = ALTO PORTUGAL
D0/0: case DBF_CHAR: row 1 null status = 0
D0/0: case DBF_CHAR: c1 = (null), c2 = ALTO PORTUGAL
D0/0: case DBF_CHAR: row 1 null status = 1
dbmi: Protocol error
Seems to be found.
Ok, try the attached diff to grass6 head.
It implements the same behaviour for all data types: null values are
sorted to the end.
Moritz
Index: dbfexe.c
===================================================================
--- dbfexe.c (révision 36571)
+++ dbfexe.c (copie de travail)
@@ -499,32 +499,47 @@
tbl = &(db.tables[cur_cmp_table]);
- switch (tbl->cols[cur_cmp_ocol].type) {
- case DBF_CHAR:
- c1 = tbl->rows[*row1].values[cur_cmp_ocol].c;
- c2 = tbl->rows[*row2].values[cur_cmp_ocol].c;
- return (strcmp(c1, c2));
- break;
- case DBF_INT:
- i1 = tbl->rows[*row1].values[cur_cmp_ocol].i;
- i2 = tbl->rows[*row2].values[cur_cmp_ocol].i;
- if (i1 < i2)
- return -1;
- if (i1 > i2)
+ if (tbl->rows[*row1].values[cur_cmp_ocol].is_null) {
+ if (tbl->rows[*row2].values[cur_cmp_ocol].is_null) {
+ return 0;
+ }
+ else {
return 1;
- return 0;
- break;
- case DBF_DOUBLE:
- d1 = tbl->rows[*row1].values[cur_cmp_ocol].d;
- d2 = tbl->rows[*row2].values[cur_cmp_ocol].d;
- if (d1 < d2)
+ }
+ }
+ else {
+ if (tbl->rows[*row2].values[cur_cmp_ocol].is_null) {
return -1;
- if (d1 > d2)
- return 1;
- return 0;
- break;
+ }
+ else {
+ switch (tbl->cols[cur_cmp_ocol].type) {
+ case DBF_CHAR:
+ c1 = tbl->rows[*row1].values[cur_cmp_ocol].c;
+ c2 = tbl->rows[*row2].values[cur_cmp_ocol].c;
+ return (strcmp(c1, c2));
+ break;
+ case DBF_INT:
+ i1 = tbl->rows[*row1].values[cur_cmp_ocol].i;
+ i2 = tbl->rows[*row2].values[cur_cmp_ocol].i;
+ if (i1 < i2)
+ return -1;
+ if (i1 > i2)
+ return 1;
+ return 0;
+ break;
+ case DBF_DOUBLE:
+ d1 = tbl->rows[*row1].values[cur_cmp_ocol].d;
+ d2 = tbl->rows[*row2].values[cur_cmp_ocol].d;
+ if (d1 < d2)
+ return -1;
+ if (d1 > d2)
+ return 1;
+ return 0;
+ break;
+ }
+ return 0;
+ }
}
- return 0;
}
static int cmp_row_desc(const void *pa, const void *pb)
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user