[GRASS-SVN] r60969 - grass/trunk/lib/python/pygrass/vector

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 25 07:33:27 PDT 2014


Author: zarch
Date: 2014-06-25 07:33:27 -0700 (Wed, 25 Jun 2014)
New Revision: 60969

Modified:
   grass/trunk/lib/python/pygrass/vector/table.py
Log:
Change Table update method to avoid to overwrite the primary key values and update the documentation

Modified: grass/trunk/lib/python/pygrass/vector/table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/table.py	2014-06-25 14:10:20 UTC (rev 60968)
+++ grass/trunk/lib/python/pygrass/vector/table.py	2014-06-25 14:33:27 UTC (rev 60969)
@@ -266,7 +266,7 @@
                 odict[name] = ctype
             self.odict = odict
         values = ','.join(['?', ] * self.__len__())
-        kv = ','.join(['%s=?' % k for k in self.odict.keys()])
+        kv = ','.join(['%s=?' % k for k in self.odict.keys() if k != self.key])
         where = "%s=?" % self.key
         self.insert_str = sql.INSERT.format(tname=self.tname, values=values)
         self.update_str = sql.UPDATE_WHERE.format(tname=self.tname,
@@ -1096,22 +1096,23 @@
             return cur.executemany(self.columns.insert_str, values)
         return cur.execute(self.columns.insert_str, values)
 
-    def update(self, key, values, cursor=None, many=False):
-        """Update a column for each row
+    def update(self, key, values, cursor=None):
+        """Update a table row
 
-        :param key: the name of column
-        :param values: the values to insert
-        :type values: str
+        :param key: the rowid
+        :type key: int
+        :param values: the values to insert without row id.
+                       For example if we have a table with four columns:
+                       cat, c0, c1, c2 the values list should
+                       containing only c0, c1, c2 values.
+        :type values: list
         :param cursor: the cursor to connect, if None it use the cursor
-                     of connection table object
+                       of connection table object
         :type cursor: Cursor object
-        :param many: True to run executemany function
-        :type many: bool
         """
         cur = cursor if cursor else self.conn.cursor()
-        vals = list(values)
-        vals.append(key)
-        return cur.execute(self.columns.update_str, vals)
+        values.append(key)
+        return cur.execute(self.columns.update_str, values)
 
     def create(self, cols, name=None, overwrite=False, cursor=None):
         """Create a new table



More information about the grass-commit mailing list