什么是空白的GQL结果? [英] What Does a Blank GQL Result Look Like?
问题描述
我正在研究Google App Engine应用程序,并且在使用GQL查询和if语句时遇到了一些问题。这是代码:
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:
...
运行此操作时,页面会返回找到的已发现结果:但我知道实际上没有找到结果。有没有办法检查查询返回的结果是否为空?从 GqlQuery
look 返回的空白结果是什么样的?
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.
推荐答案
在这个例子中,q是一个GQL查询对象。虽然你可以把它当作一个迭代对象,但是调用get()会返回一个结果,并且你需要将这个结果赋值给一个变量。您也可以通过检查q.count(1)是否大于0来检查是否有结果。
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.
这篇关于什么是空白的GQL结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!