mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 20:20:55 +00:00
Merge pull request #4198 from CadenGuo/enhancement/orm_mysql_operator_consolidate
Enhancement/Add a new MySQL operator for strict case sensitive query
This commit is contained in:
commit
f6519b29a8
11
orm/db.go
11
orm/db.go
@ -36,10 +36,11 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
operators = map[string]bool{
|
operators = map[string]bool{
|
||||||
"exact": true,
|
"exact": true,
|
||||||
"iexact": true,
|
"iexact": true,
|
||||||
"contains": true,
|
"strictexact": true,
|
||||||
"icontains": true,
|
"contains": true,
|
||||||
|
"icontains": true,
|
||||||
// "regex": true,
|
// "regex": true,
|
||||||
// "iregex": true,
|
// "iregex": true,
|
||||||
"gt": true,
|
"gt": true,
|
||||||
@ -1202,7 +1203,7 @@ func (d *dbBase) GenerateOperatorSQL(mi *modelInfo, fi *fieldInfo, operator stri
|
|||||||
}
|
}
|
||||||
sql = d.ins.OperatorSQL(operator)
|
sql = d.ins.OperatorSQL(operator)
|
||||||
switch operator {
|
switch operator {
|
||||||
case "exact":
|
case "exact", "strictexact":
|
||||||
if arg == nil {
|
if arg == nil {
|
||||||
params[0] = "IS NULL"
|
params[0] = "IS NULL"
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ import (
|
|||||||
|
|
||||||
// mysql operators.
|
// mysql operators.
|
||||||
var mysqlOperators = map[string]string{
|
var mysqlOperators = map[string]string{
|
||||||
"exact": "= ?",
|
"exact": "= ?",
|
||||||
"iexact": "LIKE ?",
|
"iexact": "LIKE ?",
|
||||||
"contains": "LIKE BINARY ?",
|
"strictexact": "= BINARY ?",
|
||||||
"icontains": "LIKE ?",
|
"contains": "LIKE BINARY ?",
|
||||||
|
"icontains": "LIKE ?",
|
||||||
// "regex": "REGEXP BINARY ?",
|
// "regex": "REGEXP BINARY ?",
|
||||||
// "iregex": "REGEXP ?",
|
// "iregex": "REGEXP ?",
|
||||||
"gt": "> ?",
|
"gt": "> ?",
|
||||||
|
@ -822,6 +822,17 @@ func TestOperators(t *testing.T) {
|
|||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
throwFail(t, AssertIs(num, 1))
|
throwFail(t, AssertIs(num, 1))
|
||||||
|
|
||||||
|
if IsMysql {
|
||||||
|
// Now only mysql support `strictexact`
|
||||||
|
num, err = qs.Filter("user_name__strictexact", "Slene").Count()
|
||||||
|
throwFail(t, err)
|
||||||
|
throwFail(t, AssertIs(num, 0))
|
||||||
|
|
||||||
|
num, err = qs.Filter("user_name__strictexact", "slene").Count()
|
||||||
|
throwFail(t, err)
|
||||||
|
throwFail(t, AssertIs(num, 1))
|
||||||
|
}
|
||||||
|
|
||||||
num, err = qs.Filter("user_name__contains", "e").Count()
|
num, err = qs.Filter("user_name__contains", "e").Count()
|
||||||
throwFail(t, err)
|
throwFail(t, err)
|
||||||
throwFail(t, AssertIs(num, 2))
|
throwFail(t, AssertIs(num, 2))
|
||||||
|
Loading…
Reference in New Issue
Block a user