Browse Source

v.db.addtable: fails gracefully when vector is open level 1

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70373 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 years ago
parent
commit
be5a8a466b
1 changed files with 12 additions and 5 deletions
  1. 12 5
      scripts/v.db.addtable/v.db.addtable.py

+ 12 - 5
scripts/v.db.addtable/v.db.addtable.py

@@ -86,7 +86,7 @@ def main():
         grass.verbose(_("Using user specified table name: %s") % table)
 
     # check if DB parameters are set, and if not set them.
-    grass.run_command('db.connect', flags='c')
+    grass.run_command('db.connect', flags='c', quiet=True)
     grass.verbose(_("Creating new DB connection based on default mapset settings..."))
     kv = grass.db_connection()
     database = kv['database']
@@ -133,10 +133,17 @@ def main():
                       map=map_name, database=database, driver=driver,
                       layer=layer, table=table, key=key)
 
-    # finally we have to add cats into the attribute DB to make modules such as v.what.rast happy:
-    # (creates new row for each vector line):
-    grass.run_command('v.to.db', map=map_name, layer=layer,
-                      option='cat', column=key, qlayer=layer)
+    # finally we have to add cats into the attribute DB to make
+    # modules such as v.what.rast happy: (creates new row for each
+    # vector line):
+    try:
+        grass.run_command('v.to.db', map=map_name, layer=layer,
+                          option='cat', column=key, qlayer=layer)
+    except CalledModuleError:
+        # remove link
+        grass.run_command('v.db.connect', quiet=True, flags='d',
+                          map=map_name, layer=layer)
+        return 1
 
     grass.verbose(_("Current attribute table links:"))
     if grass.verbosity() > 2: