How to get GetNext-requests to work on dynamic tables from DB
Kjersti Grønnevik
kgr____morecom.no
Fri Mar 22 15:59:04 CET 2002
Hi
I have problems with the getNext-request in my dynamic table I fetch up from DB every time I get a new request.
After every finished request I delete every row I have fetched from DB for that particularly request.
If I then get a new request of the type GetNext(oid.getNext...), I get the row of the oid before (like, get next oid in same row...)
and the next oid in the same row in the next collumn, which is wrong. What I want is to get the next row in the DB and from that row - the oid in the same collumn and the next row.
Are there any things I have overssen here? or some tricks I can add to my code?
Hope this is understandable and thanks so much for great help so far!
Best regards,
Kjersti
Here's some of my kode, maybe it will help to get my point clearer.
void lvAptEntry::update(Request* req, int subReqIndex)
{
start_synch();
currentSubReqIndex = subReqIndex;
update( req );
lastReqId = req->get_request_id();
end_synch();
}
void lvAptEntry::update(Request* req)
{
// clear table rows if this is a new request
unsigned long currentReqId = req->get_request_id();
if( lastReqId != currentReqId )
{
removeAllAPTEntries();
}
Oidx oid = req->get_oid( currentSubReqIndex );
Oidx oid_aptId = getPrimaryKeyAsOID( oid ); //fetch the index from the oid
MibTableRow* existingRow = find_index( oid_aptId );
if( existingRow == 0 )
{
//fetch row from db
long aptId = getPrimaryKeyAsLong( oid );
LVDatabase *db = LVDatabase::getInstance();
APTEntry aptEntry;
if(req->get_type() == 160)
{
aptEntry = db->getAPTEntry( aptId );
}
else if(req->get_type() == 161)
{
aptEntry = db->getNextAPTEntry( aptId );
}
addEntry( aptEntry, oid_aptId ); // add the row with the row data from db
}
}
Oidx lvAptEntry::find_succ(const Oidx& oid, Request* req)
{
/*Oidx oid_aptId = getPrimaryKeyAsOID( oid ); //fetch the index from the oid
MibTableRow* existingRow = find_index( oid_aptId );
if( existingRow == 0 )
{
long aptId = getPrimaryKeyAsLong( oid );
LVDatabase *db = LVDatabase::getInstance();
APTEntry nextAptEntry = db->getNextAPTEntry( aptId );
// add the row with the row data from db
addEntry( nextAptEntry, oid_aptId );
} */
MibLeaf* leaf = find_next( oid );
if( leaf )
return leaf->get_oid();
else
return Oidx();
}
void lvAptEntry::addEntry( APTEntry& entry, const Oidx& oid_aptId)
{
MibTableRow* newRow = add_row( oid_aptId );
LVDatabase *db = LVDatabase::getInstance();
set_row(
newRow,
(long)entry.getId(),
(char*)entry.getFriendlyName().c_str(),
.....
}
Oidx lvAptEntry::getPrimaryKeyAsOID( const Oidx& oid )
{
return oid.cut_left( 16 );//fetch the db primary key from the oid
}
long lvAptEntry::getPrimaryKeyAsLong( const Oidx& oid )
{
return oid.last();
}
void lvAptEntry::removeAllAPTEntries()
{
//remove old rows from MibTable
clear();
delete_rows.clearAll();
notready_rows.clearAll();
}
More information about the AGENTPP
mailing list