Attached is a patch to allow the dal.py to keep track of query counts and types.
Usage >>> db.qry_count() {'SELECT': 5, 'INSERT': 2, 'DELETE': 1} Massimo, do you accept? -Thadeus -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
diff -r ef8d90c29480 gluon/dal.py --- a/gluon/dal.py Fri Mar 26 22:59:54 2010 -0500 +++ b/gluon/dal.py Mon Apr 05 14:15:40 2010 -0500 @@ -571,10 +571,25 @@ return False def log_execute(self,*a,**b): + # Make sure its defined! + if not self.__dict__.has_key('qry_count'): + self.qry_count = {} + self.db._lastsql = a[0] self.db._logger.write(datetime.datetime.now().isoformat()+'\n'+a[0]+'\n') try: ret = self.cursor.execute(*a,**b) + + # Get the type of the query, + # This is usually the first + # word of the SQL statement + qry_type = a[0].split(' ')[0] + + # Add to our counter + if self.qry_count.has_key(qry_type): + self.qry_count[qry_type] += 1 + else: + self.qry_count[qry_type] = 1 finally: self.db._logger.write(traceback.format_exc()) return ret @@ -2016,6 +2031,13 @@ if name.upper() in self.RSK[backend]: raise SyntaxError, 'invalid table/column name "%s" is a "%s" reserved SQL keyword' % (name, backend.upper()) + def qry_count(self): + if self._adapter.__dict__.has_key('qry_count'): + ret = self._adapter.qry_count + else: + ret = None + return ret + def define_table( self, tablename,