diff --git a/cxx/db.cpp b/cxx/db.cpp index 468f6195434..53a1b9219ca 100644 --- a/cxx/db.cpp +++ b/cxx/db.cpp @@ -69,6 +69,16 @@ int Db::open(DbTxn *txn, const char *filename, const char *subname, DBTYPE typ, return the_Env->maybe_throw_error(ret); } +int Db::del(DbTxn *txn, Dbt *key, u_int32_t flags) { + int ret = the_db->del(the_db, txn->get_DB_TXN(), key->get_DBT(), flags); + return the_Env->maybe_throw_error(ret); +} + +int Db::get(DbTxn *txn, Dbt *key, Dbt *data, u_int32_t flags) { + int ret = the_db->get(the_db, txn->get_DB_TXN(), key->get_DBT(), data->get_DBT(), flags); + return the_Env->maybe_throw_error(ret); +} + int Db::put(DbTxn *txn, Dbt *key, Dbt *data, u_int32_t flags) { int ret = the_db->put(the_db, txn->get_DB_TXN(), key->get_DBT(), data->get_DBT(), flags); return the_Env->maybe_throw_error(ret); diff --git a/cxx/tests/Makefile b/cxx/tests/Makefile index 8f0b779d404..b6bd730df8d 100644 --- a/cxx/tests/Makefile +++ b/cxx/tests/Makefile @@ -29,3 +29,4 @@ check: $(TARGETS) diff foo.out foo.expectout $(VGRIND) ./db_dump_e foo.db > foo.out diff foo.out foo.expectout + $(VGRIND) ./exceptions diff --git a/cxx/tests/exceptions.cpp b/cxx/tests/exceptions.cpp index 89c6ccb1426..360d058eda1 100644 --- a/cxx/tests/exceptions.cpp +++ b/cxx/tests/exceptions.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define TC(expr, expect) ({ \ try { \ @@ -97,8 +98,8 @@ void test_db_exceptions (void) { curs->close(); // no deleting cursors. } Dbt key,val; - //TC(db.del(0, &key, -1), EINVAL); - //TC(db.get(0, &key, &val, -1), EINVAL); + TC(db.del(0, &key, -1), EINVAL); + TC(db.get(0, &key, &val, -1), EINVAL); TC(db.put(0, &key, &val, -1), EINVAL); } @@ -106,5 +107,6 @@ void test_db_exceptions (void) { int main(int argc, char *argv[]) { test_env_exceptions(); test_db_exceptions(); + system("rm *.tokulog"); return 0; } diff --git a/include/db_cxx.h b/include/db_cxx.h index 8adbe607039..d55c3f1bfae 100644 --- a/include/db_cxx.h +++ b/include/db_cxx.h @@ -97,10 +97,10 @@ class Db { /* C++ analogues of the C functions. */ int close(u_int32_t /*flags*/); - int cursor(DbTxn */*txnid*/, Dbc **/*cursorp*/, u_int32_t /*flags*/); - int del(DbTxn */*txnid*/, Dbt */*key*/, u_int32_t /*flags*/); - int get(DbTxn */*txnid*/, Dbt */*key*/, Dbt */*data*/, u_int32_t /*flags*/); - int open(DbTxn */*txnid*/, const char */*name*/, const char */*subname*/, DBTYPE, u_int32_t/*flags*/, int/*mode*/); + int cursor(DbTxn */*txn*/, Dbc **/*cursorp*/, u_int32_t /*flags*/); + int del(DbTxn */*txn*/, Dbt */*key*/, u_int32_t /*flags*/); + int get(DbTxn */*txn*/, Dbt */*key*/, Dbt */*data*/, u_int32_t /*flags*/); + int open(DbTxn */*txn*/, const char */*name*/, const char */*subname*/, DBTYPE, u_int32_t/*flags*/, int/*mode*/); int put(DbTxn *, Dbt *, Dbt *, u_int32_t); int get_flags(u_int32_t *); int set_flags(u_int32_t); diff --git a/src/ydb.c b/src/ydb.c index 0c7404d175f..a37e2701c58 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -891,6 +891,7 @@ static int toku_c_close(DBC * c) { static int toku_db_get_noassociate(DB * db, DB_TXN * txn, DBT * key, DBT * data, u_int32_t flags) { int r; unsigned int brtflags; + if (flags!=0 && flags!=DB_GET_BOTH) return EINVAL; toku_brt_get_flags(db->i->brt, &brtflags); if ((brtflags & TOKU_DB_DUPSORT) || flags == DB_GET_BOTH) { @@ -913,6 +914,7 @@ static int toku_db_get_noassociate(DB * db, DB_TXN * txn, DBT * key, DBT * data, static int toku_db_del_noassociate(DB * db, DB_TXN * txn, DBT * key, u_int32_t flags) { int r; + if (flags!=0 && flags!=DB_DELETE_ANY) return EINVAL; //DB_DELETE_ANY supresses the BDB DB->del return value indicating that the key was not found prior to the delete if (!(flags & DB_DELETE_ANY)) { DBT search_val; memset(&search_val, 0, sizeof search_val);