[GRASS-SVN] r38095 - in grass/trunk/scripts: . v.db.dropcolumn

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 27 06:57:45 EDT 2009


Author: martinl
Date: 2009-06-27 06:57:45 -0400 (Sat, 27 Jun 2009)
New Revision: 38095

Added:
   grass/trunk/scripts/v.db.dropcolumn/
   grass/trunk/scripts/v.db.dropcolumn/Makefile
   grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.html
   grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.py
Removed:
   grass/trunk/scripts/v.db.dropcol/
   grass/trunk/scripts/v.db.dropcolumn/Makefile
   grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.html
   grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.py
Log:
v.db.dropcol renamed to v.db.dropcolumn (part 2)



Property changes on: grass/trunk/scripts/v.db.dropcolumn
___________________________________________________________________
Added: svn:mergeinfo
   + 

Deleted: grass/trunk/scripts/v.db.dropcolumn/Makefile
===================================================================
--- grass/trunk/scripts/v.db.dropcol/Makefile	2009-06-26 23:14:44 UTC (rev 38090)
+++ grass/trunk/scripts/v.db.dropcolumn/Makefile	2009-06-27 10:57:45 UTC (rev 38095)
@@ -1,7 +0,0 @@
-MODULE_TOPDIR = ../..
-
-PGM = v.db.dropcol
-
-include $(MODULE_TOPDIR)/include/Make/Script.make
-
-default: script

Copied: grass/trunk/scripts/v.db.dropcolumn/Makefile (from rev 38094, grass/trunk/scripts/v.db.dropcol/Makefile)
===================================================================
--- grass/trunk/scripts/v.db.dropcolumn/Makefile	                        (rev 0)
+++ grass/trunk/scripts/v.db.dropcolumn/Makefile	2009-06-27 10:57:45 UTC (rev 38095)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.db.dropcolumn
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Deleted: grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.html
===================================================================
--- grass/trunk/scripts/v.db.dropcol/v.db.dropcol.html	2009-06-26 23:14:44 UTC (rev 38090)
+++ grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.html	2009-06-27 10:57:45 UTC (rev 38095)
@@ -1,38 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.db.dropcol</em> drops a column from the attribute table connected
-to a given vector map. It automatically checks the connection for the specified
-layer. <em>v.db.dropcol</em> omits to delete the 'cat' column which is
-relevant to keep the connection between vector map and table.
-
-<h2>NOTES</h2>
-
-v.db.dropcol is a front-end to <em>db.execute</em> to allow easier usage.
-
-The existing database connection(s) can be verified with <em>v.db.connect</em>.
-
-<h2>EXAMPLES</h2>
-
-Dropping a column:<br>
-<div class="code"><pre>
-v.db.dropcol sentiero_brenta_points column=slope
-v.info -c sentiero_brenta_points
-</pre></div>
-
-<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>,
-<em><a HREF="v.db.connect.html">v.db.connect</a></em>,
-<em><a HREF="v.db.droptable.html">v.db.droptable</a></em>,
-<em><a HREF="v.db.select.html">v.db.select</a></em>,
-<em><a HREF="v.db.update.html">v.db.update</a></em>
-
-
-<h2>AUTHOR</h2>
-
-Markus Neteler
-
-<p><i>Last changed: $Date$</i>

