This commit is contained in:
苏尹岚
2021-03-31 15:37:59 +08:00
parent ebb7424282
commit 423c1f8845
2 changed files with 39 additions and 16 deletions

View File

@@ -147,6 +147,15 @@ func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (e
return err
}
func GetRowsTx(txDB orm.TxOrmer, inPtr interface{}, sql string, values ...interface{}) (err error) {
if txDB == nil {
return
}
_, err = txDB.Raw(sql, values).QueryRows(inPtr)
// _, err = db.Db.Raw(sql, values).QueryRows(inPtr)
return err
}
func GetEntity(db *DaoDB, item interface{}, cols ...string) (err error) {
if db == nil {
db = GetDB()
@@ -225,8 +234,22 @@ func ExecuteSQL(db *DaoDB, sql string, params ...interface{}) (num int64, err er
// 此函数要求db在事务中否则可能导致取得到的是另一个连接的数据
func GetLastTotalRowCount(db *DaoDB) int {
countInfo := &struct{ Ct int }{}
// if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
// return countInfo.Ct
// }
if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
return countInfo.Ct
}
return 0
}
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 {
return countInfo.Ct
}
// if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
// return countInfo.Ct
// }
return 0
}