On Tue, May 13, 2008 at 4:31 PM, Thomas Kuczek <thomas...@gmail.com> wrote:
>
> I have a query object representing a query. How can I print the
> resulting Gql to log it with the logger framework?
>
> E.g:
> class Story(db.Model):
> title = db.StringProperty()
> date = db.DateTimeProperty()
>
> query = db.Query(Story)
>
> query.filter('title =', 'Foo')
> query.order('-date')
> query.ancestor(key)
>
> Now I would like to do something like:
> logging.debug('Gql is: %s', query)
I use monkey patching:
def wr(orig_func, self, *args, **kwargs):
t0 = time.time()
r = orig_func(self, *args, **kwargs)
t1 = time.time()
gqls_debugging.append( "%5.0fms GQL %s\n args: %r %r "
% ((t1-t0)*1000, ("%s" % self._ToPb()).replace("\n", "\n
").strip(), args, kwargs) )
return r
monkey_patch(datastore.Query, '_Run', wr)
Full code of my simplistic debugger:
http://ai.pjwstk.edu.pl/~majek/dump/debug.py
To use it you need to inherit from debug.DebugMiddleware
instead of webapp.RequestHandler. (I'm talking about webapp
framework, not django).
Some more information (look for 'debugging datastore access'):
http://popcnt.org/2008/05/google-app-engine-tips.html
Cheers!
Marek Majkowski
--
blog: http://popcnt.org/
Anyway what I am trying to say, is the code doesnt actully build a GQL
query, so if want one will have to build yourself.
See
http://googleappengine.googlecode.com/svn/trunk/google/appengine/ext/gql/__init__.py
--
Barry