CacheGlobalOrder example to iterate over global and get data
I managed to use CacheGlobalOrder to iterate over global and return the next subscript:
int GetGlobalStr(char *global, int subscript, CACHE_EXSTRP result)
{
int push = CACHEPUSHGLOBAL(strlen(global), global);
int pushS = CACHEPUSHINT(subscript);
// narg Number of subscript expressions pushed onto the argument stack.
int narg = 1;
// Direction for the $Order is 1 for forward, -1 for reverse.
int dir = 1;
// Indicates whether the data value, if there is one, should be returned.
int valueflag = 0;
int order = CACHEGLOBALORDER(narg, dir, valueflag);
int pop = CACHEPOPEXSTR(result);
//pop = CACHEPOPEXSTR(result);
return ZF_SUCCESS;
}I'm using valueflag = 0. so data is not returned, only next subscript. However, it I set valueflag to 1 I don't receive global data or next subscript, only 1 or 0 depending on whenever next key exists.
Discussion (1)0
Comments
Working code:
int GetGlobalOrder(char *global, int start, int end, CACHE_EXSTRP result)
{
if (isInitialized == false) {
Initialize(NULL);
}
// narg Number of subscript expressions pushed onto the argument stack.
int narg = 1;
// Direction for the $Order is 1 for forward, -1 for reverse.
int dir = 1;
// Indicates whether the data value, if there is one, should be returned.
int valueflag = 1;
// Has argument flag
int flag = 0;
// key - current subscript
int key = start - 1;
// row count
int c=0;
while (key<end) {
CACHEPUSHGLOBAL(strlen(global), global);
CACHEPUSHINT(key);
CACHEGLOBALORDER(narg, dir, valueflag);
CACHEPOPINT(&flag);
if (flag) {
//use CACHETYPE() to get the value type, then the appropriate CACHEPOP for the subscript
CACHEEXSTRKILL(result);
CACHEPOPEXSTR(result);
// do stuff with result
}
//use CACHETYPE() to get the subscript type, then the appropriate CACHEPOP for the subscript
int type = CACHETYPE();
CACHEPOPINT(&key);
if (key==NULL) {
break;
}
c++;
}
return ZF_SUCCESS;
}Thanks to @Charles.SorensonIIfor help!