gtpc2me2C/C++ Language Support User's Guide

TO2_getCollectionType-Get the Type Value of the Collection

This function retrieves a pointer to a string that identifies the type of the collection.

Format

#include <c$to2.h>
char * TO2_getCollectionType (const TO2_PID_PTR   pid_ptr,
                                    TO2_ENV_PTR   env_ptr);

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

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

Normal Return

The normal return is a pointer to a C string, TYPE is the type of the collection and CODE is the string returned:

TYPE
CODE

array
ARRAY

bag
BAG

BLOB
BYTEARRAY

key bag
KEYBAG

key set
KEYSET

key sorted bag
KEYSORTEDBAG

key sorted set
KEYSORTEDSET

keyed log
KEYEDLOG

log
LOG

sequence
SEQUENCE

set
SET

sorted bag
SORTEDBAG

sorted set
SORTEDSET

Error Return

An error return is indicated by a NULL pointer. When a NULL pointer 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_PID

TO2_ERROR_ZERO_PID

Programming Considerations

This function does not use TPF transaction services on behalf of the caller.

Examples

The following example retrieves a string-identifier type for the specified TPFCS collection.

#include <c$to2.h>               /* TO2 API function prototypes     */
#include <string.h>              /* strcmp()                        */
#include <stdio.h>               /* APIs for standard I/O functions */
 
void processVariousCollectionTypes (TO2_ENV_PTR env_ptr,
                                    TO2_PID_PTR pid_ptr)
{
   char *objecttype = TO2_getCollectionType(pid_ptr, env_ptr);
 
   if (objecttype = NULL)
   {
 
   printf("TO2_getCollectionType failed!\n");
   process_error(env_ptr);
   }
else
   {
   if (strcmp(objecttype, "ARRAY") == 0)
   {
   /* Processing for ARRAY type collection */
   }
else if (strcmp(objecttype, "BAG") == 0)
   {
   /* Processing for BAG type collection */
   }
else if (strcmp(objecttype, "BYTEARRAY") == 0)
   {
   /* Processing for BLOB type collection */
   }

  ·
  ·
  ·
printf("TO2_getCollectionType successful!-n"); } }

Related Information

TO2_isCollection-Test If PID Is for a Collection.