Deleted: grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.py
===================================================================
--- grass/trunk/scripts/v.db.dropcol/v.db.dropcol.py	2009-06-26 23:14:44 UTC (rev 38090)
+++ grass/trunk/scripts/v.db.dropcolumn/v.db.dropcol.py	2009-06-27 10:57:45 UTC (rev 38095)
@@ -1,120 +0,0 @@
-#!/usr/bin/env python
-
-############################################################################
-#
-# MODULE:       v.db.dropcolumn
-# AUTHOR(S):    Markus Neteler
-#               Converted to Python by Glynn Clements
-# PURPOSE:      interface to db.execute to drop a column from the 
-#               attribute table connected to a given vector map
-#               - Based on v.db.addcol
-#               - with special trick for SQLite
-# COPYRIGHT:    (C) 2007 by 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 a column from the attribute table connected to a given vector map.
-#%  keywords: vector, database, attribute table
-#%End
-
-#%option
-#% key: map
-#% type: string
-#% gisprompt: old,vector,vector
-#% key_desc : name
-#% description: Vector map for which to drop attribute column
-#% required : yes
-#%end
-
-#%option
-#% key: layer
-#% type: integer
-#% description: Layer where to drop column
-#% answer: 1
-#% required : no
-#%end
-
-#%option
-#% key: column
-#% type: string
-#% description: Name of the column
-#% required : yes
-#%end
-
-import sys
-import os
-import string
-import grass.script as grass
-
-def main():
-    map = options['map']
-    layer = options['layer']
-    column = options['column']
-
-    mapset = grass.gisenv()['MAPSET']
-
-    # does map exist in CURRENT mapset?
-    if not grass.find_file(map, element = 'vector', mapset = mapset):
-	grass.fatal("Vector map <%s> not found in current mapset" % map)
-
-    f = grass.vector_layer_db(map, layer)
-
-    table = f['table']
-    keycol = f['key']
-    database = f['database']
-    driver = f['driver']
-
-    if not table:
-	grass.fatal("There is no table connected to the input vector map Cannot delete any column")
-
-    if column == keycol:
-	grass.fatal("Cannot delete <$col> column as it is needed to keep table <%s> connected to the input vector map <%s>" % (table, map))
-
-    if not grass.vector_columns(map, layer).has_key(column):
-	grass.fatal("Column <%s> not found in table <%s>" % (column, table))
-
-    if driver == "sqlite":
-	#echo "Using special trick for SQLite"
-	# http://www.sqlite.org/faq.html#q13
-	colnames = []
-	coltypes = []
-	for f in grass.db_describe(table)['cols']:
-	    if f[0] == column:
-		continue
-	    colnames.append(f[0])
-	    coltypes.append("%s %s" % (f[0], f[1]))
-
-	colnames = ", ".join(colnames)
-	coltypes = ", ".join(coltypes)
-
-	cmds = [
-	    "BEGIN TRANSACTION",
-	    "CREATE TEMPORARY TABLE ${table}_backup(${coldef})",
-	    "INSERT INTO ${table}_backup SELECT ${colnames} FROM ${table}",
-	    "DROP TABLE ${table}",
-	    "CREATE TABLE ${table}(${coldef})",
-	    "INSERT INTO ${table} SELECT ${colnames} FROM ${table}_backup",
-	    "DROP TABLE ${table}_backup",
-	    "COMMIT"
-	    ]
-	tmpl = string.Template(';\n'.join(cmds))
-	sql = tmpl.substitute(table = table, coldef = coltypes, colnames = colnames)
-    else:
-	sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
-
-    if grass.write_command('db.execute', database = database, driver = driver,
-			   stdin = sql) != 0:
-	grass.fatal("Cannot continue (problem deleting column).")
-
-    # write cmd history:
-    grass.vector_history(map)
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()

Copied: grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.html (from rev 38094, grass/trunk/scripts/v.db.dropcol/v.db.dropcolumn.html)
===================================================================
--- grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.html	                        (rev 0)
+++ grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.html	2009-06-27 10:57:45 UTC (rev 38095)
@@ -0,0 +1,38 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.db.dropcolumn</em> drops a column from the attribute table connected
+to a given vector map. It automatically checks the connection for the specified
+layer. <em>v.db.dropcolumn</em> omits to delete the 'cat' column which is
+relevant to keep the connection between vector map and table.
+
+<h2>NOTES</h2>
+
+v.db.dropcolumn is a front-end to <em>db.execute</em> to allow easier usage.
+
+The existing database connection(s) can be verified with <em>v.db.connect</em>.
+
+<h2>EXAMPLES</h2>
+
+Dropping a column:<br>
+<div class="code"><pre>
+v.db.dropcolumn sentiero_brenta_points column=slope
+v.info -c sentiero_brenta_points
+</pre></div>
+
+<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>,
+<em><a HREF="v.db.connect.html">v.db.connect</a></em>,
+<em><a HREF="v.db.droptable.html">v.db.droptable</a></em>,
+<em><a HREF="v.db.select.html">v.db.select</a></em>,
+<em><a HREF="v.db.update.html">v.db.update</a></em>
+
+
+<h2>AUTHOR</h2>
+
+Markus Neteler
+
+<p><i>Last changed: $Date$</i>

