|
|
@ -161,6 +161,16 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...interface{}) error { |
|
|
|
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...interface{}) error { |
|
|
|
|
|
|
|
elemType := containerValue.Type().Elem() |
|
|
|
|
|
|
|
var isPointer bool |
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Ptr { |
|
|
|
|
|
|
|
isPointer = true |
|
|
|
|
|
|
|
elemType = elemType.Elem() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Ptr { |
|
|
|
|
|
|
|
return errors.New("pointer to pointer is not supported") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rows, err := session.queryRows(sqlStr, args...) |
|
|
|
rows, err := session.queryRows(sqlStr, args...) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
@ -177,31 +187,8 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var newElemFunc func(fields []string) reflect.Value |
|
|
|
var newElemFunc = func(fields []string) reflect.Value { |
|
|
|
elemType := containerValue.Type().Elem() |
|
|
|
return utils.New(elemType, len(fields), len(fields)) |
|
|
|
var isPointer bool |
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Ptr { |
|
|
|
|
|
|
|
isPointer = true |
|
|
|
|
|
|
|
elemType = elemType.Elem() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Ptr { |
|
|
|
|
|
|
|
return errors.New("pointer to pointer is not supported") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newElemFunc = func(fields []string) reflect.Value { |
|
|
|
|
|
|
|
switch elemType.Kind() { |
|
|
|
|
|
|
|
case reflect.Slice: |
|
|
|
|
|
|
|
slice := reflect.MakeSlice(elemType, len(fields), len(fields)) |
|
|
|
|
|
|
|
x := reflect.New(slice.Type()) |
|
|
|
|
|
|
|
x.Elem().Set(slice) |
|
|
|
|
|
|
|
return x |
|
|
|
|
|
|
|
case reflect.Map: |
|
|
|
|
|
|
|
mp := reflect.MakeMap(elemType) |
|
|
|
|
|
|
|
x := reflect.New(mp.Type()) |
|
|
|
|
|
|
|
x.Elem().Set(mp) |
|
|
|
|
|
|
|
return x |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return reflect.New(elemType) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var containerValueSetFunc func(*reflect.Value, schemas.PK) error |
|
|
|
var containerValueSetFunc func(*reflect.Value, schemas.PK) error |
|
|
@ -226,10 +213,15 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect |
|
|
|
|
|
|
|
|
|
|
|
containerValueSetFunc = func(newValue *reflect.Value, pk schemas.PK) error { |
|
|
|
containerValueSetFunc = func(newValue *reflect.Value, pk schemas.PK) error { |
|
|
|
keyValue := reflect.New(keyType) |
|
|
|
keyValue := reflect.New(keyType) |
|
|
|
err := convertPKToValue(table, keyValue.Interface(), pk) |
|
|
|
cols := table.PKColumns() |
|
|
|
if err != nil { |
|
|
|
if len(cols) == 1 { |
|
|
|
|
|
|
|
if err := convert.AssignValue(keyValue, pk[0]); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
keyValue.Set(reflect.ValueOf(&pk)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if isPointer { |
|
|
|
if isPointer { |
|
|
|
containerValue.SetMapIndex(keyValue.Elem(), newValue.Elem().Addr()) |
|
|
|
containerValue.SetMapIndex(keyValue.Elem(), newValue.Elem().Addr()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -241,8 +233,7 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect |
|
|
|
|
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Struct { |
|
|
|
if elemType.Kind() == reflect.Struct { |
|
|
|
var newValue = newElemFunc(fields) |
|
|
|
var newValue = newElemFunc(fields) |
|
|
|
dataStruct := utils.ReflectValue(newValue.Interface()) |
|
|
|
tb, err := session.engine.tagParser.ParseWithCache(newValue) |
|
|
|
tb, err := session.engine.tagParser.ParseWithCache(dataStruct) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -266,7 +257,6 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect |
|
|
|
default: |
|
|
|
default: |
|
|
|
err = rows.Scan(bean) |
|
|
|
err = rows.Scan(bean) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -278,16 +268,6 @@ func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect |
|
|
|
return rows.Err() |
|
|
|
return rows.Err() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func convertPKToValue(table *schemas.Table, dst interface{}, pk schemas.PK) error { |
|
|
|
|
|
|
|
cols := table.PKColumns() |
|
|
|
|
|
|
|
if len(cols) == 1 { |
|
|
|
|
|
|
|
return convert.Assign(dst, pk[0], nil, nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dst = pk |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr interface{}, args ...interface{}) (err error) { |
|
|
|
func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr interface{}, args ...interface{}) (err error) { |
|
|
|
if !session.canCache() || |
|
|
|
if !session.canCache() || |
|
|
|
utils.IndexNoCase(sqlStr, "having") != -1 || |
|
|
|
utils.IndexNoCase(sqlStr, "having") != -1 || |
|
|
|