diff --git a/collection.go b/collection.go index bd17f2e..3f61a78 100644 --- a/collection.go +++ b/collection.go @@ -1135,10 +1135,6 @@ func (col *Collection) ReadCollectionOpts(opts CollectionReadOpts) (CollectionRe ccon := col.con.GetCcon() for int(C.gorods_rclReadCollectionCols(ccon, &col.cColHandle, &colEnt, cOpts)) >= 0 { - - colTotal = int(col.cColHandle.collSqlResult.totalRowCount) - colCnt = int(col.cColHandle.collSqlResult.rowCnt) - if newCol, er := initCollection(&colEnt, col); er == nil { col.add(newCol) } else { @@ -1146,7 +1142,18 @@ func (col *Collection) ReadCollectionOpts(opts CollectionReadOpts) (CollectionRe } } + colTotal = int(col.cColHandle.collSqlResult.totalRowCount) + colCnt = int(col.cColHandle.collSqlResult.rowCnt) + + C.clearCollSqlResult(&col.cColHandle.collSqlResult) + newLimit := opts.Limit - colCnt + newOffset := opts.Offset + + if colCnt == 0 && colTotal > 0 { + newOffset = opts.Offset - colTotal + } + if newLimit == 0 { // We're done, don't grab any objects info = CollectionReadInfo{colCnt, objCnt, (colCnt + objCnt), colTotal, objTotal, (colTotal + objTotal)} @@ -1157,16 +1164,18 @@ func (col *Collection) ReadCollectionOpts(opts CollectionReadOpts) (CollectionRe return info, col.Close() } else { cOpts.limit = C.int(newLimit) + cOpts.offset = C.int(newOffset) } for int(C.gorods_rclReadCollectionObjs(ccon, &col.cColHandle, &colEnt, cOpts)) >= 0 { + col.add(initDataObj(&colEnt, col, col.con)) + } - objTotal = int(col.cColHandle.dataObjSqlResult.totalRowCount) - objCnt = int(col.cColHandle.dataObjSqlResult.rowCnt) + objTotal = int(col.cColHandle.dataObjSqlResult.totalRowCount) + objCnt = int(col.cColHandle.dataObjSqlResult.rowCnt) - col.add(initDataObj(&colEnt, col, col.con)) + C.clearDataObjSqlResult(&col.cColHandle.dataObjSqlResult) - } col.con.ReturnCcon(ccon) info = CollectionReadInfo{colCnt, objCnt, (colCnt + objCnt), colTotal, objTotal, (colTotal + objTotal)} diff --git a/wrapper.c b/wrapper.c index 3075e0c..90b3fef 100755 --- a/wrapper.c +++ b/wrapper.c @@ -2145,6 +2145,10 @@ int gorods_genCollResInColl( queryHandle_t *queryHandle, collHandle_t *collHandl rodsLog( LOG_ERROR, "genCollResInColl: query collection error for %s. status = %d", collHandle->dataObjInp.objPath, status ); + } else { + // Set the total result size even if there are no rows in this response + collHandle->collSqlResult.totalRowCount = genQueryOut->totalRowCount; + collHandle->collSqlResult.rowCnt = genQueryOut->rowCnt; } freeGenQueryOut( &genQueryOut ); return status; @@ -2193,6 +2197,10 @@ int gorods_genDataResInColl( queryHandle_t *queryHandle, collHandle_t *collHandl rodsLog( LOG_ERROR, "genDataResInColl: query dataObj error for %s. status = %d", collHandle->dataObjInp.objPath, status ); + } else { + // Set the total result size even if there are no rows in this response + collHandle->dataObjSqlResult.totalRowCount = genQueryOut->totalRowCount; + collHandle->dataObjSqlResult.rowCnt = genQueryOut->rowCnt; } freeGenQueryOut( &genQueryOut ); return status; @@ -2303,9 +2311,6 @@ int gorods_getNextCollMetaInfo( collHandle_t *collHandle, collEnt_t *outCollEnt if ( collHandle->rowInx >= collSqlResult->rowCnt ) { genQueryOut_t *genQueryOut = NULL; int continueInx = collSqlResult->continueInx; - clearCollSqlResult( collSqlResult ); - - // TODO: MESS WITH THIS SECTION TO PREVENT MORE QUEURIES return CAT_NO_ROWS_FOUND; } value = collSqlResult->collName.value; @@ -2385,9 +2390,7 @@ int gorods_getNextDataObjMetaInfo( collHandle_t *collHandle, collEnt_t *outCollE if ( collHandle->rowInx >= dataObjSqlResult->rowCnt ) { genQueryOut_t *genQueryOut = NULL; int continueInx = dataObjSqlResult->continueInx; - clearDataObjSqlResult( dataObjSqlResult ); - // TODO: MESS WITH THIS SECTION TO PREVENT MORE QUEURIES return CAT_NO_ROWS_FOUND; }