dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

how to copy a cursor? check my code please? - berkeley-db

This is a discussion on how to copy a cursor? check my code please? - berkeley-db ; 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 ...


Home > Database Forum > Other Databases > berkeley-db > how to copy a cursor? check my code please?

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 02-02-2010, 06:19 PM
Database Newbie
 
Join Date: Feb 2010
Posts: 2
stefo666 is on a distinguished road
Default 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;
Reply With Quote
  #2  
Old 02-03-2010, 05:57 PM
Database Newbie
 
Join Date: Feb 2010
Posts: 2
stefo666 is on a distinguished road
Default 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...
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 09:47 AM.