这是我的数据:
ID/名称 createdTime customerName itemName price 数量 status user_orderid id=5681726336532480 2013-10-12 05:07:47.794000 "joe" "Nexus 5" 349.00 1 "pending" "1"
运行这两个查询中的任何一个都会给我数据:
SELECT * FROM order
SELECT * FROM order ORDER BY createdTime DESC
但是运行以下命令什么也没给我:
SELECT * FROM order WHERE status = 'pending'
SELECT * FROM order WHERE status = 'pending' ORDER BY createdTime DESC
我在执行以下操作时看到了结果:
SELECT * FROM order WHERE status != 'pending'
所以我知道 WHERE 子句有一些效果。我只是无法在 GQL 查询中获得“待处理”来匹配数据存储中的“待处理”。
我的索引是这样定义的:
order status ▲ , createdTime ▼ Serving
我删除了记录并重新添加它以确保它是在索引到位后创建的。那没有帮助。我一遍又一遍地阅读 GQL 参考页面,但没有发现任何真正有用的东西。stackoverflow 上的一些帖子表明我执行 WHERE = 'string' 的语法是正确的。但无论我做什么,我都无法让它为数据存储查看器或尝试运行此查询的实际应用程序返回数据。
我在执行此处托管的 App Engine 代码实验室练习 8 时遇到了这个问题:http: //googcloudlabs.appspot.com/codelabexercise8.html
更新:这是所要求的模型:
/**
* <p>Java class for order complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="order">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="customer" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="user_orderid" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="item" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}positiveInteger"/>
* <element name="price" type="{http://www.w3.org/2001/XMLSchema}decimal"/>
* </sequence>
* <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}long" />
* </restriction>
* </complexContent>
* </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 ...
这是数据库索引:
<datastore-indexes>
<datastore-index kind="order" ancestor="false" source="auto">
<property name="status" direction="asc"/>
<property name="createdTime" direction="desc"/>
</datastore-index>
</datastore-indexes>
更新:已修复。数据应该是这样的,而不是我上面发布的。
ID/名称 createdTime customerName itemName price 数量 status user_orderid
id=5760616295825408 2013-10-12 19:25:13.098000 joe Nexus 5 349.00 1 pending 12