[GRASS-SVN] r46969 - grass/branches/releasebranch_6_4/db/drivers/dbf

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 4 10:24:33 EDT 2011


Author: mmetz
Date: 2011-07-04 07:24:33 -0700 (Mon, 04 Jul 2011)
New Revision: 46969

Modified:
   grass/branches/releasebranch_6_4/db/drivers/dbf/column.c
   grass/branches/releasebranch_6_4/db/drivers/dbf/cursor.c
   grass/branches/releasebranch_6_4/db/drivers/dbf/dbfexe.c
   grass/branches/releasebranch_6_4/db/drivers/dbf/globals.h
   grass/branches/releasebranch_6_4/db/drivers/dbf/main.c
   grass/branches/releasebranch_6_4/db/drivers/dbf/main_debug.c
Log:
backport dbf driver patches from trunk

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/column.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/column.c	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/column.c	2011-07-04 14:24:33 UTC (rev 46969)
@@ -32,6 +32,16 @@
 	    "add_column(): tab = %d, type = %d, name = %s, width = %d, decimals = %d",
 	    tab, type, name, width, decimals);
 
+    /* truncate column name */
+    if (strlen(name) > DBF_COL_NAME - 1) {
+	char buf[2000];
+
+	sprintf(buf, "DBMI-DBF driver: column name '%s'", name);
+	name[DBF_COL_NAME - 1] = '\0';
+	sprintf(buf + strlen(buf), " truncated to '%s'", name);
+	G_warning(buf);
+    }
+
     /* Check if the column exists */
     for (c = 0; c < db.tables[tab].ncols; c++) {
 	if (G_strcasecmp(db.tables[tab].cols[c].name, name) == 0) {

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/cursor.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/cursor.c	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/cursor.c	2011-07-04 14:24:33 UTC (rev 46969)
@@ -47,6 +47,8 @@
 	return c;
     }
 
+    c->st = NULL;
+    c->cols = NULL;
     /* tokenize it */
     c->token = db_new_token(c);
     if (c->token < 0) {
@@ -62,5 +64,7 @@
 {
     db_drop_token(c->token);
     sqpFreeStmt(c->st);
+    if (c->cols)
+	G_free(c->cols);
     G_free(c);
 }

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/dbfexe.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/dbfexe.c	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/dbfexe.c	2011-07-04 14:24:33 UTC (rev 46969)
@@ -49,7 +49,7 @@
     ROW *dbrows;
     VALUE *dbval;
     int row, nrows;
-    int *cols, ncols, col;
+    int *cols = NULL, ncols, col;
     int *selset;
     int dtype, stype;
     int width, decimals;
@@ -311,6 +311,8 @@
     }
     if (st->command != SQLP_SELECT) {	/* because statement is released with cursor */
 	sqpFreeStmt(st);
+	if (cols)
+	    G_free(cols);
     }
 
     return DB_OK;

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/globals.h
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/globals.h	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/globals.h	2011-07-04 14:24:33 UTC (rev 46969)
@@ -1,6 +1,6 @@
 #include <grass/sqlp.h>
 
-#define DBF_COL_NAME 20		/* maximum column name (in fact shouldn't be > 10) */
+#define DBF_COL_NAME 11		/* maximum column name (10 characters plus \0) */
 
 /* 
  * DBF API:      http://shapelib.maptools.org/dbf_api.html
@@ -78,10 +78,5 @@
     int *order;			/* array of row indexes (sorted by ORDER BY) */
 } cursor;
 
-#ifdef MAIN
-DATABASE db;
-dbString *errMsg = NULL;
-#else
 extern DATABASE db;
 extern dbString *errMsg;
-#endif

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/main.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/main.c	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/main.c	2011-07-04 14:24:33 UTC (rev 46969)
@@ -15,7 +15,6 @@
 *
 *****************************************************************************/
 
-#define MAIN
 #include <stdlib.h>
 #include <string.h>
 #include <grass/dbmi.h>
@@ -23,6 +22,9 @@
 #include "proto.h"
 #include "dbdriver.h"
 
+DATABASE db;
+dbString *errMsg = NULL;
+
 int main(int argc, char *argv[])
 {
     char *name;

Modified: grass/branches/releasebranch_6_4/db/drivers/dbf/main_debug.c
===================================================================
--- grass/branches/releasebranch_6_4/db/drivers/dbf/main_debug.c	2011-07-04 14:24:11 UTC (rev 46968)
+++ grass/branches/releasebranch_6_4/db/drivers/dbf/main_debug.c	2011-07-04 14:24:33 UTC (rev 46969)
@@ -3,7 +3,6 @@
 * just a test for debugging purpose, imitating dbf driver -a.sh.
 *****************************************************************************/
 
-#define MAIN
 #include <stdlib.h>
 #include <grass/dbmi.h>
 #include <grass/gis.h>



More information about the grass-commit mailing list