cursor/registerMembers.c
static RDM_RETCODE registerMembers (
RDM_CURSOR club,
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);
}
{
rc = rdm_cursorLinkRow (member, REF_MEMBERS, club);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToPrevious (member);
rc = sOKAY;
}
if (rc == sOKAY)
{
rc = rdm_cursorComparePosition (
member, beforeFirstMember, &comparison);
}
}
rdm_cursorFree (member);
return rc;
}
static RDM_RETCODE registerJuniorMembers (
RDM_CURSOR club,
RDM_CURSOR firstMember,
RDM_CURSOR afterLastMember,
RDM_DB /*db*/)
{
RDM_RETCODE rc = sOKAY;
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);
}
{
rc = rdm_cursorLinkRow (member, REF_JUNIOR_MEMBERS, club);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToNext (member);
if (rc == sENDOFCURSOR)
rc = sOKAY;
}
if (rc == sOKAY)
{
rc = rdm_cursorComparePosition (
member, afterLastMember, &comparison);
}
}
rdm_cursorFree (member);
return rc;
}
{
RDM_RETCODE rc;
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_CURSOR_COMPARE
Enumeration for RaimaDB cursor comparisons.
Definition: rdmtypes.h:243
RDM_RETCODE rdm_cursorComparePosition(RDM_CURSOR cursorPrimary, RDM_CURSOR cursorSecondary, RDM_CURSOR_COMPARE *comparison)
compare the position of a cursor relative to another cursor
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.
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.
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_rdmGetBeforeFirst(RDM_CURSOR *pCursor)
Get the special BeforeFirst cursor.