On Wed, 2007-08-08 at 22:40 +0200, Markus Neteler wrote:
> Hi Didrik,
> 
> oh - the --q in my patch should have been -q.
> 
> Attached the revised patch. Due to failing of v.info
> the rest also fails (say, the new trick fails to
> work around the indicated problem).
> 
> Let me know,
> Markus
> 

Hi Markus,

The patch does not work :

----------------------------------------------------------------------------
GRASS 6.2.2 (ALMERIA):~/projets/ucl/alert/alertprog/grass > v.db.update
map=base_cells column=irrigated value="b_irr_area * area_new\
/ b_area_tot"
Sorry, <q> is not a valid flag

Description:
 Outputs basic information about a user-specified vector map layer.

Keywords:
 vector

Usage:
 v.info [-hcg] map=name [layer=value]

Flags:
  -h   Print vector history instead of info
  -c   Print types/names of table columns for specified layer instead of
info
  -g   Print vector map region only

Parameters:
    map   Name of input vector map
  layer   Layer number
          default: 1
DBMI-Postgres driver error:
Cannot execute: 
UPDATE base_cells SET irrigated='b_irr_area * area_new/ b_area_tot'

ERROR:  invalid input syntax for type double precision: "b_irr_area *
area_new/ b_area_tot"


ERROR: Error while executing: "UPDATE base_cells SET
irrigated='b_irr_area
       * area_new/ b_area_tot'
       "
----------------------------------------------------------------------------

Just removing the -q in the v.info line solved the problem and make it
work. I've attached the running version.

Didrik
Index: scripts/v.db.update/v.db.update
===================================================================
RCS file: /grassrepository/grass6/scripts/v.db.update/v.db.update,v
retrieving revision 1.6.4.5
diff -u -r1.6.4.5 v.db.update
--- scripts/v.db.update/v.db.update	15 May 2007 10:57:18 -0000	1.6.4.5
+++ scripts/v.db.update/v.db.update	8 Aug 2007 20:39:11 -0000
@@ -78,8 +78,12 @@
 LC_NUMERIC=C
 export LC_NUMERIC
 
-# does map exist?
-eval `g.findfile element=vector file=$GIS_OPT_MAP`
+### setup enviro vars ###
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+
+# does map exist in CURRENT mapset?
+eval `g.findfile element=vector file=$GIS_OPT_MAP mapset=$MAPSET`
 if [ ! "$file" ] ; then
    echo "Vector map '$GIS_OPT_MAP' not found in mapset search path"
    exit 1
@@ -94,11 +98,20 @@
 database=`v.db.connect $GIS_OPT_MAP -g | grep -w $GIS_OPT_LAYER | awk '{print $4}'`
 driver=`v.db.connect $GIS_OPT_MAP -g | grep -w $GIS_OPT_LAYER | awk '{print $5}'`
 
+# checking column types
+coltype=`v.info -c map=$GIS_OPT_MAP | grep -w $GIS_OPT_COLUMN | cut -d'|' -f1`
+# we insert a value
+if [ "$coltype" = "INTEGER" -o "$coltype" = "DOUBLE PRECISION" ] ; then
+    value=$GIS_OPT_VALUE
+else
+    value=\'$GIS_OPT_VALUE\'
+fi
+
 if [ -n "$GIS_OPT_WHERE" ]
   then
-	echo "UPDATE $table SET $GIS_OPT_COLUMN='$GIS_OPT_VALUE' WHERE $GIS_OPT_WHERE" | db.execute database=$database driver=$driver
-  else
-	echo "UPDATE $table SET $GIS_OPT_COLUMN='$GIS_OPT_VALUE'" | db.execute database=$database driver=$driver
+       echo "UPDATE $table SET $GIS_OPT_COLUMN=$value WHERE $GIS_OPT_WHERE" | db.execute database=$database driver=$driver
+else
+       echo "UPDATE $table SET $GIS_OPT_COLUMN=$value" | db.execute database=$database driver=$driver
 fi
 
 exit 0

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/pkg-grass-devel

Reply via email to