|
@@ -91,14 +91,14 @@ type Condition struct { |
|
@@ -91,14 +91,14 @@ type Condition struct { |
|
91
|
|
91
|
|
|
92
|
func (c Condition) SetWhere(q *gorm.DB) {
|
92
|
func (c Condition) SetWhere(q *gorm.DB) {
|
|
93
|
if len(c.Like) > 0 {
|
93
|
if len(c.Like) > 0 {
|
|
94
|
- q.Where(fmt.Sprintf("%v like '%%%v%%'", c.Field.SQLName, c.Like))
|
94
|
+ q.Where(fmt.Sprintf("%v like '%%%v%%'", FormatIfNull(c.Field), c.Like))
|
|
95
|
}
|
95
|
}
|
|
96
|
if len(c.In) > 0 {
|
96
|
if len(c.In) > 0 {
|
|
97
|
- q.Where(fmt.Sprintf("%v in %v", c.Field.SQLName, c.InArgs(c.In)))
|
97
|
+ q.Where(fmt.Sprintf("%v in %v", FormatIfNull(c.Field), c.InArgs(c.In)))
|
|
98
|
}
|
98
|
}
|
|
99
|
if len(c.Ex) > 0 {
|
99
|
if len(c.Ex) > 0 {
|
|
100
|
in := c.InArgs(c.Ex)
|
100
|
in := c.InArgs(c.Ex)
|
|
101
|
- q.Where(fmt.Sprintf("%v not in %v", c.Field.SQLName, in))
|
101
|
+ q.Where(fmt.Sprintf("%v not in %v", FormatIfNull(c.Field), in))
|
|
102
|
}
|
102
|
}
|
|
103
|
if len(c.Range) > 0 {
|
103
|
if len(c.Range) > 0 {
|
|
104
|
for _, item := range c.Range {
|
104
|
for _, item := range c.Range {
|
|
@@ -115,7 +115,7 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
@@ -115,7 +115,7 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
115
|
continue
|
115
|
continue
|
|
116
|
}
|
116
|
}
|
|
117
|
q.Where(fmt.Sprintf("%s %s %s",
|
117
|
q.Where(fmt.Sprintf("%s %s %s",
|
|
118
|
- c.Field.SQLName,
|
118
|
+ FormatIfNull(c.Field),
|
|
119
|
opVal,
|
119
|
opVal,
|
|
120
|
c.formatByOp(item.Op, val),
|
120
|
c.formatByOp(item.Op, val),
|
|
121
|
))
|
121
|
))
|
|
@@ -129,6 +129,13 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
@@ -129,6 +129,13 @@ func (c Condition) SetWhere(q *gorm.DB) { |
|
129
|
}
|
129
|
}
|
|
130
|
}
|
130
|
}
|
|
131
|
|
131
|
|
|
|
|
132
|
+func FormatIfNull(f *domain.Field) string {
|
|
|
|
133
|
+ if domain.SQLType(f.SQLType).IsString() {
|
|
|
|
134
|
+ return fmt.Sprintf("ifnull(%s,'')", f.SQLName)
|
|
|
|
135
|
+ }
|
|
|
|
136
|
+ return f.SQLName
|
|
|
|
137
|
+}
|
|
|
|
138
|
+
|
|
132
|
var opMap = map[string]string{
|
139
|
var opMap = map[string]string{
|
|
133
|
"=": "=",
|
140
|
"=": "=",
|
|
134
|
">": ">",
|
141
|
">": ">",
|