Home page  
Help >
ddlSetFetchDataCb() - set Fetch Data Callback
Version 7.11
ddlSetFetchDataCb() - set Fetch Data Callback ddlSetFetchDataCb() - set Fetch Data Callback

Prototype:
   void ddlSetFetchDataCb(
      CONTROL *ctl,
      char *pszTableName,
      FetchDataRtn UserFetch,
      WtCastPtr UserWord)
 
   Prototype of the fetch callback function:
 
   typedef int (STDCALL *FetchDataRtn)(
      /* value: 0 - OK; > 0 - terminate; < 0 - deleted record */
      WtCastPtr UserWord,
      char *DestImage,           /* [IN/OUT] virtual TB rec */
      TBAPI_FETCHCB_HEADER *sFetchInfoArray,   /* [IN] */
      char *pszTableAliasName,   /* [IN] */
      long RecNo);
 
   Structures used by the fetch callback:
 
   typedef struct TBAPI_FETCHCB_HEADER{
      int iStructureLength;     /* total length of this structure in bytes */
      int iItemCount;           /* number of TBAPI_FETCHCB_INFO{} members */
      int iOffsetToInfo;        /* offset to first TBAPI_FETCHCB_INFO{} */
    
      /* added in TBAPI 8.0.115 ... */
      int iFetchCbFlags;        /* Ref TBAPI_FETCHCB_FLAG_xxx */
      int iItemBuffSize;        /* size of DestImage (virtual TB record) */
      int iReserved[4];         /* reserved for future use */
    
      char szInternalTableName[TBAPI_INTERNAL_TABLENAME_LENGTH+8];
   }TBAPI_FETCHCB_HEADER;
    
   typedef struct TBAPI_FETCHCB_INFO{
      int iDataType;            /* Ref DdDataType enum{} */
      int iStartOffset;         /* 0-rel offset to start of data */
      int iDataLength;
      int iDataPoint;           /* for N() data type only */
      char szInternalColumnName[TBAPI_INTERNAL_COLUMNNAME_LENGTH+8];
      char cVirtualDataFlag;    /* !=0 - virtual; 0 - non-virtual */
      char cNullFlag;           /* !=0 - null; 0 - non-null; [non-virtual data only */
      char cDataRequestFlag;    /* !=0 - data is requested [virtual data only] */
   }TBAPI_FETCHCB_INFO;
 
   Symbolic constants for TBAPI_FETCHCB_HEADER iFetchCbFlags
 
   enum{
      TBAPI_FETCHCB_FLAG_NONE     = 0x0000,
      TBAPI_FETCHCB_FLAG_FIRST    = 0x0001,
      TBAPI_FETCHCB_FLAG_NOBATCH  = 0x0002,
      TBAPI_FETCHCB_FLAG_RANDOM   = 0x0004,
   };

Description:
The ddlSetFetchDataCb() API function defines a user callback that is triggered whenever a TBAPI function requests virtual data. The fetch callback is defined for a specific table whenever the ddlSetFetchDataCb() parameter UserFetch is non-null. The fetch callback is undefined for a specific table whenever the UserFetch parameter is null; the fetch callback is also undefined by default.

In particular, the fetch callback is triggered whenever a TB API read data function:
       1) requests data from a virtual table; AND
       2) the request includes one or more virtual columns;

With one specific exception, the fetch callback cannot call another TBAPI function. The exception is DdGetFetchInfo().

The description of collection processing modes gives more insight into the various contexts where the fetch callback is invoked. A simple graphical outline of the connection between a TB API function, TB API internal and the UserFetch CB:

      ddlGetRec() etal ...      TB API call from user App
            |
            +
       db_rdata()               TB API internal call
            |
            +
       db_rdataVirt()           TB API internal call
            |
            +
        UserFetch()             TB API call to user fetch callback 

A simple logical outline of the connection between a TB API function, TB API internal and the UserFetch CB:

   1) Read non-virtual record to buffer;
   2) Move non-virtual data to new buffer using virtual csp;
   3) Call DefaultFetchRtn();
   4) If defined, call UserFetch CB;
   5) If UserFetch CB returned non-zero value, exit
   6) Else, move virtual buffer to user's buffer using user's csp;

Description of ddlSetFetchDataCb() Parameter pszTableName:
char *pszTableName is the null-terminated ascii (internal) name of the table to be associated with UserFetch(); each virtual table must have its own callback instance.

Callbacks for table aliases use the callback instance of the parent table.

Description of ddlSetFetchDataCb() Parameter UserFetch:
FetchDataRtn UserFetch is a pointer to the UserFetch() callback function, or is 0 if no callback function is being specified.


Description of ddlSetFetchDataCb() Parameter UserWord:
WtCastPtr UserWord is a word that is passed as a parameter of UserFetch(). This word can be used as a re-cast pointer to a context for the fetch callback.

Description of FetchDataRtn() Parameter DestImage:
char *DestImage is the buffer that is used for passing data both to and from FetchDataRtn(). The size of this buffer is the size of the virtual record for pszTableName. The format of this buffer is the format defined in the schema.

On entry to FetchDataRtn(), DestImage contains the latest version of all non-virtual fields; and it contains null metas for all virtual fields.

On exit from FetcDataRtn(), DestImage is assumed to contain all requested virtual fields.

Description of FetchDataRtn() Parameter sFetchInfoArray:
TBAPI_FETCHCB_HEADER *sFetchInfoArray is a header followed by an array of structures that describe the format of DestImage. These structures are stored in a monolithic array in the format:
   TBAPI_FETCHCB_HEADER
   TBAPI_FETCHCB_ITEM #1
   TBAPI_FETCHCB_ITEM #2
   ...
   TBAPI_FETCHCB_ITEM #N
 
   TBAPI_FETCHCB_HEADER *header = 0;
   TBAPI_FETCHCB_ITEM *item = 0;
 
   header->iItemCount is the number of items being returned;
   header->iOffsetToInfo is Buffer-0 relative offset to the first item;
   header->iFetchCbFlags is one or more of the constants TBAPI_FETCHCB_FLAG_xxx;
   header->iItemBuffSize is the size of DestImage;

Description of FetchDataRtn() Parameter pszTableAliasName:
char *pszTableAliasName is the table name [if it is not a table alias] of the requesting table; otherwise, it is the table alias name. This name should be passed in to DdGetFetchInfo() as the pszTableAliasName parameter.

Note that this is an incompatibility in TB API 8.0.127.

Description of FetchDataRtn() Parameter RecNo:
long RecNo is the pszTableName 1-relative record number of the record that is being requested.

Copyright © 2019 , WhamTech, Inc.  All rights reserved. This document is provided for information purposes only and the contents hereof are subject to change without notice. Names may be trademarks of their respective owners.