From d0c374f34edfc2f5b4e52f4f5bb18efbc978cee6 Mon Sep 17 00:00:00 2001 From: hoteas Date: Mon, 30 Jul 2018 18:09:42 +0000 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=EF=BC=8C=E4=BB=A5=E5=8F=8A=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?is=20null=E5=92=8Cis=20not=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache_memory.go | 19 +++++++++++++------ db.go | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/cache_memory.go b/cache_memory.go index 9892b50..7af41d8 100644 --- a/cache_memory.go +++ b/cache_memory.go @@ -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) diff --git a/db.go b/db.go index 84c4f85..012831a 100644 --- a/db.go +++ b/db.go @@ -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