gtpc2mc4C/C++ Language Support User's Guide

TO2_atRBA-Retrieve Data from a BLOB

This function can be called to read either a complete binary large object (BLOB) or only a part of a BLOB by specifying the starting byte position.

The number of bytes read will be the length specified (up to 4 MB (4 194 304)) or the size of the BLOB, whichever is smaller.

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

Format

#include <c$to2.h>
void * TO2_atRBA (const TO2_PID_PTR   pid_ptr,
                        TO2_ENV_PTR   env_ptr,
                  const long         *relativeByteToRead,
                        long         *lengthToRead,
                        long         *updateSeqCtr);

pid_ptr
The pointer to the persistent identifier (PID) assigned to the collection.

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

relativeByteToRead
The pointer to a value that specifies the relative byte position in the collection to start the read. This position is 1-based.

lengthToRead
The pointer to a value that specifies the number of bytes that will be read. This field will be overlaid with the actual number of bytes read. The maximum length that can be read is 4 MB (4 194 304).

updateSeqCtr
The pointer to a field where the actual sequence counter value will be stored.

Normal Return

The normal return is a pointer to a buffer containing the requested data. Once the caller has stopped using the returned data, it is the responsibility of the caller to free the data buffer. The lengthToRead parameter is updated with the actual number of bytes read.

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_DATA_LGH

TO2_ERROR_EMPTY

TO2_ERROR_ENV

TO2_ERROR_EODAD

TO2_ERROR_INDEX

TO2_ERROR_METHOD

TO2_ERROR_PID

TO2_ERROR_REREAD

TO2_ERROR_SEQCTR

TO2_ERROR_ZERO_PID

TO2_ERROR_NOT_INIT

Note:
The sequence counter field will be updated with the current sequence counter value from the BLOB whenever error codes TO2_ERROR_EODAD and TO2_ERROR_EMPTY are set in the environment.

Programming Considerations

Examples

The following example obtains a buffer with a copy of the data from a given BLOB starting at a specified relative byte position for a specified length.

#include <c$to2.h>              /* Needed for TO2 API functions     */
#include <stdio.h>              /* APIs for standard I/O functions  */
 
TO2_PID             blob;       /* Pointer to the TO2 environment   */
TO2_ENV_PTR         env_ptr;    /* Pointer to the TO2 environment   */
long                position=5; /* We will try to get starting at 5 */
long                seq_ctr;    /* will hold update sequence count  */
long                size=40;    /* number bytes to copy             */
char                * buf_ptr;

  ·
  ·
  ·
/********************************************************************/ /* Copy data from the BLOB starting at the 5th position for a */ /* length of 40 bytes. */ /********************************************************************/ buf_ptr = TO2_atRBA(&blob, env_ptr, &position, &size, &seq_ctr); if (buf_ptr == NULL) { printf("TO2_atRBA failed !\n"); process_error(env_ptr); } else { printf("TO2_atRBA successful!\n"); }

Related Information