i starting use berkeleydb. wrote following method insert values database:
void put(int key, int value){ db *dbp; int ret; if((ret=db_create(&dbp,null,0))!=0){ fprintf(stderr,"db_create failed: %s\n",db_strerror(ret)); exit(1); } ret=dbp->open( dbp, null, "berkeley.db", null, db_btree, db_create, 0 ); dbt bin_key, bin_value; memset(&bin_key,0,sizeof(dbt)); memset(&bin_value,0,sizeof(dbt)); bin_key.data=&key; bin_value.data=&value; bin_key.size=sizeof(int); bin_value.size=sizeof(int); if((ret=dbp->put(dbp, null, &bin_key, &bin_value, db_nooverwrite))!=0){ printf("put failed"); }; return; } after calling put() method, no errors. dumping database tool dump_db berkeley.db gets database. has been created, still there no values in database.
any idea?
in case don't close database before exiting program, might want that, example, @ end of put() function:
if(dbp->close(dbp, 0)) != 0) { printf("close failed\n"); } it might data put database added cache , not written disk. in case function close() needs called in order flush data disk:
description
the
db->closefunction flushes cached database information disk, closes open cursors, frees allocated resources, , closes underlying files. because key/data pairs cached in memory, failing sync filedb->closeordb->syncfunction may result in inconsistent or lost information.
Comments
Post a Comment