Commit ad0a6695 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

add Db::del and Db::get and check that their exceptions are OK. Fixes #219.

git-svn-id: file:///svn/tokudb@1335 c7de825b-a66e-492c-adef-691d508d4ae1
parent d2667c26
......@@ -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);
......
......@@ -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
......@@ -2,6 +2,7 @@
#include <db_cxx.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#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;
}
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment