cursor/registerVoters.c
static RDM_RETCODE registerVoters (RDM_CURSOR adults, RDM_DB db)
{
RDM_CURSOR voters = NULL;
RDM_CURSOR system = NULL;
uint64_t count{};
rc = rdm_dbGetRows (db, TABLE_SYSTEM_TBL, &system);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToFirst (system);
}
if (rc == sOKAY)
{
rc = rdm_cursorGetMemberCount (system, REF_VOTERS, &count);
}
if (rc == sOKAY)
{
printf ("Registering %d voters", (int) count);
rc = rdm_cursorGetMemberRows (system, REF_VOTERS, &voters);
}
if (rc == sOKAY)
{
rc = rdm_cursorMoveToFirst (adults);
}
while (rc == sOKAY)
{
rc = rdm_cursorAddMember (voters, adults);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToNext (adults);
}
}
if (rc == sENDOFCURSOR)
rc = sOKAY;
/* The King can not vote, lets unlink him */
if (rc == sOKAY)
{
rc = rdm_cursorMoveToKey (voters, KEY_ADULT_ADULT_NAME, "The King", 0);
}
if (rc == sOKAY)
{
rc = rdm_cursorRemoveMember (voters);
}
rdm_cursorFree (voters);
rdm_cursorFree (system);
return rc;
}
RDM_RETCODE rdm_cursorMoveToFirst(RDM_CURSOR cursor)
Position a cursor to the first row in the collection.
RDM_RETCODE rdm_cursorMoveToNext(RDM_CURSOR cursor)
Position a cursor to the next row in the collection.
RDM_RETCODE rdm_cursorGetMemberCount(RDM_CURSOR cursor, RDM_REF_ID refId, uint64_t *memberCount)
Get the member count for a set owner row.
@ sENDOFCURSOR
Definition: rdmretcodetypes.h:58
RDM_RETCODE rdm_cursorRemoveMember(RDM_CURSOR setCursor)
Remove a row from a set cursor (unlink)
struct RDM_CURSOR_S * RDM_CURSOR
Definition: rdmtypes.h:347
@ sOKAY
Definition: rdmretcodetypes.h:100
RDM_RETCODE rdm_cursorAddMember(RDM_CURSOR setCursor, RDM_CURSOR memberCursor)
Add a row to a set cursor (link)
RDM_RETCODE rdm_cursorFree(RDM_CURSOR cursor)
Free an RDM_CURSOR.
enum RDM_RETCODE_E RDM_RETCODE
RaimaDB status and error return codes.
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_cursorGetMemberRows(RDM_CURSOR ownerCursor, RDM_REF_ID refId, RDM_CURSOR *pCursor)
Associate an RDM_CURSOR with members.
RDM_RETCODE rdm_cursorMoveToKey(RDM_CURSOR cursor, RDM_KEY_ID keyId, const void *keyValue, size_t bytesIn)
Position a cursor based on a key value.
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:346