- try to fix SQL_CALC_FOUND_ROWS (use transaction)

This commit is contained in:
gazebo
2018-09-15 23:04:46 +08:00
parent 04e105d8d1
commit a8ae37c641
3 changed files with 5 additions and 5 deletions

View File

@@ -10,7 +10,6 @@ import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
)
type SkuNamesInfo struct {
@@ -266,13 +265,10 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
}
sqlParams = append(sqlParams, pageSize, offset)
skuNamesInfo = &SkuNamesInfo{}
globals.SugarLogger.Debug(sqlData)
globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
dao.Begin(db)
dao.Begin(db) // todo 这里用事务的原因是SQL_CALC_FOUND_ROWS会出错
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
countInfo := &struct{ Ct int }{}
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
globals.SugarLogger.Debug(utils.Format4Output(countInfo, false))
skuNamesInfo.TotalCount = countInfo.Ct
for _, skuName := range skuNamesInfo.SkuNames {
if skuName.SkusStr != "" {

View File

@@ -183,12 +183,14 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
sqlParams = append(sqlParams, pageSize, offset)
retVal = &StoresInfo{}
db := dao.GetDB()
dao.Begin(db)
if err = dao.GetRows(db, &retVal.Stores, sql, sqlParams...); err == nil {
countInfo := &struct{ Ct int }{}
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
retVal.TotalCount = countInfo.Ct
}
}
dao.Commit(db)
return retVal, err
}

View File

@@ -155,6 +155,7 @@ func GetStoreSkus(storeID int, keyword string, params map[string]interface{}, of
sqlParams = append(sqlParams, pageSize, offset)
skuNamesInfo = &StoreSkuNamesInfo{}
// globals.SugarLogger.Debug(sqlData)
dao.Begin(db)
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
countInfo := &struct{ Ct int }{}
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
@@ -168,6 +169,7 @@ func GetStoreSkus(storeID int, keyword string, params map[string]interface{}, of
}
}
}
dao.Commit(db)
return skuNamesInfo, err
}