add truncate and sync

This commit is contained in:
danj 2006-04-24 18:21:01 +00:00
parent 593fbdeb54
commit fd1dfef645

37
bdb.c
View file

@ -560,6 +560,39 @@ VALUE db_rename(VALUE obj, VALUE vdisk_file,
return Qtrue; return Qtrue;
} }
VALUE db_sync(VALUE obj)
{
t_dbh *dbh;
int rv;
Data_Get_Struct(obj,t_dbh,dbh);
rv=dbh->db->sync(dbh->db,NOFLAGS);
if (rv)
raise_error(rv,"db_sync failed: %s",db_strerror(rv));
return Qtrue;
}
VALUE db_truncate(VALUE obj, VALUE vtxn)
{
t_dbh *dbh;
t_txnh *txn=NULL;
int rv;
VALUE result;
u_int32_t count;
if ( ! NIL_P(vtxn) )
Data_Get_Struct(vtxn,t_txnh,txn);
Data_Get_Struct(obj,t_dbh,dbh);
rv=dbh->db->truncate(dbh->db,txn?txn->txn:NULL,&count,NOFLAGS);
if (rv)
raise_error(rv,"db_truncate: %s",db_strerror(rv));
return INT2FIX(count);
}
VALUE db_key_range(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags) VALUE db_key_range(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags)
{ {
t_dbh *dbh; t_dbh *dbh;
@ -1570,6 +1603,10 @@ void Init_bdb2() {
rb_define_method(cDb,"stat",db_stat,2); rb_define_method(cDb,"stat",db_stat,2);
cDbStat = rb_define_class_under(cDb,"Stat",rb_cObject); cDbStat = rb_define_class_under(cDb,"Stat",rb_cObject);
rb_define_method(cDbStat,"[]",stat_aref,1); rb_define_method(cDbStat,"[]",stat_aref,1);
rb_define_method(cDb,"sync",db_sync,0);
rb_define_method(cDb,"truncate",db_truncate,1);
#if DB_VERSION_MINOR > 3 #if DB_VERSION_MINOR > 3
rb_define_method(cDb,"compact",db_compact,5); rb_define_method(cDb,"compact",db_compact,5);
#endif #endif