Browse Source

fix drop table function

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55053 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 years ago
parent
commit
e171fd7284
1 changed files with 19 additions and 5 deletions
  1. 19 5
      lib/python/pygrass/vector/table.py

+ 19 - 5
lib/python/pygrass/vector/table.py

@@ -17,7 +17,9 @@ except:
 import grass.lib.vector as libvect
 import grass.lib.vector as libvect
 from grass.pygrass.gis import Mapset
 from grass.pygrass.gis import Mapset
 from grass.pygrass.errors import DBError
 from grass.pygrass.errors import DBError
-
+from grass.script.db import db_table_in_vector
+from grass.script.core import warning
+import sys
 import sql
 import sql
 
 
 
 
@@ -773,7 +775,7 @@ class DBlinks(object):
         if force:
         if force:
             link = self.by_name(key)
             link = self.by_name(key)
             table = link.table()
             table = link.table()
-            table._drop()
+            table.drop()
         if isinstance(key, str):
         if isinstance(key, str):
             key = self.from_name_to_num(key)
             key = self.from_name_to_num(key)
         libvect.Vect_map_del_dblink(self.c_mapinfo, key)
         libvect.Vect_map_del_dblink(self.c_mapinfo, key)
@@ -849,14 +851,26 @@ class Table(object):
         """Return the number of rows"""
         """Return the number of rows"""
         return self.n_rows()
         return self.n_rows()
 
 
-    def _drop(self, name=None):
+    def drop(self, name=None, force=False):
         """Private method to drop table from database"""
         """Private method to drop table from database"""
         if name:
         if name:
             name = name
             name = name
         else:
         else:
             name = self.name
             name = self.name
-        cur = self.conn.cursor()
-        cur.execute(sql.DROP_TAB.format(tname=name))
+        used = db_table_in_vector(name)
+        if len(used) > 0:
+            warning(_("Deleting table <%s> which is attached to following map(s):") % table)
+            for vect in used:
+                warning("%s" % vect)
+            if not force:
+                warning(_("You must use the force flag to actually remove it. Exiting."))
+                sys.exit(0)
+            else:
+                cur = self.conn.cursor()
+                cur.execute(sql.DROP_TAB.format(tname=name))
+        else:
+            cur = self.conn.cursor()
+            cur.execute(sql.DROP_TAB.format(tname=name))
 
 
     def n_rows(self):
     def n_rows(self):
         """Return the number of rows
         """Return the number of rows