db._execute=lambda *a,**b: timer(db,lambda:db._execute(*a,**b))
File "gluon/sql.py", line 305, in __setattr__
raise SyntaxError, 'Object exists and cannot be redefined'
SyntaxError: Object exists and cannot be redefined
On Dec 22, 5: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))
>
> On Dec 22, 2:54 am, vince <[email protected]> wrote:
>
> > db._lastsql only record the last sql query right? is that any easy way
> > to log all the sql query it's executing to a file like sql.log does
> > for table update? i think it's really useful for preference fine tune.
>
> > -vince
>
> > On Dec 22, 4:26 pm, mdipierro <[email protected]> wrote:
>
> > > Will think about it but for now:
>
> > > def timer(myfile,db,f):
> > > import time
> > > t0=time.time()
> > > f()
> > > t0=time.time()-t0
> > > myfile.wriite('%s: %s\n' % (t0,db._lastsql)
>
> > > myfile=open('mylogfile.log','w')
> > > rows=timer(myfile,db,lambda:db(db.table.id>0).select())
>
> > > Massimo
>
> > > On Dec 22, 1:04 am, Jonathan Benn <[email protected]> wrote:
>
> > > > Hi,
>
> > > > On Dec 22, 4:52 am, vince <[email protected]> wrote:
>
> > > > > also is it possible to enable logging for all SQL query execution?
>
> > > > Logging with a timer included would be really handy.
>
> > > > 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
-~----------~----~----~----~------~----~------~--~---