I have a simple question:
In GQL syntax summary
<condition> := <property> {< | <= | > | >= | = | != } <value>
but in an example here
if users.get_current_user():
user_pets = db.GqlQuery("SELECT * FROM Pet WHERE owner = :1",
users.get_current_user())
What is :1 ?
According to syntax there should be := there.
Thanks.
The GQL grammar on the syntax link you posted is this:
The
:=in the last three lines means that<condition>in the main expression can be replaced with the expression to the right of the:=in any of the three<condition>statements.In the example, they have chosen to select
*instead of__key__, the<kind>isPet, there is only oneWHEREcondition, and there are noORDER BY,LIMITorOFFSETclauses.So the main expression simplifies to:
We can then substitute the first condition expression, ie:
Resulting in:
In the example,
<property>isowner, the operator is=, and the<value>is:1, ie:According to the documentation for the
GqlQueryclass, the :1 means that the value will be bound to the first argument toGqlQuery()(after the query). So in the example, the value isusers.get_current_user().Update:
I don’t think either of those would work, because they are both missing a double quote to end the string of the query. However, both of the following should work:
Once you have the query object you can call
fetch()on it to get the items as a list. Or, you can also iterate directly over the query.