|
From: <ki...@us...> - 2003-12-04 03:16:06
|
Update of /cvsroot/pymerase/pymerase/pymerase/output/dbAPI
In directory sc8-pr-cvs1:/tmp/cvs-serv3589
Modified Files:
init.pyt
Log Message:
Added getObjectCount and getObjectCountWhere functions to DBSession class.
Index: init.pyt
===================================================================
RCS file: /cvsroot/pymerase/pymerase/pymerase/output/dbAPI/init.pyt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** init.pyt 11 Nov 2003 02:05:27 -0000 1.1
--- init.pyt 4 Dec 2003 03:16:03 -0000 1.2
***************
*** 185,188 ****
--- 185,234 ----
sql = "SELECT * FROM \"%s\" where %s" % (class_ref.table_name, where_clause)
return self.loadRecords(class_ref, sql)
+
+ def getObjectCount(self, class_functor):
+ """
+ Returns the number of objects which exist for a given class
+ """
+ class_ref = self.__getClassRef(class_functor)
+
+ sql = "SELECT count(*) FROM \"%s\"" % (class_ref.table_name)
+
+ try:
+ cursor = self.db.cursor()
+ try:
+ cursor.execute(sql)
+ record = cursor.fetchone()
+ finally:
+ cursor.close()
+ except Exception, e:
+ # pgdb isn't too informative about exception
+ sys.stderr.write(str(e))
+ sys.stderr.write(os.linesep)
+
+ return record.pop()
+
+ def getObjectCountWhere(self, class_functor, where_clause):
+ """
+ Returns the number of objects which exist for a given class,
+ given a where clause.
+ """
+ class_ref = self.__getClassRef(class_functor)
+
+ sql = "SELECT count(*) FROM \"%s\" where %s" % (class_ref.table_name,
+ where_clause)
+
+ try:
+ cursor = self.db.cursor()
+ try:
+ cursor.execute(sql)
+ record = cursor.fetchone()
+ finally:
+ cursor.close()
+ except Exception, e:
+ # pgdb isn't too informative about exception
+ sys.stderr.write(str(e))
+ sys.stderr.write(os.linesep)
+
+ return record.pop()
def loadRecords(self, class_ref, sql):
|