Some of the information here may be outdated, please check the book instead
[edit]

The following code will log each of your database queries to a file, along with the amount of time it took for the query to execute.

This should work on any platform except for Google App Engine (on GAE you cannot write to a file).

db=SQLDB(...)
def timer(db,f):
  import time,os
  import gluon.portalocker
  myfile=open(os.path.join(request.folder,'databases','sql.log'),'a')
  gluon.portalocker,lock(myfile, gluon.portalocker.LOCK_EX)
  t0=time.time()
  f()
  t0=time.time()-t0
  gluon.portalocker,unlock(myfile)
  myfile.wriite('%s: %s\n' % (t0,db._lastsql)
_old_execute=db._execute
db['_execute']=lambda *a,**b: timer(db,lambda:_old_execute(*a,**b))
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.