数据库驱动增加字符串检索匹配,以及条件is null和is not null

This commit is contained in:
hoteas 2018-07-30 18:09:42 +00:00
parent 3f0780e6ea
commit d0c374f34e
2 changed files with 43 additions and 10 deletions

View File

@ -16,6 +16,10 @@ type CacheMemory struct {
//获取Cache键只能为string类型
func (this *CacheMemory) get(key string) interface{} {
this.Error.SetError(nil)
if this.Map == nil {
this.Map = Map{}
}
if this.Map[key] == nil {
return nil
}
@ -23,7 +27,7 @@ func (this *CacheMemory) get(key string) interface{} {
if this.GetError() != nil {
return nil
}
//data:=cacheMap[key];
if data.time < time.Now().Unix() {
delete(this.Map, key)
return nil
@ -51,7 +55,12 @@ func (this *CacheMemory) refreshMap() {
func (this *CacheMemory) set(key string, value interface{}, time int64) {
this.Error.SetError(nil)
var data cacheData
dd := this.Map.Get(key, &this.Error)
if this.Map == nil {
this.Map = Map{}
}
dd := this.Map[key]
if dd == nil {
data = cacheData{}
@ -62,9 +71,7 @@ func (this *CacheMemory) set(key string, value interface{}, time int64) {
data.time = time
data.data = value
if this.Map == nil {
this.Map = Map{}
}
this.Map.Put(key, data)
}
@ -113,12 +120,12 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
}
if len(data) == 1 {
if this.Time == 0 {
this.Time = Config.GetInt64("cacheShortTime")
}
tim = tim + this.Time
}
if len(data) == 2 {
this.Error.SetError(nil)

34
db.go
View File

@ -627,6 +627,21 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
where += "`" + k + "` LIKE ? "
v = "%" + ObjToStr(v) + "%"
res = append(res, v)
case "[!~]"://左边任意
k = strings.Replace(k, "[~]", "", -1)
where += "`" + k + "` LIKE ? "
v = "%" + ObjToStr(v)
res = append(res, v)
case "[!~]"://右边任意
k = strings.Replace(k, "[~]", "", -1)
where += "`" + k + "` LIKE ? "
v = ObjToStr(v) +"%"
res = append(res, v)
case "[~~]"://手动任意
k = strings.Replace(k, "[~]", "", -1)
where += "`" + k + "` LIKE ? "
//v = ObjToStr(v)
res = append(res, v)
default:
def = true
@ -706,8 +721,14 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
//res=append(res,(v.(Slice))[i])
}
} else {
where += "`" + k + "`=? "
res = append(res, v)
if v!=nil{
where += "`" + k + "`=? "
res = append(res, v)
}else{
where += "`" + k + "` IS NULL"
//res = append(res, v)
}
}
}
@ -741,8 +762,13 @@ func (this *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
//res=append(res,(v.(Slice))[i])
}
} else {
where += "`" + k + "` !=? "
res = append(res, v)
if v!=nil{
where += "`" + k + "` !=? "
res = append(res, v)
}else{
where += "`" + k + "` IS NOT NULL "
}
}
return where, res