rtree/deleteZipcode.c
static RDM_RETCODE deleteZipCode (RDM_DB db)
{
RDM_CURSOR cursor = NULL;
POINTSOFINTEREST_CITY_KEY keyVal = {{0}};
RDM_RANGE_KEY range = {0};
/* Set the key value for the lookup */
strcpy (keyVal.city, "Nampa");
/* Set key lookup information */
range.value = &keyVal;
range.bytesIn = sizeof (POINTSOFINTEREST_CITY_KEY);
range.numKeyCols = 1;
/* Start an update transaction */
rc = rdm_dbStartUpdate (db, RDM_LOCK_ALL, 0, NULL, 0, NULL);
if (rc == sOKAY)
{
/* Get a range cursor based on the city key */
db, KEY_POINTSOFINTEREST_CITY, &range, &range, &cursor);
if (rc == sOKAY)
{
/* Move to the first (should be only) row in the cursor */
rc = rdm_cursorMoveToFirst (cursor);
while (rc == sOKAY)
{
/* Delete the row */
rc = rdm_cursorDeleteRow (cursor);
if (rc == sOKAY)
{
rc = rdm_cursorMoveToNext (cursor);
}
}
/* We expect sENDOFCURSOR when we break out of the loop */
if (rc == sENDOFCURSOR)
{
rc = sOKAY;
}
/* Free the cursor */
(void) rdm_cursorFree (cursor);
}
if (rc == sOKAY)
{
/* Commit the successful transaction */
rc = rdm_dbEnd (db);
}
else
{
/* Rollback the failed transaction */
(void) rdm_dbEndRollback (db);
}
}
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.
const void * value
Definition: rdmtypes.h:116
RDM_RETCODE rdm_dbEnd(RDM_DB db)
End a transactional operation.
struct RDM_CURSOR_S * RDM_CURSOR
Definition: rdmtypes.h:306
RDM_RETCODE rdm_cursorDeleteRow(RDM_CURSOR cursor)
Delete a row from a table.
@ RDM_RANGE_OPEN
Definition: rdmtypes.h:109
RDM_RANGE range
Definition: rdmtypes.h:125
@ sOKAY
Definition: rdmretcodetypes.h:97
RDM_RETCODE rdm_cursorFree(RDM_CURSOR cursor)
Free an RDM_CURSOR.
RDM_RETCODE rdm_dbEndRollback(RDM_DB db)
End and rollback a transactional operation.
The RDM Range Key data structure.
Definition: rdmtypes.h:115
uint16_t numKeyCols
Definition: rdmtypes.h:118
size_t bytesIn
Definition: rdmtypes.h:117
RDM_RETCODE rdm_dbGetRowsByKeyInRangeKeyRange(RDM_DB db, RDM_KEY_ID keyId, const RDM_RANGE_KEY *startValue, const RDM_RANGE_KEY *endValue, RDM_CURSOR *pCursor)
Associate an RDM_CURSOR with rows in a specified key range.
struct RDM_DB_S * RDM_DB
Definition: rdmtypes.h:305
#define RDM_LOCK_ALL
Definition: rdmtypes.h:170
RDM_RETCODE rdm_dbStartUpdate(RDM_DB db, const RDM_TABLE_ID *writeTableIds, uint32_t numWriteTableIds, const RDM_TABLE_ID *readTableIds, uint32_t numReadTableIds, RDM_TRANS *pTrans)
Get write locks.
@ sENDOFCURSOR
Definition: rdmretcodetypes.h:58
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43