我有以下代码:

_q = db.Query("SELECT * FROM Area WHERE suburb_town_lower == :1", i.lower())
try:
    _areas = _q.fetch(1000)
except AttributeError, e:
    logging.info(e)
    logging.info(dir(_q))
    logging.info("Query: %s" % _q)
    logging.info("Area: %s" % i)
    logging.info("Area_: %s" % i.lower())
    return


我得到这个结果:

INFO     2012-03-04 16:54:38,489 dev_appserver.py:2884] "GET /import-data HTTP/1.1" 200 -
INFO     2012-03-04 16:54:38,758 dev_appserver.py:2884] "GET /favicon.ico HTTP/1.1" 200 -
INFO     2012-03-04 16:54:39,141 import_data.py:112] 'str' object has no attribute 'kind'
INFO     2012-03-04 16:54:39,142 import_data.py:113] ['_Query__ancestor', '_Query__filter_disjunction', '_Query__orderings', '_Query__query_sets', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getstate__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_app', '_compile', '_cursor', '_end_cursor', '_get_query', '_keys_only', '_model_class', '_namespace', 'ancestor', 'count', 'cursor', 'fetch', 'filter', 'get', 'is_keys_only', 'order', 'run', 'with_cursor']
INFO     2012-03-04 16:54:39,142 import_data.py:114] Query: <google.appengine.ext.db.Query object at 0xdb2a44c>
INFO     2012-03-04 16:54:39,143 import_data.py:115] Area: Blacktown City Council LG
INFO     2012-03-04 16:54:39,143 import_data.py:116] Area_: blacktown city council lg
INFO     2012-03-04 16:54:39,150 dev_appserver.py:2884] "POST /import-data/task HTTP/1.1" 200 -


提前致谢

最佳答案

有几件事对我来说是错误的:


我认为您不能像这样使用Query。看来您想使用GqlQuery代替。
在GQL中,相等运算符为=(不是==)。 Here's a link to the GQL syntax reference


例如:

_q = db.GqlQuery("SELECT * FROM Area WHERE suburb_town_lower = :1", i.lower())


我已经测试过这种查询在这里起作用:http://shell.appspot.com/

10-05 22:09