mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 20:40:55 +00:00
add a new mysql operator for force case sensitie query
This commit is contained in:
parent
8736ffaf6f
commit
60bb057783
11
orm/db.go
11
orm/db.go
@ -36,10 +36,11 @@ var (
|
||||
|
||||
var (
|
||||
operators = map[string]bool{
|
||||
"exact": true,
|
||||
"iexact": true,
|
||||
"contains": true,
|
||||
"icontains": true,
|
||||
"exact": true,
|
||||
"iexact": true,
|
||||
"strictexact": true,
|
||||
"contains": true,
|
||||
"icontains": true,
|
||||
// "regex": true,
|
||||
// "iregex": true,
|
||||
"gt": true,
|
||||
@ -1202,7 +1203,7 @@ func (d *dbBase) GenerateOperatorSQL(mi *modelInfo, fi *fieldInfo, operator stri
|
||||
}
|
||||
sql = d.ins.OperatorSQL(operator)
|
||||
switch operator {
|
||||
case "exact":
|
||||
case "exact", "strictexact":
|
||||
if arg == nil {
|
||||
params[0] = "IS NULL"
|
||||
}
|
||||
|
@ -22,10 +22,11 @@ import (
|
||||
|
||||
// mysql operators.
|
||||
var mysqlOperators = map[string]string{
|
||||
"exact": "= BINARY ?",
|
||||
"iexact": "LIKE ?",
|
||||
"contains": "LIKE BINARY ?",
|
||||
"icontains": "LIKE ?",
|
||||
"exact": "= ?",
|
||||
"iexact": "LIKE ?",
|
||||
"strictexact": "= BINARY ?",
|
||||
"contains": "LIKE BINARY ?",
|
||||
"icontains": "LIKE ?",
|
||||
// "regex": "REGEXP BINARY ?",
|
||||
// "iregex": "REGEXP ?",
|
||||
"gt": "> ?",
|
||||
|
@ -822,6 +822,14 @@ func TestOperators(t *testing.T) {
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(num, 1))
|
||||
|
||||
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()
|
||||
throwFail(t, err)
|
||||
throwFail(t, AssertIs(num, 2))
|
||||
|
Loading…
Reference in New Issue
Block a user