|
@@ -55,34 +55,37 @@ import string
|
|
|
import grass.script as grass
|
|
|
|
|
|
def main():
|
|
|
- map = options['map']
|
|
|
- layer = options['layer']
|
|
|
+ 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"))
|
|
|
-
|
|
|
+ grass.fatal(_("There is no table connected to the input vector map. "
|
|
|
+ "Unable to delete any column. Exiting."))
|
|
|
+
|
|
|
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))
|
|
|
-
|
|
|
+ grass.fatal(_("Unable to delete <%s> column as it is needed to keep table <%s> "
|
|
|
+ "connected to the input vector map <%s>") % \
|
|
|
+ (column, 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"
|
|
|
+ # echo "Using special trick for SQLite"
|
|
|
# http://www.sqlite.org/faq.html#q13
|
|
|
colnames = []
|
|
|
coltypes = []
|
|
@@ -109,14 +112,14 @@ def main():
|
|
|
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', input = '-', database = database, driver = driver,
|
|
|
stdin = sql) != 0:
|
|
|
- grass.fatal(_("Cannot continue (problem deleting column)."))
|
|
|
-
|
|
|
+ grass.fatal(_("Deleting column failed"))
|
|
|
+
|
|
|
# write cmd history:
|
|
|
grass.vector_history(map)
|
|
|
-
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
options, flags = grass.parser()
|
|
|
main()
|