This commit is contained in:
苏尹岚
2021-03-31 16:42:26 +08:00
parent e3d995c85d
commit b784fa92ca

View File

@@ -139,6 +139,26 @@ func GetRow(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (er
return err
}
func GetRowTx(txDB orm.TxOrmer, inPtr interface{}, sql string, values ...interface{}) (err error) {
if txDB == nil {
return
}
typeInfo := reflect.TypeOf(inPtr)
if typeInfo.Kind() != reflect.Ptr {
return errors.New("inPtr must be ptr")
}
slice := reflect.New(reflect.SliceOf(typeInfo.Elem()))
if err = GetRowsTx(txDB, slice.Interface(), sql, values...); err == nil {
slice = slice.Elem()
if slice.Len() > 0 {
reflect.ValueOf(inPtr).Elem().Set(slice.Index(0))
} else {
return orm.ErrNoRows
}
}
return err
}
func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (err error) {
if db == nil {
db = GetDB()
@@ -245,11 +265,8 @@ func GetLastTotalRowCount(db *DaoDB) int {
func GetLastTotalRowCount2(db *DaoDB, txDB orm.TxOrmer) int {
countInfo := &struct{ Ct int }{}
if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
if err := GetRowTx(txDB, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
return countInfo.Ct
}
// if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
// return countInfo.Ct
// }
return 0
}