gtpc2mfiC/C++ Language Support User's Guide

TO2_locate-Locate Key and Point Cursor to Its Element

This function locates and points the cursor at the element with a key or sort field that matches the argument.

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

Format

#include <c$to2.h>
long TO2_locate (const TO2_PID_PTR  cursorPidPtr,
                       TO2_ENV_PTR  env_ptr,
                 const long        *argumentLength,
                 const void        *argument);

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.

argumentLength
A pointer to a field that contains the length of the argument used to search the collection.

argument
A pointer to the argument to search the collection for a match.

Normal Return

The normal return is a positive value.

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_LOCATOR_LGH

TO2_ERROR_LOCATOR_NOT_FOUND

TO2_ERROR_METHOD

TO2_ERROR_PID

TO2_ERROR_ZERO_PID

Programming Considerations

Examples

The following example shows how the element is located in the cursor that matches the search key and positions the cursor to point to it.

#include <c$to2.h>                 /* Needed for TO2 API Functions     */
#include <stdio.h>                 /* APIs for standard I/O functions  */
 
TO2_ERR_CODE      err_code;        /* TO2 error code value             */
TO2_PID           cursor;
TO2_ENV_PTR       env_ptr;         /* Pointer to TO2 environment       */
u_char            argument;
long              arg_Length;

  ·
  ·
  ·
/***********************************************************************/ /* Locate and point the cursor to the element matching the key. */ /***********************************************************************/ if (TO2_locate(&cursor, env_ptr, &arg_Length, &argument) == TO2_ERROR) { err_code = TO2_getErrorCode(env_ptr); if (err_code == TO2_ERROR_LOCATOR_NOT_FOUND) { printf("There are no elements that match the search criteria.\n"); } else { printf("TO2_locate failed!\n"); process_error(env_ptr); } } else { printf("TO2_locate successful!\n"); }

Related Information