-
how to copy a cursor? check my code please?
The function below is supposed to accept a database and a read cursor, and create a write cursor pointing to the the same record. It is supposed to work for databases with duplicate keys allowed (a requirement - although the combination of key and data is guaranteed to be unique.)
It doesnt work. the write cursor get function always returns DB_NOTFOUND and I cant figure out why.
thanks for any help you can give.
Steve
int DBUtil::createWriteCursor(Db* database, Dbc* readCursor, Dbc** writeCursor)
{
int result;
*writeCursor = NULL;
Dbt key;
Dbt data;
memset((void*) &key, 0, sizeof(Dbt));
memset((void*) &data, 0, sizeof(Dbt));
// first get the key and data from the current cursor, which represents a unique combination
result = readCursor->get(&key, &data, DB_CURRENT);
if (result != 0)
return result;
try
{
// open the writecursor
database->cursor(NULL, writeCursor, DB_WRITECURSOR);
}
catch(DbException ex)
{
return -1;
}
// move the cursor to the position in the database that matches the combo
result = (*writeCursor)->get(&key, &data, DB_GET_BOTH);
if (result != 0)
(*writeCursor)->close();
// will return 0 on success, or DB_NOTFOUND if some other error
return result;
-
Re: how to copy a cursor? check my code please?
To put it another way - why does
cursor->get(key,data, DB_GET_BOTH)
return DB_NOT_FOUND? clearly in my code the key and data contain valid information because I just read it!
confused...