gtpc2mffC/C++ Language Support User's Guide

TO2_key-Return Current Key Value

This function returns the key value for the element pointed to by the cursor. The current key is returned for dictionaries, key bags, key sets, and key sorted bags. The sort field is returned for sorted bag and sorted set collections.

Note:
This function does not support all collections. See Table 48 for collections that are supported for this function.

Format

#include <c$to2.h>
TO2_BUF_PTR TO2_key (const TO2_PID_PTR cursorPidPtr,
                           TO2_ENV_PTR env_ptr);

cursorPidPtr
The pointer to the cursor persistent identifier (PID) created by one of the TPF collection support (TPFCS) create cursor application programming interfaces (APIs).

env_ptr
The pointer to the environment as returned by the TO2_createEnv function.

Normal Return

The normal return is a pointer (TO2_BUF_PTR) to a structure (buffer) of type TO2_BUF_HDR (see Type Definitions).

Error Return

An error return is indicated by a zero. When zero is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.

The following error codes are common for this function:

TO2_ERROR_CURSOR

TO2_ERROR_ENV

TO2_ERROR_METHOD

TO2_ERROR_PID

TO2_ERROR_ZERO_PID

Programming Considerations

Examples

The following example shows how the key value is retrieved from the item to which the cursor is currently pointing.

#include <c$to2.h>                /* Needed for TO2 API Functions     */
#include <stdio.h>                /* APIs for standard I/O functions  */
 
TO2_PID          cursor;
TO2_ENV_PTR      env_ptr;
TO2_BUF_PTR      buffer_ptr;      /* Pointer to returned buffer       */
u_char           *key;            /* The key of the element           */
TO2_ERR_CODE     err_code;        /* TO2 error code value             */
TO2_ERR_TEXT_PTR err_text_ptr;    /* TO2 error code text pointer      */

  ·
  ·
  ·
/**********************************************************************/ /* Retrieve the key from the item pointed to by the cursor. */ /**********************************************************************/ if ((buffer_ptr = TO2_key(&cursor, env_ptr)) == NULL) { printf("TO2_key failed!\n"); process_error(env_ptr); } else { key = buffer_ptr->data; printf("TO2_key successful!\n"); }

Related Information