[GRASS-SVN] r36575 - grass/trunk/db/drivers/dbf

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 3 03:55:58 EDT 2009


Author: mlennert
Date: 2009-04-03 03:55:58 -0400 (Fri, 03 Apr 2009)
New Revision: 36575

Modified:
   grass/trunk/db/drivers/dbf/dbfexe.c
Log:
check for nulls and sort them to the end in ORDER BY clauses (merge from devel6 36574)


Modified: grass/trunk/db/drivers/dbf/dbfexe.c
===================================================================
--- grass/trunk/db/drivers/dbf/dbfexe.c	2009-04-03 07:49:23 UTC (rev 36574)
+++ grass/trunk/db/drivers/dbf/dbfexe.c	2009-04-03 07:55:58 UTC (rev 36575)
@@ -477,32 +477,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)



More information about the grass-commit mailing list