get_array_info() can modifiy DBADDR::pfield

Allow the record support function get_array_info()
to modify its first argument to provide a different
pointer from which values should be read.

Remember the original and restore it afterwards.
This commit is contained in:
Michael Davidsaver
2013-01-23 10:38:30 -05:00
parent af2693241f
commit 4f6040d35b
2 changed files with 16 additions and 2 deletions

View File

@@ -780,6 +780,7 @@ long dbGet(DBADDR *paddr, short dbrType,
void *pbuffer, long *options, long *nRequest, void *pflin)
{
char *pbuf = pbuffer;
void *pfieldsave;
db_field_log *pfl = (db_field_log *)pflin;
short field_type;
long no_elements;
@@ -815,6 +816,13 @@ long dbGet(DBADDR *paddr, short dbrType,
return S_db_badDbrtype;
}
/* For array field, the rset function
* get_array_info() is allowed to modify
* paddr->pfield. So we store the original
* value and restore it later.
*/
pfieldsave = paddr->pfield;
/* check for array */
if ((!pfl || pfl->type == dbfl_type_rec) &&
paddr->special == SPC_DBADDR &&
@@ -860,7 +868,8 @@ long dbGet(DBADDR *paddr, short dbrType,
sprintf(message, "dbGet: Missing conversion for [%d][%d]\n",
field_type, dbrType);
recGblDbaddrError(S_db_badDbrtype, paddr, message);
return S_db_badDbrtype;
status = S_db_badDbrtype;
goto done;
}
/* convert database field and place it in the buffer */
if (n <= 0) {
@@ -880,6 +889,8 @@ long dbGet(DBADDR *paddr, short dbrType,
status = convert(&localAddr, pbuf, n, no_elements, offset);
}
}
done:
paddr->pfield = pfieldsave;
return status;
}

View File

@@ -104,7 +104,9 @@ static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
if (chan->addr.special == SPC_DBADDR &&
nSource > 1 &&
(prset = dbGetRset(&chan->addr)) &&
prset->get_array_info) {
prset->get_array_info)
{
void *pfieldsave = chan->addr.pfield;
prec = dbChannelRecord(chan);
dbScanLock(prec);
prset->get_array_info(&chan->addr, &nSource, &offset);
@@ -126,6 +128,7 @@ static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
pfl->u.r.field = pdst;
}
dbScanUnlock(prec);
chan->addr.pfield = pfieldsave;
}
/* Extract from buffer */