[GRASS-SVN] r29538 - in grass/trunk/scripts: . db.dropcol db.droptable v.db.addtable v.db.dropcol v.db.droptable

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 30 06:48:58 EST 2007


Author: neteler
Date: 2007-12-30 06:48:58 -0500 (Sun, 30 Dec 2007)
New Revision: 29538

Added:
   grass/trunk/scripts/db.droptable/
   grass/trunk/scripts/db.droptable/Makefile
   grass/trunk/scripts/db.droptable/db.droptable
   grass/trunk/scripts/db.droptable/description.html
Modified:
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/db.dropcol/description.html
   grass/trunk/scripts/v.db.addtable/description.html
   grass/trunk/scripts/v.db.dropcol/description.html
   grass/trunk/scripts/v.db.droptable/description.html
Log:
new db.droptable command

Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2007-12-30 11:47:46 UTC (rev 29537)
+++ grass/trunk/scripts/Makefile	2007-12-30 11:48:58 UTC (rev 29538)
@@ -19,6 +19,7 @@
 	d.text.freetype \
 	d.vect.thematic \
 	db.dropcol \
+	db.droptable \
 	db.in.ogr \
 	db.out.ogr \
 	db.test \

Modified: grass/trunk/scripts/db.dropcol/description.html
===================================================================
--- grass/trunk/scripts/db.dropcol/description.html	2007-12-30 11:47:46 UTC (rev 29537)
+++ grass/trunk/scripts/db.dropcol/description.html	2007-12-30 11:48:58 UTC (rev 29538)
@@ -30,6 +30,7 @@
 
 <h2>SEE ALSO</h2>
 
+<em><a HREF="db.droptable.html">db.droptable</a></em>,
 <em><a HREF="db.execute.html">db.execute</a></em>,
 <em><a HREF="v.db.dropcol.html">v.db.dropcol</a></em>
 

Added: grass/trunk/scripts/db.droptable/Makefile
===================================================================
--- grass/trunk/scripts/db.droptable/Makefile	                        (rev 0)
+++ grass/trunk/scripts/db.droptable/Makefile	2007-12-30 11:48:58 UTC (rev 29538)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = db.droptable
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass/trunk/scripts/db.droptable/Makefile
___________________________________________________________________
Name: svn:eol-style
   + native

