cursor/registerMembers.c
static RDM_RETCODE registerMembers (
RDM_CURSOR lastMember,
RDM_CURSOR beforeFirstMember,
RDM_DB db)
{
RDM_CURSOR member = NULL;
RDM_CURSOR_COMPARE comparison;
/* Clone fistMember to keep its position as is */
rc = rdm_cursorGetClone (lastMember, &member);
if (rc == sOKAY)
{
rc = rdm_cursorComparePosition (member, beforeFirstMember, &comparison);
}
while (rc == sOKAY && comparison == CURSOR_AFTER)
{
rc = rdm_cursorLinkRow (member, REF_MEMBERS, club);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToPrevious (member);
if (rc == sENDOFCURSOR)
rc = sOKAY;
}
if (rc == sOKAY)
{
member, beforeFirstMember, &comparison);
}
}
rdm_cursorFree (member);
return rc;
}
static RDM_RETCODE registerJuniorMembers (
RDM_CURSOR firstMember,
RDM_CURSOR afterLastMember,
RDM_DB db)
{
RDM_CURSOR member = NULL;
RDM_CURSOR_COMPARE comparison;
/* Clone fistMember to keep its position as is */
rc = rdm_cursorGetClone (firstMember, &member);
if (rc == sOKAY)
{
rc = rdm_cursorComparePosition (member, afterLastMember, &comparison);
}
while (rc == sOKAY && comparison == CURSOR_BEFORE)
{
rc = rdm_cursorLinkRow (member, REF_JUNIOR_MEMBERS, club);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToNext (member);
if (rc == sENDOFCURSOR)
rc = sOKAY;
}
if (rc == sOKAY)
{
member, afterLastMember, &comparison);
}
}
rdm_cursorFree (member);
return rc;
}
static RDM_RETCODE registerHalfOfTheAdultsAsMembers (RDM_CURSOR club, RDM_DB db)
{
uint64_t numMembers;
RDM_CURSOR adults = NULL;
RDM_CURSOR beforeFirst = NULL;
uint64_t i;
printf ("Register half of the adults as members:\n");
rc = rdm_rdmGetBeforeFirst (&beforeFirst);
if (rc == sOKAY)
{
rc = rdm_dbGetRows (db, TABLE_ADULT, &adults);
}
if (rc == sOKAY)
{
rc = rdm_cursorGetCount (adults, &numMembers);
}
if (rc == sOKAY)
{
rc = rdm_cursorMoveToLast (adults);
}
for (i = 0; rc == sOKAY && i < numMembers / 2; i++)
{
rc = rdm_cursorMoveToPrevious (adults);
}
if (rc == sOKAY)
{
rc = registerMembers (club, adults, beforeFirst, db);
}
rdm_cursorFree (adults);
return rc;
}
RDM_RETCODE rdm_cursorMoveToNext(RDM_CURSOR cursor)
Position a cursor to the next row in the collection.
struct RDM_CURSOR_S * RDM_CURSOR
Definition: rdmtypes.h:306
RDM_CURSOR_COMPARE
Enumeration for RDM cursor comparisons.
Definition: rdmtypes.h:228
RDM_RETCODE rdm_cursorComparePosition(RDM_CURSOR cursorPrimary, RDM_CURSOR cursorSecondary, RDM_CURSOR_COMPARE *comparison)
compare the position of a cursor relative to another cursor
@ CURSOR_BEFORE
Definition: rdmtypes.h:229
RDM_RETCODE rdm_cursorGetCount(RDM_CURSOR cursor, uint64_t *count)
Get the row count for a cursor.
RDM_RETCODE rdm_cursorLinkRow(RDM_CURSOR cursor, RDM_REF_ID refId, RDM_CURSOR cursorOwner)
Link a row to an owner.
@ sOKAY
Definition: rdmretcodetypes.h:97
RDM_RETCODE rdm_cursorMoveToPrevious(RDM_CURSOR cursor)
Position a cursor to the previous row in the collection.
RDM_RETCODE rdm_cursorFree(RDM_CURSOR cursor)
Free an RDM_CURSOR.
RDM_RETCODE rdm_dbGetRows(RDM_DB db, RDM_TABLE_ID tableId, RDM_CURSOR *pCursor)
Associate an RDM_CURSOR with rows based on a table id.
@ CURSOR_AFTER
Definition: rdmtypes.h:233
RDM_RETCODE rdm_cursorGetClone(RDM_CURSOR sourceCursor, RDM_CURSOR *pCursor)
Associate an RDM_CURSOR as a clone of an existing RDM_CURSOR.
RDM_RETCODE rdm_cursorMoveToLast(RDM_CURSOR cursor)
Position a cursor to the last row in the collection.
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:305
@ sENDOFCURSOR
Definition: rdmretcodetypes.h:58
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43
RDM_RETCODE rdm_rdmGetBeforeFirst(RDM_CURSOR *pCursor)
Get the special BeforeFirst cursor.