Search code examples
google-app-enginegqlgqlquery

GAE Datastore Viewer by GQL WHERE query for a String does not seem to work


Here is my data:

ID/Name createdTime customerName itemName price quantity status user_orderid id=5681726336532480 2013-10-12 05:07:47.794000 "joe" "Nexus 5" 349.00 1 "pending" "1"

Running either of these two queries gives me data:
SELECT * FROM order
SELECT * FROM order ORDER BY createdTime DESC

But running the following gives me nothing:
SELECT * FROM order WHERE status = 'pending'
SELECT * FROM order WHERE status = 'pending' ORDER BY createdTime DESC

I see results when doing the following:
SELECT * FROM order WHERE status != 'pending'

So I know that the WHERE clause is having some effect. I just can't get 'pending' in the GQL query to match "pending" in the datastore.

My index is defined as so:
order status ▲ , createdTime ▼ Serving

I deleted the record and re-adding it to make sure that it was created after the index was in place. That did not help. I read the GQL Reference page over and over but didn't find anything really helpful. Some posts on stackoverflow indicated that my syntax for doing a WHERE = 'string' is correct. But no matter what I do, I can't get this to return data either for the Datastore Viewer or my actual application which is trying to run this query.

I ran into this while doing the App Engine code lab Exercise 8 hosted here: http://googcloudlabs.appspot.com/codelabexercise8.html

Update: Here is the model as requested:

/**
 * <p>Java class for order complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="order">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="customer" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="user_orderid" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="item" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
 *         &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/>
 *       &lt;/sequence>
 *       &lt;attribute name="id" type="{http://www.w3.org/2001/XMLSchema}long" />
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "order", propOrder = {
    "customer",
    "status",
    "userOrderid",
    "item",
    "quantity",
    "price"
})
public class Order {

    @XmlElement(required = true)
    protected String customer;
    @XmlElement(required = true)
    protected String status;
    @XmlElement(name = "user_orderid", required = true)
    protected String userOrderid;
    @XmlElement(required = true)
    protected String item;
    @XmlElement(required = true)
    protected BigInteger quantity;
    @XmlElement(required = true)
    protected BigDecimal price;
    @XmlAttribute
    protected Long id;

    ... getters and setters ...

Here is the database index:

<datastore-indexes>
    <datastore-index kind="order" ancestor="false" source="auto">
        <property name="status" direction="asc"/>
        <property name="createdTime" direction="desc"/>
    </datastore-index>
</datastore-indexes>

Update: Fixed. The data should look like this instead of what I posted above.
ID/Name createdTime customerName itemName price quantity status user_orderid
id=5760616295825408 2013-10-12 19:25:13.098000 joe Nexus 5 349.00 1 pending 12


Solution

  • You have quote marks around several of the fields in your data, so it won't match your query. Clean up the data and you should be good to go.