[GRASS-SVN] r34495 - grass/branches/develbranch_6/vector/v.to.db

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 26 04:28:30 EST 2008


Author: neteler
Date: 2008-11-26 04:28:30 -0500 (Wed, 26 Nov 2008)
New Revision: 34495

Modified:
   grass/branches/develbranch_6/vector/v.to.db/query.c
   grass/branches/develbranch_6/vector/v.to.db/update.c
Log:
fix to use qlayer to find table to read from (fixes wrong access if layer>1 is used) (merge from tunk, #34494)

Modified: grass/branches/develbranch_6/vector/v.to.db/query.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/query.c	2008-11-26 09:28:13 UTC (rev 34494)
+++ grass/branches/develbranch_6/vector/v.to.db/query.c	2008-11-26 09:28:30 UTC (rev 34495)
@@ -81,6 +81,8 @@
     if ((Fi = Vect_get_field(Map, options.qfield)) == NULL)
 	G_fatal_error(_("Database connection not defined for layer %d. Use v.db.connect first."),
 		      options.qfield);
+    G_debug(3, "Reading from map <%s>, query layer %d: updating table <%s>, column <%s>",
+            options.name, options.qfield, Fi->table, Fi->key);
 
     /* Open driver */
     driver = db_start_driver_open_database(Fi->driver, Fi->database);

Modified: grass/branches/develbranch_6/vector/v.to.db/update.c
===================================================================
--- grass/branches/develbranch_6/vector/v.to.db/update.c	2008-11-26 09:28:13 UTC (rev 34494)
+++ grass/branches/develbranch_6/vector/v.to.db/update.c	2008-11-26 09:28:30 UTC (rev 34495)
@@ -10,7 +10,7 @@
 {
     int i, *catexst, *cex, upd, fcat;
     char buf1[2000], buf2[2000], left[20], right[20];
-    struct field_info *Fi;
+    struct field_info *qFi, *Fi;
     dbString stmt;
     dbDriver *driver;
 
@@ -22,9 +22,16 @@
 
     db_init_string(&stmt);
 
+    /* layer to find table to read from */
+    if ((qFi = Vect_get_field(Map, options.qfield)) == NULL)
+        G_fatal_error(_("Database connection not defined for layer %d. Use v.db.connect first."),
+                      options.qfield);
+    /* layer to find table to write to */
     if ((Fi = Vect_get_field(Map, options.field)) == NULL)
 	G_fatal_error(_("Database connection not defined for layer %d. Use v.db.connect first."),
 		      options.field);
+    G_debug(3, "Reading from map <%s>, query layer %d: updating table <%s>, column <%s>", 
+            options.name, options.qfield, Fi->table, Fi->key);
 
     /* Open driver */
     driver = db_start_driver_open_database(Fi->driver, Fi->database);
@@ -36,7 +43,7 @@
     db_begin_transaction(driver);
 
     /* select existing categories to array (array is sorted) */
-    vstat.select = db_select_int(driver, Fi->table, Fi->key, NULL, &catexst);
+    vstat.select = db_select_int(driver, qFi->table, Fi->key, NULL, &catexst);
 
     /* create beginning of stmt */
     switch (options.option) {
@@ -62,6 +69,8 @@
 	break;
     }
 
+    G_debug(3, "Existing categories: %d", vstat.rcat);
+
     /* update */
     G_message(_("Updating database..."));
     for (i = 0; i < vstat.rcat; i++) {
@@ -180,6 +189,7 @@
 	    }
 	}
 
+	G_debug(3, "SQL: %s", buf2);
 	db_set_string(&stmt, buf2);
 
 	/* category exist in DB ? */



More information about the grass-commit mailing list