Another Cache Error

AlexRO

AlexRO

Well Known Member
Hello all,

I have a little trouble with a cache fetch. Here is my scenario:
I initialize the cache, I insert records in it, but when I try to fetch a position based on a index it fails to retrieve anything and I know the record is inserted because if I don't find any record I try to insert it and it fails also (unique index)
tongue.gif
. I'm attaching some source code for you all to diagnose.

Cache Initialization: <font color="green"> (works) </font>

Index->nNumSegments = 1;

Index->CacheKey[0].nOffset = offsetof(DSDQ480901, szCorrAccNumber1);
Index->CacheKey[0].nSize = DIM(dsCacheStruct.szCorrAccNumber1);
Index->CacheKey[0].idDataType = EVDT_STRING;

jdeCacheCode = jdeCacheInit (hUser, lphCache, lpDS->szCacheName, Index);

Cache write: <font color="green"> (works) </font>

jdeStrncpy(dsCacheStruct.szAccountId, (const JCHAR*)(lpDS->szAccountId), DIM(dsCacheStruct.szAccountId));
dsCacheStruct.mnDebitAmountField = (lpDS->mnDebitAmountField);
dsCacheStruct.mnCreditAmountField = (lpDS->mnCreditAmountField);
jdeStrncpy(dsCacheStruct.szCorrAccNumber1, (const JCHAR*)(lpDS->szCorrAccNumber1),DIM(dsCacheStruct.szCorrAccNumber1));

jdeCacheCode = jdeCacheAdd(hCache, (void*) &dsCacheStruct, sizeof(dsCacheStruct));


Cache Fetch: <font color="red"> (fails) </font>

jdeStrncpy(dsCacheKey.szCorrAccNumber1,lpDS->szCorrAccNumber1, DIM(dsCacheKey.szCorrAccNumber1));

jdeCacheCode = jdeCacheFetchPosition(hCache, hCursor,&dsCacheKey, (short) 1, &dsCacheStruct, sizeof(dsCacheStruct));

if (jdeCacheCode == JDECM_PASSED)
{
Cache write: <font color="red"> (fails) </font>
}

Alex.
 
Hello Craig,

Thank you for your quick answer. It is initialized just before the jdeCacheFetchPosition call.

nNumRecsInCache = jdeCacheGetNumRecords( hCache );

if (nNumRecsInCache > 0)
{

jdeCacheCode = jdeCacheOpenCursor(hCache, &hCursor);
if (jdeCacheCode == JDECM_PASSED)
{
jdeCacheCode = jdeCacheFetchPosition(...
...
}
}

Alex.
 
Since you dont show it in your code listing, check to make sure that both szCacheStruct and dsCacheKey are declared as DSDQ480901.

You also need to set Index.nKeyID = 1

Also, not that this is the problem just as a general rule, jdeStrncpy s/b
jdeStrncpy(dest,src,DIM(dest)-1)
not
jdeStrncpy(dest,src,DIM(dest))
 
Wow.

Thank you BOster. Your advice did the job. The cache Key was a wrong type. Now the function works. Thanx for the advices.

Cheers,
Alex.
 
Back
Top