What Does a Blank GQL Result Look Like?

风流意气都作罢 提交于 2019-12-13 02:38:07

问题


I am working on a Google App Engine application, and have been facing some issues with a GQL query and an if statement. This is the code:

q = Song.gql("WHERE title = :1", self.request.get('song_title'))
q.get()
  if q:
    r = "Excisting Results Found: <br />"
    print q
    for song in q:
      r += song.title+" by "+song.artist+"<br />"
    self.response.out.write(r)
  else: 
    ...

When this is run, the page returns "Excisting Results Found:" however I know that no results were in fact found. Is there a way to check if the results returned by the query are empty? What would a blank result returned from GqlQuery look like?

Any help would be greatly appreciated,
Thanks.


回答1:


In this example, q is a GQL query object. Although you can treat it as an iterable, calling get() on it will return a single result, and you'd need to assign this result to a variable. You can also check if there are results by checking if q.count(1) is greater than 0.



来源:https://stackoverflow.com/questions/1943924/what-does-a-blank-gql-result-look-like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!