1
This commit is contained in:
parent
5d16a05656
commit
1d17c0c75a
72
dbpool.go
72
dbpool.go
@ -408,6 +408,78 @@ func (this *dbPool) StreamPageQuery(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *dbPool) StreamPageQuery1(
|
||||||
|
dataSource string,
|
||||||
|
pageSize int32,
|
||||||
|
cursor int64,
|
||||||
|
sql string,
|
||||||
|
params []string,
|
||||||
|
filter DbQueryFilter,
|
||||||
|
orderBy string,
|
||||||
|
cb SteamPageQueryCb,
|
||||||
|
fillCb func(*DataSet)) {
|
||||||
|
if (pageSize <= 0) {
|
||||||
|
pageSize = 1
|
||||||
|
}
|
||||||
|
if (pageSize > 1000) {
|
||||||
|
pageSize = 1000
|
||||||
|
}
|
||||||
|
var pagination StreamPagination
|
||||||
|
finalySql := sql
|
||||||
|
if filter != nil {
|
||||||
|
finalySql += filter.GenSql()
|
||||||
|
}
|
||||||
|
if orderBy != "" {
|
||||||
|
finalySql += " " + orderBy + " "
|
||||||
|
}
|
||||||
|
//finalySql += fmt.Sprintf(" LIMIT %d ", pageSize + 1)
|
||||||
|
//GetSysLog().Info("finalySql:%s", finalySql)
|
||||||
|
this.queryOne(
|
||||||
|
dataSource,
|
||||||
|
fmt.Sprintf("SELECT COUNT(*) FROM (%s) as t", finalySql),
|
||||||
|
params,
|
||||||
|
func(err error, rows *DataSet) {
|
||||||
|
if err != nil {
|
||||||
|
cb(err, &pagination)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var total int32
|
||||||
|
var totalPages int32
|
||||||
|
if rows != nil && rows.Next() {
|
||||||
|
total = q5.ToInt32(rows.GetByIndex(0))
|
||||||
|
totalPages = int32(math.Ceil(q5.ToFloat64(rows.GetByIndex(0)) /
|
||||||
|
float64(pageSize)))
|
||||||
|
}
|
||||||
|
if cursor <= 0 {
|
||||||
|
cursor = 1
|
||||||
|
}
|
||||||
|
start := pageSize * (int32(cursor) - 1)
|
||||||
|
limit := pageSize
|
||||||
|
this.query(
|
||||||
|
dataSource,
|
||||||
|
fmt.Sprintf("%s LIMIT %d, %d", finalySql, start, limit),
|
||||||
|
params,
|
||||||
|
func(err error, rows *DataSet) {
|
||||||
|
if err != nil {
|
||||||
|
cb(err, &pagination)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//pagination.Rows = rows
|
||||||
|
pagination.PreviousCursor = cursor
|
||||||
|
for rows.Next() {
|
||||||
|
fillCb(rows)
|
||||||
|
pagination.Count += 1
|
||||||
|
}
|
||||||
|
if int32(cursor) < totalPages {
|
||||||
|
pagination.NextCursor = cursor + 1
|
||||||
|
pagination.Remaining = 1
|
||||||
|
}
|
||||||
|
pagination.TotalCount = total
|
||||||
|
cb(nil, &pagination)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (this *dbPool) borrowConn(name string) *dataSource {
|
func (this *dbPool) borrowConn(name string) *dataSource {
|
||||||
tryCount := 0
|
tryCount := 0
|
||||||
for tryCount < 5 {
|
for tryCount < 5 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user