gtpc2mfb | C/C++ Language Support User's Guide |
This function allows an application program to retrieve the value of the key being used to access the data element to which the cursor is pointing. This differs from the TO2_key function, which will always return the primary key. The TO2_getCurrentKey function returns either the primary key (if the primary key path is in use) or the appropriate key if an alternate key path is being used to access the data element.
Format
#include <c$to2.h> TO2_BUF_PTR TO2_getCurrentKey (const TO2_PID_PTR cursorPid_ptr, TO2_ENV_PTR env_ptr);
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_ENV
TO2_ERROR_METHOD
TO2_ERROR_NOT_INIT
TO2_ERROR_PID
TO2_ERROR_ZERO_PID
Programming Considerations
Examples
The following example retrieves the current access key value of the current data element.
#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 */
·
·
·
/**********************************************************************/ /* Retrieve the key from the item pointed to by the cursor. */ /**********************************************************************/ if ((buffer_ptr = TO2_getCurrentKey(&cursor, env_ptr)) == NULL) { printf("TO2_getCurrentkey failed!\n"); process_error(env_ptr); } else { key = buffer_ptr->data; printf("TO2_getCurrrentKey successful!\n"); }
·
·
·
free (buffer_ptr);
Related Information