diff --git a/dbpool.go b/dbpool.go index 71333ca..5d1a317 100644 --- a/dbpool.go +++ b/dbpool.go @@ -110,6 +110,35 @@ func (this *dbPool) SyncSelectCustomQuery(dataSource string, sql string, cb Quer } } +func (this *dbPool) SyncBatchLoadFullTable(dataSource string, sqlTpl string, + cb func(*DataSet), errCb func(error)) { + var lastIdx int64 + var done = false + for !done { + this.SyncSelectCustomQuery( + dataSource, + fmt.Sprintf(sqlTpl, lastIdx), + func (err error, ds *DataSet) { + if err != nil { + errCb(err) + return + } + for ds.Next() { + idx := q5.ToInt64(ds.GetByName("idx")) + cb(ds) + if idx > lastIdx { + lastIdx = idx + } else { + panic(fmt.Sprintf("SyncBatchLoadFullTable idx error:%s %s", idx, lastIdx)) + } + } + if ds.NumOfReaded() <= 0 { + done = true + } + }) + } +} + func (this *dbPool) SelectLike( dataSource string, tblName string,