C Examples: DbiGetField

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

C Examples: DbiGetField

Return to chapter overview

Example 1: Get the field value by field number.

This example uses the following input:
         fDbiGetField1(hPXCur, pPXRecBuf, 1, (pBYTE)&DFloat);

DBIResult fDbiGetField1(hDBICur hTmpCur, pBYTE pTmpRecBuf, INT16 FldNum, pBYTE Info)

{

   DBIResult      rslt;

   rslt = Chk(DbiGetField(hTmpCur, FldNum, pTmpRecBuf, Info, NULL));

   return rslt;

}

 

Example 2: Get the field value specified by a field name.

If Info is NULL, this function will check to see if a field exists. If an invalid field name is given, an error is returned. This example uses the following input:
         fDbiGetField2(hPXCur, pPXRecBuf, "STOCK NO", (pBYTE)&DFloat);

DBIResult fDbiGetField2(hDBICur hTmpCur, pBYTE pTmpRecBuf, pCHAR FldName, pBYTE Info)

{

   DBIResult      rslt;

   CURProps       CurProps;

   pFLDDesc       pFldDesc;

   UINT16         Field;

   BOOL           Found = FALSE;

   rslt = Chk(DbiGetCursorProps(hTmpCur, &CurProps));

   if (rslt != DBIERR_NONE)

      return rslt;

   pFldDesc = (pFLDDesc)malloc(CurProps.iFields * sizeof(FLDDesc));

   if (pFldDesc == NULL)

      return DBIERR_NOMEMORY;

   rslt = Chk(DbiGetFieldDescs(hTmpCur, pFldDesc));

   if (rslt != DBIERR_NONE)

   {

      free(pFldDesc);

      return rslt;

   }

   for(Field = 0; Field < CurProps.iFields; Field++)

   {

      if (strcmpi(pFldDesc[Field].szName, FldName) == 0)

      {

         Found = TRUE;

         if (Info != NULL)

            rslt = Chk(DbiGetField(hTmpCur, pFldDesc[Field].iFldNum, pTmpRecBuf, Info, NULL));

      }

   }

   if (Found == FALSE)

     rslt = DBIERR_INVALIDFIELDNAME;

   free(pFldDesc);

   return rslt;

}