WSW
Member
I am new to C++ programing and am having a problem where I am trying to use multiple segments in an index for cache. Any one of the three segments will work alone but when multiple are selected only the first is being used with the others ignored. Thus any change in the other two segments data will not force a new cache record. The cache record with the first match will be updated instead.
The definition is identical for both the initialize and terminate functions which I have not included below.
Any help in identifying what I have done wrong would be appreciated.
HCACHE hUtilCache = NULL;
HJDECURSOR hUtilCursor = NULL;
JDECMINDEXSTRUCT Index1[1];
/************************************************************************
* Declare structures
************************************************************************/
DSUTILCACHE dsUtilCache;
/************************************************************************
* Main Processing
************************************************************************/
/* Initialize Data Structures to NULL */
memset(&dsUtilCache, 0x00, sizeof(DSUTILCACHE));
/* Initialize Cache Index to NULL */
memset(&Index1, 0x00, sizeof(JDECMINDEXSTRUCT));
/* Set up Index to Cache */
Index1->nNumSegments = 1;
Index1->CacheKey[0].nOffset = offsetof(DSUTILCACHE, PayPeriodEndDate);
Index1->CacheKey[0].nSize = sizeof(dsUtilCache.PayPeriodEndDate);
Index1->CacheKey[0].idDataType = EVDT_JDEDATE;
Index1->CacheKey[1].nOffset = offsetof(DSUTILCACHE, MinorityCode);
Index1->CacheKey[1].nSize = sizeof(dsUtilCache.MinorityCode);
Index1->CacheKey[1].idDataType = EVDT_CHAR;
Index1->CacheKey[2].nOffset = offsetof(DSUTILCACHE, Sex);
Index1->CacheKey[2].nSize = 1;
Index1->CacheKey[2].idDataType = EVDT_CHAR;
/* Get Cache Handle */
jdeCacheCode = jdeCacheInit(hUser, &hUtilCache, lpDS->UtilizationCache, Index1);
/* Determine Processing Mode: Add/Retrieval */
if (lpDS->ProcessingMode == _J('0'))
{
/* Add/Update Mode */
dsUtilCache.PayPeriodEndDate = lpDS->PayPeriodEndDate;
jdeStrncpy(dsUtilCache.MinorityCode, (const JCHAR *) (lpDS->MinorityCode),
DIM(dsUtilCache.MinorityCode)-1);
dsUtilCache.Sex = lpDS->Sex;
/* Determine whether the Cache has records */
if (jdeCacheGetNumRecords(hUtilCache) > (long) 0)
{
******* This is what does not work properly
/* Open Cursor - Point to first record in Cache */
jdeCacheCode = jdeCacheOpenCursor(hUtilCache, &hUtilCursor);
/* Attempt to Fetch Matching Record */
jdeCacheCode = jdeCacheFetchPosition(hUtilCache, hUtilCursor, (void *) &dsUtilCache,
1, (void *) &dsUtilCache, (long int) sizeof(dsUtilCache));
*******
if (jdeCacheCode == JDECM_FAILED)
{
/* Add Detail to Cache */
}
else
{
/* Update Cache */
jdeCacheCode = jdeCacheUpdate(hUtilCache, hUtilCursor, (void *) &dsUtilCache,
(long int) sizeof(dsUtilCache));
}
}
else
{
/* Add Detail to Cache */
jdeCacheCode = jdeCacheAdd(hUtilCache, (void *) &dsUtilCache, sizeof(dsUtilCache));
}
}
else if (lpDS->ProcessingMode == _J('1'))
{
/* Retrieval Mode */
}
The definition is identical for both the initialize and terminate functions which I have not included below.
Any help in identifying what I have done wrong would be appreciated.
HCACHE hUtilCache = NULL;
HJDECURSOR hUtilCursor = NULL;
JDECMINDEXSTRUCT Index1[1];
/************************************************************************
* Declare structures
************************************************************************/
DSUTILCACHE dsUtilCache;
/************************************************************************
* Main Processing
************************************************************************/
/* Initialize Data Structures to NULL */
memset(&dsUtilCache, 0x00, sizeof(DSUTILCACHE));
/* Initialize Cache Index to NULL */
memset(&Index1, 0x00, sizeof(JDECMINDEXSTRUCT));
/* Set up Index to Cache */
Index1->nNumSegments = 1;
Index1->CacheKey[0].nOffset = offsetof(DSUTILCACHE, PayPeriodEndDate);
Index1->CacheKey[0].nSize = sizeof(dsUtilCache.PayPeriodEndDate);
Index1->CacheKey[0].idDataType = EVDT_JDEDATE;
Index1->CacheKey[1].nOffset = offsetof(DSUTILCACHE, MinorityCode);
Index1->CacheKey[1].nSize = sizeof(dsUtilCache.MinorityCode);
Index1->CacheKey[1].idDataType = EVDT_CHAR;
Index1->CacheKey[2].nOffset = offsetof(DSUTILCACHE, Sex);
Index1->CacheKey[2].nSize = 1;
Index1->CacheKey[2].idDataType = EVDT_CHAR;
/* Get Cache Handle */
jdeCacheCode = jdeCacheInit(hUser, &hUtilCache, lpDS->UtilizationCache, Index1);
/* Determine Processing Mode: Add/Retrieval */
if (lpDS->ProcessingMode == _J('0'))
{
/* Add/Update Mode */
dsUtilCache.PayPeriodEndDate = lpDS->PayPeriodEndDate;
jdeStrncpy(dsUtilCache.MinorityCode, (const JCHAR *) (lpDS->MinorityCode),
DIM(dsUtilCache.MinorityCode)-1);
dsUtilCache.Sex = lpDS->Sex;
/* Determine whether the Cache has records */
if (jdeCacheGetNumRecords(hUtilCache) > (long) 0)
{
******* This is what does not work properly
/* Open Cursor - Point to first record in Cache */
jdeCacheCode = jdeCacheOpenCursor(hUtilCache, &hUtilCursor);
/* Attempt to Fetch Matching Record */
jdeCacheCode = jdeCacheFetchPosition(hUtilCache, hUtilCursor, (void *) &dsUtilCache,
1, (void *) &dsUtilCache, (long int) sizeof(dsUtilCache));
*******
if (jdeCacheCode == JDECM_FAILED)
{
/* Add Detail to Cache */
}
else
{
/* Update Cache */
jdeCacheCode = jdeCacheUpdate(hUtilCache, hUtilCursor, (void *) &dsUtilCache,
(long int) sizeof(dsUtilCache));
}
}
else
{
/* Add Detail to Cache */
jdeCacheCode = jdeCacheAdd(hUtilCache, (void *) &dsUtilCache, sizeof(dsUtilCache));
}
}
else if (lpDS->ProcessingMode == _J('1'))
{
/* Retrieval Mode */
}