Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Fixed bug in limit and offset collection params
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquayj committed Feb 15, 2017
1 parent d525ffc commit 5a8a875
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
25 changes: 17 additions & 8 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,18 +1135,25 @@ 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 {
return errInfo, er
}
}

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)}
Expand All @@ -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)}
Expand Down
13 changes: 8 additions & 5 deletions wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5a8a875

Please sign in to comment.