Copied: grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.py (from rev 38094, grass/trunk/scripts/v.db.dropcol/v.db.dropcolumn.py)
===================================================================
--- grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.py	                        (rev 0)
+++ grass/trunk/scripts/v.db.dropcolumn/v.db.dropcolumn.py	2009-06-27 10:57:45 UTC (rev 38095)
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       v.db.dropcolumn
+# AUTHOR(S):    Markus Neteler
+#               Converted to Python by Glynn Clements
+# PURPOSE:      interface to db.execute to drop a column from the 
+#               attribute table connected to a given vector map
+#               - Based on v.db.addcol
+#               - with special trick for SQLite
+# COPYRIGHT:    (C) 2007 by 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 a column from the attribute table connected to a given vector map.
+#%  keywords: vector, database, attribute table
+#%End
+
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc : name
+#% description: Vector map for which to drop attribute column
+#% required : yes
+#%end
+
+#%option
+#% key: layer
+#% type: integer
+#% description: Layer where to drop column
+#% answer: 1
+#% required : no
+#%end
+
+#%option
+#% key: column
+#% type: string
+#% description: Name of the column
+#% required : yes
+#%end
+
+import sys
+import os
+import string
+import grass.script as grass
+
+def main():
+    map = options['map']
+    layer = options['layer']
+    column = options['column']
+
+    mapset = grass.gisenv()['MAPSET']
+
+    # does map exist in CURRENT mapset?
+    if not grass.find_file(map, element = 'vector', mapset = mapset):
+	grass.fatal("Vector map <%s> not found in current mapset" % map)
+
+    f = grass.vector_layer_db(map, layer)
+
+    table = f['table']
+    keycol = f['key']
+    database = f['database']
+    driver = f['driver']
+
+    if not table:
+	grass.fatal("There is no table connected to the input vector map Cannot delete any column")
+
+    if column == keycol:
+	grass.fatal("Cannot delete <$col> column as it is needed to keep table <%s> connected to the input vector map <%s>" % (table, map))
+
+    if not grass.vector_columns(map, layer).has_key(column):
+	grass.fatal("Column <%s> not found in table <%s>" % (column, table))
+
+    if driver == "sqlite":
+	#echo "Using special trick for SQLite"
+	# http://www.sqlite.org/faq.html#q13
+	colnames = []
+	coltypes = []
+	for f in grass.db_describe(table)['cols']:
+	    if f[0] == column:
+		continue
+	    colnames.append(f[0])
+	    coltypes.append("%s %s" % (f[0], f[1]))
+
+	colnames = ", ".join(colnames)
+	coltypes = ", ".join(coltypes)
+
+	cmds = [
+	    "BEGIN TRANSACTION",
+	    "CREATE TEMPORARY TABLE ${table}_backup(${coldef})",
+	    "INSERT INTO ${table}_backup SELECT ${colnames} FROM ${table}",
+	    "DROP TABLE ${table}",
+	    "CREATE TABLE ${table}(${coldef})",
+	    "INSERT INTO ${table} SELECT ${colnames} FROM ${table}_backup",
+	    "DROP TABLE ${table}_backup",
+	    "COMMIT"
+	    ]
+	tmpl = string.Template(';\n'.join(cmds))
+	sql = tmpl.substitute(table = table, coldef = coltypes, colnames = colnames)
+    else:
+	sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
+
+    if grass.write_command('db.execute', database = database, driver = driver,
+			   stdin = sql) != 0:
+	grass.fatal("Cannot continue (problem deleting column).")
+
+    # write cmd history:
+    grass.vector_history(map)
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()



More information about the grass-commit mailing list