Added: grass/trunk/scripts/db.droptable/db.droptable
===================================================================
--- grass/trunk/scripts/db.droptable/db.droptable	                        (rev 0)
+++ grass/trunk/scripts/db.droptable/db.droptable	2007-12-30 11:48:58 UTC (rev 29538)
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       db.droptable
+# AUTHOR(S):   	Markus Neteler
+# PURPOSE:      interface to db.execute to drop an attribute table
+# COPYRIGHT:    (C) 2007 by Markus Neteler and the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+
+#%Module
+#%  description: Drops an attribute table
+#%  keywords: database, attribute table
+#%End
+
+#%flag
+#%  key: f
+#%  description: Force removal (required for actual deletion of files)
+#%end
+
+#%option
+#% key: table
+#% type: string
+#% key_desc : name
+#% description: Table to drop
+#% required : yes
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." >&2
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+fi
+
+PROG=`basename $0`
+
+# setting environment, so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+# what to do in case of user break:
+exitprocedure()
+{
+ g.message -e 'User break!'
+ exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exitprocedure" 2 3 15
+
+### setup enviro vars ###
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+
+table=$GIS_OPT_TABLE
+database=`db.connect -p | grep 'database' | cut -d ':' -f2`
+driver=`db.connect -p | grep 'driver' | cut -d ':' -f2`
+# schema needed for PG?
+col="$GIS_OPT_COLUMN"
+
+force=$GIS_FLAG_F
+if [ $force -eq 1 ] ; then
+   g.message "Forcing ..."
+fi
+
+# check if table exists
+db.describe -c $GIS_OPT_TABLE 2>/dev/null
+if [ $? -ne 0 ] ; then
+        g.message -e "Table <$table> not found in current mapset"
+        exit 1
+fi
+
+# check if table is used somewhere (connected to vector map)
+USEDINMAPS="`grep $table ${GISDBASE}/${LOCATION_NAME}/*/vector/*/dbln | cut -d':' -f1 | sed 's+/dbln++g'`"
+if  [ ! -z "$USEDINMAPS" ] ; then
+   g.message -w "Deleting <$table> table which is attached to following map(s):"
+   for i in $USEDINMAPS ; do
+       echo "`basename $i`"
+   done
+fi
+
+if [ $force -eq 0 ] ; then
+    g.message "The <$table> table would be deleted."
+    g.message message=""
+    g.message "You must use the force flag to actually remove it. Exiting."
+    exit 0
+fi
+
+
+echo "DROP TABLE $table" | db.execute database=$database driver=$driver
+if [ $? -eq 1 ] ; then
+  	g.message -e "Cannot continue (problem deleting column)."
+    	exit 1
+fi
+
+exit 0


Property changes on: grass/trunk/scripts/db.droptable/db.droptable
___________________________________________________________________
Name: svn:executable
   + *

Added: grass/trunk/scripts/db.droptable/description.html
===================================================================
--- grass/trunk/scripts/db.droptable/description.html	                        (rev 0)
+++ grass/trunk/scripts/db.droptable/description.html	2007-12-30 11:48:58 UTC (rev 29538)
@@ -0,0 +1,38 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.droptable</em> drops an attribute table.
+If the <b>-f</b> force flag is not given then nothing is removed, instead
+a preview of the action to be taken is printed.
+
+<h2>NOTES</h2>
+
+<em>db.droptable</em> is a front-end to <em>db.execute</em> to allow easier
+usage. To some extent it is verified if the table is connected to a vector map.
+
+<h2>EXAMPLES</h2>
+
+Dropping a table (Spearfish):
+<p>
+<div class="code"><pre>
+# work on own copy
+g.copy vect=roads,myroads
+
+# only shows what would happen
+db.droptable myroads
+
+# actually drop the table
+db.droptable -f myroads
+
+db.tables -p
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="db.execute.html">db.execute</a></em>,
+<em><a HREF="v.db.droptable.html">v.db.droptable</a></em>
+
+<h2>AUTHOR</h2>
+
+Markus Neteler
+
+<p><i>Last changed: $Date: 2007-07-14 12:59:51 +0200 (Sat, 14 Jul 2007) $</i>

Modified: grass/trunk/scripts/v.db.addtable/description.html
===================================================================
--- grass/trunk/scripts/v.db.addtable/description.html	2007-12-30 11:47:46 UTC (rev 29537)
+++ grass/trunk/scripts/v.db.addtable/description.html	2007-12-30 11:48:58 UTC (rev 29538)
@@ -35,6 +35,7 @@
 <h2>SEE ALSO</h2>
 
 <em><a HREF="db.connect.html">db.connect</a></em>,
+<em><a HREF="db.droptable.html">db.droptable</a></em>,
 <em><a HREF="db.execute.html">db.execute</a></em>,
 <em><a HREF="v.db.addcol.html">v.db.addcol</a></em>,
 <em><a HREF="v.db.connect.html">v.db.connect</a></em>,

Modified: grass/trunk/scripts/v.db.dropcol/description.html
===================================================================
--- grass/trunk/scripts/v.db.dropcol/description.html	2007-12-30 11:47:46 UTC (rev 29537)
+++ grass/trunk/scripts/v.db.dropcol/description.html	2007-12-30 11:48:58 UTC (rev 29538)
@@ -21,6 +21,7 @@
 
 <h2>SEE ALSO</h2>
 
+<em><a HREF="db.droptable.html">db.droptable</a></em>,
 <em><a HREF="db.execute.html">db.execute</a></em>,
 <em><a HREF="v.db.addcol.html">v.db.addcol</a></em>,
 <em><a HREF="v.db.addtable.html">v.db.addtable</a></em>,

Modified: grass/trunk/scripts/v.db.droptable/description.html
===================================================================
--- grass/trunk/scripts/v.db.droptable/description.html	2007-12-30 11:47:46 UTC (rev 29537)
+++ grass/trunk/scripts/v.db.droptable/description.html	2007-12-30 11:48:58 UTC (rev 29538)
@@ -20,6 +20,7 @@
 
 <h2>SEE ALSO</h2>
 
+<em><a HREF="db.droptable.html">db.droptable</a></em>,
 <em><a HREF="db.execute.html">db.execute</a></em>,
 <em><a HREF="v.db.addcol.html">v.db.addcol</a></em>,
 <em><a HREF="v.db.addtable.html">v.db.addtable</a></em>,



More information about the grass-commit mailing list