[GRASS-SVN] r46968 - grass/branches/develbranch_6/db/drivers/dbf
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 4 10:24:11 EDT 2011
Author: mmetz
Date: 2011-07-04 07:24:11 -0700 (Mon, 04 Jul 2011)
New Revision: 46968
Modified:
grass/branches/develbranch_6/db/drivers/dbf/column.c
grass/branches/develbranch_6/db/drivers/dbf/cursor.c
grass/branches/develbranch_6/db/drivers/dbf/globals.h
grass/branches/develbranch_6/db/drivers/dbf/main.c
grass/branches/develbranch_6/db/drivers/dbf/main_debug.c
Log:
backport dbf driver patches from trunk
Modified: grass/branches/develbranch_6/db/drivers/dbf/column.c
===================================================================
--- grass/branches/develbranch_6/db/drivers/dbf/column.c 2011-07-04 11:07:18 UTC (rev 46967)
+++ grass/branches/develbranch_6/db/drivers/dbf/column.c 2011-07-04 14:24:11 UTC (rev 46968)
@@ -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/develbranch_6/db/drivers/dbf/cursor.c
===================================================================
--- grass/branches/develbranch_6/db/drivers/dbf/cursor.c 2011-07-04 11:07:18 UTC (rev 46967)
+++ grass/branches/develbranch_6/db/drivers/dbf/cursor.c 2011-07-04 14:24:11 UTC (rev 46968)
@@ -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/develbranch_6/db/drivers/dbf/globals.h
===================================================================
--- grass/branches/develbranch_6/db/drivers/dbf/globals.h 2011-07-04 11:07:18 UTC (rev 46967)
+++ grass/branches/develbranch_6/db/drivers/dbf/globals.h 2011-07-04 14:24:11 UTC (rev 46968)
@@ -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/develbranch_6/db/drivers/dbf/main.c
===================================================================
--- grass/branches/develbranch_6/db/drivers/dbf/main.c 2011-07-04 11:07:18 UTC (rev 46967)
+++ grass/branches/develbranch_6/db/drivers/dbf/main.c 2011-07-04 14:24:11 UTC (rev 46968)
@@ -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/develbranch_6/db/drivers/dbf/main_debug.c
===================================================================
--- grass/branches/develbranch_6/db/drivers/dbf/main_debug.c 2011-07-04 11:07:18 UTC (rev 46967)
+++ grass/branches/develbranch_6/db/drivers/dbf/main_debug.c 2011-07-04 14:24:11 UTC (rev 46968)
@@ -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