i am still seeking the way to log all sql query for SQLDB. the
following error still have error. i tried to look into sql.py but
really have no quick solution myself. the way  jonathan use to wrap
the whole db class seems working except when using  cache.

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.write('%s: %s\n' % (t0,db._lastsql))

db['_execute']=lambda f=db._execute,*a,**b: timer(db,lambda:f(*a,**b))

  File "gluon/sql.py", line 1184, in select
    r=response(query)
  File "gluon/sql.py", line 1180, in response
    self._db._execute(query)
  File "/home/web2py/applications/cychurch/models/db.py", line 255, in
<lambda>
    db['_execute']=lambda f=db._execute,*a,**b: timer(db,lambda:f
(*a,**b))
  File "/home/web2py/applications/cychurch/models/db.py", line 248, in
timer
    f()
  File "/home/web2py/applications/cychurch/models/db.py", line 255, in
<lambda>
    db['_execute']=lambda f=db._execute,*a,**b: timer(db,lambda:f
(*a,**b))
TypeError: 'str' object is not callable

-vince

On Dec 23, 9:41 pm, mdipierro <[email protected]> wrote:
> in latest trunk, _lastsql on GAE is a string but only says "select" ,
> "delete", "insert" etc. Better than nothing for now.
>
> Massimo
>
> On Dec 23, 12:14 am, Jonathan Benn <[email protected]> wrote:
>
> > Hi all,
>
> > On Dec 22, 12:43 pm, mdipierro <[email protected]> wrote:
>
> > > 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)
> > > db._execute=lambda *a,**b: timer(db,lambda:db._execute(*a,**b))
>
> > Unfortunately the above code doesn't work for for GAE. I tried the
> > following solution in my model:
>
> > import time, logging
> > class DatabaseDecorator(GQLDB):
> >     def __timer(self, where):
> >         if not self._lastsql:
> >             value = GQLDB.__call__(self, where)
> >         else:
> >             t0 = time.time()
> >             value = GQLDB.__call__(self, where)
> >             t1 = time.time() - t0
> >             logging.critical('%s : %.0f ms' % (self._lastsql, t1))
> >         return value
>
> >     def __call__(self, where=''):
> >         return self.__timer(where)
>
> > db=DatabaseDecorator()  # connect to Google BigTable
>
> > There's only one big problem: GQLDB._lastsql gives you Google's
> > "Query" object, which doesn't have a string representation.  I wonder
> > if there's an easy way to store the query string in GQLDB, as
> > GQLDB._lastsqlstring or something?
>
> > Sincerely,
>
> > --Jonathan
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to