对StringProperty的gql查询中的where子句不区分大小写 [英] Case insensitive where clause in gql query for StringProperty

查看:138
本文介绍了对StringProperty的gql查询中的where子句不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用google appengine数据存储,是否有一种方法可以执行gql查询,该查询在不区分大小写的StringProperty数据类型上指定WHERE子句?我并不总是知道价值会在什么情况下。文档指定了我的值的区分大小写,有没有办法使这种不敏感?



例如db模型应该是这样的:

  from google.appengine.ext import db 
class Product(db。模型):
id = db.IntegerProperty()
category = db.StringProperty()

,数据如下所示:

  id分类
========= ==========
1 cat1
2 cat2
3 Cat1
4 CAT1
5 CAT3
6 Cat4
7 CaT1
8 CAT5

我想说

  gqlstring =WHERE category ='{0}'。format('cat1')
returnvalue = Product.gql(gqlstring)

并且包含 returnvalue 包含

  id分类
===================
1 cat1
3 Cat1
4 CAT1
7 CaT1


解决方案

我不认为数据存储中有这样的运算符。 / p>

您是否控制类别数据的输入?如果是这样,你应该选择一个规范形式来存储它(全部小写或全部大写)。如果您因某种原因需要保存原始案例,那么您可以只保存两列 - 一个与原始案例,一个与标准案例。这样你可以做一个正常的WHERE子句。


Using the google appengine datastore, is there a way to perform a gql query that specifies a WHERE clause on a StringProperty datatype that is case insensitive? I am not always sure what case the value will be in. The docs specify that the where is case sensitive for my values, is there a way to make this insensitive?

for instance the db Model would be this:

from google.appengine.ext import db
class Product(db.Model):
    id = db.IntegerProperty()
    category = db.StringProperty()

and the data looks like this:

id         category
===================
1          cat1
2          cat2
3          Cat1
4          CAT1
5          CAT3
6          Cat4
7          CaT1
8          CAT5

i would like to say

gqlstring = "WHERE category = '{0}'".format('cat1')
returnvalue = Product.gql(gqlstring)

and have returnvalue contain

id         category
===================
1          cat1
3          Cat1
4          CAT1
7          CaT1

解决方案

I don't think there is an operator like that in the datastore.

Do you control the input of the category data? If so, you should choose a canonical form to store it in (all lowercase or all uppercase). If you need to store the original case for some reason, then you could just store two columns - one with the original, one with the standardized one. That way you can do a normal WHERE clause.

这篇关于对StringProperty的gql查询中的where子句不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