简体   繁体   English

Google App Engine查询数据按字符串开头存储

[英]Google App Engine query data store by a string start with

How to write a query that can find me all item_number start with a certain value ? 如何编写一个查询,可以找到我所有item_number以某个值开始?

For instance there are item_numbers like these : 例如,有这样的item_numbers:

123_abc
123_xyz
ierireire
321_add
999_pop

My current query looks like this : 我当前的查询如下所示:

"select from "+PayPal_Message.class.getName()+" where item_number == '"+Item_Number+"' order by item_number desc" “select from”+ PayPal_Message.class.getName()+“where item_number =='”+ Item_Number +“'order by item_number desc”

What's a query look like that can return all item_numbers start with "123_" ? 什么是查询看起来可以返回所有item_numbers以“123_”开头?

Quoted from the google app engine docs: 引自谷歌应用引擎文档:

Tip : Query filters do not have an explicit way to match just part of a string value, but you can fake a prefix match using inequality filters: 提示 :查询过滤器没有明确的方法来匹配字符串值的一部分,但您可以使用不等式过滤器伪造前缀匹配:

db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND prop < :2", "abc", u"abc" + u"\ufffd")

This matches every MyModel entity with a string property prop that begins with the characters abc . 这将匹配每个MyModel实体,其字符串属性prop以字符abc开头。 The unicode string u"\�" represents the largest possible Unicode character. unicode字符串u"\�"表示最大可能的Unicode字符。 When the property values are sorted in an index, the values that fall in this range are all of the values that begin with the given prefix. 当属性值在索引中排序时,属于此范围的值是以给定前缀开头的所有值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM