Browse Source

use the mapset's default DB instead of being locked to the one that layer 1 has used. (bug https://trac.osgeo.org/grass/ticket/809)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@40337 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 15 years ago
parent
commit
91ac27c5b9
2 changed files with 8 additions and 16 deletions
  1. 2 2
      scripts/v.db.addtable/v.db.addtable.html
  2. 6 14
      scripts/v.db.addtable/v.db.addtable.py

+ 2 - 2
scripts/v.db.addtable/v.db.addtable.html

@@ -18,8 +18,8 @@ and then use either a combinatino of <em>v.category</em> + <em>v.to.db</em> or
 <em><a href="wxGUI.Vector_Digitizing_Tool.html">wxGUI vector digitizer</a></em> to add the relevant lines to the table.
 <em><a href="wxGUI.Vector_Digitizing_Tool.html">wxGUI vector digitizer</a></em> to add the relevant lines to the table.
 
 
 The supported types of columns depend on the database backend. However, all
 The supported types of columns depend on the database backend. However, all
-backends should support VARCHAR, INT, DOUBLE PRECISION and DATE. The default
-dbf backend supports only these types.
+backends should support VARCHAR, INT, DOUBLE PRECISION and DATE.
+The dbf backend supports only these types.
 
 
 The existing database connection(s) can be verified with <em>v.db.connect</em>.
 The existing database connection(s) can be verified with <em>v.db.connect</em>.
 
 

+ 6 - 14
scripts/v.db.addtable/v.db.addtable.py

@@ -15,7 +15,7 @@
 #############################################################################
 #############################################################################
 
 
 #%Module
 #%Module
-#%  description: Creates and adds a new attribute table to a given layer of an existing vector map.
+#%  description: Creates and connects a new attribute table to a given layer of an existing vector map.
 #%  keywords: vector
 #%  keywords: vector
 #%  keywords: database
 #%  keywords: database
 #%  keywords: attribute table
 #%  keywords: attribute table
@@ -83,21 +83,13 @@ def main():
     # check if DB parameters are set, and if not set them.
     # 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')
 
 
-    #check if anything is connected:
-    nuldev = file(os.devnull, 'w')
-    db = grass.vector_db(map, stderr = nuldev)
-    if db:
-	f = db[min(db.keys())]
-	database = f['database']
-	driver = f['driver']
-    else:
-	# nothing defined
-	grass.message(_("Creating new DB connection based on default mapset settings..."))
-	kv = grass.db_connection()
-	database = kv['database']
-	driver = kv['driver']
+    grass.message(_("Creating new DB connection based on default mapset settings..."))
+    kv = grass.db_connection()
+    database = kv['database']
+    driver = kv['driver']
 
 
     # maybe there is already a table linked to the selected layer?
     # maybe there is already a table linked to the selected layer?
+    nuldev = file(os.devnull, 'w')
     try:
     try:
         grass.vector_db(map, stderr = nuldev)[int(layer)]
         grass.vector_db(map, stderr = nuldev)[int(layer)]
 	grass.fatal(_("There is already a table linked to layer <%s>") % layer)
 	grass.fatal(_("There is already a table linked to layer <%s>") % layer)