[GRASS-SVN] r54639 - grass/trunk/lib/python/pygrass/vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 15 05:10:48 PST 2013
Author: zarch
Date: 2013-01-15 05:10:48 -0800 (Tue, 15 Jan 2013)
New Revision: 54639
Modified:
grass/trunk/lib/python/pygrass/vector/table.py
Log:
Add update method to the Table class
Modified: grass/trunk/lib/python/pygrass/vector/table.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/table.py 2013-01-15 13:10:35 UTC (rev 54638)
+++ grass/trunk/lib/python/pygrass/vector/table.py 2013-01-15 13:10:48 UTC (rev 54639)
@@ -211,7 +211,11 @@
odict[name] = ctype
self.odict = odict
values = ','.join(['?', ] * self.__len__())
+ kv = ','.join(['%s=?' % k for k in self.odict.keys()])
+ 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,
+ values=kv, condition=where)
def sql_descr(self, remove=None):
"""Return a string with description of columns.
@@ -819,9 +823,9 @@
def __len__(self):
"""Return the nuber of rows"""
- return self.num_rows()
+ return self.n_rows()
- def num_rows(self):
+ def n_rows(self):
cur = self.conn.cursor()
cur.execute(sql.SELECT.format(cols='Count(*)', tname=self.name))
number = cur.fetchone()[0]
@@ -851,6 +855,15 @@
except:
raise ValueError("The SQL is not correct:\n%r" % sqlc)
- def insert(self, values):
+ def insert(self, values, many=False):
cur = self.conn.cursor()
- return cur.execute(self.columns.insert_str, values)
\ No newline at end of file
+ if many:
+ return cur.executemany(self.columns.insert_str, values)
+ return cur.execute(self.columns.insert_str, values)
+
+ def update(self, key, values):
+ cur = self.conn.cursor()
+ vals = list(values)
+ vals.append(key)
+ print self.columns.update_str, vals
+ return cur.execute(self.columns.update_str, vals)
\ No newline at end of file
More information about the grass-commit
mailing list