dbTalk Databases Forums  

question about secondary database

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss question about secondary database in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joe
 
Posts: n/a

Default question about secondary database - 01-19-2006 , 05:44 AM






I have a question in using the secondary database.

For primary database

Db * my_database;

and the secondary database

Db * my_index;

There is always a mistake when I try to associate them but set the
primary database flast DB_DUP as

my_database->set_flags(DB_DUP);

what's the problem and how to solve it.

Sincerely,
Joe


Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: question about secondary database - 01-19-2006 , 06:45 AM






What is the error message you are getting? Make sure you have verbose
error messages turned on.
If you need info on how to turn on verbose error messages search in
this newsgroup or

http://www.sleepycat.com/docs/api_c/...t_errfile.html

If you still can't find the problem, post your code (that compiles
cleanly) here. A code
snippet (that compiles cleanly) will also work.

Ron


Reply With Quote
  #3  
Old   
Joe
 
Posts: n/a

Default Re: question about secondary database - 01-20-2006 , 12:06 AM



Dear Ron,

I post my codes as follows, and the error is that

testing.cpp: Primary databases may not be configured with duplicates

//----------------------------------------------------------------------------------------------------
#include "stdafx.h"

#define DATABASE_HOME ".\\database"
#define CONFIG_DATA_DIR ".\\files"

DbEnv * env = new DbEnv(0);
Db * db, * sdb;

int open_database();
int close_database();
int dewey_rep(Db *sdbp, const Dbt *pkey, const Dbt *pdata, Dbt *skey);

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
try
{
open_database();

close_database();
}
catch(DbException e)
{
cerr << e.what() << endl;
return e.get_errno();
}

return 0;
}

int open_database()
{
env->set_error_stream(&cerr);
env->set_errpfx("testing.cpp");

(void)env->set_data_dir(CONFIG_DATA_DIR);

env->open(DATABASE_HOME, DB_INIT_MPOOL, 0);

db = new Db(env, 0);
db->set_flags(DB_DUP);
db->open(0, "primary.db", NULL, DB_BTREE, DB_CREATE, 0);

sdb = new Db(env, 0);
sdb->set_flags(DB_DUPSORT);
sdb->open(0, "secondary.db", NULL, DB_BTREE, DB_CREATE, 0);

db->associate(NULL, sdb, dewey_rep, 0) );

return 0;
}

int close_database()
{
db->close(0);
sdb->close(0);
env->close(0);

return 0;
}

int
dewey_rep(Db *sdbp, // secondary db handle
const Dbt *pkey, // primary db record's key
const Dbt *pdata, // primary db record's data
Dbt *skey) // secondary db record's key
{
skey->set_data( pdata->get_data() );
skey->set_size( pdata->get_size() );

// Return 0 to indicate that the record can be created/updated.

return (0);
}

//----------------------------------------------------------------------------------------------------

Regards,
Joe


Reply With Quote
  #4  
Old   
clayne
 
Posts: n/a

Default Re: question about secondary database - 01-20-2006 , 01:01 AM



"Primary databases may not be configured with duplicates"

Is the problem.

Just what it says. You cannot associate a secondary database to a
primary database configured with DB_DUP or DB_DUPSORT. End of story.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.