aa
This commit is contained in:
@@ -139,6 +139,26 @@ func GetRow(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (er
|
|||||||
return err
|
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) {
|
func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||||
if db == nil {
|
if db == nil {
|
||||||
db = GetDB()
|
db = GetDB()
|
||||||
@@ -245,11 +265,8 @@ func GetLastTotalRowCount(db *DaoDB) int {
|
|||||||
|
|
||||||
func GetLastTotalRowCount2(db *DaoDB, txDB orm.TxOrmer) int {
|
func GetLastTotalRowCount2(db *DaoDB, txDB orm.TxOrmer) int {
|
||||||
countInfo := &struct{ Ct 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
|
return countInfo.Ct
|
||||||
}
|
}
|
||||||
// if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
|
||||||
// return countInfo.Ct
|
|
||||||
// }
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user