更新slice

This commit is contained in:
hoteas 2017-11-09 10:15:55 +00:00
parent 93c37015a9
commit 6bb0bce557
3 changed files with 15 additions and 18 deletions

2
db.go
View File

@ -598,7 +598,7 @@ func (this *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
case "[~]": case "[~]":
k = strings.Replace(k, "[~]", "", -1) k = strings.Replace(k, "[~]", "", -1)
where += "`" + k + "` LIKE ? " where += "`" + k + "` LIKE ? "
v = "%" + v.(string) + "%" v = "%" + ObjToStr(v) + "%"
res = append(res, v) res = append(res, v)
default: default:
def = true def = true

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"strconv" "strconv"
"strings" //"strings"
) )
//仅限于hotime.Slice //仅限于hotime.Slice
@ -68,6 +68,9 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
for i := 0; i < len(obj.([]string)); i++ { for i := 0; i < len(obj.([]string)); i++ {
v = append(v, obj.([]string)[i]) v = append(v, obj.([]string)[i])
} }
case string:
v = Slice{}
err = json.Unmarshal([]byte(obj.(string)), &v)
default: default:
v = nil v = nil
@ -255,8 +258,8 @@ func StrToMap(string string) Map {
//转换为Slice //转换为Slice
func StrToSlice(string string) Slice { func StrToSlice(string string) Slice {
data := Slice{}
data.JsonToSlice(string) data := ObjToSlice(string)
return data return data
} }
@ -266,10 +269,13 @@ func StrArrayToJsonStr(a string) string {
if len(a) != 0 { if len(a) != 0 {
if a[0] == ',' { if a[0] == ',' {
a = Substr(a, 1, len(a)) a = Substr(a, 1, len(a)-1)
} }
a = strings.Replace(a, ",", `","`, -1) if a[len(a)-1] == ',' {
a = `["` + a + `"]` a = Substr(a, 1, len(a)-2)
}
//a = strings.Replace(a, ",", `,`, -1)
a = `[` + a + `]`
} else { } else {
a = "[]" a = "[]"
} }
@ -278,12 +284,12 @@ func StrArrayToJsonStr(a string) string {
//字符串数组: a1,a2,a3转["a1","a2","a3"] //字符串数组: a1,a2,a3转["a1","a2","a3"]
func JsonStrToStrArray(a string) string { func JsonStrToStrArray(a string) string {
a = strings.Replace(a, `"`, "", -1) //a = strings.Replace(a, `"`, "", -1)
if len(a) != 0 { if len(a) != 0 {
a = Substr(a, 1, len(a)-2) a = Substr(a, 1, len(a)-2)
} }
return "," + a return "," + a + ","
} }
//字符串转int //字符串转int

View File

@ -1,7 +1,6 @@
package hotime package hotime
import ( import (
"encoding/json"
"errors" "errors"
) )
@ -65,11 +64,3 @@ func (this Slice) Put(key int, value interface{}) {
func (this Slice) ToJsonString() string { func (this Slice) ToJsonString() string {
return ObjToStr(this) return ObjToStr(this)
} }
func (this Slice) JsonToSlice(jsonStr string) {
json.Unmarshal([]byte(jsonStr), &this)
}